diff options
| author | hjk <hjk121@nokiamail.com> | 2014-08-20 15:05:32 +0200 |
|---|---|---|
| committer | hjk <hjk121@nokiamail.com> | 2014-08-20 15:15:26 +0200 |
| commit | c35e9286506508002cf0c2ed7fa90d9ba57591d1 (patch) | |
| tree | 94429b297bb82e6439c1d096adb21891ff609f2e /src/plugins/pythoneditor/pythoneditor.cpp | |
| parent | ddf1de387bcba5472d7f2b3d41abf57191eb08f2 (diff) | |
| download | qt-creator-c35e9286506508002cf0c2ed7fa90d9ba57591d1.tar.gz | |
PythonEditor: Convert to new editor setup scheme
Change-Id: Ibf886c891bb1884d6bc3c08bfe83c4978d17b2f6
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Diffstat (limited to 'src/plugins/pythoneditor/pythoneditor.cpp')
| -rw-r--r-- | src/plugins/pythoneditor/pythoneditor.cpp | 85 |
1 files changed, 71 insertions, 14 deletions
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 <coreplugin/editormanager/editormanager.h> #include <coreplugin/icore.h> #include <coreplugin/mimedatabase.h> + +#include <texteditor/texteditoractionhandler.h> +#include <texteditor/fontsettings.h> #include <texteditor/texteditorconstants.h> +#include <texteditor/basetextdocument.h> +#include <texteditor/indenter.h> +#include <texteditor/autocompleter.h> + +#include <utils/qtcassert.h> #include <QFileInfo> +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 |
