TextEditor: Move comment definitions back to *Widget

Only used there, and avoids back-links to editors.

Change-Id: I81206057ce89d42aef7febb840cf9e44b869df0e
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-09-01 16:16:44 +02:00
parent b9f861f1cb
commit 6775e623ee
12 changed files with 35 additions and 38 deletions

View File

@@ -50,6 +50,11 @@ void CommentDefinition::setStyle(Style style)
multiLineStart.clear(); multiLineStart.clear();
multiLineEnd.clear(); multiLineEnd.clear();
break; break;
case NoStyle:
singleLine.clear();
multiLineStart.clear();
multiLineEnd.clear();
break;
} }
} }

View File

@@ -45,7 +45,7 @@ class QTCREATOR_UTILS_EXPORT CommentDefinition
public: public:
CommentDefinition(); CommentDefinition();
enum Style { CppStyle, HashStyle }; enum Style { NoStyle, CppStyle, HashStyle };
void setStyle(Style style); void setStyle(Style style);
bool isValid() const; bool isValid() const;

View File

@@ -59,7 +59,6 @@ public:
{ {
addContext(Constants::C_JAVA_EDITOR); addContext(Constants::C_JAVA_EDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
} }
}; };
@@ -112,6 +111,7 @@ JavaEditorFactory::JavaEditorFactory()
setDocumentCreator([]() { return new JavaDocument; }); setDocumentCreator([]() { return new JavaDocument; });
setAutoCompleterCreator([]() { return new JavaAutoCompleter; }); setAutoCompleterCreator([]() { return new JavaAutoCompleter; });
setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE)); setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE));
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_JAVA_EDITOR, setEditorActionHandlers(Constants::C_JAVA_EDITOR,
TextEditor::TextEditorActionHandler::UnCommentSelection); TextEditor::TextEditorActionHandler::UnCommentSelection);

View File

@@ -67,7 +67,6 @@ CMakeEditor::CMakeEditor()
{ {
addContext(Constants::C_CMAKEEDITOR); addContext(Constants::C_CMAKEEDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
} }
@@ -288,6 +287,7 @@ CMakeEditorFactory::CMakeEditorFactory()
setEditorWidgetCreator([]() { return new CMakeEditorWidget; }); setEditorWidgetCreator([]() { return new CMakeEditorWidget; });
setDocumentCreator([]() { return new CMakeDocument; }); setDocumentCreator([]() { return new CMakeDocument; });
setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE)); setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE));
setCommentStyle(Utils::CommentDefinition::HashStyle);
setEditorActionHandlers(Constants::C_CMAKEEDITOR, setEditorActionHandlers(Constants::C_CMAKEEDITOR,
TextEditorActionHandler::UnCommentSelection TextEditorActionHandler::UnCommentSelection

View File

@@ -96,7 +96,6 @@ CppEditor::CppEditor()
m_context.add(ProjectExplorer::Constants::LANG_CXX); m_context.add(ProjectExplorer::Constants::LANG_CXX);
m_context.add(TextEditor::Constants::C_TEXTEDITOR); m_context.add(TextEditor::Constants::C_TEXTEDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider([this] () -> TextEditor::CompletionAssistProvider * { setCompletionAssistProvider([this] () -> TextEditor::CompletionAssistProvider * {
if (CppEditorDocument *document = qobject_cast<CppEditorDocument *>(textDocument())) if (CppEditorDocument *document = qobject_cast<CppEditorDocument *>(textDocument()))
return document->completionAssistProvider(); return document->completionAssistProvider();

View File

@@ -91,6 +91,7 @@ public:
setEditorWidgetCreator([]() { return new CppEditorWidget; }); setEditorWidgetCreator([]() { return new CppEditorWidget; });
setEditorCreator([]() { return new CppEditor; }); setEditorCreator([]() { return new CppEditor; });
setAutoCompleterCreator([]() { return new CppAutoCompleter; }); setAutoCompleterCreator([]() { return new CppAutoCompleter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_CPPEDITOR, setEditorActionHandlers(Constants::C_CPPEDITOR,
TextEditorActionHandler::Format TextEditorActionHandler::Format

View File

@@ -336,7 +336,6 @@ public:
{ {
addContext(Constants::C_GLSLEDITOR_ID); addContext(Constants::C_GLSLEDITOR_ID);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
} }
@@ -368,6 +367,7 @@ GlslEditorFactory::GlslEditorFactory()
setEditorCreator([]() { return new GlslEditor; }); setEditorCreator([]() { return new GlslEditor; });
setIndenterCreator([]() { return new GlslIndenter; }); setIndenterCreator([]() { return new GlslIndenter; });
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; }); setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_GLSLEDITOR_ID, setEditorActionHandlers(Constants::C_GLSLEDITOR_ID,
TextEditorActionHandler::Format TextEditorActionHandler::Format

View File

@@ -64,7 +64,6 @@ public:
{ {
addContext(Constants::C_PYTHONEDITOR_ID); addContext(Constants::C_PYTHONEDITOR_ID);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
} }
bool open(QString *errorString, const QString &fileName, const QString &realFileName) bool open(QString *errorString, const QString &fileName, const QString &realFileName)
@@ -111,6 +110,7 @@ PythonEditorFactory::PythonEditorFactory()
setEditorCreator([]() { return new PythonEditor; }); setEditorCreator([]() { return new PythonEditor; });
setIndenterCreator([]() { return new PythonIndenter; }); setIndenterCreator([]() { return new PythonIndenter; });
setSyntaxHighlighterCreator([]() { return new PythonHighlighter; }); setSyntaxHighlighterCreator([]() { return new PythonHighlighter; });
setCommentStyle(Utils::CommentDefinition::HashStyle);
} }
} // namespace Internal } // namespace Internal

View File

@@ -62,7 +62,6 @@ public:
{ {
addContext(Constants::C_PROFILEEDITOR); addContext(Constants::C_PROFILEEDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
} }
}; };
@@ -229,6 +228,7 @@ ProFileEditorFactory::ProFileEditorFactory()
setEditorWidgetCreator([]() { return new ProFileEditorWidget; }); setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
setEditorCreator([]() { return new ProFileEditor; }); setEditorCreator([]() { return new ProFileEditor; });
setCommentStyle(Utils::CommentDefinition::HashStyle);
setEditorActionHandlers(Constants::C_PROFILEEDITOR, setEditorActionHandlers(Constants::C_PROFILEEDITOR,
TextEditorActionHandler::UnCommentSelection TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor); | TextEditorActionHandler::JumpToFileUnderCursor);

View File

@@ -880,7 +880,6 @@ QmlJSEditor::QmlJSEditor()
addContext(Constants::C_QMLJSEDITOR_ID); addContext(Constants::C_QMLJSEDITOR_ID);
addContext(ProjectExplorer::Constants::LANG_QMLJS); addContext(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
} }
@@ -917,13 +916,13 @@ QmlJSEditorFactory::QmlJSEditorFactory()
setEditorWidgetCreator([]() { return new QmlJSEditorWidget; }); setEditorWidgetCreator([]() { return new QmlJSEditorWidget; });
setEditorCreator([]() { return new QmlJSEditor; }); setEditorCreator([]() { return new QmlJSEditor; });
setAutoCompleterCreator([]() { return new AutoCompleter; }); setAutoCompleterCreator([]() { return new AutoCompleter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_QMLJSEDITOR_ID, setEditorActionHandlers(Constants::C_QMLJSEDITOR_ID,
TextEditorActionHandler::Format TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection | TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll | TextEditorActionHandler::UnCollapseAll
| TextEditorActionHandler::FollowSymbolUnderCursor); | TextEditorActionHandler::FollowSymbolUnderCursor);
} }
} // namespace Internal } // namespace Internal

View File

@@ -230,7 +230,6 @@ class BaseTextEditorPrivate
public: public:
BaseTextEditorPrivate() {} BaseTextEditorPrivate() {}
CommentDefinition m_commentDefinition;
std::function<CompletionAssistProvider *()> m_completionAssistProvider; std::function<CompletionAssistProvider *()> m_completionAssistProvider;
QPointer<BaseTextEditorFactory> m_origin; QPointer<BaseTextEditorFactory> m_origin;
@@ -442,6 +441,7 @@ public:
bool m_editorIsFallBack; bool m_editorIsFallBack;
QScopedPointer<AutoCompleter> m_autoCompleter; QScopedPointer<AutoCompleter> m_autoCompleter;
CommentDefinition m_commentDefinition;
}; };
BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent) BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent)
@@ -1540,18 +1540,17 @@ void BaseTextEditorWidgetPrivate::moveLineUpDown(bool up)
m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers); m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers);
bool shouldReindent = true; bool shouldReindent = true;
const CommentDefinition &cd = q->editor()->commentDefinition(); if (m_commentDefinition.isValid()) {
if (cd.isValid()) {
QString trimmedText(text.trimmed()); QString trimmedText(text.trimmed());
if (cd.hasSingleLineStyle()) { if (m_commentDefinition.hasSingleLineStyle()) {
if (trimmedText.startsWith(cd.singleLine)) if (trimmedText.startsWith(m_commentDefinition.singleLine))
shouldReindent = false; shouldReindent = false;
} }
if (shouldReindent && cd.hasMultiLineStyle()) { if (shouldReindent && m_commentDefinition.hasMultiLineStyle()) {
// Don't have any single line comments; try multi line. // Don't have any single line comments; try multi line.
if (trimmedText.startsWith(cd.multiLineStart) if (trimmedText.startsWith(m_commentDefinition.multiLineStart)
&& trimmedText.endsWith(cd.multiLineEnd)) { && trimmedText.endsWith(m_commentDefinition.multiLineEnd)) {
shouldReindent = false; shouldReindent = false;
} }
} }
@@ -6022,7 +6021,7 @@ void BaseTextEditorWidget::rewrapParagraph()
void BaseTextEditorWidget::unCommentSelection() void BaseTextEditorWidget::unCommentSelection()
{ {
Utils::unCommentSelection(this, editor()->commentDefinition()); Utils::unCommentSelection(this, d->m_commentDefinition);
} }
void BaseTextEditorWidget::showEvent(QShowEvent* e) void BaseTextEditorWidget::showEvent(QShowEvent* e)
@@ -6708,16 +6707,6 @@ void BaseTextEditor::select(int toPos)
editorWidget()->setTextCursor(tc); editorWidget()->setTextCursor(tc);
} }
CommentDefinition &BaseTextEditor::commentDefinition() const
{
return d->m_commentDefinition;
}
void BaseTextEditor::setCommentStyle(CommentDefinition::Style style)
{
d->m_commentDefinition.setStyle(style);
}
CompletionAssistProvider *BaseTextEditor::completionAssistProvider() CompletionAssistProvider *BaseTextEditor::completionAssistProvider()
{ {
return d->m_completionAssistProvider(); return d->m_completionAssistProvider();
@@ -7132,11 +7121,10 @@ void BaseTextEditorWidget::configureMimeType(const MimeType &mimeType)
const QSharedPointer<HighlightDefinition> &definition = const QSharedPointer<HighlightDefinition> &definition =
Manager::instance()->definition(definitionId); Manager::instance()->definition(definitionId);
if (!definition.isNull() && definition->isValid()) { if (!definition.isNull() && definition->isValid()) {
CommentDefinition &cd = editor()->commentDefinition(); d->m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
cd.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces(); d->m_commentDefinition.singleLine = definition->singleLineComment();
cd.singleLine = definition->singleLineComment(); d->m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
cd.multiLineStart = definition->multiLineCommentStart(); d->m_commentDefinition.multiLineEnd = definition->multiLineCommentEnd();
cd.multiLineEnd = definition->multiLineCommentEnd();
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
} }
@@ -7227,6 +7215,7 @@ BaseTextEditorFactory::BaseTextEditorFactory(QObject *parent)
{ {
m_editorCreator = []() { return new BaseTextEditor; }; m_editorCreator = []() { return new BaseTextEditor; };
m_widgetCreator = []() { return new BaseTextEditorWidget; }; m_widgetCreator = []() { return new BaseTextEditorWidget; };
m_commentStyle = CommentDefinition::NoStyle;
} }
void BaseTextEditorFactory::setDocumentCreator(const DocumentCreator &creator) void BaseTextEditorFactory::setDocumentCreator(const DocumentCreator &creator)
@@ -7278,6 +7267,11 @@ void BaseTextEditorFactory::setEditorActionHandlers(uint optionalActions)
new TextEditorActionHandler(this, id(), optionalActions); new TextEditorActionHandler(this, id(), optionalActions);
} }
void BaseTextEditorFactory::setCommentStyle(CommentDefinition::Style style)
{
m_commentStyle = style;
}
BaseTextEditor *BaseTextEditorFactory::duplicateTextEditor(BaseTextEditor *other) BaseTextEditor *BaseTextEditorFactory::duplicateTextEditor(BaseTextEditor *other)
{ {
BaseTextEditor *editor = createEditorHelper(other->editorWidget()->textDocumentPtr()); BaseTextEditor *editor = createEditorHelper(other->editorWidget()->textDocumentPtr());
@@ -7312,6 +7306,7 @@ BaseTextEditor *BaseTextEditorFactory::createEditorHelper(const BaseTextDocument
widget->setTextDocument(document); widget->setTextDocument(document);
widget->d->m_codeAssistant.configure(editor); widget->d->m_codeAssistant.configure(editor);
widget->d->m_commentDefinition.setStyle(m_commentStyle);
if (m_autoCompleterCreator) if (m_autoCompleterCreator)
widget->setAutoCompleter(m_autoCompleterCreator()); widget->setAutoCompleter(m_autoCompleterCreator());

View File

@@ -199,11 +199,6 @@ public:
/*! Selects text between current cursor position and \a toPos. */ /*! Selects text between current cursor position and \a toPos. */
virtual void select(int toPos); virtual void select(int toPos);
/*! Full access to comment definition, */
Utils::CommentDefinition &commentDefinition() const;
/*! Convenience style setter. */
void setCommentStyle(Utils::CommentDefinition::Style style);
CompletionAssistProvider *completionAssistProvider(); CompletionAssistProvider *completionAssistProvider();
void setCompletionAssistProvider(CompletionAssistProvider *provider); // Not owned. void setCompletionAssistProvider(CompletionAssistProvider *provider); // Not owned.
@@ -654,6 +649,8 @@ public:
void setEditorActionHandlers(Core::Id contextId, uint optionalActions); void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
void setEditorActionHandlers(uint optionalActions); void setEditorActionHandlers(uint optionalActions);
void setCommentStyle(Utils::CommentDefinition::Style style);
Core::IEditor *createEditor(); Core::IEditor *createEditor();
private: private:
@@ -669,6 +666,7 @@ private:
AutoCompleterCreator m_autoCompleterCreator; AutoCompleterCreator m_autoCompleterCreator;
IndenterCreator m_indenterCreator; IndenterCreator m_indenterCreator;
SyntaxHighLighterCreator m_syntaxHighlighterCreator; SyntaxHighLighterCreator m_syntaxHighlighterCreator;
Utils::CommentDefinition::Style m_commentStyle;
}; };
} // namespace TextEditor } // namespace TextEditor