Commit eacaf93a authored by hjk's avatar hjk

TextEditor: Factory cosmetics

Pimpl, add some convenience setters.

Change-Id: I525c080179fddab6fe2bd2270505fdbf33e56be2
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 9ee73a4f
......@@ -98,6 +98,7 @@ JavaEditorFactory::JavaEditorFactory()
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection);
setCompletionAssistProvider(new JavaCompletionAssistProvider);
setMarksVisible(true);
}
} // namespace Internal
......
......@@ -144,7 +144,7 @@ QString CMakeEditor::contextHelpId() const
class CMakeEditorWidget : public TextEditorWidget
{
public:
CMakeEditorWidget();
CMakeEditorWidget() {}
private:
bool save(const QString &fileName = QString());
......@@ -152,11 +152,6 @@ private:
void contextMenuEvent(QContextMenuEvent *e);
};
CMakeEditorWidget::CMakeEditorWidget()
{
setCodeFoldingSupported(true);
}
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
{
showDefaultContextMenu(e, Constants::M_CONTEXT);
......@@ -283,6 +278,7 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeSettingsPage *settingsPage)
setDocumentCreator([]() { return new CMakeDocument; });
setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE));
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCodeFoldingSupported(true);
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider(settingsPage));
......
......@@ -150,9 +150,6 @@ void CppEditorWidget::finalizeInitialization()
d->m_cppEditorDocument = qobject_cast<CppEditorDocument *>(textDocument());
setLanguageSettingsId(CppTools::Constants::CPP_SETTINGS_ID);
setCodeFoldingSupported(true);
setMarksVisible(true);
setParenthesesMatchingEnabled(true);
setRevisionsVisible(true);
// function combo box sorting
......
......@@ -91,6 +91,9 @@ public:
setEditorCreator([]() { return new CppEditor; });
setAutoCompleterCreator([]() { return new CppAutoCompleter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCodeFoldingSupported(true);
setMarksVisible(true);
setParenthesesMatchingEnabled(true);
setEditorActionHandlers(TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
......
......@@ -137,9 +137,6 @@ GlslEditorWidget::GlslEditorWidget()
{
setAutoCompleter(new GlslCompleter);
m_outlineCombo = 0;
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_updateDocumentTimer.setSingleShot(true);
......@@ -344,6 +341,9 @@ GlslEditorFactory::GlslEditorFactory()
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(new GlslCompletionAssistProvider);
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
setEditorActionHandlers(TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
......
......@@ -45,26 +45,6 @@ using namespace TextEditor;
namespace PythonEditor {
namespace Internal {
//
// PythonEditorWidget
//
class PythonEditorWidget : public TextEditorWidget
{
public:
PythonEditorWidget()
{
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
}
};
//
// PythonEditorFactory
//
PythonEditorFactory::PythonEditorFactory()
{
setId(Constants::C_PYTHONEDITOR_ID);
......@@ -76,10 +56,12 @@ PythonEditorFactory::PythonEditorFactory()
| TextEditorActionHandler::UnCollapseAll);
setDocumentCreator([]() { return new TextDocument(Constants::C_PYTHONEDITOR_ID); });
setEditorWidgetCreator([]() { return new PythonEditorWidget; });
setIndenterCreator([]() { return new PythonIndenter; });
setSyntaxHighlighterCreator([]() { return new PythonHighlighter; });
setCommentStyle(Utils::CommentDefinition::HashStyle);
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
}
} // namespace Internal
......
......@@ -114,9 +114,6 @@ QmlJSEditorWidget::QmlJSEditorWidget()
m_firstSementicInfo = true;
m_findReferences = new FindReferences(this);
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
}
......@@ -920,6 +917,9 @@ QmlJSEditorFactory::QmlJSEditorFactory()
setEditorCreator([]() { return new QmlJSEditor; });
setAutoCompleterCreator([]() { return new AutoCompleter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
addHoverHandler(new QmlJSHoverHandler);
setCompletionAssistProvider(new QmlJSCompletionAssistProvider);
......
......@@ -232,7 +232,7 @@ class BaseTextEditorPrivate
public:
BaseTextEditorPrivate() {}
QPointer<TextEditorFactory> m_origin;
TextEditorFactoryPrivate *m_origin;
};
class TextEditorWidgetPrivate : public QObject
......@@ -7199,66 +7199,93 @@ void TextEditorWidget::setupAsPlainEditor()
updateEditorInfoBar(this);
}
IEditor *BaseTextEditor::duplicate()
{
// Use new standard setup if that's available.
if (d->m_origin)
return d->m_origin->duplicateTextEditor(this);
// If neither is sufficient, you need to implement 'YourEditor::duplicate'.
QTC_CHECK(false);
return 0;
}
//
// BaseTextEditorFactory
//
TextEditorFactory::TextEditorFactory(QObject *parent)
: IEditorFactory(parent)
namespace Internal {
class TextEditorFactoryPrivate
{
m_editorCreator = []() { return new BaseTextEditor; };
m_widgetCreator = []() { return new TextEditorWidget; };
m_commentStyle = CommentDefinition::NoStyle;
m_duplicatedSupported = true;
m_completionAssistProvider = 0;
}
public:
TextEditorFactoryPrivate(TextEditorFactory *parent) :
q(parent),
m_widgetCreator([]() { return new TextEditorWidget; }),
m_editorCreator([]() { return new BaseTextEditor; }),
m_commentStyle(CommentDefinition::NoStyle),
m_completionAssistProvider(0),
m_duplicatedSupported(true),
m_codeFoldingSupported(false),
m_paranthesesMatchinEnabled(false),
m_marksVisible(false)
{}
BaseTextEditor *duplicateTextEditor(BaseTextEditor *other)
{
BaseTextEditor *editor = createEditorHelper(other->editorWidget()->textDocumentPtr());
editor->editorWidget()->finalizeInitializationAfterDuplication(other->editorWidget());
return editor;
}
BaseTextEditor *createEditorHelper(const TextDocumentPtr &doc);
TextEditorFactory *q;
TextEditorFactory::DocumentCreator m_documentCreator;
TextEditorFactory::EditorWidgetCreator m_widgetCreator;
TextEditorFactory::EditorCreator m_editorCreator;
TextEditorFactory::AutoCompleterCreator m_autoCompleterCreator;
TextEditorFactory::IndenterCreator m_indenterCreator;
TextEditorFactory::SyntaxHighLighterCreator m_syntaxHighlighterCreator;
Utils::CommentDefinition::Style m_commentStyle;
QList<BaseHoverHandler *> m_hoverHandlers; // owned
CompletionAssistProvider * m_completionAssistProvider; // owned
bool m_duplicatedSupported;
bool m_codeFoldingSupported;
bool m_paranthesesMatchinEnabled;
bool m_marksVisible;
};
} /// namespace Internal
TextEditorFactory::TextEditorFactory(QObject *parent)
: IEditorFactory(parent), d(new TextEditorFactoryPrivate(this))
{}
TextEditorFactory::~TextEditorFactory()
{
qDeleteAll(m_hoverHandlers);
delete m_completionAssistProvider;
qDeleteAll(d->m_hoverHandlers);
delete d->m_completionAssistProvider;
delete d;
}
void TextEditorFactory::setDocumentCreator(const DocumentCreator &creator)
{
m_documentCreator = creator;
d->m_documentCreator = creator;
}
void TextEditorFactory::setEditorWidgetCreator(const EditorWidgetCreator &creator)
{
m_widgetCreator = creator;
d->m_widgetCreator = creator;
}
void TextEditorFactory::setEditorCreator(const EditorCreator &creator)
{
m_editorCreator = creator;
d->m_editorCreator = creator;
}
void TextEditorFactory::setIndenterCreator(const IndenterCreator &creator)
{
m_indenterCreator = creator;
d->m_indenterCreator = creator;
}
void TextEditorFactory::setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator)
{
m_syntaxHighlighterCreator = creator;
d->m_syntaxHighlighterCreator = creator;
}
void TextEditorFactory::setGenericSyntaxHighlighter(const QString &mimeType)
{
m_syntaxHighlighterCreator = [this, mimeType]() -> SyntaxHighlighter * {
d->m_syntaxHighlighterCreator = [this, mimeType]() -> SyntaxHighlighter * {
Highlighter *highlighter = new Highlighter;
setMimeTypeForHighlighter(highlighter, MimeDatabase::findByType(mimeType));
return highlighter;
......@@ -7267,7 +7294,7 @@ void TextEditorFactory::setGenericSyntaxHighlighter(const QString &mimeType)
void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &creator)
{
m_autoCompleterCreator = creator;
d->m_autoCompleterCreator = creator;
}
void TextEditorFactory::setEditorActionHandlers(Id contextId, uint optionalActions)
......@@ -7282,52 +7309,64 @@ void TextEditorFactory::setEditorActionHandlers(uint optionalActions)
void TextEditorFactory::addHoverHandler(BaseHoverHandler *handler)
{
m_hoverHandlers.append(handler);
d->m_hoverHandlers.append(handler);
}
void TextEditorFactory::setCompletionAssistProvider(CompletionAssistProvider *provider)
{
m_completionAssistProvider = provider;
d->m_completionAssistProvider = provider;
}
void TextEditorFactory::setCommentStyle(CommentDefinition::Style style)
{
m_commentStyle = style;
d->m_commentStyle = style;
}
void TextEditorFactory::setDuplicatedSupported(bool on)
{
m_duplicatedSupported = on;
d->m_duplicatedSupported = on;
}
BaseTextEditor *TextEditorFactory::duplicateTextEditor(BaseTextEditor *other)
void TextEditorFactory::setMarksVisible(bool on)
{
BaseTextEditor *editor = createEditorHelper(other->editorWidget()->textDocumentPtr());
editor->editorWidget()->finalizeInitializationAfterDuplication(other->editorWidget());
return editor;
d->m_marksVisible = on;
}
void TextEditorFactory::setCodeFoldingSupported(bool on)
{
d->m_codeFoldingSupported = on;
}
void TextEditorFactory::setParenthesesMatchingEnabled(bool on)
{
d->m_paranthesesMatchinEnabled = on;
}
IEditor *TextEditorFactory::createEditor()
{
TextDocumentPtr doc(m_documentCreator());
TextDocumentPtr doc(d->m_documentCreator());
if (m_indenterCreator)
doc->setIndenter(m_indenterCreator());
if (d->m_indenterCreator)
doc->setIndenter(d->m_indenterCreator());
if (m_syntaxHighlighterCreator)
doc->setSyntaxHighlighter(m_syntaxHighlighterCreator());
if (d->m_syntaxHighlighterCreator)
doc->setSyntaxHighlighter(d->m_syntaxHighlighterCreator());
doc->setCompletionAssistProvider(m_completionAssistProvider);
doc->setCompletionAssistProvider(d->m_completionAssistProvider);
return createEditorHelper(doc);
return d->createEditorHelper(doc);
}
BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &document)
BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentPtr &document)
{
TextEditorWidget *widget = m_widgetCreator();
widget->setMarksVisible(m_marksVisible);
widget->setParenthesesMatchingEnabled(m_paranthesesMatchinEnabled);
widget->setCodeFoldingSupported(m_codeFoldingSupported);
BaseTextEditor *editor = m_editorCreator();
editor->setDuplicateSupported(m_duplicatedSupported);
editor->addContext(id());
editor->addContext(q->id());
editor->d->m_origin = this;
editor->m_widget = widget;
......@@ -7342,13 +7381,13 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc
widget->d->m_codeAssistant.configure(widget);
widget->d->m_commentDefinition.setStyle(m_commentStyle);
connect(widget, &TextEditorWidget::activateEditor,
[editor]() { Core::EditorManager::activateEditor(editor); });
QObject::connect(widget, &TextEditorWidget::activateEditor,
[editor]() { Core::EditorManager::activateEditor(editor); });
widget->finalizeInitialization();
editor->finalizeInitialization();
connect(widget->d->m_cursorPositionLabel, &LineColumnLabel::clicked, [editor] {
QObject::connect(widget->d->m_cursorPositionLabel, &LineColumnLabel::clicked, [editor] {
EditorManager::activateEditor(editor, EditorManager::IgnoreNavigationHistory);
if (Core::Command *cmd = ActionManager::command(Core::Constants::GOTO)) {
if (QAction *act = cmd->action())
......@@ -7358,6 +7397,18 @@ BaseTextEditor *TextEditorFactory::createEditorHelper(const TextDocumentPtr &doc
return editor;
}
IEditor *BaseTextEditor::duplicate()
{
// Use new standard setup if that's available.
if (d->m_origin)
return d->m_origin->duplicateTextEditor(this);
// If neither is sufficient, you need to implement 'YourEditor::duplicate'.
QTC_CHECK(false);
return 0;
}
} // namespace TextEditor
#include "texteditor.moc"
......@@ -74,9 +74,10 @@ class CompletionAssistProvider;
typedef QList<RefactorMarker> RefactorMarkers;
namespace Internal {
class BaseTextEditorPrivate;
class TextEditorWidgetPrivate;
class TextEditorOverlay;
class BaseTextEditorPrivate;
class TextEditorFactoryPrivate;
class TextEditorWidgetPrivate;
class TextEditorOverlay;
}
class AutoCompleter;
......@@ -200,6 +201,7 @@ public:
private:
friend class TextEditorFactory;
friend class Internal::TextEditorFactoryPrivate;
Internal::BaseTextEditorPrivate *d;
};
......@@ -615,6 +617,7 @@ private:
Internal::TextEditorWidgetPrivate *d;
friend class BaseTextEditor;
friend class TextEditorFactory;
friend class Internal::TextEditorFactoryPrivate;
friend class Internal::TextEditorWidgetPrivate;
friend class Internal::TextEditorOverlay;
friend class RefactorOverlay;
......@@ -651,26 +654,16 @@ public:
void setCommentStyle(Utils::CommentDefinition::Style style);
void setDuplicatedSupported(bool on);
void setMarksVisible(bool on);
void setParenthesesMatchingEnabled(bool on);
void setCodeFoldingSupported(bool on);
Core::IEditor *createEditor();
private:
friend class BaseTextEditor;
friend class PlainTextEditorFactory;
BaseTextEditor *createEditorHelper(const TextDocumentPtr &doc);
BaseTextEditor *duplicateTextEditor(BaseTextEditor *);
DocumentCreator m_documentCreator;
EditorWidgetCreator m_widgetCreator;
EditorCreator m_editorCreator;
AutoCompleterCreator m_autoCompleterCreator;
IndenterCreator m_indenterCreator;
SyntaxHighLighterCreator m_syntaxHighlighterCreator;
Utils::CommentDefinition::Style m_commentStyle;
QList<BaseHoverHandler *> m_hoverHandlers; // owned
CompletionAssistProvider * m_completionAssistProvider; // owned
bool m_duplicatedSupported;
Internal::TextEditorFactoryPrivate *d;
};
} // namespace TextEditor
......
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