forked from qt-creator/qt-creator
Python: Use new plugin items setup pattern for PythonEditor
Change-Id: Ie8516960a106ddeff415b6412d9af66f7d2f0f36 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#include "pythonindenter.h"
|
#include "pythonindenter.h"
|
||||||
#include "pythonkitaspect.h"
|
#include "pythonkitaspect.h"
|
||||||
#include "pythonlanguageclient.h"
|
#include "pythonlanguageclient.h"
|
||||||
#include "pythonplugin.h"
|
|
||||||
#include "pythonsettings.h"
|
#include "pythonsettings.h"
|
||||||
#include "pythontr.h"
|
#include "pythontr.h"
|
||||||
#include "pythonutils.h"
|
#include "pythonutils.h"
|
||||||
@@ -28,6 +27,7 @@
|
|||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
|
#include <texteditor/texteditor.h>
|
||||||
#include <texteditor/texteditoractionhandler.h>
|
#include <texteditor/texteditoractionhandler.h>
|
||||||
|
|
||||||
#include <utils/stylehelper.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()
|
PythonDocument::PythonDocument()
|
||||||
: TextDocument(Constants::C_PYTHONEDITOR_ID)
|
: TextDocument(Constants::C_PYTHONEDITOR_ID)
|
||||||
{
|
{
|
||||||
@@ -331,4 +309,35 @@ void PythonDocument::updatePython(const FilePath &python)
|
|||||||
emit pythonUpdated(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
|
} // Python::Internal
|
||||||
|
|||||||
@@ -4,18 +4,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditor.h>
|
|
||||||
|
|
||||||
namespace Python::Internal {
|
namespace Python::Internal {
|
||||||
|
|
||||||
class PythonEditorFactory : public TextEditor::TextEditorFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PythonEditorFactory();
|
|
||||||
private:
|
|
||||||
QObject m_guard;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PythonDocument : public TextEditor::TextDocument
|
class PythonDocument : public TextEditor::TextDocument
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -29,4 +20,6 @@ signals:
|
|||||||
void pythonUpdated(const Utils::FilePath &python);
|
void pythonUpdated(const Utils::FilePath &python);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void setupPythonEditorFactory(QObject *guard);
|
||||||
|
|
||||||
} // Python::Internal
|
} // Python::Internal
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ QObject *pluginInstance()
|
|||||||
class PythonPluginPrivate
|
class PythonPluginPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PythonEditorFactory editorFactory;
|
|
||||||
PythonOutputFormatterFactory outputFormatterFactory;
|
PythonOutputFormatterFactory outputFormatterFactory;
|
||||||
PythonRunConfigurationFactory runConfigFactory;
|
PythonRunConfigurationFactory runConfigFactory;
|
||||||
PySideBuildStepFactory buildStepFactory;
|
PySideBuildStepFactory buildStepFactory;
|
||||||
@@ -72,6 +71,8 @@ private:
|
|||||||
{
|
{
|
||||||
d = new PythonPluginPrivate;
|
d = new PythonPluginPrivate;
|
||||||
|
|
||||||
|
setupPythonEditorFactory(this);
|
||||||
|
|
||||||
KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()
|
KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()
|
||||||
+ QSet<Id>{PythonKitAspect::id()});
|
+ QSet<Id>{PythonKitAspect::id()});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user