aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/coreplugin/documentmanager.cpp82
-rw-r--r--src/plugins/coreplugin/documentmanager.h2
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp88
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.h1
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager_p.h1
-rw-r--r--src/plugins/projectexplorer/foldernavigationwidget.cpp5
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp3
-rw-r--r--src/plugins/resourceeditor/resourceeditorplugin.cpp3
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.cpp3
9 files changed, 95 insertions, 93 deletions
diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp
index dd70c122be..81ba85f32f 100644
--- a/src/plugins/coreplugin/documentmanager.cpp
+++ b/src/plugins/coreplugin/documentmanager.cpp
@@ -1375,88 +1375,6 @@ void DocumentManager::notifyFilesChangedInternally(const QStringList &files)
emit m_instance->filesChangedInternally(files);
}
-static void openEditorWith(const QString &fileName, Core::Id editorId)
-{
- // close any open editors that have this file open
- // remember the views to open new editors in there
- QList<EditorView *> views;
- QList<IEditor *> editorsOpenForFile
- = DocumentModel::editorsForFilePath(fileName);
- foreach (IEditor *openEditor, editorsOpenForFile) {
- EditorView *view = EditorManagerPrivate::viewForEditor(openEditor);
- if (view && view->currentEditor() == openEditor) // visible
- views.append(view);
- }
- if (!EditorManager::closeEditors(editorsOpenForFile)) // don't open if cancel was pressed
- return;
-
- if (views.isEmpty()) {
- EditorManager::openEditor(fileName, editorId);
- } else {
- if (EditorView *currentView = EditorManagerPrivate::currentEditorView()) {
- if (views.removeOne(currentView))
- views.prepend(currentView); // open editor in current view first
- }
- EditorManager::OpenEditorFlags flags;
- foreach (EditorView *view, views) {
- IEditor *editor = EditorManagerPrivate::openEditor(view, fileName, editorId, flags);
- // Do not change the current editor after opening the first one. That
- // * prevents multiple updates of focus etc which are not necessary
- // * lets us control which editor is made current by putting the current editor view
- // to the front (if that was in the list in the first place)
- flags |= EditorManager::DoNotChangeCurrentEditor;
- // do not try to open more editors if this one failed, or editor type does not
- // support duplication anyhow
- if (!editor || !editor->duplicateSupported())
- break;
- }
- }
-}
-
-void DocumentManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
-{
- typedef QList<IEditorFactory*> EditorFactoryList;
- typedef QList<IExternalEditor*> ExternalEditorList;
-
- menu->clear();
-
- bool anyMatches = false;
-
- Utils::MimeDatabase mdb;
- const Utils::MimeType mt = mdb.mimeTypeForFile(fileName);
- if (mt.isValid()) {
- const EditorFactoryList factories = EditorManager::editorFactories(mt, false);
- const ExternalEditorList externalEditors = EditorManager::externalEditors(mt, false);
- anyMatches = !factories.empty() || !externalEditors.empty();
- if (anyMatches) {
- // Add all suitable editors
- foreach (IEditorFactory *editorFactory, factories) {
- Core::Id editorId = editorFactory->id();
- // Add action to open with this very editor factory
- QString const actionTitle = editorFactory->displayName();
- QAction *action = menu->addAction(actionTitle);
- // Below we need QueuedConnection because otherwise, if a qrc file
- // is inside of a qrc file itself, and the qrc editor opens the Open with menu,
- // crashes happen, because the editor instance is deleted by openEditorWith
- // while the menu is still being processed.
- connect(action, &QAction::triggered, EditorManager::instance(),
- [fileName, editorId]() {
- openEditorWith(fileName, editorId);
- }, Qt::QueuedConnection);
- }
- // Add all suitable external editors
- foreach (IExternalEditor *externalEditor, externalEditors) {
- QAction *action = menu->addAction(externalEditor->displayName());
- Core::Id editorId = externalEditor->id();
- connect(action, &QAction::triggered, [fileName, editorId]() {
- EditorManager::openExternalEditor(fileName, editorId);
- });
- }
- }
- }
- menu->setEnabled(anyMatches);
-}
-
bool DocumentManager::eventFilter(QObject *obj, QEvent *e)
{
if (obj == qApp && e->type() == QEvent::ApplicationActivate) {
diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h
index bb49d2b51d..5b809550a9 100644
--- a/src/plugins/coreplugin/documentmanager.h
+++ b/src/plugins/coreplugin/documentmanager.h
@@ -137,8 +137,6 @@ public:
static QString buildDirectory();
static void setBuildDirectory(const QString &directory);
- static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
-
/* Used to notify e.g. the code model to update the given files. Does *not*
lead to any editors to reload or any other editor manager actions. */
static void notifyFilesChangedInternally(const QStringList &files);
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 01fedf0d6f..c000e0a4cb 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -686,6 +686,48 @@ IEditor *EditorManagerPrivate::openEditorAt(EditorView *view, const QString &fil
return editor;
}
+IEditor *EditorManagerPrivate::openEditorWith(const QString &fileName, Core::Id editorId)
+{
+ // close any open editors that have this file open
+ // remember the views to open new editors in there
+ QList<EditorView *> views;
+ QList<IEditor *> editorsOpenForFile
+ = DocumentModel::editorsForFilePath(fileName);
+ foreach (IEditor *openEditor, editorsOpenForFile) {
+ EditorView *view = EditorManagerPrivate::viewForEditor(openEditor);
+ if (view && view->currentEditor() == openEditor) // visible
+ views.append(view);
+ }
+ if (!EditorManager::closeEditors(editorsOpenForFile)) // don't open if cancel was pressed
+ return 0;
+
+ IEditor *openedEditor = 0;
+ if (views.isEmpty()) {
+ openedEditor = EditorManager::openEditor(fileName, editorId);
+ } else {
+ if (EditorView *currentView = EditorManagerPrivate::currentEditorView()) {
+ if (views.removeOne(currentView))
+ views.prepend(currentView); // open editor in current view first
+ }
+ EditorManager::OpenEditorFlags flags;
+ foreach (EditorView *view, views) {
+ IEditor *editor = EditorManagerPrivate::openEditor(view, fileName, editorId, flags);
+ if (!openedEditor && editor)
+ openedEditor = editor;
+ // Do not change the current editor after opening the first one. That
+ // * prevents multiple updates of focus etc which are not necessary
+ // * lets us control which editor is made current by putting the current editor view
+ // to the front (if that was in the list in the first place)
+ flags |= EditorManager::DoNotChangeCurrentEditor;
+ // do not try to open more editors if this one failed, or editor type does not
+ // support duplication anyhow
+ if (!editor || !editor->duplicateSupported())
+ break;
+ }
+ }
+ return openedEditor;
+}
+
IEditor *EditorManagerPrivate::activateEditorForDocument(EditorView *view, IDocument *document,
EditorManager::OpenEditorFlags flags)
{
@@ -2087,7 +2129,51 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
QMenu *openWith = contextMenu->addMenu(tr("Open With"));
openWith->setEnabled(enabled);
if (enabled)
- DocumentManager::populateOpenWithMenu(openWith, entry->fileName().toString());
+ populateOpenWithMenu(openWith, entry->fileName().toString());
+}
+
+void EditorManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
+{
+ typedef QList<IEditorFactory*> EditorFactoryList;
+ typedef QList<IExternalEditor*> ExternalEditorList;
+
+ menu->clear();
+
+ bool anyMatches = false;
+
+ Utils::MimeDatabase mdb;
+ const Utils::MimeType mt = mdb.mimeTypeForFile(fileName);
+ if (mt.isValid()) {
+ const EditorFactoryList factories = editorFactories(mt, false);
+ const ExternalEditorList extEditors = externalEditors(mt, false);
+ anyMatches = !factories.empty() || !extEditors.empty();
+ if (anyMatches) {
+ // Add all suitable editors
+ foreach (IEditorFactory *editorFactory, factories) {
+ Core::Id editorId = editorFactory->id();
+ // Add action to open with this very editor factory
+ QString const actionTitle = editorFactory->displayName();
+ QAction *action = menu->addAction(actionTitle);
+ // Below we need QueuedConnection because otherwise, if a qrc file
+ // is inside of a qrc file itself, and the qrc editor opens the Open with menu,
+ // crashes happen, because the editor instance is deleted by openEditorWith
+ // while the menu is still being processed.
+ connect(action, &QAction::triggered, d,
+ [fileName, editorId]() {
+ EditorManagerPrivate::openEditorWith(fileName, editorId);
+ }, Qt::QueuedConnection);
+ }
+ // Add all suitable external editors
+ foreach (IExternalEditor *externalEditor, extEditors) {
+ QAction *action = menu->addAction(externalEditor->displayName());
+ Core::Id editorId = externalEditor->id();
+ connect(action, &QAction::triggered, [fileName, editorId]() {
+ EditorManager::openExternalEditor(fileName, editorId);
+ });
+ }
+ }
+ }
+ menu->setEnabled(anyMatches);
}
void EditorManager::saveDocument()
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index 6d0f208f44..a844f3588f 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -169,6 +169,7 @@ public:
static void addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry,
IEditor *editor = 0);
static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry);
+ static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
signals:
void currentEditorChanged(Core::IEditor *editor);
diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h
index 28872f3a02..a448dba0fb 100644
--- a/src/plugins/coreplugin/editormanager/editormanager_p.h
+++ b/src/plugins/coreplugin/editormanager/editormanager_p.h
@@ -85,6 +85,7 @@ public:
Id editorId = Id(),
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags,
bool *newEditor = 0);
+ static IEditor *openEditorWith(const QString &fileName, Core::Id editorId);
static IEditor *duplicateEditor(IEditor *editor);
static IEditor *activateEditor(EditorView *view, IEditor *editor,
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags);
diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp
index 6b2a85b440..779fe77529 100644
--- a/src/plugins/projectexplorer/foldernavigationwidget.cpp
+++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp
@@ -37,7 +37,6 @@
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/fileiconprovider.h>
-#include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/coreconstants.h>
@@ -365,8 +364,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
// open with...
if (hasCurrentItem && !isDirectory) {
QMenu *openWith = menu.addMenu(tr("Open With"));
- Core::DocumentManager::populateOpenWithMenu(openWith,
- m_fileSystemModel->filePath(current));
+ Core::EditorManager::populateOpenWithMenu(openWith,
+ m_fileSystemModel->filePath(current));
}
// Open file dialog to choose a path starting from current
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index f993aff06f..c619ca318e 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -2944,7 +2944,8 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
m_removeFileAction->setVisible(!enableDelete || enableRemove);
m_renameFileAction->setEnabled(actions.contains(Rename));
- DocumentManager::populateOpenWithMenu(m_openWithMenu, ProjectTree::currentNode()->path().toString());
+ EditorManager::populateOpenWithMenu(m_openWithMenu,
+ ProjectTree::currentNode()->path().toString());
}
if (actions.contains(HidePathActions)) {
diff --git a/src/plugins/resourceeditor/resourceeditorplugin.cpp b/src/plugins/resourceeditor/resourceeditorplugin.cpp
index 22de88bc9f..4eefe8fb51 100644
--- a/src/plugins/resourceeditor/resourceeditorplugin.cpp
+++ b/src/plugins/resourceeditor/resourceeditorplugin.cpp
@@ -37,7 +37,6 @@
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
-#include <coreplugin/documentmanager.h>
#include <coreplugin/id.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -346,7 +345,7 @@ void ResourceEditorPlugin::updateContextActions(Node *node, Project *)
m_removeNonExisting->setVisible(isResourceNode);
if (isResourceNode)
- Core::DocumentManager::populateOpenWithMenu(m_openWithMenu, node->path().toString());
+ Core::EditorManager::populateOpenWithMenu(m_openWithMenu, node->path().toString());
else
m_openWithMenu->clear();
m_openWithMenu->menuAction()->setVisible(!m_openWithMenu->actions().isEmpty());
diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp
index e53df74ccc..0b9a26c82e 100644
--- a/src/plugins/resourceeditor/resourceeditorw.cpp
+++ b/src/plugins/resourceeditor/resourceeditorw.cpp
@@ -39,7 +39,6 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/commandbutton.h>
#include <coreplugin/editormanager/editormanager.h>
-#include <coreplugin/documentmanager.h>
#include <coreplugin/find/itemviewfind.h>
#include <utils/reloadpromptutils.h>
#include <utils/fileutils.h>
@@ -280,7 +279,7 @@ void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo)
void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName)
{
- Core::DocumentManager::populateOpenWithMenu(m_openWithMenu, fileName);
+ Core::EditorManager::populateOpenWithMenu(m_openWithMenu, fileName);
m_currentFileName = fileName;
m_renameAction->setEnabled(!document()->isFileReadOnly());
m_contextMenu->popup(globalPoint);