Commit 9df34942 authored by mae's avatar mae
Browse files

more stuff works, but this requires more refactoring

parent 624df3c8
...@@ -128,6 +128,7 @@ const char * const ZOOM_WINDOW = "QtCreator.ZoomWindow"; ...@@ -128,6 +128,7 @@ const char * const ZOOM_WINDOW = "QtCreator.ZoomWindow";
const char * const SPLIT = "QtCreator.Split"; const char * const SPLIT = "QtCreator.Split";
const char * const SPLIT_SIDE_BY_SIDE = "QtCreator.SplitSideBySide"; const char * const SPLIT_SIDE_BY_SIDE = "QtCreator.SplitSideBySide";
const char * const UNSPLIT = "QtCreator.Unsplit"; const char * const UNSPLIT = "QtCreator.Unsplit";
const char * const GOTO_OTHER_WINDOW = "QtCreator.GotoOtherWindow";
const char * const SAVEASDEFAULT = "QtCreator.SaveAsDefaultLayout"; const char * const SAVEASDEFAULT = "QtCreator.SaveAsDefaultLayout";
const char * const RESTOREDEFAULT = "QtCreator.RestoreDefaultLayout"; const char * const RESTOREDEFAULT = "QtCreator.RestoreDefaultLayout";
const char * const CLOSE = "QtCreator.Close"; const char * const CLOSE = "QtCreator.Close";
......
...@@ -159,6 +159,7 @@ struct EditorManagerPrivate { ...@@ -159,6 +159,7 @@ struct EditorManagerPrivate {
QAction *m_splitAction; QAction *m_splitAction;
QAction *m_splitSideBySideAction; QAction *m_splitSideBySideAction;
QAction *m_unsplitAction; QAction *m_unsplitAction;
QAction *m_gotoOtherWindowAction;
QList<IEditor *> m_editorHistory; QList<IEditor *> m_editorHistory;
QList<EditLocation *> m_navigationHistory; QList<EditLocation *> m_navigationHistory;
...@@ -352,6 +353,11 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) : ...@@ -352,6 +353,11 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_unsplitAction, SIGNAL(triggered()), this, SLOT(unsplit())); connect(m_d->m_unsplitAction, SIGNAL(triggered()), this, SLOT(unsplit()));
m_d->m_gotoOtherWindowAction = new QAction(tr("Goto other window"), this);
cmd = am->registerAction(m_d->m_gotoOtherWindowAction, Constants::GOTO_OTHER_WINDOW, editManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,o")));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_gotoOtherWindowAction, SIGNAL(triggered()), this, SLOT(gotoOtherWindow()));
ActionContainer *medit = am->actionContainer(Constants::M_EDIT); ActionContainer *medit = am->actionContainer(Constants::M_EDIT);
...@@ -384,8 +390,6 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) : ...@@ -384,8 +390,6 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
this, SLOT(updateEditorHistory())); this, SLOT(updateEditorHistory()));
m_d->m_view = new EditorView(m_d->m_editorModel, this); m_d->m_view = new EditorView(m_d->m_editorModel, this);
m_d->m_splitter = new SplitterOrView(m_d->m_view); m_d->m_splitter = new SplitterOrView(m_d->m_view);
connect(m_d->m_view, SIGNAL(closeRequested(Core::IEditor *)),
this, SLOT(closeEditor(Core::IEditor *)));
m_d->m_stackedLayout = new QStackedLayout(this); m_d->m_stackedLayout = new QStackedLayout(this);
m_d->m_stackedLayout->addWidget(m_d->m_splitter); m_d->m_stackedLayout->addWidget(m_d->m_splitter);
...@@ -489,6 +493,13 @@ void EditorManager::updateCurrentEditorAndGroup(IContext *context) ...@@ -489,6 +493,13 @@ void EditorManager::updateCurrentEditorAndGroup(IContext *context)
qDebug() << "leaving method" << Q_FUNC_INFO; qDebug() << "leaving method" << Q_FUNC_INFO;
} }
IEditor *EditorManager::activateEditor(IEditor *editor, bool ignoreNavigationHistory)
{
if (m_d->m_suppressEditorChanges)
return editor;
return activateEditor(m_d->m_splitter->findView(m_d->m_currentEditor)->view(), editor, ignoreNavigationHistory);
}
void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory) void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory)
{ {
if (debugEditorManager) if (debugEditorManager)
...@@ -499,13 +510,19 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto ...@@ -499,13 +510,19 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto
return; return;
m_d->m_currentEditor = editor; m_d->m_currentEditor = editor;
if (editor) { if (editor) {
qDebug() << "EditorManager::setCurrentEditor" << editor << editor->file()->fileName();
bool addToHistory = (!ignoreNavigationHistory && editor != currentEditor()); bool addToHistory = (!ignoreNavigationHistory && editor != currentEditor());
if (debugEditorManager) if (debugEditorManager)
qDebug() << Q_FUNC_INFO << (addToHistory ? "adding to history" : "not adding to history"); qDebug() << Q_FUNC_INFO << (addToHistory ? "adding to history" : "not adding to history");
if (addToHistory) if (addToHistory)
addCurrentPositionToNavigationHistory(true); addCurrentPositionToNavigationHistory(true);
m_d->m_suppressEditorChanges = true; m_d->m_suppressEditorChanges = true;
m_d->m_view->setCurrentEditor(editor);
EditorView *view = m_d->m_splitter->findView(editor)->view();
if (view == m_d->m_view && m_d->m_splitter)
unsplitAll();
view->setCurrentEditor(editor);
m_d->m_suppressEditorChanges = false; m_d->m_suppressEditorChanges = false;
if (addToHistory) if (addToHistory)
addCurrentPositionToNavigationHistory(); addCurrentPositionToNavigationHistory();
...@@ -545,26 +562,23 @@ void EditorManager::closeEditor() ...@@ -545,26 +562,23 @@ void EditorManager::closeEditor()
QTimer::singleShot(0, this, SLOT(closeEditor())); QTimer::singleShot(0, this, SLOT(closeEditor()));
postpone = false; postpone = false;
} else { } else {
closeEditor(currentEditor()); closeEditor(m_d->m_splitter->findView(m_d->m_currentEditor)->view(), m_d->m_currentEditor);
postpone = true; postpone = true;
} }
} }
void EditorManager::closeEditor(IEditor *editor) void EditorManager::closeEditor(Core::Internal::EditorView *view, Core::IEditor *editor)
{ {
if (!editor) if (!editor || !view)
editor = currentEditor();
if (!editor)
return; return;
qDebug() << "EditorManager::closeEditor"; Q_ASSERT(view->hasEditor(editor));
if (m_d->m_view->hasEditor(editor)) { if (view == m_d->m_view) {
qDebug() << "it's a main editor, do unsplit";
unsplitAll();
closeEditors(QList<IEditor *>() << editor); closeEditors(QList<IEditor *>() << editor);
} else { } else {
// ### TODO close duplicate editor view->removeEditor(editor);
closeDuplicate(editor, true);
} }
...@@ -688,12 +702,14 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA ...@@ -688,12 +702,14 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
void EditorManager::closeDuplicate(Core::IEditor *editor, bool doDelete) void EditorManager::closeDuplicate(Core::IEditor *editor, bool doDelete)
{ {
m_d->m_editorHistory.removeAll(editor);
emit editorAboutToClose(editor); emit editorAboutToClose(editor);
emit editorsClosed(QList<Core::IEditor *>() << editor);
if (doDelete) if (doDelete)
delete editor; delete editor;
} }
void EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor) Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, bool ignoreNavigationHistory)
{ {
Q_ASSERT(view && editor); Q_ASSERT(view && editor);
Q_ASSERT(m_d->m_view->hasEditor(editor)); Q_ASSERT(m_d->m_view->hasEditor(editor));
...@@ -705,18 +721,17 @@ void EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEdit ...@@ -705,18 +721,17 @@ void EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEdit
if (view == m_d->m_view || view->hasEditor(editor)) { if (view == m_d->m_view || view->hasEditor(editor)) {
view->setCurrentEditor(editor); view->setCurrentEditor(editor);
return; return editor;
} }
QList<IEditor*> editors = view->editors(); QList<IEditor*> editors = view->editors();
IEditor *duplicate = duplicateEditor(editor); IEditor *duplicate = duplicateEditor(editor);
view->addEditor(duplicate); view->addEditor(duplicate);
view->setCurrentEditor(duplicate); view->setCurrentEditor(duplicate, ignoreNavigationHistory);
foreach(IEditor *e, editors) { foreach(IEditor *e, editors) {
view->removeEditor(e); view->removeEditor(e);
closeDuplicate(e, true); closeDuplicate(e, true);
} }
return duplicate;
} }
/* Find editors for a mimetype, best matching at the front /* Find editors for a mimetype, best matching at the front
...@@ -808,14 +823,13 @@ IEditor *EditorManager::createEditor(const QString &editorKind, ...@@ -808,14 +823,13 @@ IEditor *EditorManager::createEditor(const QString &editorKind,
} }
void EditorManager::insertEditor(IEditor *editor, void EditorManager::insertEditor(IEditor *editor,
bool ignoreNavigationHistory) bool /*ignoreNavigationHistory*/)
{ {
if (!editor) if (!editor)
return; return;
m_d->m_core->addContextObject(editor); m_d->m_core->addContextObject(editor);
registerEditor(editor); registerEditor(editor);
m_d->m_view->addEditor(editor); m_d->m_view->addEditor(editor);
setCurrentEditor(editor, ignoreNavigationHistory);
emit editorOpened(editor); emit editorOpened(editor);
} }
...@@ -892,8 +906,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito ...@@ -892,8 +906,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito
const QList<IEditor *> editors = editorsForFileName(fileName); const QList<IEditor *> editors = editorsForFileName(fileName);
if (!editors.isEmpty()) { if (!editors.isEmpty()) {
setCurrentEditor(editors.first(), ignoreNavigationHistory); return activateEditor(m_d->m_splitter->findView(m_d->m_currentEditor)->view(), editors.first(), ignoreNavigationHistory);
return editors.first();
} }
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
IEditor *editor = createEditor(editorKind, fileName); IEditor *editor = createEditor(editorKind, fileName);
...@@ -908,8 +921,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito ...@@ -908,8 +921,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito
restoreEditorState(editor); restoreEditorState(editor);
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
ensureEditorManagerVisible(); ensureEditorManagerVisible();
setCurrentEditor(editor); return activateEditor(editor, ignoreNavigationHistory);
return editor;
} }
QStringList EditorManager::getOpenFileNames() const QStringList EditorManager::getOpenFileNames() const
...@@ -1138,17 +1150,25 @@ bool EditorManager::saveFileAs(IEditor *editor) ...@@ -1138,17 +1150,25 @@ bool EditorManager::saveFileAs(IEditor *editor)
void EditorManager::gotoNextDocHistory() void EditorManager::gotoNextDocHistory()
{ {
OpenEditorsWindow *dialog = windowPopup(); OpenEditorsWindow *dialog = windowPopup();
dialog->setMode(OpenEditorsWindow::HistoryMode); if (dialog->isVisible()) {
dialog->selectNextEditor(); dialog->selectNextEditor();
showWindowPopup(); } else {
dialog->setEditors(m_d->m_editorHistory, m_d->m_currentEditor);
dialog->selectNextEditor();
showWindowPopup();
}
} }
void EditorManager::gotoPreviousDocHistory() void EditorManager::gotoPreviousDocHistory()
{ {
OpenEditorsWindow *dialog = windowPopup(); OpenEditorsWindow *dialog = windowPopup();
dialog->setMode(OpenEditorsWindow::HistoryMode); if (dialog->isVisible()) {
dialog->selectPreviousEditor(); dialog->selectPreviousEditor();
showWindowPopup(); } else {
dialog->setEditors(m_d->m_editorHistory, m_d->m_currentEditor);
dialog->selectPreviousEditor();
showWindowPopup();
}
} }
void EditorManager::makeCurrentEditorWritable() void EditorManager::makeCurrentEditorWritable()
...@@ -1560,19 +1580,33 @@ Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor) ...@@ -1560,19 +1580,33 @@ Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
return duplicate; return duplicate;
} }
void EditorManager::split(Qt::Orientation orientation)
{
SplitterOrView *view = m_d->m_currentEditor ? m_d->m_splitter->findView(m_d->m_currentEditor)
: m_d->m_splitter->findFirstView();
if (!view) {
view = m_d->m_splitter;
view->unsplit(0);
}
view->split(orientation);
}
void EditorManager::split() void EditorManager::split()
{ {
m_d->m_splitter->split(Qt::Vertical); split(Qt::Vertical);
} }
void EditorManager::splitSideBySide() void EditorManager::splitSideBySide()
{ {
m_d->m_splitter->split(Qt::Horizontal); split(Qt::Horizontal);
} }
void EditorManager::unsplit() void EditorManager::unsplit()
{ {
unsplitAll(); // ### TODO qDebug() << "unsplit" << (m_d->m_currentEditor ? m_d->m_currentEditor->file()->fileName() : QString("no current editor"));
SplitterOrView *splitter = m_d->m_currentEditor ? m_d->m_splitter->findSplitter(m_d->m_currentEditor) : m_d->m_splitter;
qDebug() << "splitter" << splitter;
if (splitter)
splitter->unsplit(m_d->m_currentEditor);
} }
void EditorManager::unsplitAll() void EditorManager::unsplitAll()
...@@ -1582,6 +1616,26 @@ void EditorManager::unsplitAll() ...@@ -1582,6 +1616,26 @@ void EditorManager::unsplitAll()
setCurrentEditor(e); setCurrentEditor(e);
} }
void EditorManager::gotoOtherWindow()
{
qDebug() << "gotoOtherWindow";
if (!m_d->m_currentEditor)
return;
qDebug() << "current editor" << m_d->m_currentEditor->file()->fileName();
if (m_d->m_splitter->isSplitter()) {
qDebug() << "we have a splitter";
SplitterOrView *view = m_d->m_splitter->findNextView(m_d->m_currentEditor);
qDebug() << "next view is" << view;
if (!view)
view = m_d->m_splitter->findFirstView();
if (view) {
if (IEditor *editor = view->editor()) {
qDebug() << "set new current editor to" << editor->file()->fileName();
view->view()->setCurrentEditor(editor);
}
}
}
}
//===================EditorClosingCoreListener====================== //===================EditorClosingCoreListener======================
EditorClosingCoreListener::EditorClosingCoreListener(EditorManager *em) EditorClosingCoreListener::EditorClosingCoreListener(EditorManager *em)
......
...@@ -118,6 +118,7 @@ public: ...@@ -118,6 +118,7 @@ public:
void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false); void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
IEditor *currentEditor() const; IEditor *currentEditor() const;
IEditor *activateEditor(IEditor *editor, bool ignoreNavigationHistory = false);
// EditorGroup *currentEditorGroup() const; // EditorGroup *currentEditorGroup() const;
QList<IEditor*> openedEditors() const; QList<IEditor*> openedEditors() const;
...@@ -189,7 +190,6 @@ private slots: ...@@ -189,7 +190,6 @@ private slots:
bool saveFile(Core::IEditor *editor = 0); bool saveFile(Core::IEditor *editor = 0);
bool saveFileAs(Core::IEditor *editor = 0); bool saveFileAs(Core::IEditor *editor = 0);
void closeEditor(); void closeEditor();
void closeEditor(Core::IEditor *editor);
void gotoNextDocHistory(); void gotoNextDocHistory();
void gotoPreviousDocHistory(); void gotoPreviousDocHistory();
...@@ -200,10 +200,12 @@ private slots: ...@@ -200,10 +200,12 @@ private slots:
void goBackInNavigationHistory(); void goBackInNavigationHistory();
void goForwardInNavigationHistory(); void goForwardInNavigationHistory();
void makeCurrentEditorWritable(); void makeCurrentEditorWritable();
void split(Qt::Orientation orientation);
void split(); void split();
void splitSideBySide(); void splitSideBySide();
void unsplit(); void unsplit();
void unsplitAll(); void unsplitAll();
void gotoOtherWindow();
private: private:
QList<IFile *> filesForEditors(QList<IEditor *> editors) const; QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
...@@ -218,7 +220,8 @@ private: ...@@ -218,7 +220,8 @@ private:
Core::IEditor *duplicateEditor(IEditor *editor); Core::IEditor *duplicateEditor(IEditor *editor);
void closeDuplicate(Core::IEditor *editor, bool doDelete); void closeDuplicate(Core::IEditor *editor, bool doDelete);
void activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor); Core::IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, bool ignoreNavigationHistory = false);
void closeEditor(Core::Internal::EditorView *view, Core::IEditor *editor);
static EditorManager *m_instance; static EditorManager *m_instance;
EditorManagerPrivate *m_d; EditorManagerPrivate *m_d;
......
...@@ -335,8 +335,9 @@ void EditorView::insertEditor(int index, IEditor *editor) ...@@ -335,8 +335,9 @@ void EditorView::insertEditor(int index, IEditor *editor)
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
if (m_container->count() == 1) { if (m_container->count() == 1) {
updateToolBar(editor); m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row());
updateEditorStatus(editor); updateEditorStatus(editor);
updateToolBar(editor);
} }
} }
...@@ -347,7 +348,8 @@ bool EditorView::hasEditor(IEditor *editor) const ...@@ -347,7 +348,8 @@ bool EditorView::hasEditor(IEditor *editor) const
void EditorView::sendCloseRequest() void EditorView::sendCloseRequest()
{ {
emit closeRequested(currentEditor()); EditorManager *em = CoreImpl::instance()->editorManager();
em->closeEditor(this, currentEditor());
} }
void EditorView::removeEditor(IEditor *editor) void EditorView::removeEditor(IEditor *editor)
...@@ -379,19 +381,18 @@ IEditor *EditorView::currentEditor() const ...@@ -379,19 +381,18 @@ IEditor *EditorView::currentEditor() const
return 0; return 0;
} }
void EditorView::setCurrentEditor(IEditor *editor) void EditorView::setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory)
{ {
if (!editor || m_container->count() <= 0 if (!editor || m_container->count() <= 0
|| m_container->indexOf(editor->widget()) == -1) || m_container->indexOf(editor->widget()) == -1)
return; return;
if (editor) if (editor)
qDebug() << "EditorView::setCurrentEditor" << editor->file()->fileName(); qDebug() << "EditorView::setCurrentEditor" << editor->file()->fileName();
const int idx = m_container->indexOf(editor->widget()); const int idx = m_container->indexOf(editor->widget());
QTC_ASSERT(idx >= 0, return); QTC_ASSERT(idx >= 0, return);
if (m_container->currentIndex() != idx) { m_container->setCurrentIndex(idx);
m_container->setCurrentIndex(idx); m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row());
m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row());
}
setEditorFocus(idx); setEditorFocus(idx);
updateEditorStatus(editor); updateEditorStatus(editor);
updateToolBar(editor); updateToolBar(editor);
...@@ -401,6 +402,9 @@ void EditorView::setCurrentEditor(IEditor *editor) ...@@ -401,6 +402,9 @@ void EditorView::setCurrentEditor(IEditor *editor)
m_infoWidget->hide(); m_infoWidget->hide();
m_editorForInfoWidget = 0; m_editorForInfoWidget = 0;
} }
EditorManager *em = CoreImpl::instance()->editorManager();
if (em->currentEditor() != editor)
em->setCurrentEditor(editor, ignoreNavigationHistory);
} }
void EditorView::checkEditorStatus() void EditorView::checkEditorStatus()
...@@ -490,9 +494,23 @@ SplitterOrView::SplitterOrView(Core::IEditor *editor, QWidget *parent) ...@@ -490,9 +494,23 @@ SplitterOrView::SplitterOrView(Core::IEditor *editor, QWidget *parent)
m_layout->addWidget(m_view); m_layout->addWidget(m_view);
} }
SplitterOrView *SplitterOrView::findFirstView()
{
if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i)))
if (SplitterOrView *result = splitterOrView->findFirstView())
return result;
}
return 0;
}
return this;
}
SplitterOrView *SplitterOrView::findView(Core::IEditor *editor) SplitterOrView *SplitterOrView::findView(Core::IEditor *editor)
{ {
if (hasEditor(editor)) if (!editor || hasEditor(editor))
return this; return this;
if (m_splitter) { if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) { for (int i = 0; i < m_splitter->count(); ++i) {
...@@ -519,6 +537,37 @@ SplitterOrView *SplitterOrView::findSplitter(Core::IEditor *editor) ...@@ -519,6 +537,37 @@ SplitterOrView *SplitterOrView::findSplitter(Core::IEditor *editor)
return 0; return 0;
} }
SplitterOrView *SplitterOrView::findNextView(Core::IEditor *editor)
{
bool found = false;
return findNextView_helper(editor, &found);
}
SplitterOrView *SplitterOrView::findNextView_helper(Core::IEditor *editor, bool *found)
{
qDebug() << "check view " << this << "view" << m_view << "splitter" << m_splitter << "found" << *found;
if (*found && m_view) {
qDebug() << "found next!";
return this;
}
if (hasEditor(editor)) {
qDebug() << "found editor";
*found = true;
return 0;
}
if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
if (SplitterOrView *result = splitterOrView->findNextView_helper(editor, found))
return result;
}
}