forked from qt-creator/qt-creator
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
This commit is contained in:
@@ -1079,48 +1079,40 @@ QString EditorManager::getOpenWithEditorKind(const QString &fileName,
|
|||||||
static QString formatFileFilters(const Core::ICore *core, QString *selectedFilter)
|
static QString formatFileFilters(const Core::ICore *core, QString *selectedFilter)
|
||||||
{
|
{
|
||||||
QString rc;
|
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();
|
QStringList filters = core->mimeDatabase()->filterStrings();
|
||||||
filters.sort();
|
filters.sort();
|
||||||
selectedFilter->clear();
|
selectedFilter->clear();
|
||||||
if (filters.empty())
|
if (filters.empty())
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
const QString filterSeparator = QLatin1String(";;");
|
const QString filterSeparator = QLatin1String(";;");
|
||||||
bool hasAllFilter = false;
|
foreach (const QString &filterString, filters) {
|
||||||
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 (*)");
|
|
||||||
if (!rc.isEmpty())
|
if (!rc.isEmpty())
|
||||||
allFilesFilter += filterSeparator;
|
rc += filterSeparator;
|
||||||
rc.prepend(allFilesFilter);
|
rc += filterString;
|
||||||
*selectedFilter = allFilesFilter;
|
|
||||||
} else {
|
|
||||||
*selectedFilter = filters.front();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorKind,
|
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorKind,
|
||||||
EditorManager::OpenEditorFlags flags)
|
OpenEditorFlags flags)
|
||||||
{
|
{
|
||||||
return openEditor(0, fileName, editorKind, flags);
|
return openEditor(0, fileName, editorKind, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName,
|
IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName,
|
||||||
const QString &editorKind, EditorManager::OpenEditorFlags flags)
|
const QString &editorKind, OpenEditorFlags flags)
|
||||||
{
|
{
|
||||||
if (debugEditorManager)
|
if (debugEditorManager)
|
||||||
qDebug() << Q_FUNC_INFO << fileName << editorKind;
|
qDebug() << Q_FUNC_INFO << fileName << editorKind;
|
||||||
|
@@ -1086,8 +1086,11 @@ QStringList MimeDatabasePrivate::filterStrings() const
|
|||||||
{
|
{
|
||||||
QStringList rc;
|
QStringList rc;
|
||||||
const TypeMimeTypeMap::const_iterator cend = m_typeMimeTypeMap.constEnd();
|
const TypeMimeTypeMap::const_iterator cend = m_typeMimeTypeMap.constEnd();
|
||||||
for (TypeMimeTypeMap::const_iterator it = m_typeMimeTypeMap.constBegin(); it != cend; ++it)
|
for (TypeMimeTypeMap::const_iterator it = m_typeMimeTypeMap.constBegin(); it != cend; ++it) {
|
||||||
rc += it.value().type.filterString();
|
const QString filterString = it.value().type.filterString();
|
||||||
|
if (!filterString.isEmpty())
|
||||||
|
rc += filterString;
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user