diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index c16838fb049f36a5578be45055d9f4a492171325..b0066c9b7880813dfd3a1a4ca076f5521e83ad81 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -128,6 +128,7 @@ const char * const ZOOM_WINDOW = "QtCreator.ZoomWindow"; const char * const SPLIT = "QtCreator.Split"; const char * const SPLIT_SIDE_BY_SIDE = "QtCreator.SplitSideBySide"; const char * const UNSPLIT = "QtCreator.Unsplit"; +const char * const GOTO_OTHER_WINDOW = "QtCreator.GotoOtherWindow"; const char * const SAVEASDEFAULT = "QtCreator.SaveAsDefaultLayout"; const char * const RESTOREDEFAULT = "QtCreator.RestoreDefaultLayout"; const char * const CLOSE = "QtCreator.Close"; diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index bbbf0fdaed089fe70186832fee496ef35eb8d4cc..7792f8ee383d7b21b17b5f06ee150ca1acae5d7b 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -159,6 +159,7 @@ struct EditorManagerPrivate { QAction *m_splitAction; QAction *m_splitSideBySideAction; QAction *m_unsplitAction; + QAction *m_gotoOtherWindowAction; QList<IEditor *> m_editorHistory; QList<EditLocation *> m_navigationHistory; @@ -352,6 +353,11 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) : mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); 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); @@ -384,8 +390,6 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) : this, SLOT(updateEditorHistory())); m_d->m_view = new EditorView(m_d->m_editorModel, this); 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->addWidget(m_d->m_splitter); @@ -489,6 +493,13 @@ void EditorManager::updateCurrentEditorAndGroup(IContext *context) 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) { if (debugEditorManager) @@ -499,13 +510,19 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto return; m_d->m_currentEditor = editor; if (editor) { + qDebug() << "EditorManager::setCurrentEditor" << editor << editor->file()->fileName(); bool addToHistory = (!ignoreNavigationHistory && editor != currentEditor()); if (debugEditorManager) qDebug() << Q_FUNC_INFO << (addToHistory ? "adding to history" : "not adding to history"); if (addToHistory) addCurrentPositionToNavigationHistory(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; if (addToHistory) addCurrentPositionToNavigationHistory(); @@ -545,26 +562,23 @@ void EditorManager::closeEditor() QTimer::singleShot(0, this, SLOT(closeEditor())); postpone = false; } else { - closeEditor(currentEditor()); + closeEditor(m_d->m_splitter->findView(m_d->m_currentEditor)->view(), m_d->m_currentEditor); postpone = true; } } -void EditorManager::closeEditor(IEditor *editor) +void EditorManager::closeEditor(Core::Internal::EditorView *view, Core::IEditor *editor) { - if (!editor) - editor = currentEditor(); - if (!editor) + if (!editor || !view) return; - qDebug() << "EditorManager::closeEditor"; - if (m_d->m_view->hasEditor(editor)) { - qDebug() << "it's a main editor, do unsplit"; - unsplitAll(); + Q_ASSERT(view->hasEditor(editor)); + if (view == m_d->m_view) { closeEditors(QList<IEditor *>() << editor); } else { - // ### TODO close duplicate editor + view->removeEditor(editor); + closeDuplicate(editor, true); } @@ -688,12 +702,14 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA void EditorManager::closeDuplicate(Core::IEditor *editor, bool doDelete) { + m_d->m_editorHistory.removeAll(editor); emit editorAboutToClose(editor); + emit editorsClosed(QList<Core::IEditor *>() << editor); if (doDelete) 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(m_d->m_view->hasEditor(editor)); @@ -705,18 +721,17 @@ void EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEdit if (view == m_d->m_view || view->hasEditor(editor)) { view->setCurrentEditor(editor); - return; + return editor; } QList<IEditor*> editors = view->editors(); IEditor *duplicate = duplicateEditor(editor); view->addEditor(duplicate); - view->setCurrentEditor(duplicate); + view->setCurrentEditor(duplicate, ignoreNavigationHistory); foreach(IEditor *e, editors) { view->removeEditor(e); closeDuplicate(e, true); } - - + return duplicate; } /* Find editors for a mimetype, best matching at the front @@ -808,14 +823,13 @@ IEditor *EditorManager::createEditor(const QString &editorKind, } void EditorManager::insertEditor(IEditor *editor, - bool ignoreNavigationHistory) + bool /*ignoreNavigationHistory*/) { if (!editor) return; m_d->m_core->addContextObject(editor); registerEditor(editor); m_d->m_view->addEditor(editor); - setCurrentEditor(editor, ignoreNavigationHistory); emit editorOpened(editor); } @@ -892,8 +906,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito const QList<IEditor *> editors = editorsForFileName(fileName); if (!editors.isEmpty()) { - setCurrentEditor(editors.first(), ignoreNavigationHistory); - return editors.first(); + return activateEditor(m_d->m_splitter->findView(m_d->m_currentEditor)->view(), editors.first(), ignoreNavigationHistory); } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); IEditor *editor = createEditor(editorKind, fileName); @@ -908,8 +921,7 @@ IEditor *EditorManager::openEditor(const QString &fileName, const QString &edito restoreEditorState(editor); QApplication::restoreOverrideCursor(); ensureEditorManagerVisible(); - setCurrentEditor(editor); - return editor; + return activateEditor(editor, ignoreNavigationHistory); } QStringList EditorManager::getOpenFileNames() const @@ -1138,17 +1150,25 @@ bool EditorManager::saveFileAs(IEditor *editor) void EditorManager::gotoNextDocHistory() { OpenEditorsWindow *dialog = windowPopup(); - dialog->setMode(OpenEditorsWindow::HistoryMode); - dialog->selectNextEditor(); - showWindowPopup(); + if (dialog->isVisible()) { + dialog->selectNextEditor(); + } else { + dialog->setEditors(m_d->m_editorHistory, m_d->m_currentEditor); + dialog->selectNextEditor(); + showWindowPopup(); + } } void EditorManager::gotoPreviousDocHistory() { OpenEditorsWindow *dialog = windowPopup(); - dialog->setMode(OpenEditorsWindow::HistoryMode); - dialog->selectPreviousEditor(); - showWindowPopup(); + if (dialog->isVisible()) { + dialog->selectPreviousEditor(); + } else { + dialog->setEditors(m_d->m_editorHistory, m_d->m_currentEditor); + dialog->selectPreviousEditor(); + showWindowPopup(); + } } void EditorManager::makeCurrentEditorWritable() @@ -1560,19 +1580,33 @@ Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor) 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() { - m_d->m_splitter->split(Qt::Vertical); + split(Qt::Vertical); } void EditorManager::splitSideBySide() { - m_d->m_splitter->split(Qt::Horizontal); + split(Qt::Horizontal); } 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() @@ -1582,6 +1616,26 @@ void EditorManager::unsplitAll() 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(EditorManager *em) diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index bb3cd7bd691e6e3848b59349d403b51008213601..36448d44a333ce6c3254ab2776a4af58bf5f1f7c 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -118,6 +118,7 @@ public: void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false); IEditor *currentEditor() const; + IEditor *activateEditor(IEditor *editor, bool ignoreNavigationHistory = false); // EditorGroup *currentEditorGroup() const; QList<IEditor*> openedEditors() const; @@ -189,7 +190,6 @@ private slots: bool saveFile(Core::IEditor *editor = 0); bool saveFileAs(Core::IEditor *editor = 0); void closeEditor(); - void closeEditor(Core::IEditor *editor); void gotoNextDocHistory(); void gotoPreviousDocHistory(); @@ -200,10 +200,12 @@ private slots: void goBackInNavigationHistory(); void goForwardInNavigationHistory(); void makeCurrentEditorWritable(); + void split(Qt::Orientation orientation); void split(); void splitSideBySide(); void unsplit(); void unsplitAll(); + void gotoOtherWindow(); private: QList<IFile *> filesForEditors(QList<IEditor *> editors) const; @@ -218,7 +220,8 @@ private: Core::IEditor *duplicateEditor(IEditor *editor); 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; EditorManagerPrivate *m_d; diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 10db489707e2d9819036053c0c01b83f3d9c3dbe..3d0ffb0724e001b4fd658d1231542fa8bb94842f 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -335,8 +335,9 @@ void EditorView::insertEditor(int index, IEditor *editor) connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); if (m_container->count() == 1) { - updateToolBar(editor); + m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row()); updateEditorStatus(editor); + updateToolBar(editor); } } @@ -347,7 +348,8 @@ bool EditorView::hasEditor(IEditor *editor) const void EditorView::sendCloseRequest() { - emit closeRequested(currentEditor()); + EditorManager *em = CoreImpl::instance()->editorManager(); + em->closeEditor(this, currentEditor()); } void EditorView::removeEditor(IEditor *editor) @@ -379,19 +381,18 @@ IEditor *EditorView::currentEditor() const return 0; } -void EditorView::setCurrentEditor(IEditor *editor) +void EditorView::setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory) { if (!editor || m_container->count() <= 0 || m_container->indexOf(editor->widget()) == -1) return; if (editor) qDebug() << "EditorView::setCurrentEditor" << editor->file()->fileName(); + const int idx = m_container->indexOf(editor->widget()); QTC_ASSERT(idx >= 0, return); - if (m_container->currentIndex() != idx) { - m_container->setCurrentIndex(idx); - m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row()); - } + m_container->setCurrentIndex(idx); + m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row()); setEditorFocus(idx); updateEditorStatus(editor); updateToolBar(editor); @@ -401,6 +402,9 @@ void EditorView::setCurrentEditor(IEditor *editor) m_infoWidget->hide(); m_editorForInfoWidget = 0; } + EditorManager *em = CoreImpl::instance()->editorManager(); + if (em->currentEditor() != editor) + em->setCurrentEditor(editor, ignoreNavigationHistory); } void EditorView::checkEditorStatus() @@ -490,9 +494,23 @@ SplitterOrView::SplitterOrView(Core::IEditor *editor, QWidget *parent) 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) { - if (hasEditor(editor)) + if (!editor || hasEditor(editor)) return this; if (m_splitter) { for (int i = 0; i < m_splitter->count(); ++i) { @@ -519,6 +537,37 @@ SplitterOrView *SplitterOrView::findSplitter(Core::IEditor *editor) 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; + } + } + } + return 0; +} + void SplitterOrView::split(Qt::Orientation orientation) { Q_ASSERT(m_view && m_splitter == 0); @@ -526,14 +575,14 @@ void SplitterOrView::split(Qt::Orientation orientation) m_splitter->setOrientation(orientation); Core::IEditor *e = m_view->currentEditor(); - Core::IEditor *focus = e; + SplitterOrView *focusView = 0; + if (m_isRoot) { Core::IEditor *duplicateA = CoreImpl::instance()->editorManager()->duplicateEditor(e); - m_splitter->addWidget(new SplitterOrView(duplicateA)); - focus = duplicateA; + m_splitter->addWidget((focusView = new SplitterOrView(duplicateA))); } else { m_view->removeEditor(e); - m_splitter->addWidget(new SplitterOrView(e)); + m_splitter->addWidget((focusView = new SplitterOrView(e))); Q_ASSERT(m_view->currentEditor() == 0); } Core::IEditor *duplicate = CoreImpl::instance()->editorManager()->duplicateEditor(e); @@ -547,7 +596,7 @@ void SplitterOrView::split(Qt::Orientation orientation) m_layout->setCurrentWidget(m_splitter); } - focus->widget()->setFocus(); + focusView->view()->setCurrentEditor(focusView->editor()); } void SplitterOrView::close() @@ -576,8 +625,8 @@ void SplitterOrView::unsplit(Core::IEditor *editor) if (!m_isRoot) { m_view = new EditorView(CoreImpl::instance()->editorManager()->openedEditorsModel()); m_view->addEditor(editor); - m_view->setCurrentEditor(editor); m_layout->addWidget(m_view); + m_view->setCurrentEditor(editor); } closeSplitterEditors(); delete m_splitter; diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h index bfcdcb965bd1ec8452d9ea320ba76e02e4e4cfa1..3b0f732f119f72dbf5e0d2402b0a6f985b077c41 100644 --- a/src/plugins/coreplugin/editormanager/editorview.h +++ b/src/plugins/coreplugin/editormanager/editorview.h @@ -104,7 +104,7 @@ public: void insertEditor(int i, IEditor *editor); void removeEditor(IEditor *editor); IEditor *currentEditor() const; - void setCurrentEditor(IEditor *editor); + void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false); bool hasEditor(IEditor *editor) const; @@ -117,9 +117,6 @@ public: void focusInEvent(QFocusEvent *e); -signals: - void closeRequested(Core::IEditor *editor); - private slots: void sendCloseRequest(); void updateEditorStatus(Core::IEditor *editor = 0); @@ -159,6 +156,7 @@ public: void unsplit(Core::IEditor *editor); bool isView() const { return m_view != 0; } + bool isSplitter() const { return m_splitter != 0; } Core::IEditor *editor() const { return m_view ? m_view->currentEditor() : 0; } QList<Core::IEditor *> editors() const { return m_view ? m_view->editors() : QList<Core::IEditor*>(); } bool hasEditor(Core::IEditor *editor) const { return m_view && m_view->hasEditor(editor); } @@ -166,11 +164,15 @@ public: QSplitter *splitter() const { return m_splitter; } SplitterOrView *findView(Core::IEditor *editor); + SplitterOrView *findFirstView(); SplitterOrView *findSplitter(Core::IEditor *editor); + SplitterOrView *findNextView(Core::IEditor *editor); + private: void close(); void closeSplitterEditors(); + SplitterOrView *findNextView_helper(Core::IEditor *editor, bool *found); bool m_isRoot; QStackedLayout *m_layout; EditorView *m_view; diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp index e58b1566befb3c61c57e6cdbb929801147d03ba1..9af2376505330b3f208bd49193f7d4d9115e507f 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp @@ -97,7 +97,7 @@ void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor) void OpenEditorsWidget::selectEditor(const QModelIndex &index) { IEditor *editor = index.data(Qt::UserRole).value<IEditor*>(); - EditorManager::instance()->setCurrentEditor(editor); + EditorManager::instance()->activateEditor(editor); } diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp index 792a9e746d9baf2037f284b59315f5acc99f0901..316843c88e91f706b8ff319d0fafddce5788d110 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp @@ -58,7 +58,6 @@ bool OpenEditorsWindow::isSameFile(IEditor *editorA, IEditor *editorB) const OpenEditorsWindow::OpenEditorsWindow(QWidget *parent) : QWidget(parent, Qt::Popup), m_editorList(new QTreeWidget(this)), - m_mode(HistoryMode), m_current(0) { resize(QSize(WIDTH, HEIGHT)); @@ -79,13 +78,6 @@ OpenEditorsWindow::OpenEditorsWindow(QWidget *parent) : m_autoHide.setSingleShot(true); connect(&m_autoHide, SIGNAL(timeout()), this, SLOT(selectAndHide())); - EditorManager *em = EditorManager::instance(); - connect(em, SIGNAL(editorOpened(Core::IEditor *)), - this, SLOT(updateEditorList())); - connect(em, SIGNAL(editorsClosed(QList<Core::IEditor *>)), - this, SLOT(updateEditorList())); - connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), - this, SLOT(updateEditorList())); } void OpenEditorsWindow::selectAndHide() @@ -98,7 +90,6 @@ void OpenEditorsWindow::setVisible(bool visible) { QWidget::setVisible(visible); if (visible) { - updateEditorList(m_current); m_autoHide.start(600); setFocus(); } @@ -106,8 +97,6 @@ void OpenEditorsWindow::setVisible(bool visible) bool OpenEditorsWindow::isCentering() { - if (m_mode == OpenEditorsWindow::HistoryMode || m_editorList->topLevelItemCount() < 3) - return false; int internalMargin = m_editorList->viewport()->mapTo(m_editorList, QPoint(0,0)).y(); QRect rect0 = m_editorList->visualItemRect(m_editorList->topLevelItem(0)); QRect rect1 = m_editorList->visualItemRect(m_editorList->topLevelItem(m_editorList->topLevelItemCount()-1)); @@ -118,11 +107,6 @@ bool OpenEditorsWindow::isCentering() return false; } -void OpenEditorsWindow::setMode(Mode mode) -{ - m_mode = mode; - updateEditorList(m_current); -} bool OpenEditorsWindow::event(QEvent *e) { if (e->type() == QEvent::KeyRelease) { @@ -187,89 +171,17 @@ void OpenEditorsWindow::selectUpDown(bool up) count++; } if (editor) - updateEditorList(editor); + setSelectedEditor(editor); } void OpenEditorsWindow::selectPreviousEditor() { - selectUpDown(m_mode == ListMode); + selectUpDown(false); } void OpenEditorsWindow::selectNextEditor() { - selectUpDown(m_mode != ListMode); -} - -void OpenEditorsWindow::updateEditorList(IEditor *editor) -{ - if (!editor) - editor = EditorManager::instance()->currentEditor(); - m_current = editor; - if (m_mode == ListMode) - updateList(); - else if (m_mode == HistoryMode) - updateHistory(); -} - -void OpenEditorsWindow::updateHistory() -{ - EditorManager *em = EditorManager::instance(); - QList<IEditor *> history = em->editorHistory(); - int oldNum = m_editorList->topLevelItemCount(); - int num = history.count(); - int common = qMin(oldNum, num); - int selectedIndex = -1; - QTreeWidgetItem *item; - for (int i = 0; i < common; ++i) { - item = m_editorList->topLevelItem(i); - updateItem(item, history.at(i)); - if (isSameFile(history.at(i), m_current)) - selectedIndex = i; - } - for (int i = common; i < num; ++i) { - item = new QTreeWidgetItem(QStringList() << ""); - updateItem(item, history.at(i)); - m_editorList->addTopLevelItem(item); - if (isSameFile(history.at(i), m_current)) - selectedIndex = i; - } - for (int i = oldNum-1; i >= common; --i) { - delete m_editorList->takeTopLevelItem(i); - } - if (isCentering()) - centerOnItem(selectedIndex); - updateSelectedEditor(); -} - -void OpenEditorsWindow::updateList() -{ - EditorManager *em = EditorManager::instance(); - int oldNum = m_editorList->topLevelItemCount(); - int curItem = 0; - int selectedIndex = -1; - QTreeWidgetItem *item; - foreach (IEditor *editor, em->openedEditors()){ - if (curItem < oldNum) { - item = m_editorList->topLevelItem(curItem); - } else { - item = new QTreeWidgetItem(QStringList()<<""); - m_editorList->addTopLevelItem(item); - } - updateItem(item, editor); - if (isSameFile(editor, m_current)) { - m_editorList->setCurrentItem(item); - selectedIndex = curItem; - } - curItem++; - } - for (int i = oldNum-1; i >= curItem; --i) { - delete m_editorList->takeTopLevelItem(i); - } - if (isCentering()) - centerOnItem(selectedIndex); - if (m_current == 0 && m_editorList->currentItem()) - m_editorList->currentItem()->setSelected(false); - m_editorList->scrollTo(m_editorList->currentIndex(), QAbstractItemView::PositionAtCenter); + selectUpDown(true); } void OpenEditorsWindow::centerOnItem(int selectedIndex) @@ -290,22 +202,34 @@ void OpenEditorsWindow::centerOnItem(int selectedIndex) } } -void OpenEditorsWindow::updateItem(QTreeWidgetItem *item, IEditor *editor) +void OpenEditorsWindow::setEditors(const QList<IEditor *>&editors, IEditor *current) { static const QIcon lockedIcon(QLatin1String(":/core/images/locked.png")); static const QIcon emptyIcon(QLatin1String(":/core/images/empty14.png")); - QString title = editor->displayName(); - if (editor->file()->isModified()) - title += tr("*"); - item->setIcon(0, editor->file()->isReadOnly() ? lockedIcon : emptyIcon); - item->setText(0, title); - item->setToolTip(0, editor->file()->fileName()); - item->setData(0, Qt::UserRole, QVariant::fromValue(editor)); - item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - item->setTextAlignment(0, Qt::AlignLeft); + m_editorList->clear(); + + foreach (IEditor *editor, editors) { + QTreeWidgetItem *item = new QTreeWidgetItem(); + + QString title = editor->displayName(); + if (editor->file()->isModified()) + title += tr("*"); + item->setIcon(0, editor->file()->isReadOnly() ? lockedIcon : emptyIcon); + item->setText(0, title); + item->setToolTip(0, editor->file()->fileName()); + item->setData(0, Qt::UserRole, QVariant::fromValue(editor)); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + item->setTextAlignment(0, Qt::AlignLeft); + + m_editorList->addTopLevelItem(item); + + } + setSelectedEditor(current); } + void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item) { IEditor *editor = 0; @@ -320,6 +244,13 @@ void OpenEditorsWindow::editorClicked(QTreeWidgetItem *item) setFocus(); } + +void OpenEditorsWindow::setSelectedEditor(IEditor *editor) +{ + m_current = editor; + updateSelectedEditor(); +} + void OpenEditorsWindow::updateSelectedEditor() { if (m_current == 0 && m_editorList->currentItem()) { @@ -330,7 +261,7 @@ void OpenEditorsWindow::updateSelectedEditor() for (int i = 0; i < num; ++i) { IEditor *editor = m_editorList->topLevelItem(i) ->data(0, Qt::UserRole).value<IEditor *>(); - if (isSameFile(editor,m_current)) { + if (editor == m_current) { m_editorList->setCurrentItem(m_editorList->topLevelItem(i)); break; } @@ -338,7 +269,3 @@ void OpenEditorsWindow::updateSelectedEditor() m_editorList->scrollTo(m_editorList->currentIndex(), QAbstractItemView::PositionAtCenter); } -void OpenEditorsWindow::setSelectedEditor(IEditor *editor) -{ - updateEditorList(editor); -} diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.h b/src/plugins/coreplugin/editormanager/openeditorswindow.h index 6d3eaf371e0ecc86a1dd37bf7d2ae5ba1421549a..2114a8962b366102e448e49c69cb80051052a807 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.h +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.h @@ -57,20 +57,18 @@ public: OpenEditorsWindow(QWidget *parent = 0); ~OpenEditorsWindow() {} - void setMode(Mode mode); - Mode mode() const { return m_mode; } + void setEditors(const QList<IEditor *>&editors, IEditor *current); bool event(QEvent *e); bool eventFilter(QObject *src, QEvent *e); void focusInEvent(QFocusEvent *); void setVisible(bool visible); - void setSelectedEditor(IEditor *editor); void selectNextEditor(); void selectPreviousEditor(); IEditor *selectedEditor() const { return m_current; } + void setSelectedEditor(IEditor *); private slots: - void updateEditorList(IEditor *current = 0); void editorClicked(QTreeWidgetItem *item); void selectEditor(QTreeWidgetItem *item); void selectAndHide(); @@ -81,8 +79,6 @@ private: static const int MARGIN; static void updateItem(QTreeWidgetItem *item, IEditor *editor); - void updateList(); - void updateHistory(); void updateSelectedEditor(); bool isCentering(); void centerOnItem(int selectedIndex); @@ -91,7 +87,6 @@ private: bool isSameFile(IEditor *editorA, IEditor *editorB) const; QTreeWidget *m_editorList; - Mode m_mode; QTimer m_autoHide; IEditor *m_current; };