Core: add convenience function generating a documents context menu

Change-Id: I1f00bccf3c24d0bde8764277e1cfb4ef0c6e758b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2024-07-04 13:22:12 +02:00
parent 5382d735fb
commit 3d37e20dd6
5 changed files with 15 additions and 15 deletions

View File

@@ -2928,6 +2928,16 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
populateOpenWithMenu(openWith, entry->filePath()); populateOpenWithMenu(openWith, entry->filePath());
} }
void EditorManager::addContextMenuActions(
QMenu *contextMenu, DocumentModel::Entry *entry, IEditor *editor)
{
EditorManager::addSaveAndCloseEditorActions(contextMenu, entry, editor);
contextMenu->addSeparator();
EditorManager::addPinEditorActions(contextMenu, entry);
contextMenu->addSeparator();
EditorManager::addNativeDirAndOpenWithActions(contextMenu, entry);
}
/*! /*!
Populates the \uicontrol {Open With} menu \a menu with editors that are Populates the \uicontrol {Open With} menu \a menu with editors that are
suitable for opening the document \a filePath. suitable for opening the document \a filePath.

View File

@@ -141,6 +141,8 @@ public:
IEditor *editor = nullptr); IEditor *editor = nullptr);
static void addPinEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry); static void addPinEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry);
static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry); static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry);
static void addContextMenuActions(
QMenu *contextMenu, DocumentModel::Entry *entry, IEditor *editor = nullptr);
static void populateOpenWithMenu(QMenu *menu, const Utils::FilePath &filePath); static void populateOpenWithMenu(QMenu *menu, const Utils::FilePath &filePath);
static void runWithTemporaryEditor(const Utils::FilePath &filePath, static void runWithTemporaryEditor(const Utils::FilePath &filePath,

View File

@@ -381,11 +381,7 @@ void EditorView::fillListContextMenu(QMenu *menu) const
IEditor *editor = currentEditor(); IEditor *editor = currentEditor();
DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document()) DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document())
: nullptr; : nullptr;
EditorManager::addSaveAndCloseEditorActions(menu, entry, editor); EditorManager::addContextMenuActions(menu, entry, editor);
menu->addSeparator();
EditorManager::addPinEditorActions(menu, entry);
menu->addSeparator();
EditorManager::addNativeDirAndOpenWithActions(menu, entry);
} }
void EditorView::splitHorizontally() void EditorView::splitHorizontally()

View File

@@ -153,11 +153,7 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos)
QModelIndex editorIndex = indexAt(pos); QModelIndex editorIndex = indexAt(pos);
const int row = m_model->mapToSource(editorIndex).row(); const int row = m_model->mapToSource(editorIndex).row();
DocumentModel::Entry *entry = DocumentModel::entryAtRow(row); DocumentModel::Entry *entry = DocumentModel::entryAtRow(row);
EditorManager::addSaveAndCloseEditorActions(&contextMenu, entry); EditorManager::addContextMenuActions(&contextMenu, entry);
contextMenu.addSeparator();
EditorManager::addPinEditorActions(&contextMenu, entry);
contextMenu.addSeparator();
EditorManager::addNativeDirAndOpenWithActions(&contextMenu, entry);
contextMenu.exec(mapToGlobal(pos)); contextMenu.exec(mapToGlobal(pos));
} }

View File

@@ -341,11 +341,7 @@ void EditorToolBar::fillListContextMenu(QMenu *menu)
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document()) DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document())
: nullptr; : nullptr;
EditorManager::addSaveAndCloseEditorActions(menu, entry, editor); EditorManager::addContextMenuActions(menu, entry, editor);
menu->addSeparator();
EditorManager::addPinEditorActions(menu, entry);
menu->addSeparator();
EditorManager::addNativeDirAndOpenWithActions(menu, entry);
} }
} }