diff options
author | Eike Ziller <eike.ziller@qt.io> | 2018-06-21 15:11:39 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2018-06-25 08:08:14 +0000 |
commit | a8c5af56a9438bdd8e6df2787082666350cb9b37 (patch) | |
tree | 7c1e9bdb74a7c57d18574667d574267d48998294 /src/plugins/coreplugin/editormanager | |
parent | e00218b997ad6c4061ab9c9ed7a29b1ab40b3563 (diff) | |
download | qt-creator-a8c5af56a9438bdd8e6df2787082666350cb9b37.tar.gz |
Remove unneeded checks for validity of mime types
mimeTypeForFile(...) is documented to never return an invalid mime type
(it will fall back to binary if everything else fails), so remove
unneeded checks.
This also removes fallback code that used text/plain in case of invalid
mime type, which is probably a relict from the old mime implementation.
Change-Id: I88ed41fa3b81704f110f9f481b0f01424a487cbb
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/coreplugin/editormanager')
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.cpp | 61 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/ieditorfactory.cpp | 5 |
2 files changed, 27 insertions, 39 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 318bc0a071..aa7ed30851 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -936,10 +936,7 @@ void EditorManagerPrivate::showPopupOrSelectDocument() Id EditorManagerPrivate::getOpenWithEditorId(const QString &fileName, bool *isExternalEditor) { // Collect editors that can open the file - Utils::MimeType mt = Utils::mimeTypeForFile(fileName); - //Unable to determine mime type of fileName. Falling back to text/plain", - if (!mt.isValid()) - mt = Utils::mimeTypeForName("text/plain"); + const Utils::MimeType mt = Utils::mimeTypeForFile(fileName); QList<Id> allEditorIds; QStringList allEditorDisplayNames; QList<Id> externalEditorIds; @@ -2470,37 +2467,33 @@ void EditorManager::populateOpenWithMenu(QMenu *menu, const QString &fileName) menu->clear(); - bool anyMatches = false; - const Utils::MimeType mt = Utils::mimeTypeForFile(fileName); - if (mt.isValid()) { - const EditorFactoryList factories = IEditorFactory::editorFactories(mt, false); - const ExternalEditorList extEditors = IExternalEditor::externalEditors(mt); - 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); - }); - } + const EditorFactoryList factories = IEditorFactory::editorFactories(mt, false); + const ExternalEditorList extEditors = IExternalEditor::externalEditors(mt); + const bool 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); diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp index ad17ef5b2f..46f3050abd 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp +++ b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp @@ -65,11 +65,6 @@ const EditorFactoryList IEditorFactory::editorFactories(const QString &fileName, const QFileInfo fileInfo(fileName); // Find by mime type Utils::MimeType mimeType = Utils::mimeTypeForFile(fileInfo); - if (!mimeType.isValid()) { - qWarning("%s unable to determine mime type of %s. Falling back to text/plain", - Q_FUNC_INFO, fileName.toUtf8().constData()); - mimeType = Utils::mimeTypeForName("text/plain"); - } // open text files > 48 MB in binary editor if (fileInfo.size() > EditorManager::maxTextFileSize() && mimeType.inherits("text/plain")) { |