forked from qt-creator/qt-creator
TextEditor: Use new setup pattern for markdown and json editor
And remove the now-empty plugin pimpl. Change-Id: Ie00b747a4a41bc6efc84ea43db81a71e8364df3d Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "autocompleter.h"
|
#include "autocompleter.h"
|
||||||
#include "textdocument.h"
|
#include "textdocument.h"
|
||||||
|
#include "texteditor.h"
|
||||||
#include "texteditoractionhandler.h"
|
#include "texteditoractionhandler.h"
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
#include "textindenter.h"
|
#include "textindenter.h"
|
||||||
@@ -149,19 +150,28 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonEditorFactory::JsonEditorFactory()
|
class JsonEditorFactory final : public TextEditorFactory
|
||||||
{
|
{
|
||||||
setId(JSON_EDITOR_ID);
|
public:
|
||||||
setDisplayName(Tr::tr("JSON Editor"));
|
JsonEditorFactory()
|
||||||
addMimeType(Utils::Constants::JSON_MIMETYPE);
|
{
|
||||||
|
setId(JSON_EDITOR_ID);
|
||||||
|
setDisplayName(Tr::tr("JSON Editor"));
|
||||||
|
addMimeType(Utils::Constants::JSON_MIMETYPE);
|
||||||
|
|
||||||
setEditorCreator([] { return new BaseTextEditor; });
|
setEditorCreator([] { return new BaseTextEditor; });
|
||||||
setEditorWidgetCreator([] { return new TextEditorWidget; });
|
setEditorWidgetCreator([] { return new TextEditorWidget; });
|
||||||
setDocumentCreator([] { return new TextDocument(JSON_EDITOR_ID); });
|
setDocumentCreator([] { return new TextDocument(JSON_EDITOR_ID); });
|
||||||
setAutoCompleterCreator([] { return new JsonAutoCompleter; });
|
setAutoCompleterCreator([] { return new JsonAutoCompleter; });
|
||||||
setIndenterCreator([](QTextDocument *doc) { return new JsonIndenter(doc); });
|
setIndenterCreator([](QTextDocument *doc) { return new JsonIndenter(doc); });
|
||||||
setEditorActionHandlers(TextEditorActionHandler::Format);
|
setEditorActionHandlers(TextEditorActionHandler::Format);
|
||||||
setUseGenericHighlighter(true);
|
setUseGenericHighlighter(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setupJsonEditor()
|
||||||
|
{
|
||||||
|
static JsonEditorFactory theJsonEditorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TextEditor::Internal
|
} // TextEditor::Internal
|
||||||
|
|||||||
@@ -3,14 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "texteditor.h"
|
|
||||||
|
|
||||||
namespace TextEditor::Internal {
|
namespace TextEditor::Internal {
|
||||||
|
|
||||||
class JsonEditorFactory final : public TextEditorFactory
|
void setupJsonEditor();
|
||||||
{
|
|
||||||
public:
|
|
||||||
JsonEditorFactory();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // TextEditor::Internal
|
} // TextEditor::Internal
|
||||||
|
|||||||
@@ -8,13 +8,18 @@
|
|||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
#include <aggregation/aggregate.h>
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/coreplugintr.h>
|
#include <coreplugin/coreplugintr.h>
|
||||||
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/minisplitter.h>
|
#include <coreplugin/minisplitter.h>
|
||||||
|
|
||||||
|
#include <texteditor/texteditoractionhandler.h>
|
||||||
|
|
||||||
#include <utils/ranges.h>
|
#include <utils/ranges.h>
|
||||||
|
#include <utils/parameteraction.h>
|
||||||
#include <utils/qtcsettings.h>
|
#include <utils/qtcsettings.h>
|
||||||
#include <utils/qtcsettings.h>
|
#include <utils/qtcsettings.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
@@ -491,6 +496,22 @@ private:
|
|||||||
std::optional<QPoint> m_previewRestoreScrollPosition;
|
std::optional<QPoint> m_previewRestoreScrollPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MarkdownEditorFactory final : public IEditorFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MarkdownEditorFactory();
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextEditorActionHandler m_actionHandler;
|
||||||
|
Action m_emphasisAction;
|
||||||
|
Action m_strongAction;
|
||||||
|
Action m_inlineCodeAction;
|
||||||
|
Action m_linkAction;
|
||||||
|
Action m_toggleEditorAction;
|
||||||
|
Action m_togglePreviewAction;
|
||||||
|
Action m_swapAction;
|
||||||
|
};
|
||||||
|
|
||||||
MarkdownEditorFactory::MarkdownEditorFactory()
|
MarkdownEditorFactory::MarkdownEditorFactory()
|
||||||
: m_actionHandler(MARKDOWNVIEWER_ID,
|
: m_actionHandler(MARKDOWNVIEWER_ID,
|
||||||
MARKDOWNVIEWER_TEXT_CONTEXT,
|
MARKDOWNVIEWER_TEXT_CONTEXT,
|
||||||
@@ -663,6 +684,11 @@ void MarkdownEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupMarkdownEditor()
|
||||||
|
{
|
||||||
|
static MarkdownEditorFactory theMarkdownEditorFactory;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TextEditor::Internal
|
} // namespace TextEditor::Internal
|
||||||
|
|
||||||
#include "markdowneditor.moc"
|
#include "markdowneditor.moc"
|
||||||
|
|||||||
@@ -3,28 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
|
||||||
|
|
||||||
#include <texteditor/texteditoractionhandler.h>
|
|
||||||
|
|
||||||
#include <utils/parameteraction.h>
|
|
||||||
|
|
||||||
namespace TextEditor::Internal {
|
namespace TextEditor::Internal {
|
||||||
|
|
||||||
class MarkdownEditorFactory final : public Core::IEditorFactory
|
void setupMarkdownEditor();
|
||||||
{
|
|
||||||
public:
|
|
||||||
MarkdownEditorFactory();
|
|
||||||
|
|
||||||
private:
|
|
||||||
TextEditor::TextEditorActionHandler m_actionHandler;
|
|
||||||
Utils::Action m_emphasisAction;
|
|
||||||
Utils::Action m_strongAction;
|
|
||||||
Utils::Action m_inlineCodeAction;
|
|
||||||
Utils::Action m_linkAction;
|
|
||||||
Utils::Action m_toggleEditorAction;
|
|
||||||
Utils::Action m_togglePreviewAction;
|
|
||||||
Utils::Action m_swapAction;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // TextEditor::Internal
|
} // TextEditor::Internal
|
||||||
|
|||||||
@@ -64,25 +64,12 @@ const char kCurrentDocumentColumnCount[] = "CurrentDocument:ColumnCount";
|
|||||||
const char kCurrentDocumentFontSize[] = "CurrentDocument:FontSize";
|
const char kCurrentDocumentFontSize[] = "CurrentDocument:FontSize";
|
||||||
const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor";
|
const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor";
|
||||||
|
|
||||||
class TextEditorPluginPrivate : public QObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MarkdownEditorFactory markdownEditorFactory;
|
|
||||||
JsonEditorFactory jsonEditorFactory;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TextEditorPlugin final : public ExtensionSystem::IPlugin
|
class TextEditorPlugin final : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TextEditor.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TextEditor.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~TextEditorPlugin() final
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
d = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ShutdownFlag aboutToShutdown() final;
|
ShutdownFlag aboutToShutdown() final;
|
||||||
|
|
||||||
void initialize() final;
|
void initialize() final;
|
||||||
@@ -93,8 +80,6 @@ public:
|
|||||||
void updateCurrentSelection(const QString &text);
|
void updateCurrentSelection(const QString &text);
|
||||||
|
|
||||||
void createStandardContextMenu();
|
void createStandardContextMenu();
|
||||||
|
|
||||||
TextEditorPluginPrivate *d = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void TextEditorPlugin::initialize()
|
void TextEditorPlugin::initialize()
|
||||||
@@ -122,7 +107,8 @@ void TextEditorPlugin::initialize()
|
|||||||
setupFindInCurrentFile();
|
setupFindInCurrentFile();
|
||||||
setupFindInOpenFiles();
|
setupFindInOpenFiles();
|
||||||
|
|
||||||
d = new TextEditorPluginPrivate;
|
setupMarkdownEditor();
|
||||||
|
setupJsonEditor();
|
||||||
|
|
||||||
Context context(TextEditor::Constants::C_TEXTEDITOR);
|
Context context(TextEditor::Constants::C_TEXTEDITOR);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user