Core: Add Open next/previous document actions

Fixes: QTCREATORBUG-1208
Change-Id: I27c84e2c4fb64751b0aa92042518e8351eed0034
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-07-11 15:13:55 +02:00
parent de7f0e3a2a
commit 231de93b26
3 changed files with 41 additions and 0 deletions

View File

@@ -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";

View File

@@ -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<int> 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);

View File

@@ -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;