From c35e9286506508002cf0c2ed7fa90d9ba57591d1 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 20 Aug 2014 15:05:32 +0200 Subject: PythonEditor: Convert to new editor setup scheme Change-Id: Ibf886c891bb1884d6bc3c08bfe83c4978d17b2f6 Reviewed-by: Christian Stenger --- src/plugins/pythoneditor/pythoneditor.cpp | 85 ++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 14 deletions(-) (limited to 'src/plugins/pythoneditor/pythoneditor.cpp') diff --git a/src/plugins/pythoneditor/pythoneditor.cpp b/src/plugins/pythoneditor/pythoneditor.cpp index 367ccb6f77..a491358c50 100644 --- a/src/plugins/pythoneditor/pythoneditor.cpp +++ b/src/plugins/pythoneditor/pythoneditor.cpp @@ -27,37 +27,52 @@ ** ****************************************************************************/ -/** - \class PyEditor::Editor implements interface Core::IEditor - This editor makes possible to edit Python source files - */ - #include "pythoneditor.h" #include "pythoneditorconstants.h" #include "pythoneditorplugin.h" -#include "pythoneditorwidget.h" +#include "tools/pythonindenter.h" +#include "tools/pythonhighlighter.h" +#include #include #include + +#include +#include #include +#include +#include +#include + +#include #include +using namespace TextEditor; + namespace PythonEditor { namespace Internal { +////////////////////////////////////////////////////////////////// +// +// PythonEditor +// +////////////////////////////////////////////////////////////////// + PythonEditor::PythonEditor() { - setContext(Core::Context(Constants::C_PYTHONEDITOR_ID, - TextEditor::Constants::C_TEXTEDITOR)); + addContext(Constants::C_PYTHONEDITOR_ID); setDuplicateSupported(true); setCommentStyle(Utils::CommentDefinition::HashStyle); -} + setEditorCreator([]() { return new PythonEditor; }); + setWidgetCreator([]() { return new PythonEditorWidget; }); -Core::IEditor *PythonEditor::duplicate() -{ - PythonEditorWidget *widget = new PythonEditorWidget(editorWidget()->textDocumentPtr()); - return widget->editor(); + setDocumentCreator([]() -> BaseTextDocument * { + auto doc = new BaseTextDocument(Constants::C_PYTHONEDITOR_ID); + doc->setIndenter(new PythonIndenter); + new PythonHighlighter(doc); + return doc; + }); } bool PythonEditor::open(QString *errorString, @@ -66,7 +81,49 @@ bool PythonEditor::open(QString *errorString, { Core::MimeType mimeType = Core::MimeDatabase::findByFile(QFileInfo(fileName)); textDocument()->setMimeType(mimeType.type()); - return TextEditor::BaseTextEditor::open(errorString, fileName, realFileName); + return BaseTextEditor::open(errorString, fileName, realFileName); +} + + +////////////////////////////////////////////////////////////////// +// +// PythonEditorWidget +// +////////////////////////////////////////////////////////////////// + +PythonEditorWidget::PythonEditorWidget() +{ + setParenthesesMatchingEnabled(true); + setMarksVisible(true); + setCodeFoldingSupported(true); +} + +BaseTextEditor *PythonEditorWidget::createEditor() +{ + QTC_ASSERT("should not happen anymore" && false, return 0); +} + + +////////////////////////////////////////////////////////////////// +// +// PythonEditorFactory +// +////////////////////////////////////////////////////////////////// + +PythonEditorFactory::PythonEditorFactory() +{ + setId(Constants::C_PYTHONEDITOR_ID); + setDisplayName(tr(Constants::C_EDITOR_DISPLAY_NAME)); + addMimeType(QLatin1String(Constants::C_PY_MIMETYPE)); + new TextEditorActionHandler(this, Constants::C_PYTHONEDITOR_ID, + TextEditorActionHandler::Format + | TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::UnCollapseAll); +} + +Core::IEditor *PythonEditorFactory::createEditor() +{ + return new PythonEditor; } } // namespace Internal -- cgit v1.2.1