From a4fa08f1379ac0205512d29d7628c64e9383d3b7 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 22 Feb 2023 19:21:28 +0100 Subject: [PATCH] EditorManger: Move BaseFileFilter::openEditor into EditorManager Change-Id: I68e41ea041583a5dfbf4a76517af07ecac065039 Reviewed-by: Qt CI Bot Reviewed-by: Reviewed-by: David Schulz Reviewed-by: Eike Ziller --- .../coreplugin/editormanager/editormanager.cpp | 12 ++++++++++++ src/plugins/coreplugin/editormanager/editormanager.h | 10 ++++++---- src/plugins/coreplugin/locator/basefilefilter.cpp | 11 +---------- src/plugins/coreplugin/locator/basefilefilter.h | 1 - src/plugins/coreplugin/locator/filesystemfilter.cpp | 3 +-- src/plugins/coreplugin/locator/ilocatorfilter.h | 3 ++- .../coreplugin/locator/opendocumentsfilter.cpp | 4 ++-- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 2953a833b70..f84465303fb 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -28,6 +28,7 @@ #include "../findplaceholder.h" #include "../icore.h" #include "../iversioncontrol.h" +#include "../locator/ilocatorfilter.h" #include "../modemanager.h" #include "../outputpane.h" #include "../outputpanemanager.h" @@ -3157,6 +3158,17 @@ IEditor *EditorManager::openEditorAt(const Link &link, newEditor); } +IEditor *EditorManager::openEditor(const LocatorFilterEntry &entry) +{ + const OpenEditorFlags defaultFlags = EditorManager::AllowExternalEditor; + if (entry.linkForEditor) + return EditorManager::openEditorAt(*entry.linkForEditor, {}, defaultFlags); + else if (!entry.filePath.isEmpty()) + return EditorManager::openEditor(entry.filePath, {}, defaultFlags); + return nullptr; +} + + /*! Opens the document at the position of the search result \a item using the editor type \a editorId and the specified \a flags. diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index c1c4c4644c3..f73142a933e 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -18,15 +18,16 @@ #include -QT_FORWARD_DECLARE_CLASS(QMenu) +QT_BEGIN_NAMESPACE +class QMenu; +QT_END_NAMESPACE -namespace Utils { -class MimeType; -} +namespace Utils { class MimeType; } namespace Core { class IDocument; +class LocatorFilterEntry; class SearchResultItem; namespace Internal { @@ -76,6 +77,7 @@ public: Utils::Id editorId = {}, OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr); + static IEditor *openEditor(const LocatorFilterEntry &entry); static void openEditorAtSearchResult(const SearchResultItem &item, Utils::Id editorId = {}, diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp index 9ce27cc0528..823b5d7fb58 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.cpp +++ b/src/plugins/coreplugin/locator/basefilefilter.cpp @@ -201,16 +201,7 @@ void BaseFileFilter::accept(const LocatorFilterEntry &selection, Q_UNUSED(newText) Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) - openEditorAt(selection); -} - -void BaseFileFilter::openEditorAt(const LocatorFilterEntry &entry) -{ - if (entry.linkForEditor) { - EditorManager::openEditorAt(*entry.linkForEditor, {}, EditorManager::AllowExternalEditor); - return; - } - EditorManager::openEditor(entry.filePath, {}, EditorManager::AllowExternalEditor); + EditorManager::openEditor(selection); } /*! diff --git a/src/plugins/coreplugin/locator/basefilefilter.h b/src/plugins/coreplugin/locator/basefilefilter.h index 710cd21edf4..47754dc08f5 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.h +++ b/src/plugins/coreplugin/locator/basefilefilter.h @@ -48,7 +48,6 @@ public: const QString &entry) override; void accept(const LocatorFilterEntry &selection, QString *newText, int *selectionStart, int *selectionLength) const override; - static void openEditorAt(const LocatorFilterEntry &entry); protected: void setFileIterator(Iterator *iterator); diff --git a/src/plugins/coreplugin/locator/filesystemfilter.cpp b/src/plugins/coreplugin/locator/filesystemfilter.cpp index 17c54c748dc..148852b1b09 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.cpp +++ b/src/plugins/coreplugin/locator/filesystemfilter.cpp @@ -3,7 +3,6 @@ #include "filesystemfilter.h" -#include "basefilefilter.h" #include "../coreplugintr.h" #include "../documentmanager.h" #include "../editormanager/editormanager.h" @@ -192,7 +191,7 @@ void FileSystemFilter::accept(const LocatorFilterEntry &selection, file.close(); VcsManager::promptToAdd(selection.filePath.absolutePath(), {selection.filePath}); } - BaseFileFilter::openEditorAt(selection); + EditorManager::openEditor(selection); }, Qt::QueuedConnection); } } diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.h b/src/plugins/coreplugin/locator/ilocatorfilter.h index e6b49ab5e9c..1e0a2fcf4b4 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.h +++ b/src/plugins/coreplugin/locator/ilocatorfilter.h @@ -21,8 +21,9 @@ namespace Core { class ILocatorFilter; -struct LocatorFilterEntry +class LocatorFilterEntry { +public: struct HighlightInfo { enum DataType { DisplayName, diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp index f8febc69f30..5a9042ce430 100644 --- a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp @@ -3,8 +3,8 @@ #include "opendocumentsfilter.h" -#include "basefilefilter.h" #include "../coreplugintr.h" +#include "../editormanager/editormanager.h" #include #include @@ -123,7 +123,7 @@ void OpenDocumentsFilter::accept(const LocatorFilterEntry &selection, Q_UNUSED(newText) Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) - BaseFileFilter::openEditorAt(selection); + EditorManager::openEditor(selection); } } // Core::Internal