Commit 984e2e3c authored by hjk's avatar hjk
Browse files

Python: Make editor factory use new BaseEditorFactory



Change-Id: I6ec02161d5248592ff13eb1cdfcaae0bf2090d6d
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 5d414215
...@@ -53,77 +53,69 @@ using namespace TextEditor; ...@@ -53,77 +53,69 @@ using namespace TextEditor;
namespace PythonEditor { namespace PythonEditor {
namespace Internal { namespace Internal {
//////////////////////////////////////////////////////////////////
// //
// PythonEditor // PythonEditor
// //
//////////////////////////////////////////////////////////////////
PythonEditor::PythonEditor() class PythonEditor : public TextEditor::BaseTextEditor
{ {
addContext(Constants::C_PYTHONEDITOR_ID); public:
setDuplicateSupported(true); PythonEditor()
setCommentStyle(Utils::CommentDefinition::HashStyle); {
setEditorCreator([]() { return new PythonEditor; }); addContext(Constants::C_PYTHONEDITOR_ID);
setWidgetCreator([]() { return new PythonEditorWidget; }); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setDocumentCreator([]() -> BaseTextDocument * { }
auto doc = new BaseTextDocument(Constants::C_PYTHONEDITOR_ID);
doc->setIndenter(new PythonIndenter); bool open(QString *errorString, const QString &fileName, const QString &realFileName)
new PythonHighlighter(doc); {
return doc; Core::MimeType mimeType = Core::MimeDatabase::findByFile(QFileInfo(fileName));
}); textDocument()->setMimeType(mimeType.type());
} return BaseTextEditor::open(errorString, fileName, realFileName);
}
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);
}
//////////////////////////////////////////////////////////////////
// //
// PythonEditorWidget // PythonEditorWidget
// //
//////////////////////////////////////////////////////////////////
PythonEditorWidget::PythonEditorWidget() class PythonEditorWidget : public TextEditor::BaseTextEditorWidget
{ {
setParenthesesMatchingEnabled(true); public:
setMarksVisible(true); PythonEditorWidget()
setCodeFoldingSupported(true); {
} setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
}
BaseTextEditor *PythonEditorWidget::createEditor() TextEditor::BaseTextEditor *createEditor()
{ {
QTC_ASSERT("should not happen anymore" && false, return 0); QTC_ASSERT("should not happen anymore" && false, return 0);
} }
};
//////////////////////////////////////////////////////////////////
// //
// PythonEditorFactory // PythonEditorFactory
// //
//////////////////////////////////////////////////////////////////
PythonEditorFactory::PythonEditorFactory() PythonEditorFactory::PythonEditorFactory()
{ {
setId(Constants::C_PYTHONEDITOR_ID); setId(Constants::C_PYTHONEDITOR_ID);
setDisplayName(tr(Constants::C_EDITOR_DISPLAY_NAME)); setDisplayName(tr(Constants::C_EDITOR_DISPLAY_NAME));
addMimeType(QLatin1String(Constants::C_PY_MIMETYPE)); addMimeType(QLatin1String(Constants::C_PY_MIMETYPE));
new TextEditorActionHandler(this, Constants::C_PYTHONEDITOR_ID,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll);
}
Core::IEditor *PythonEditorFactory::createEditor() setEditorActionHandlers(TextEditorActionHandler::Format
{ | TextEditorActionHandler::UnCommentSelection
return new PythonEditor; | 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 } // namespace Internal
......
...@@ -31,48 +31,16 @@ ...@@ -31,48 +31,16 @@
#define PYTHONEDITOR_EDITOR_H #define PYTHONEDITOR_EDITOR_H
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
namespace PythonEditor { namespace PythonEditor {
namespace Internal { namespace Internal {
class PythonEditorFactory : public Core::IEditorFactory class PythonEditorFactory : public TextEditor::BaseTextEditorFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
PythonEditorFactory(); PythonEditorFactory();
/**
Creates and initializes new editor widget
*/
Core::IEditor *createEditor();
};
class PythonEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
PythonEditor();
/**
Opens file for editing, actual work performed by base class
*/
bool open(QString *errorString,
const QString &fileName,
const QString &realFileName);
};
class PythonEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
PythonEditorWidget();
protected:
TextEditor::BaseTextEditor *createEditor();
}; };
} // namespace Internal } // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment