forked from qt-creator/qt-creator
Allow giving TextEditorFactory custom CommentDefinition
It was not possible to set custom comment styles. Also simplifies the code for the predefined styles. Change-Id: Id7f345d65b747bfac5a15e3eb15cd2beb106b281 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -29,29 +29,20 @@
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
CommentDefinition CommentDefinition::CppStyle = CommentDefinition("//", "/*", "*/");
|
||||
CommentDefinition CommentDefinition::HashStyle = CommentDefinition("#");
|
||||
|
||||
CommentDefinition::CommentDefinition() :
|
||||
isAfterWhiteSpaces(false)
|
||||
{}
|
||||
|
||||
void CommentDefinition::setStyle(Style style)
|
||||
CommentDefinition::CommentDefinition(const QString &single, const QString &multiStart,
|
||||
const QString &multiEnd)
|
||||
: isAfterWhiteSpaces(false),
|
||||
singleLine(single),
|
||||
multiLineStart(multiStart),
|
||||
multiLineEnd(multiEnd)
|
||||
{
|
||||
switch (style) {
|
||||
case CppStyle:
|
||||
singleLine = QLatin1String("//");
|
||||
multiLineStart = QLatin1String("/*");
|
||||
multiLineEnd = QLatin1String("*/");
|
||||
break;
|
||||
case HashStyle:
|
||||
singleLine = QLatin1Char('#');
|
||||
multiLineStart.clear();
|
||||
multiLineEnd.clear();
|
||||
break;
|
||||
case NoStyle:
|
||||
singleLine.clear();
|
||||
multiLineStart.clear();
|
||||
multiLineEnd.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CommentDefinition::isValid() const
|
||||
|
||||
@@ -38,10 +38,12 @@ namespace Utils {
|
||||
class QTCREATOR_UTILS_EXPORT CommentDefinition
|
||||
{
|
||||
public:
|
||||
CommentDefinition();
|
||||
static CommentDefinition CppStyle;
|
||||
static CommentDefinition HashStyle;
|
||||
|
||||
enum Style { NoStyle, CppStyle, HashStyle };
|
||||
void setStyle(Style style);
|
||||
CommentDefinition();
|
||||
CommentDefinition(const QString &single,
|
||||
const QString &multiStart = QString(), const QString &multiEnd = QString());
|
||||
|
||||
bool isValid() const;
|
||||
bool hasSingleLineStyle() const;
|
||||
|
||||
@@ -65,7 +65,7 @@ JavaEditorFactory::JavaEditorFactory()
|
||||
|
||||
setDocumentCreator(createJavaDocument);
|
||||
setUseGenericHighlighter(true);
|
||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||
setCommentDefinition(Utils::CommentDefinition::CppStyle);
|
||||
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection);
|
||||
setCompletionAssistProvider(new JavaCompletionAssistProvider);
|
||||
setMarksVisible(true);
|
||||
|
||||
@@ -220,7 +220,7 @@ CMakeEditorFactory::CMakeEditorFactory()
|
||||
setDocumentCreator(createCMakeDocument);
|
||||
setIndenterCreator([]() { return new CMakeIndenter; });
|
||||
setUseGenericHighlighter(true);
|
||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
||||
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||
setCodeFoldingSupported(true);
|
||||
|
||||
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider);
|
||||
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
setEditorWidgetCreator([]() { return new CppEditorWidget; });
|
||||
setEditorCreator([]() { return new CppEditor; });
|
||||
setAutoCompleterCreator([]() { return new CppAutoCompleter; });
|
||||
setCommentStyle(CommentDefinition::CppStyle);
|
||||
setCommentDefinition(CommentDefinition::CppStyle);
|
||||
setCodeFoldingSupported(true);
|
||||
setMarksVisible(true);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
|
||||
@@ -323,7 +323,7 @@ GlslEditorFactory::GlslEditorFactory()
|
||||
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
|
||||
setIndenterCreator([]() { return new GlslIndenter; });
|
||||
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
|
||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||
setCommentDefinition(Utils::CommentDefinition::CppStyle);
|
||||
setCompletionAssistProvider(new GlslCompletionAssistProvider);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
setMarksVisible(true);
|
||||
|
||||
@@ -65,7 +65,7 @@ NimEditorFactory::NimEditorFactory()
|
||||
setSyntaxHighlighterCreator([]() {
|
||||
return new NimHighlighter;
|
||||
});
|
||||
setCommentStyle(CommentDefinition::HashStyle);
|
||||
setCommentDefinition(CommentDefinition::HashStyle);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
setMarksVisible(false);
|
||||
setCodeFoldingSupported(true);
|
||||
|
||||
@@ -55,7 +55,7 @@ PythonEditorFactory::PythonEditorFactory()
|
||||
setDocumentCreator([] { return new TextDocument(Constants::C_PYTHONEDITOR_ID); });
|
||||
setIndenterCreator([] { return new PythonIndenter; });
|
||||
setSyntaxHighlighterCreator([] { return new PythonHighlighter; });
|
||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
||||
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
setMarksVisible(true);
|
||||
setCodeFoldingSupported(true);
|
||||
|
||||
@@ -185,7 +185,7 @@ ProFileEditorFactory::ProFileEditorFactory()
|
||||
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
|
||||
setCompletionAssistProvider(pcap);
|
||||
|
||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
||||
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
||||
| TextEditorActionHandler::JumpToFileUnderCursor);
|
||||
|
||||
|
||||
@@ -1044,7 +1044,7 @@ QmlJSEditorFactory::QmlJSEditorFactory()
|
||||
setEditorWidgetCreator([]() { return new QmlJSEditorWidget; });
|
||||
setEditorCreator([]() { return new QmlJSEditor; });
|
||||
setAutoCompleterCreator([]() { return new AutoCompleter; });
|
||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||
setCommentDefinition(Utils::CommentDefinition::CppStyle);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
setMarksVisible(true);
|
||||
setCodeFoldingSupported(true);
|
||||
|
||||
@@ -7798,7 +7798,6 @@ public:
|
||||
q(parent),
|
||||
m_widgetCreator([]() { return new TextEditorWidget; }),
|
||||
m_editorCreator([]() { return new BaseTextEditor; }),
|
||||
m_commentStyle(CommentDefinition::NoStyle),
|
||||
m_completionAssistProvider(0),
|
||||
m_useGenericHighlighter(false),
|
||||
m_duplicatedSupported(true),
|
||||
@@ -7823,7 +7822,7 @@ public:
|
||||
TextEditorFactory::AutoCompleterCreator m_autoCompleterCreator;
|
||||
TextEditorFactory::IndenterCreator m_indenterCreator;
|
||||
TextEditorFactory::SyntaxHighLighterCreator m_syntaxHighlighterCreator;
|
||||
CommentDefinition::Style m_commentStyle;
|
||||
CommentDefinition m_commentDefinition;
|
||||
QList<BaseHoverHandler *> m_hoverHandlers; // owned
|
||||
CompletionAssistProvider * m_completionAssistProvider; // owned
|
||||
bool m_useGenericHighlighter;
|
||||
@@ -7901,9 +7900,9 @@ void TextEditorFactory::setCompletionAssistProvider(CompletionAssistProvider *pr
|
||||
d->m_completionAssistProvider = provider;
|
||||
}
|
||||
|
||||
void TextEditorFactory::setCommentStyle(CommentDefinition::Style style)
|
||||
void TextEditorFactory::setCommentDefinition(CommentDefinition definition)
|
||||
{
|
||||
d->m_commentStyle = style;
|
||||
d->m_commentDefinition = definition;
|
||||
}
|
||||
|
||||
void TextEditorFactory::setDuplicatedSupported(bool on)
|
||||
@@ -7963,7 +7962,7 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP
|
||||
widget->d->m_hoverHandlers = m_hoverHandlers;
|
||||
|
||||
widget->d->m_codeAssistant.configure(widget);
|
||||
widget->d->m_commentDefinition.setStyle(m_commentStyle);
|
||||
widget->d->m_commentDefinition = m_commentDefinition;
|
||||
|
||||
QObject::connect(widget, &TextEditorWidget::activateEditor,
|
||||
[editor]() { EditorManager::activateEditor(editor); });
|
||||
|
||||
@@ -651,7 +651,7 @@ public:
|
||||
void addHoverHandler(BaseHoverHandler *handler);
|
||||
void setCompletionAssistProvider(CompletionAssistProvider *provider);
|
||||
|
||||
void setCommentStyle(Utils::CommentDefinition::Style style);
|
||||
void setCommentDefinition(Utils::CommentDefinition definition);
|
||||
void setDuplicatedSupported(bool on);
|
||||
void setMarksVisible(bool on);
|
||||
void setParenthesesMatchingEnabled(bool on);
|
||||
|
||||
Reference in New Issue
Block a user