diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-05-20 13:07:13 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-06-02 07:00:50 +0000 |
commit | 697479572f3eaf09a2e563a25502f972050fbb11 (patch) | |
tree | efed8cc9b5f4a16c7e92707b674901122c97c920 /src/plugins/coreplugin/documentmanager.cpp | |
parent | 2e4a86a87c31f0dc15f308ee3619c4a4d400888a (diff) | |
download | qt-creator-697479572f3eaf09a2e563a25502f972050fbb11.tar.gz |
Move Open With... handling to editor manager.
Change-Id: I27faa327ae33244927e21aa74875d9601aaf9e50
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
Diffstat (limited to 'src/plugins/coreplugin/documentmanager.cpp')
-rw-r--r-- | src/plugins/coreplugin/documentmanager.cpp | 82 |
1 files changed, 0 insertions, 82 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) { |