diff options
author | hjk <hjk121@nokiamail.com> | 2014-08-22 12:14:18 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2014-08-22 15:32:27 +0200 |
commit | 984e2e3cacd45280b9403b8754ad4437082ec69f (patch) | |
tree | 04a7602fdc5e626f8a4e4409494a014d09ec3122 /src/plugins/pythoneditor/pythoneditor.cpp | |
parent | 5d41421533bbccad172f106fa235147a31cf3aad (diff) | |
download | qt-creator-984e2e3cacd45280b9403b8754ad4437082ec69f.tar.gz |
Python: Make editor factory use new BaseEditorFactory
Change-Id: I6ec02161d5248592ff13eb1cdfcaae0bf2090d6d
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Diffstat (limited to 'src/plugins/pythoneditor/pythoneditor.cpp')
-rw-r--r-- | src/plugins/pythoneditor/pythoneditor.cpp | 84 |
1 files changed, 38 insertions, 46 deletions
diff --git a/src/plugins/pythoneditor/pythoneditor.cpp b/src/plugins/pythoneditor/pythoneditor.cpp index a491358c50..1f05378866 100644 --- a/src/plugins/pythoneditor/pythoneditor.cpp +++ b/src/plugins/pythoneditor/pythoneditor.cpp @@ -53,77 +53,69 @@ using namespace TextEditor; namespace PythonEditor { namespace Internal { -////////////////////////////////////////////////////////////////// // // PythonEditor // -////////////////////////////////////////////////////////////////// -PythonEditor::PythonEditor() +class PythonEditor : public TextEditor::BaseTextEditor { - addContext(Constants::C_PYTHONEDITOR_ID); - setDuplicateSupported(true); - setCommentStyle(Utils::CommentDefinition::HashStyle); - setEditorCreator([]() { return new PythonEditor; }); - setWidgetCreator([]() { return new PythonEditorWidget; }); - - setDocumentCreator([]() -> BaseTextDocument * { - auto doc = new BaseTextDocument(Constants::C_PYTHONEDITOR_ID); - doc->setIndenter(new PythonIndenter); - new PythonHighlighter(doc); - return doc; - }); -} - -bool PythonEditor::open(QString *errorString, - const QString &fileName, - const QString &realFileName) -{ - Core::MimeType mimeType = Core::MimeDatabase::findByFile(QFileInfo(fileName)); - textDocument()->setMimeType(mimeType.type()); - return BaseTextEditor::open(errorString, fileName, realFileName); -} +public: + PythonEditor() + { + addContext(Constants::C_PYTHONEDITOR_ID); + setDuplicateSupported(true); + setCommentStyle(Utils::CommentDefinition::HashStyle); + } + + bool open(QString *errorString, const QString &fileName, const QString &realFileName) + { + Core::MimeType mimeType = Core::MimeDatabase::findByFile(QFileInfo(fileName)); + textDocument()->setMimeType(mimeType.type()); + return BaseTextEditor::open(errorString, fileName, realFileName); + } +}; -////////////////////////////////////////////////////////////////// // // PythonEditorWidget // -////////////////////////////////////////////////////////////////// -PythonEditorWidget::PythonEditorWidget() +class PythonEditorWidget : public TextEditor::BaseTextEditorWidget { - setParenthesesMatchingEnabled(true); - setMarksVisible(true); - setCodeFoldingSupported(true); -} +public: + PythonEditorWidget() + { + setParenthesesMatchingEnabled(true); + setMarksVisible(true); + setCodeFoldingSupported(true); + } -BaseTextEditor *PythonEditorWidget::createEditor() -{ - QTC_ASSERT("should not happen anymore" && false, return 0); -} + TextEditor::BaseTextEditor *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; + setEditorActionHandlers(TextEditorActionHandler::Format + | TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::UnCollapseAll); + + setDocumentCreator([]() { return new BaseTextDocument(Constants::C_PYTHONEDITOR_ID); }); + setEditorWidgetCreator([]() { return new PythonEditorWidget; }); + setEditorCreator([]() { return new PythonEditor; }); + setIndenterCreator([]() { return new PythonIndenter; }); + setSyntaxHighlighterCreator([]() { return new PythonHighlighter; }); } } // namespace Internal |