forked from qt-creator/qt-creator
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:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user