diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2010-01-13 17:11:20 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2010-01-13 17:17:21 +0100 |
commit | c47f1e3a7f2a2dff6dfad86f1fb71a72ec661658 (patch) | |
tree | 0b2cf42158261d8b13c86e8441b0bea74a7f79e0 | |
parent | 87a7ed94a3e5d57c02cfc68a8be87a76109bdb0b (diff) | |
download | qt-creator-c47f1e3a7f2a2dff6dfad86f1fb71a72ec661658.tar.gz |
Made "All Files" filter always available
Needed to be able to open text files with arbitrary or no extension.
Previously, the "All Files" filter would disappear when there was no
plugin with an empty filter string, like the BinEditor plugin.
Reviewed-by: con
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.cpp | 44 | ||||
-rw-r--r-- | src/plugins/coreplugin/mimedatabase.cpp | 7 |
2 files changed, 23 insertions, 28 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 21f032904c..bd4286d38e 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -385,7 +385,7 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) : cmd->setDefaultKeySequence(QKeySequence(tr("Alt+V,Alt+I"))); advancedMenu->addAction(cmd, Constants::G_EDIT_EDITOR); connect(m_d->m_openInExternalEditorAction, SIGNAL(triggered()), this, SLOT(openInExternalEditor())); - + // Connect to VariableManager for CURRENT_DOCUMENT variable setting VariableManager *vm = VariableManager::instance(); connect(this, SIGNAL(currentEditorChanged(Core::IEditor *)), @@ -1079,48 +1079,40 @@ QString EditorManager::getOpenWithEditorKind(const QString &fileName, static QString formatFileFilters(const Core::ICore *core, QString *selectedFilter) { QString rc; - // Compile list of filter strings. If we find a glob matching all files, - // put it last and set it as default selectedFilter. + + // Compile list of filter strings QStringList filters = core->mimeDatabase()->filterStrings(); filters.sort(); selectedFilter->clear(); if (filters.empty()) return rc; + const QString filterSeparator = QLatin1String(";;"); - bool hasAllFilter = false; - const int size = filters.size(); - for (int i = 0; i < size; i++) { - const QString &filterString = filters.at(i); - if (filterString.isEmpty()) { // binary editor - hasAllFilter = true; - } else { - if (!rc.isEmpty()) - rc += filterSeparator; - rc += filterString; - } - } - if (hasAllFilter) { - // prepend all files filter - // prepending instead of appending to work around a but in Qt/Mac - QString allFilesFilter = EditorManager::tr("All Files (*)"); + foreach (const QString &filterString, filters) { if (!rc.isEmpty()) - allFilesFilter += filterSeparator; - rc.prepend(allFilesFilter); - *selectedFilter = allFilesFilter; - } else { - *selectedFilter = filters.front(); + rc += filterSeparator; + rc += filterString; } + + // prepend all files filter + // prepending instead of appending to work around a bug in Qt/Mac + QString allFilesFilter = EditorManager::tr("All Files (*)"); + if (!rc.isEmpty()) + allFilesFilter += filterSeparator; + rc.prepend(allFilesFilter); + *selectedFilter = allFilesFilter; + return rc; } IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorKind, - EditorManager::OpenEditorFlags flags) + OpenEditorFlags flags) { return openEditor(0, fileName, editorKind, flags); } IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName, - const QString &editorKind, EditorManager::OpenEditorFlags flags) + const QString &editorKind, OpenEditorFlags flags) { if (debugEditorManager) qDebug() << Q_FUNC_INFO << fileName << editorKind; diff --git a/src/plugins/coreplugin/mimedatabase.cpp b/src/plugins/coreplugin/mimedatabase.cpp index acfd1905a9..32ead14d95 100644 --- a/src/plugins/coreplugin/mimedatabase.cpp +++ b/src/plugins/coreplugin/mimedatabase.cpp @@ -1086,8 +1086,11 @@ QStringList MimeDatabasePrivate::filterStrings() const { QStringList rc; const TypeMimeTypeMap::const_iterator cend = m_typeMimeTypeMap.constEnd(); - for (TypeMimeTypeMap::const_iterator it = m_typeMimeTypeMap.constBegin(); it != cend; ++it) - rc += it.value().type.filterString(); + for (TypeMimeTypeMap::const_iterator it = m_typeMimeTypeMap.constBegin(); it != cend; ++it) { + const QString filterString = it.value().type.filterString(); + if (!filterString.isEmpty()) + rc += filterString; + } return rc; } |