summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/plaintexteditorfactory.cpp
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-08-22 19:14:48 +0200
committerhjk <hjk121@nokiamail.com>2014-08-25 15:09:29 +0200
commitf9f5fdcf2b6563d5bbbf61a1a5987bf28cc67825 (patch)
tree8f32eda94bf17607f0a8fbf97f6635bc067b5b72 /src/plugins/texteditor/plaintexteditorfactory.cpp
parent550db7d1d118444f33367f50519e43fccee33f03 (diff)
downloadqt-creator-f9f5fdcf2b6563d5bbbf61a1a5987bf28cc67825.tar.gz
TextEditor: Re-organize Plain text editor setup
Change-Id: I202e66a9cd295a85e3eea31177280e2c5d409ced Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Diffstat (limited to 'src/plugins/texteditor/plaintexteditorfactory.cpp')
-rw-r--r--src/plugins/texteditor/plaintexteditorfactory.cpp64
1 files changed, 18 insertions, 46 deletions
diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp
index 40d6e5daa5..33e8de572e 100644
--- a/src/plugins/texteditor/plaintexteditorfactory.cpp
+++ b/src/plugins/texteditor/plaintexteditorfactory.cpp
@@ -38,64 +38,36 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/infobar.h>
+#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <QDebug>
-using namespace TextEditor;
-using namespace TextEditor::Internal;
+namespace TextEditor {
+namespace Internal {
-PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
- : Core::IEditorFactory(parent)
+class PlainTextEditorWidget : public BaseTextEditorWidget
+{
+public:
+ PlainTextEditorWidget() {}
+ void finalizeInitialization() { setupAsPlainEditor(); }
+};
+
+PlainTextEditorFactory::PlainTextEditorFactory()
{
setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME));
addMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
- new TextEditorActionHandler(this,
- Core::Constants::K_DEFAULT_TEXT_EDITOR_ID,
+ setDocumentCreator([]() { return new BaseTextDocument(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); });
+ setEditorWidgetCreator([]() { return new PlainTextEditorWidget; });
+ setIndenterCreator([]() { return new NormalIndenter; });
+
+ setEditorActionHandlers(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID,
TextEditorActionHandler::Format |
TextEditorActionHandler::UnCommentSelection |
TextEditorActionHandler::UnCollapseAll);
}
-Core::IEditor *PlainTextEditorFactory::createEditor()
-{
- BaseTextDocumentPtr doc(new BaseTextDocument(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID));
- doc->setIndenter(new NormalIndenter);
- auto widget = new BaseTextEditorWidget;
- widget->setTextDocument(doc);
- widget->setupAsPlainEditor();
- connect(widget, &BaseTextEditorWidget::configured,
- this, &PlainTextEditorFactory::updateEditorInfoBar);
- updateEditorInfoBar(widget->editor());
- return widget->editor();
-}
-
-/*!
- * Test if syntax highlighter is available (or unneeded) for \a editor.
- * If not found, show a warning with a link to the relevant settings page.
- */
-void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
-{
- BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor);
- if (textEditor) {
- Core::IDocument *file = editor->document();
- if (!file)
- return;
- BaseTextEditorWidget *widget = textEditor->editorWidget();
- Core::Id infoSyntaxDefinition(Constants::INFO_SYNTAX_DEFINITION);
- Core::InfoBar *infoBar = file->infoBar();
- if (!widget->isMissingSyntaxDefinition()) {
- infoBar->removeInfo(infoSyntaxDefinition);
- } else if (infoBar->canInfoBeAdded(infoSyntaxDefinition)) {
- Core::InfoBarEntry info(infoSyntaxDefinition,
- tr("A highlight definition was not found for this file. "
- "Would you like to try to find one?"),
- Core::InfoBarEntry::GlobalSuppressionEnabled);
- info.setCustomButtonInfo(tr("Show Highlighter Options..."),
- widget, SLOT(acceptMissingSyntaxDefinitionInfo()));
- infoBar->addInfo(info);
- }
- }
-}
+} // namespace Internal
+} // namespace TextEditor