diff options
author | hjk <hjk@qt.io> | 2024-01-15 16:31:41 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2024-01-16 10:43:06 +0000 |
commit | 5de41fb40df2bc229fb32b1d7d3836daea5e0474 (patch) | |
tree | 4e516c026646a46724429726d478568654ef4bb7 /src/plugins/python | |
parent | 1992efddfc2617d77d3e39ac3c2e6a4bf8d66a19 (diff) |
Python: Use new plugin items setup pattern for PythonEditor
Change-Id: Ie8516960a106ddeff415b6412d9af66f7d2f0f36
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/python')
-rw-r--r-- | src/plugins/python/pythoneditor.cpp | 55 | ||||
-rw-r--r-- | src/plugins/python/pythoneditor.h | 11 | ||||
-rw-r--r-- | src/plugins/python/pythonplugin.cpp | 3 |
3 files changed, 36 insertions, 33 deletions
diff --git a/src/plugins/python/pythoneditor.cpp b/src/plugins/python/pythoneditor.cpp index 1c74838ea4b..a4efb19e63d 100644 --- a/src/plugins/python/pythoneditor.cpp +++ b/src/plugins/python/pythoneditor.cpp @@ -10,7 +10,6 @@ #include "pythonindenter.h" #include "pythonkitaspect.h" #include "pythonlanguageclient.h" -#include "pythonplugin.h" #include "pythonsettings.h" #include "pythontr.h" #include "pythonutils.h" @@ -28,6 +27,7 @@ #include <projectexplorer/projectmanager.h> #include <projectexplorer/target.h> +#include <texteditor/texteditor.h> #include <texteditor/texteditoractionhandler.h> #include <utils/stylehelper.h> @@ -278,28 +278,6 @@ void PythonEditorWidget::updateInterpretersSelector() }); } -PythonEditorFactory::PythonEditorFactory() -{ - registerReplAction(&m_guard); - - setId(Constants::C_PYTHONEDITOR_ID); - setDisplayName(::Core::Tr::tr(Constants::C_EDITOR_DISPLAY_NAME)); - addMimeType(Constants::C_PY_MIMETYPE); - - setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor); - - setDocumentCreator([]() { return new PythonDocument; }); - setEditorWidgetCreator([]() { return new PythonEditorWidget; }); - setIndenterCreator(&createPythonIndenter); - setSyntaxHighlighterCreator(&createPythonHighlighter); - setCommentDefinition(CommentDefinition::HashStyle); - setParenthesesMatchingEnabled(true); - setCodeFoldingSupported(true); -} - PythonDocument::PythonDocument() : TextDocument(Constants::C_PYTHONEDITOR_ID) { @@ -331,4 +309,35 @@ void PythonDocument::updatePython(const FilePath &python) emit pythonUpdated(python); } +class PythonEditorFactory final : public TextEditorFactory +{ +public: + PythonEditorFactory() + { + setId(Constants::C_PYTHONEDITOR_ID); + setDisplayName(::Core::Tr::tr(Constants::C_EDITOR_DISPLAY_NAME)); + addMimeType(Constants::C_PY_MIMETYPE); + + setEditorActionHandlers(TextEditorActionHandler::Format + | TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::UnCollapseAll + | TextEditorActionHandler::FollowSymbolUnderCursor); + + setDocumentCreator([]() { return new PythonDocument; }); + setEditorWidgetCreator([]() { return new PythonEditorWidget; }); + setIndenterCreator(&createPythonIndenter); + setSyntaxHighlighterCreator(&createPythonHighlighter); + setCommentDefinition(CommentDefinition::HashStyle); + setParenthesesMatchingEnabled(true); + setCodeFoldingSupported(true); + } +}; + +void setupPythonEditorFactory(QObject *guard) +{ + static PythonEditorFactory thePythonEditorFactory; + + registerReplAction(guard); +} + } // Python::Internal diff --git a/src/plugins/python/pythoneditor.h b/src/plugins/python/pythoneditor.h index 6f6b30c1c3e..da498be0234 100644 --- a/src/plugins/python/pythoneditor.h +++ b/src/plugins/python/pythoneditor.h @@ -4,18 +4,9 @@ #pragma once #include <texteditor/textdocument.h> -#include <texteditor/texteditor.h> namespace Python::Internal { -class PythonEditorFactory : public TextEditor::TextEditorFactory -{ -public: - PythonEditorFactory(); -private: - QObject m_guard; -}; - class PythonDocument : public TextEditor::TextDocument { Q_OBJECT @@ -29,4 +20,6 @@ signals: void pythonUpdated(const Utils::FilePath &python); }; +void setupPythonEditorFactory(QObject *guard); + } // Python::Internal diff --git a/src/plugins/python/pythonplugin.cpp b/src/plugins/python/pythonplugin.cpp index 61f1cc2421c..29964b83255 100644 --- a/src/plugins/python/pythonplugin.cpp +++ b/src/plugins/python/pythonplugin.cpp @@ -40,7 +40,6 @@ QObject *pluginInstance() class PythonPluginPrivate { public: - PythonEditorFactory editorFactory; PythonOutputFormatterFactory outputFormatterFactory; PythonRunConfigurationFactory runConfigFactory; PySideBuildStepFactory buildStepFactory; @@ -72,6 +71,8 @@ private: { d = new PythonPluginPrivate; + setupPythonEditorFactory(this); + KitManager::setIrrelevantAspects(KitManager::irrelevantAspects() + QSet<Id>{PythonKitAspect::id()}); |