diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index f4353a1fba7..b1512082844 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -118,6 +118,8 @@ const char GOTONEXTINHISTORY[] = "QtCreator.GotoNextInHistory"; const char GOTOPREVINHISTORY[] = "QtCreator.GotoPreviousInHistory"; const char GO_BACK[] = "QtCreator.GoBack"; const char GO_FORWARD[] = "QtCreator.GoForward"; +const char OPEN_PREVIOUS_DOCUMENT[] = "QtCreator.OpenPreviousDocument"; +const char OPEN_NEXT_DOCUMENT[] = "QtCreator.OpenNextDocument"; const char GOTOLASTEDIT[] = "QtCreator.GotoLastEdit"; const char REOPEN_CLOSED_EDITOR[] = "QtCreator.ReopenClosedEditor"; const char ABOUT_QTCREATOR[] = "QtCreator.AboutQtCreator"; diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index ecca2630c11..feffa84e72a 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -396,6 +396,25 @@ EditorManagerPrivate::~EditorManagerPrivate() d = nullptr; } +static void openDocumentByIdx(int idx) +{ + DocumentModel::Entry *entry = DocumentModel::entryAtRow(idx + 1); + if (!entry) + return; + EditorManager::activateEditorForEntry(entry); +}; + +static void openDocumentByDelta(int delta) +{ + const int count = DocumentModel::entryCount(); + const std::optional curIdx = DocumentModel::indexOfDocument( + EditorManager::currentDocument()); + if (!curIdx) + return; + const int newIdx = (*curIdx + delta + count) % count; + openDocumentByIdx(newIdx); +}; + void EditorManagerPrivate::init() { DocumentModel::init(); @@ -596,6 +615,22 @@ void EditorManagerPrivate::init() goForward.addToContainer(Constants::M_WINDOW, Constants::G_WINDOW_NAVIGATE); goForward.addOnTriggered(this, &EditorManager::goForwardInNavigationHistory); + ActionBuilder openPreviousDocument(this, Constants::OPEN_PREVIOUS_DOCUMENT); + openPreviousDocument.setIcon(Utils::Icons::PREV.icon()); + openPreviousDocument.setText(::Core::Tr::tr("Open Previous Document")); + openPreviousDocument.bindContextAction(&m_prevDocAction); + openPreviousDocument.setContext(editDesignContext); + openPreviousDocument.addToContainer(Constants::M_WINDOW, Constants::G_WINDOW_NAVIGATE); + openPreviousDocument.addOnTriggered(this, [] { openDocumentByDelta(-1); }); + + ActionBuilder openNextDocument(this, Constants::OPEN_NEXT_DOCUMENT); + openNextDocument.setIcon(Utils::Icons::NEXT.icon()); + openNextDocument.setText(::Core::Tr::tr("Open Next Document")); + openPreviousDocument.bindContextAction(&m_nextDocAction); + openNextDocument.setContext(editDesignContext); + openNextDocument.addToContainer(Constants::M_WINDOW, Constants::G_WINDOW_NAVIGATE); + openNextDocument.addOnTriggered(this, [] { openDocumentByDelta(1); }); + // Reopen last closed document ActionBuilder reopenLastClosedDocument(this, Constants::REOPEN_CLOSED_EDITOR); reopenLastClosedDocument.setText(::Core::Tr::tr("Reopen Last Closed Document")); @@ -2078,6 +2113,8 @@ void EditorManagerPrivate::updateActions() EditorView *view = currentEditorView(); d->m_goBackAction->setEnabled(view ? view->canGoBack() : false); d->m_goForwardAction->setEnabled(view ? view->canGoForward() : false); + d->m_nextDocAction->setEnabled(DocumentModel::entryCount() > 1); + d->m_prevDocAction->setEnabled(DocumentModel::entryCount() > 1); d->m_reopenLastClosedDocumenAction->setEnabled(view ? view->canReopen() : false); SplitterOrView *viewParent = (view ? view->parentSplitterOrView() : nullptr); diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h index 34a67457219..9fb8ab104e2 100644 --- a/src/plugins/coreplugin/editormanager/editormanager_p.h +++ b/src/plugins/coreplugin/editormanager/editormanager_p.h @@ -220,6 +220,8 @@ private: QAction *m_gotoPreviousDocHistoryAction = nullptr; QAction *m_goBackAction = nullptr; QAction *m_goForwardAction = nullptr; + QAction *m_nextDocAction = nullptr; + QAction *m_prevDocAction = nullptr; QAction *m_reopenLastClosedDocumenAction = nullptr; QAction *m_gotoLastEditAction = nullptr; QAction *m_splitAction = nullptr;