TextEditor: Allow to open all files with the text editor

Sometimes the mime detection returns unexpected results and defines a
textfile based on the ending as a binary file. We should at least make
it possible for the user to open those files in the plain text editor.

Fixes: QTCREATORBUG-31116
Change-Id: I3139a1013be9fa6f28654434229c62f7a8e79d21
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2024-06-25 08:39:54 +02:00
parent 6ffe1a8061
commit a53a72044c

View File

@@ -4,6 +4,7 @@
#include "ieditorfactory.h" #include "ieditorfactory.h"
#include "ieditorfactory_p.h" #include "ieditorfactory_p.h"
#include "editormanager.h" #include "editormanager.h"
#include "../coreconstants.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/mimeconstants.h> #include <utils/mimeconstants.h>
@@ -36,6 +37,14 @@ static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType,
} }
return true; // continue return true; // continue
}); });
// Always offer the plain text editor as a fallback for the case that the mime type
// is not detected correctly.
if (auto plainTextEditorFactory = Utils::findOrDefault(
allFactories,
Utils::equal(&IEditorFactory::id, Utils::Id(Constants::K_DEFAULT_TEXT_EDITOR_ID)))) {
if (!matches.contains(plainTextEditorFactory))
list->append(plainTextEditorFactory);
}
} }
/*! /*!