Commit 6775e623 authored by hjk's avatar hjk

TextEditor: Move comment definitions back to *Widget

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

Change-Id: I81206057ce89d42aef7febb840cf9e44b869df0e
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent b9f861f1
......@@ -50,6 +50,11 @@ void CommentDefinition::setStyle(Style style)
multiLineStart.clear();
multiLineEnd.clear();
break;
case NoStyle:
singleLine.clear();
multiLineStart.clear();
multiLineEnd.clear();
break;
}
}
......
......@@ -45,7 +45,7 @@ class QTCREATOR_UTILS_EXPORT CommentDefinition
public:
CommentDefinition();
enum Style { CppStyle, HashStyle };
enum Style { NoStyle, CppStyle, HashStyle };
void setStyle(Style style);
bool isValid() const;
......
......@@ -59,7 +59,6 @@ public:
{
addContext(Constants::C_JAVA_EDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
}
};
......@@ -112,6 +111,7 @@ JavaEditorFactory::JavaEditorFactory()
setDocumentCreator([]() { return new JavaDocument; });
setAutoCompleterCreator([]() { return new JavaAutoCompleter; });
setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE));
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_JAVA_EDITOR,
TextEditor::TextEditorActionHandler::UnCommentSelection);
......
......@@ -67,7 +67,6 @@ CMakeEditor::CMakeEditor()
{
addContext(Constants::C_CMAKEEDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
}
......@@ -288,6 +287,7 @@ CMakeEditorFactory::CMakeEditorFactory()
setEditorWidgetCreator([]() { return new CMakeEditorWidget; });
setDocumentCreator([]() { return new CMakeDocument; });
setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE));
setCommentStyle(Utils::CommentDefinition::HashStyle);
setEditorActionHandlers(Constants::C_CMAKEEDITOR,
TextEditorActionHandler::UnCommentSelection
......
......@@ -96,7 +96,6 @@ CppEditor::CppEditor()
m_context.add(ProjectExplorer::Constants::LANG_CXX);
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider([this] () -> TextEditor::CompletionAssistProvider * {
if (CppEditorDocument *document = qobject_cast<CppEditorDocument *>(textDocument()))
return document->completionAssistProvider();
......
......@@ -91,6 +91,7 @@ public:
setEditorWidgetCreator([]() { return new CppEditorWidget; });
setEditorCreator([]() { return new CppEditor; });
setAutoCompleterCreator([]() { return new CppAutoCompleter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_CPPEDITOR,
TextEditorActionHandler::Format
......
......@@ -336,7 +336,6 @@ public:
{
addContext(Constants::C_GLSLEDITOR_ID);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
}
......@@ -368,6 +367,7 @@ GlslEditorFactory::GlslEditorFactory()
setEditorCreator([]() { return new GlslEditor; });
setIndenterCreator([]() { return new GlslIndenter; });
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_GLSLEDITOR_ID,
TextEditorActionHandler::Format
......
......@@ -64,7 +64,6 @@ public:
{
addContext(Constants::C_PYTHONEDITOR_ID);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
}
bool open(QString *errorString, const QString &fileName, const QString &realFileName)
......@@ -111,6 +110,7 @@ PythonEditorFactory::PythonEditorFactory()
setEditorCreator([]() { return new PythonEditor; });
setIndenterCreator([]() { return new PythonIndenter; });
setSyntaxHighlighterCreator([]() { return new PythonHighlighter; });
setCommentStyle(Utils::CommentDefinition::HashStyle);
}
} // namespace Internal
......
......@@ -62,7 +62,6 @@ public:
{
addContext(Constants::C_PROFILEEDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
}
};
......@@ -229,6 +228,7 @@ ProFileEditorFactory::ProFileEditorFactory()
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
setEditorCreator([]() { return new ProFileEditor; });
setCommentStyle(Utils::CommentDefinition::HashStyle);
setEditorActionHandlers(Constants::C_PROFILEEDITOR,
TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
......
......@@ -880,7 +880,6 @@ QmlJSEditor::QmlJSEditor()
addContext(Constants::C_QMLJSEDITOR_ID);
addContext(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
}
......@@ -917,13 +916,13 @@ QmlJSEditorFactory::QmlJSEditorFactory()
setEditorWidgetCreator([]() { return new QmlJSEditorWidget; });
setEditorCreator([]() { return new QmlJSEditor; });
setAutoCompleterCreator([]() { return new AutoCompleter; });
setCommentStyle(Utils::CommentDefinition::CppStyle);
setEditorActionHandlers(Constants::C_QMLJSEDITOR_ID,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll
| TextEditorActionHandler::FollowSymbolUnderCursor);
}
} // namespace Internal
......
......@@ -230,7 +230,6 @@ class BaseTextEditorPrivate
public:
BaseTextEditorPrivate() {}
CommentDefinition m_commentDefinition;
std::function<CompletionAssistProvider *()> m_completionAssistProvider;
QPointer<BaseTextEditorFactory> m_origin;
......@@ -442,6 +441,7 @@ public:
bool m_editorIsFallBack;
QScopedPointer<AutoCompleter> m_autoCompleter;
CommentDefinition m_commentDefinition;
};
BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent)
......@@ -1540,18 +1540,17 @@ void BaseTextEditorWidgetPrivate::moveLineUpDown(bool up)
m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers);
bool shouldReindent = true;
const CommentDefinition &cd = q->editor()->commentDefinition();
if (cd.isValid()) {
if (m_commentDefinition.isValid()) {
QString trimmedText(text.trimmed());
if (cd.hasSingleLineStyle()) {
if (trimmedText.startsWith(cd.singleLine))
if (m_commentDefinition.hasSingleLineStyle()) {
if (trimmedText.startsWith(m_commentDefinition.singleLine))
shouldReindent = false;
}
if (shouldReindent && cd.hasMultiLineStyle()) {
if (shouldReindent && m_commentDefinition.hasMultiLineStyle()) {
// Don't have any single line comments; try multi line.
if (trimmedText.startsWith(cd.multiLineStart)
&& trimmedText.endsWith(cd.multiLineEnd)) {
if (trimmedText.startsWith(m_commentDefinition.multiLineStart)
&& trimmedText.endsWith(m_commentDefinition.multiLineEnd)) {
shouldReindent = false;
}
}
......@@ -6022,7 +6021,7 @@ void BaseTextEditorWidget::rewrapParagraph()
void BaseTextEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this, editor()->commentDefinition());
Utils::unCommentSelection(this, d->m_commentDefinition);
}
void BaseTextEditorWidget::showEvent(QShowEvent* e)
......@@ -6708,16 +6707,6 @@ void BaseTextEditor::select(int toPos)
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()
{
return d->m_completionAssistProvider();
......@@ -7132,11 +7121,10 @@ void BaseTextEditorWidget::configureMimeType(const MimeType &mimeType)
const QSharedPointer<HighlightDefinition> &definition =
Manager::instance()->definition(definitionId);
if (!definition.isNull() && definition->isValid()) {
CommentDefinition &cd = editor()->commentDefinition();
cd.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
cd.singleLine = definition->singleLineComment();
cd.multiLineStart = definition->multiLineCommentStart();
cd.multiLineEnd = definition->multiLineCommentEnd();
d->m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
d->m_commentDefinition.singleLine = definition->singleLineComment();
d->m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
d->m_commentDefinition.multiLineEnd = definition->multiLineCommentEnd();
setCodeFoldingSupported(true);
}
......@@ -7227,6 +7215,7 @@ BaseTextEditorFactory::BaseTextEditorFactory(QObject *parent)
{
m_editorCreator = []() { return new BaseTextEditor; };
m_widgetCreator = []() { return new BaseTextEditorWidget; };
m_commentStyle = CommentDefinition::NoStyle;
}
void BaseTextEditorFactory::setDocumentCreator(const DocumentCreator &creator)
......@@ -7278,6 +7267,11 @@ void BaseTextEditorFactory::setEditorActionHandlers(uint optionalActions)
new TextEditorActionHandler(this, id(), optionalActions);
}
void BaseTextEditorFactory::setCommentStyle(CommentDefinition::Style style)
{
m_commentStyle = style;
}
BaseTextEditor *BaseTextEditorFactory::duplicateTextEditor(BaseTextEditor *other)
{
BaseTextEditor *editor = createEditorHelper(other->editorWidget()->textDocumentPtr());
......@@ -7312,6 +7306,7 @@ BaseTextEditor *BaseTextEditorFactory::createEditorHelper(const BaseTextDocument
widget->setTextDocument(document);
widget->d->m_codeAssistant.configure(editor);
widget->d->m_commentDefinition.setStyle(m_commentStyle);
if (m_autoCompleterCreator)
widget->setAutoCompleter(m_autoCompleterCreator());
......
......@@ -199,11 +199,6 @@ public:
/*! Selects text between current cursor position and \a 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();
void setCompletionAssistProvider(CompletionAssistProvider *provider); // Not owned.
......@@ -654,6 +649,8 @@ public:
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
void setEditorActionHandlers(uint optionalActions);
void setCommentStyle(Utils::CommentDefinition::Style style);
Core::IEditor *createEditor();
private:
......@@ -669,6 +666,7 @@ private:
AutoCompleterCreator m_autoCompleterCreator;
IndenterCreator m_indenterCreator;
SyntaxHighLighterCreator m_syntaxHighlighterCreator;
Utils::CommentDefinition::Style m_commentStyle;
};
} // 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