forked from qt-creator/qt-creator
TextEditor: Re-organize Plain text editor setup
Change-Id: I202e66a9cd295a85e3eea31177280e2c5d409ced Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user