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;
|
using namespace Utils;
|
||||||
|
|
||||||
|
CommentDefinition CommentDefinition::CppStyle = CommentDefinition("//", "/*", "*/");
|
||||||
|
CommentDefinition CommentDefinition::HashStyle = CommentDefinition("#");
|
||||||
|
|
||||||
CommentDefinition::CommentDefinition() :
|
CommentDefinition::CommentDefinition() :
|
||||||
isAfterWhiteSpaces(false)
|
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
|
bool CommentDefinition::isValid() const
|
||||||
|
|||||||
@@ -38,10 +38,12 @@ namespace Utils {
|
|||||||
class QTCREATOR_UTILS_EXPORT CommentDefinition
|
class QTCREATOR_UTILS_EXPORT CommentDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommentDefinition();
|
static CommentDefinition CppStyle;
|
||||||
|
static CommentDefinition HashStyle;
|
||||||
|
|
||||||
enum Style { NoStyle, CppStyle, HashStyle };
|
CommentDefinition();
|
||||||
void setStyle(Style style);
|
CommentDefinition(const QString &single,
|
||||||
|
const QString &multiStart = QString(), const QString &multiEnd = QString());
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
bool hasSingleLineStyle() const;
|
bool hasSingleLineStyle() const;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ JavaEditorFactory::JavaEditorFactory()
|
|||||||
|
|
||||||
setDocumentCreator(createJavaDocument);
|
setDocumentCreator(createJavaDocument);
|
||||||
setUseGenericHighlighter(true);
|
setUseGenericHighlighter(true);
|
||||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
setCommentDefinition(Utils::CommentDefinition::CppStyle);
|
||||||
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection);
|
setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection);
|
||||||
setCompletionAssistProvider(new JavaCompletionAssistProvider);
|
setCompletionAssistProvider(new JavaCompletionAssistProvider);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ CMakeEditorFactory::CMakeEditorFactory()
|
|||||||
setDocumentCreator(createCMakeDocument);
|
setDocumentCreator(createCMakeDocument);
|
||||||
setIndenterCreator([]() { return new CMakeIndenter; });
|
setIndenterCreator([]() { return new CMakeIndenter; });
|
||||||
setUseGenericHighlighter(true);
|
setUseGenericHighlighter(true);
|
||||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
|
|
||||||
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider);
|
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider);
|
||||||
|
|||||||
@@ -95,7 +95,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(CommentDefinition::CppStyle);
|
setCommentDefinition(CommentDefinition::CppStyle);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ GlslEditorFactory::GlslEditorFactory()
|
|||||||
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
|
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
|
||||||
setIndenterCreator([]() { return new GlslIndenter; });
|
setIndenterCreator([]() { return new GlslIndenter; });
|
||||||
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
|
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
|
||||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
setCommentDefinition(Utils::CommentDefinition::CppStyle);
|
||||||
setCompletionAssistProvider(new GlslCompletionAssistProvider);
|
setCompletionAssistProvider(new GlslCompletionAssistProvider);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ NimEditorFactory::NimEditorFactory()
|
|||||||
setSyntaxHighlighterCreator([]() {
|
setSyntaxHighlighterCreator([]() {
|
||||||
return new NimHighlighter;
|
return new NimHighlighter;
|
||||||
});
|
});
|
||||||
setCommentStyle(CommentDefinition::HashStyle);
|
setCommentDefinition(CommentDefinition::HashStyle);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setMarksVisible(false);
|
setMarksVisible(false);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ PythonEditorFactory::PythonEditorFactory()
|
|||||||
setDocumentCreator([] { return new TextDocument(Constants::C_PYTHONEDITOR_ID); });
|
setDocumentCreator([] { return new TextDocument(Constants::C_PYTHONEDITOR_ID); });
|
||||||
setIndenterCreator([] { return new PythonIndenter; });
|
setIndenterCreator([] { return new PythonIndenter; });
|
||||||
setSyntaxHighlighterCreator([] { return new PythonHighlighter; });
|
setSyntaxHighlighterCreator([] { return new PythonHighlighter; });
|
||||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ ProFileEditorFactory::ProFileEditorFactory()
|
|||||||
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
|
ProFileCompletionAssistProvider *pcap = new ProFileCompletionAssistProvider;
|
||||||
setCompletionAssistProvider(pcap);
|
setCompletionAssistProvider(pcap);
|
||||||
|
|
||||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
||||||
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditorActionHandler::JumpToFileUnderCursor);
|
| TextEditorActionHandler::JumpToFileUnderCursor);
|
||||||
|
|
||||||
|
|||||||
@@ -1044,7 +1044,7 @@ 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);
|
setCommentDefinition(Utils::CommentDefinition::CppStyle);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
|
|||||||
@@ -7798,7 +7798,6 @@ public:
|
|||||||
q(parent),
|
q(parent),
|
||||||
m_widgetCreator([]() { return new TextEditorWidget; }),
|
m_widgetCreator([]() { return new TextEditorWidget; }),
|
||||||
m_editorCreator([]() { return new BaseTextEditor; }),
|
m_editorCreator([]() { return new BaseTextEditor; }),
|
||||||
m_commentStyle(CommentDefinition::NoStyle),
|
|
||||||
m_completionAssistProvider(0),
|
m_completionAssistProvider(0),
|
||||||
m_useGenericHighlighter(false),
|
m_useGenericHighlighter(false),
|
||||||
m_duplicatedSupported(true),
|
m_duplicatedSupported(true),
|
||||||
@@ -7823,7 +7822,7 @@ public:
|
|||||||
TextEditorFactory::AutoCompleterCreator m_autoCompleterCreator;
|
TextEditorFactory::AutoCompleterCreator m_autoCompleterCreator;
|
||||||
TextEditorFactory::IndenterCreator m_indenterCreator;
|
TextEditorFactory::IndenterCreator m_indenterCreator;
|
||||||
TextEditorFactory::SyntaxHighLighterCreator m_syntaxHighlighterCreator;
|
TextEditorFactory::SyntaxHighLighterCreator m_syntaxHighlighterCreator;
|
||||||
CommentDefinition::Style m_commentStyle;
|
CommentDefinition m_commentDefinition;
|
||||||
QList<BaseHoverHandler *> m_hoverHandlers; // owned
|
QList<BaseHoverHandler *> m_hoverHandlers; // owned
|
||||||
CompletionAssistProvider * m_completionAssistProvider; // owned
|
CompletionAssistProvider * m_completionAssistProvider; // owned
|
||||||
bool m_useGenericHighlighter;
|
bool m_useGenericHighlighter;
|
||||||
@@ -7901,9 +7900,9 @@ void TextEditorFactory::setCompletionAssistProvider(CompletionAssistProvider *pr
|
|||||||
d->m_completionAssistProvider = provider;
|
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)
|
void TextEditorFactory::setDuplicatedSupported(bool on)
|
||||||
@@ -7963,7 +7962,7 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP
|
|||||||
widget->d->m_hoverHandlers = m_hoverHandlers;
|
widget->d->m_hoverHandlers = m_hoverHandlers;
|
||||||
|
|
||||||
widget->d->m_codeAssistant.configure(widget);
|
widget->d->m_codeAssistant.configure(widget);
|
||||||
widget->d->m_commentDefinition.setStyle(m_commentStyle);
|
widget->d->m_commentDefinition = m_commentDefinition;
|
||||||
|
|
||||||
QObject::connect(widget, &TextEditorWidget::activateEditor,
|
QObject::connect(widget, &TextEditorWidget::activateEditor,
|
||||||
[editor]() { EditorManager::activateEditor(editor); });
|
[editor]() { EditorManager::activateEditor(editor); });
|
||||||
|
|||||||
@@ -651,7 +651,7 @@ public:
|
|||||||
void addHoverHandler(BaseHoverHandler *handler);
|
void addHoverHandler(BaseHoverHandler *handler);
|
||||||
void setCompletionAssistProvider(CompletionAssistProvider *provider);
|
void setCompletionAssistProvider(CompletionAssistProvider *provider);
|
||||||
|
|
||||||
void setCommentStyle(Utils::CommentDefinition::Style style);
|
void setCommentDefinition(Utils::CommentDefinition definition);
|
||||||
void setDuplicatedSupported(bool on);
|
void setDuplicatedSupported(bool on);
|
||||||
void setMarksVisible(bool on);
|
void setMarksVisible(bool on);
|
||||||
void setParenthesesMatchingEnabled(bool on);
|
void setParenthesesMatchingEnabled(bool on);
|
||||||
|
|||||||
Reference in New Issue
Block a user