Commit f6b48950 authored by hjk's avatar hjk

TextEditor: Re-work comment definition handling

No need for most of the machinery.

Change-Id: I9078174582d83da94c6c7f20282fd3a5f1742911
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent f3a83367
...@@ -34,12 +34,30 @@ ...@@ -34,12 +34,30 @@
using namespace Utils; using namespace Utils;
CommentDefinition::CommentDefinition() : CommentDefinition::CommentDefinition() :
isAfterWhiteSpaces(false), isAfterWhiteSpaces(false)
singleLine(QLatin1String("//")),
multiLineStart(QLatin1String("/*")),
multiLineEnd(QLatin1String("*/"))
{} {}
void CommentDefinition::setStyle(Style style)
{
switch (style) {
case CppStyle:
singleLine = QLatin1String("//");
multiLineStart = QLatin1String("/*");
multiLineEnd = QLatin1String("*/");
break;
case HashStyle:
singleLine = QLatin1String("#");
multiLineStart.clear();
multiLineEnd.clear();
break;
}
}
bool CommentDefinition::isValid() const
{
return hasSingleLineStyle() || hasMultiLineStyle();
}
bool CommentDefinition::hasSingleLineStyle() const bool CommentDefinition::hasSingleLineStyle() const
{ {
return !singleLine.isEmpty(); return !singleLine.isEmpty();
...@@ -50,13 +68,6 @@ bool CommentDefinition::hasMultiLineStyle() const ...@@ -50,13 +68,6 @@ bool CommentDefinition::hasMultiLineStyle() const
return !multiLineStart.isEmpty() && !multiLineEnd.isEmpty(); return !multiLineStart.isEmpty() && !multiLineEnd.isEmpty();
} }
void CommentDefinition::clearCommentStyles()
{
singleLine.clear();
multiLineStart.clear();
multiLineEnd.clear();
}
static bool isComment(const QString &text, int index, static bool isComment(const QString &text, int index,
const QString &commentType) const QString &commentType)
{ {
...@@ -76,7 +87,7 @@ static bool isComment(const QString &text, int index, ...@@ -76,7 +87,7 @@ static bool isComment(const QString &text, int index,
void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition) void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition)
{ {
if (!definition.hasSingleLineStyle() && !definition.hasMultiLineStyle()) if (!definition.isValid())
return; return;
QTextCursor cursor = edit->textCursor(); QTextCursor cursor = edit->textCursor();
......
...@@ -45,11 +45,13 @@ class QTCREATOR_UTILS_EXPORT CommentDefinition ...@@ -45,11 +45,13 @@ class QTCREATOR_UTILS_EXPORT CommentDefinition
public: public:
CommentDefinition(); CommentDefinition();
enum Style { CppStyle, HashStyle };
void setStyle(Style style);
bool isValid() const;
bool hasSingleLineStyle() const; bool hasSingleLineStyle() const;
bool hasMultiLineStyle() const; bool hasMultiLineStyle() const;
void clearCommentStyles();
public: public:
bool isAfterWhiteSpaces; bool isAfterWhiteSpaces;
QString singleLine; QString singleLine;
......
...@@ -55,6 +55,7 @@ JavaEditor::JavaEditor(JavaEditorWidget *editor) ...@@ -55,6 +55,7 @@ JavaEditor::JavaEditor(JavaEditorWidget *editor)
setContext(Core::Context(Constants::C_JAVA_EDITOR, setContext(Core::Context(Constants::C_JAVA_EDITOR,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
} }
Core::IEditor *JavaEditor::duplicate() Core::IEditor *JavaEditor::duplicate()
...@@ -88,18 +89,9 @@ JavaEditorWidget::JavaEditorWidget(JavaEditorWidget *other) ...@@ -88,18 +89,9 @@ JavaEditorWidget::JavaEditorWidget(JavaEditorWidget *other)
void JavaEditorWidget::ctor() void JavaEditorWidget::ctor()
{ {
m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1String("//");
m_commentDefinition.multiLineStart = QLatin1String("/*");
m_commentDefinition.multiLineEnd = QLatin1String("*/");
setAutoCompleter(new JavaAutoCompleter); setAutoCompleter(new JavaAutoCompleter);
} }
void JavaEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this, m_commentDefinition);
}
TextEditor::BaseTextEditor *JavaEditorWidget::createEditor() TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
{ {
return new JavaEditor(this); return new JavaEditor(this);
......
...@@ -59,15 +59,12 @@ public: ...@@ -59,15 +59,12 @@ public:
JavaEditorWidget(QWidget *parent = 0); JavaEditorWidget(QWidget *parent = 0);
JavaEditorWidget(JavaEditorWidget *other); JavaEditorWidget(JavaEditorWidget *other);
void unCommentSelection();
protected: protected:
TextEditor::BaseTextEditor *createEditor(); TextEditor::BaseTextEditor *createEditor();
private: private:
JavaEditorWidget(BaseTextEditorWidget *); // avoid stupidity JavaEditorWidget(BaseTextEditorWidget *); // avoid stupidity
void ctor(); void ctor();
Utils::CommentDefinition m_commentDefinition;
}; };
class JavaDocument : public TextEditor::BaseTextDocument class JavaDocument : public TextEditor::BaseTextDocument
......
...@@ -62,6 +62,7 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor) ...@@ -62,6 +62,7 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR, setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged())); connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged()));
} }
...@@ -154,32 +155,17 @@ QString CMakeEditor::contextHelpId() const ...@@ -154,32 +155,17 @@ QString CMakeEditor::contextHelpId() const
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent) CMakeEditorWidget::CMakeEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new CMakeDocument(), parent) : BaseTextEditorWidget(new CMakeDocument(), parent)
{ {}
ctor();
}
CMakeEditorWidget::CMakeEditorWidget(CMakeEditorWidget *other) CMakeEditorWidget::CMakeEditorWidget(CMakeEditorWidget *other)
: BaseTextEditorWidget(other) : BaseTextEditorWidget(other)
{ {}
ctor();
}
void CMakeEditorWidget::ctor()
{
m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1Char('#');
}
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor() TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor()
{ {
return new CMakeEditor(this); return new CMakeEditor(this);
} }
void CMakeEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this, m_commentDefinition);
}
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e) void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
{ {
showDefaultContextMenu(e, Constants::M_CONTEXT); showDefaultContextMenu(e, Constants::M_CONTEXT);
......
...@@ -78,13 +78,8 @@ protected: ...@@ -78,13 +78,8 @@ protected:
TextEditor::BaseTextEditor *createEditor(); TextEditor::BaseTextEditor *createEditor();
void contextMenuEvent(QContextMenuEvent *e); void contextMenuEvent(QContextMenuEvent *e);
public slots:
void unCommentSelection();
private: private:
CMakeEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity CMakeEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor();
Utils::CommentDefinition m_commentDefinition;
}; };
class CMakeDocument : public TextEditor::BaseTextDocument class CMakeDocument : public TextEditor::BaseTextDocument
......
...@@ -113,6 +113,7 @@ CPPEditor::CPPEditor(CPPEditorWidget *editor) ...@@ -113,6 +113,7 @@ CPPEditor::CPPEditor(CPPEditorWidget *editor)
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);
} }
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder) Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
...@@ -796,11 +797,6 @@ bool CPPEditor::open(QString *errorString, const QString &fileName, const QStrin ...@@ -796,11 +797,6 @@ bool CPPEditor::open(QString *errorString, const QString &fileName, const QStrin
return true; return true;
} }
const Utils::CommentDefinition *CPPEditor::commentDefinition() const
{
return &m_commentDefinition;
}
TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider() TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider()
{ {
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider(); return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
...@@ -836,11 +832,6 @@ void CPPEditorWidget::applyFontSettings() ...@@ -836,11 +832,6 @@ void CPPEditorWidget::applyFontSettings()
semanticRehighlight(true); semanticRehighlight(true);
} }
void CPPEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this);
}
void CPPEditorWidget::slotCodeStyleSettingsChanged(const QVariant &) void CPPEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
{ {
CppTools::QtStyleCodeFormatter formatter; CppTools::QtStyleCodeFormatter formatter;
......
...@@ -66,11 +66,7 @@ public: ...@@ -66,11 +66,7 @@ public:
const QString &fileName, const QString &fileName,
const QString &realFileName) QTC_OVERRIDE; const QString &realFileName) QTC_OVERRIDE;
const Utils::CommentDefinition *commentDefinition() const QTC_OVERRIDE;
TextEditor::CompletionAssistProvider *completionAssistProvider() QTC_OVERRIDE; TextEditor::CompletionAssistProvider *completionAssistProvider() QTC_OVERRIDE;
private:
Utils::CommentDefinition m_commentDefinition;
}; };
class CPPEditorWidget : public TextEditor::BaseTextEditorWidget class CPPEditorWidget : public TextEditor::BaseTextEditorWidget
...@@ -105,7 +101,6 @@ public slots: ...@@ -105,7 +101,6 @@ public slots:
void cut() QTC_OVERRIDE; void cut() QTC_OVERRIDE;
void selectAll() QTC_OVERRIDE; void selectAll() QTC_OVERRIDE;
void unCommentSelection() QTC_OVERRIDE;
void switchDeclarationDefinition(bool inNextSplit); void switchDeclarationDefinition(bool inNextSplit);
void showPreProcessorWidget(); void showPreProcessorWidget();
......
...@@ -263,11 +263,6 @@ void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editor) ...@@ -263,11 +263,6 @@ void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editor)
editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo); editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo);
} }
void GLSLTextEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this);
}
void GLSLTextEditorWidget::updateDocument() void GLSLTextEditorWidget::updateDocument()
{ {
m_updateDocumentTimer->start(); m_updateDocumentTimer->start();
......
...@@ -90,8 +90,6 @@ public: ...@@ -90,8 +90,6 @@ public:
GLSLTextEditorWidget(GLSLTextEditorWidget *other); GLSLTextEditorWidget(GLSLTextEditorWidget *other);
~GLSLTextEditorWidget(); ~GLSLTextEditorWidget();
virtual void unCommentSelection();
int editorRevision() const; int editorRevision() const;
bool isOutdated() const; bool isOutdated() const;
......
...@@ -49,6 +49,7 @@ GLSLEditorEditable::GLSLEditorEditable(GLSLTextEditorWidget *editor) ...@@ -49,6 +49,7 @@ GLSLEditorEditable::GLSLEditorEditable(GLSLTextEditorWidget *editor)
setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID, setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
} }
} // namespace Internal } // namespace Internal
......
...@@ -53,10 +53,7 @@ PythonEditor::PythonEditor(EditorWidget *editorWidget) ...@@ -53,10 +53,7 @@ PythonEditor::PythonEditor(EditorWidget *editorWidget)
setContext(Core::Context(Constants::C_PYTHONEDITOR_ID, setContext(Core::Context(Constants::C_PYTHONEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
} setCommentStyle(Utils::CommentDefinition::HashStyle);
PythonEditor::~PythonEditor()
{
} }
Core::IEditor *PythonEditor::duplicate() Core::IEditor *PythonEditor::duplicate()
......
...@@ -43,7 +43,6 @@ class PythonEditor : public TextEditor::BaseTextEditor ...@@ -43,7 +43,6 @@ class PythonEditor : public TextEditor::BaseTextEditor
public: public:
explicit PythonEditor(EditorWidget *editorWidget); explicit PythonEditor(EditorWidget *editorWidget);
virtual ~PythonEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
......
...@@ -64,10 +64,6 @@ EditorWidget::EditorWidget(EditorWidget *other) ...@@ -64,10 +64,6 @@ EditorWidget::EditorWidget(EditorWidget *other)
void EditorWidget::ctor() void EditorWidget::ctor()
{ {
m_commentDefinition.multiLineStart.clear();
m_commentDefinition.multiLineEnd.clear();
m_commentDefinition.singleLine = QLatin1Char('#');
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
setMarksVisible(true); setMarksVisible(true);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
...@@ -75,18 +71,6 @@ void EditorWidget::ctor() ...@@ -75,18 +71,6 @@ void EditorWidget::ctor()
new PythonHighlighter(baseTextDocument()); new PythonHighlighter(baseTextDocument());
} }
EditorWidget::~EditorWidget()
{
}
/**
Comments or uncomments selection using Python commenting syntax
*/
void EditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this, m_commentDefinition);
}
TextEditor::BaseTextEditor *EditorWidget::createEditor() TextEditor::BaseTextEditor *EditorWidget::createEditor()
{ {
return new PythonEditor(this); return new PythonEditor(this);
......
...@@ -43,9 +43,6 @@ class EditorWidget : public TextEditor::BaseTextEditorWidget ...@@ -43,9 +43,6 @@ class EditorWidget : public TextEditor::BaseTextEditorWidget
public: public:
EditorWidget(QWidget *parent = 0); EditorWidget(QWidget *parent = 0);
EditorWidget(EditorWidget *other); EditorWidget(EditorWidget *other);
virtual ~EditorWidget();
virtual void unCommentSelection();
protected: protected:
TextEditor::BaseTextEditor *createEditor(); TextEditor::BaseTextEditor *createEditor();
...@@ -53,7 +50,6 @@ protected: ...@@ -53,7 +50,6 @@ protected:
private: private:
EditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity EditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor(); void ctor();
Utils::CommentDefinition m_commentDefinition;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -58,6 +58,7 @@ ProFileEditor::ProFileEditor(ProFileEditorWidget *editor) ...@@ -58,6 +58,7 @@ ProFileEditor::ProFileEditor(ProFileEditorWidget *editor)
setContext(Core::Context(Constants::C_PROFILEEDITOR, setContext(Core::Context(Constants::C_PROFILEEDITOR,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
} }
Core::IEditor *ProFileEditor::duplicate() Core::IEditor *ProFileEditor::duplicate()
...@@ -79,26 +80,11 @@ TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider() ...@@ -79,26 +80,11 @@ TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider()
ProFileEditorWidget::ProFileEditorWidget(QWidget *parent) ProFileEditorWidget::ProFileEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new ProFileDocument(), parent) : BaseTextEditorWidget(new ProFileDocument(), parent)
{ {}
ctor();
}
ProFileEditorWidget::ProFileEditorWidget(ProFileEditorWidget *other) ProFileEditorWidget::ProFileEditorWidget(ProFileEditorWidget *other)
: BaseTextEditorWidget(other) : BaseTextEditorWidget(other)
{ {}
ctor();
}
void ProFileEditorWidget::ctor()
{
m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1Char('#');
}
void ProFileEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this, m_commentDefinition);
}
static bool isValidFileNameChar(const QChar &c) static bool isValidFileNameChar(const QChar &c)
{ {
......
...@@ -59,8 +59,6 @@ public: ...@@ -59,8 +59,6 @@ public:
ProFileEditorWidget(QWidget *parent = 0); ProFileEditorWidget(QWidget *parent = 0);
ProFileEditorWidget(ProFileEditorWidget *other); ProFileEditorWidget(ProFileEditorWidget *other);
void unCommentSelection();
protected: protected:
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true, virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
bool inNextSplit = false); bool inNextSplit = false);
...@@ -69,8 +67,6 @@ protected: ...@@ -69,8 +67,6 @@ protected:
private: private:
ProFileEditorWidget(BaseTextEditorWidget *); // avoid stupidity ProFileEditorWidget(BaseTextEditorWidget *); // avoid stupidity
void ctor();
Utils::CommentDefinition m_commentDefinition;
}; };
class ProFileDocument : public TextEditor::BaseTextDocument class ProFileDocument : public TextEditor::BaseTextDocument
......
...@@ -800,11 +800,6 @@ void QmlJSTextEditorWidget::resizeEvent(QResizeEvent *event) ...@@ -800,11 +800,6 @@ void QmlJSTextEditorWidget::resizeEvent(QResizeEvent *event)
hideContextPane(); hideContextPane();
} }
void QmlJSTextEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this);
}
QmlJSEditorDocument *QmlJSTextEditorWidget::qmlJsEditorDocument() const QmlJSEditorDocument *QmlJSTextEditorWidget::qmlJsEditorDocument() const
{ {
return m_qmlJsEditorDocument; return m_qmlJsEditorDocument;
......
...@@ -78,8 +78,6 @@ public: ...@@ -78,8 +78,6 @@ public:
QmlJSTextEditorWidget(QmlJSTextEditorWidget *other); QmlJSTextEditorWidget(QmlJSTextEditorWidget *other);
~QmlJSTextEditorWidget(); ~QmlJSTextEditorWidget();
virtual void unCommentSelection();
QmlJSEditorDocument *qmlJsEditorDocument() const; QmlJSEditorDocument *qmlJsEditorDocument() const;
QModelIndex outlineModelIndex(); QModelIndex outlineModelIndex();
......
...@@ -54,6 +54,7 @@ QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor) ...@@ -54,6 +54,7 @@ QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor)
m_context.add(TextEditor::Constants::C_TEXTEDITOR); m_context.add(TextEditor::Constants::C_TEXTEDITOR);
m_context.add(ProjectExplorer::Constants::LANG_QMLJS); m_context.add(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
} }
bool QmlJSEditor::isDesignModePreferred() const bool QmlJSEditor::isDesignModePreferred() const
...@@ -65,11 +66,6 @@ bool QmlJSEditor::isDesignModePreferred() const ...@@ -65,11 +66,6 @@ bool QmlJSEditor::isDesignModePreferred() const
return false; return false;
} }
const Utils::CommentDefinition *QmlJSEditor::commentDefinition() const
{
return &m_commentDefinition;
}
TextEditor::CompletionAssistProvider *QmlJSEditor::completionAssistProvider() TextEditor::CompletionAssistProvider *QmlJSEditor::completionAssistProvider()
{ {
return ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>(); return ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>();
......
...@@ -50,11 +50,7 @@ public: ...@@ -50,11 +50,7 @@ public:
bool open(QString *errorString, const QString &fileName, const QString &realFileName); bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const; bool isDesignModePreferred() const;
const Utils::CommentDefinition *commentDefinition() const;
TextEditor::CompletionAssistProvider *completionAssistProvider(); TextEditor::CompletionAssistProvider *completionAssistProvider();
private:
Utils::CommentDefinition m_commentDefinition;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -197,6 +197,7 @@ public: ...@@ -197,6 +197,7 @@ public:
Utils::LineColumnLabel *m_cursorPositionLabel; Utils::LineColumnLabel *m_cursorPositionLabel;
QAction *m_fileEncodingLabelAction; QAction *m_fileEncodingLabelAction;
Utils::LineColumnLabel *m_fileEncodingLabel; Utils::LineColumnLabel *m_fileEncodingLabel;
CommentDefinition m_commentDefinition;