forked from qt-creator/qt-creator
TextEditor: Re-work comment definition handling
No need for most of the machinery. Change-Id: I9078174582d83da94c6c7f20282fd3a5f1742911 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -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
|
|||||||
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,
|
|||||||
|
|
||||||
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
|
|||||||
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)
|
|||||||
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)
|
|||||||
|
|
||||||
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:
|
|||||||
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)
|
|||||||
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
|
|||||||
|
|
||||||
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:
|
|||||||
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)
|
|||||||
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
|
|||||||
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()
|
|||||||
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:
|
|||||||
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:
|
|||||||
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)
|
|||||||
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:
|
|||||||
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)
|
|||||||
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)
|
|||||||
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
|
|||||||
|
|
||||||
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)
|
|||||||
|
|
||||||
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()
|
|||||||
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
|
|||||||
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:
|
|||||||
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)
|
|||||||
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()
|
|||||||
|
|
||||||
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:
|
|||||||
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:
|
|||||||
|
|
||||||
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)
|
|||||||
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:
|
|||||||
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)
|
|||||||
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
|
|||||||
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:
|
|||||||
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:
|
|||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BaseTextEditorWidgetPrivate
|
class BaseTextEditorWidgetPrivate
|
||||||
@@ -367,7 +368,6 @@ public:
|
|||||||
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
|
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
|
||||||
|
|
||||||
bool m_isMissingSyntaxDefinition;
|
bool m_isMissingSyntaxDefinition;
|
||||||
Utils::CommentDefinition m_commentDefinition;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextEditExtraArea : public QWidget
|
class TextEditExtraArea : public QWidget
|
||||||
@@ -531,8 +531,6 @@ void BaseTextEditorWidgetPrivate::ctor(const QSharedPointer<BaseTextDocument> &d
|
|||||||
QObject::connect(&m_delayedUpdateTimer, SIGNAL(timeout()), q->viewport(), SLOT(update()));
|
QObject::connect(&m_delayedUpdateTimer, SIGNAL(timeout()), q->viewport(), SLOT(update()));
|
||||||
|
|
||||||
m_moveLineUndoHack = false;
|
m_moveLineUndoHack = false;
|
||||||
|
|
||||||
m_commentDefinition.clearCommentStyles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTextEditorWidget::~BaseTextEditorWidget()
|
BaseTextEditorWidget::~BaseTextEditorWidget()
|
||||||
@@ -1396,18 +1394,18 @@ void BaseTextEditorWidgetPrivate::moveLineUpDown(bool up)
|
|||||||
m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers);
|
m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers);
|
||||||
|
|
||||||
bool shouldReindent = true;
|
bool shouldReindent = true;
|
||||||
const CommentDefinition *commentDefinition = q->editor()->commentDefinition();
|
const CommentDefinition &cd = q->editor()->commentDefinition();
|
||||||
if (commentDefinition) {
|
if (cd.isValid()) {
|
||||||
QString trimmedText(text.trimmed());
|
QString trimmedText(text.trimmed());
|
||||||
|
|
||||||
if (commentDefinition->hasSingleLineStyle()) {
|
if (cd.hasSingleLineStyle()) {
|
||||||
if (trimmedText.startsWith(commentDefinition->singleLine))
|
if (trimmedText.startsWith(cd.singleLine))
|
||||||
shouldReindent = false;
|
shouldReindent = false;
|
||||||
}
|
}
|
||||||
if (shouldReindent && commentDefinition->hasMultiLineStyle()) {
|
if (shouldReindent && cd.hasMultiLineStyle()) {
|
||||||
// Don't have any single line comments; try multi line.
|
// Don't have any single line comments; try multi line.
|
||||||
if (trimmedText.startsWith(commentDefinition->multiLineStart)
|
if (trimmedText.startsWith(cd.multiLineStart)
|
||||||
&& trimmedText.endsWith(commentDefinition->multiLineEnd)) {
|
&& trimmedText.endsWith(cd.multiLineEnd)) {
|
||||||
shouldReindent = false;
|
shouldReindent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5883,7 +5881,7 @@ void BaseTextEditorWidget::rewrapParagraph()
|
|||||||
|
|
||||||
void BaseTextEditorWidget::unCommentSelection()
|
void BaseTextEditorWidget::unCommentSelection()
|
||||||
{
|
{
|
||||||
Utils::unCommentSelection(this, d->m_commentDefinition);
|
Utils::unCommentSelection(this, editor()->commentDefinition());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::showEvent(QShowEvent* e)
|
void BaseTextEditorWidget::showEvent(QShowEvent* e)
|
||||||
@@ -6577,9 +6575,14 @@ void BaseTextEditor::select(int toPos)
|
|||||||
d->m_editorWidget->setTextCursor(tc);
|
d->m_editorWidget->setTextCursor(tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentDefinition *BaseTextEditor::commentDefinition() const
|
CommentDefinition &BaseTextEditor::commentDefinition() const
|
||||||
{
|
{
|
||||||
return 0;
|
return d->m_commentDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::setCommentStyle(CommentDefinition::Style style)
|
||||||
|
{
|
||||||
|
d->m_commentDefinition.setStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionAssistProvider *BaseTextEditor::completionAssistProvider()
|
CompletionAssistProvider *BaseTextEditor::completionAssistProvider()
|
||||||
@@ -6987,10 +6990,11 @@ 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()) {
|
||||||
d->m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
|
CommentDefinition &cd = editor()->commentDefinition();
|
||||||
d->m_commentDefinition.singleLine = definition->singleLineComment();
|
cd.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
|
||||||
d->m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
|
cd.singleLine = definition->singleLineComment();
|
||||||
d->m_commentDefinition.multiLineEnd = definition->multiLineCommentEnd();
|
cd.multiLineStart = definition->multiLineCommentStart();
|
||||||
|
cd.multiLineEnd = definition->multiLineCommentEnd();
|
||||||
|
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,8 @@
|
|||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/find/ifindsupport.h>
|
#include <coreplugin/find/ifindsupport.h>
|
||||||
|
|
||||||
|
#include <utils/uncommentselection.h>
|
||||||
|
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -53,11 +55,6 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Core { class MimeType; }
|
namespace Core { class MimeType; }
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
class CommentDefinition;
|
|
||||||
class LineColumnLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class TabSettings;
|
class TabSettings;
|
||||||
@@ -183,7 +180,10 @@ 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);
|
||||||
|
|
||||||
virtual const Utils::CommentDefinition *commentDefinition() const;
|
/*! Full access to comment definition, */
|
||||||
|
Utils::CommentDefinition &commentDefinition() const;
|
||||||
|
/*! Convenience style setter. */
|
||||||
|
void setCommentStyle(Utils::CommentDefinition::Style style);
|
||||||
|
|
||||||
virtual CompletionAssistProvider *completionAssistProvider();
|
virtual CompletionAssistProvider *completionAssistProvider();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user