Commit c47f1e3a authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

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
parent 87a7ed94
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment