forked from qt-creator/qt-creator
DiffEditorController: Add an option to set a syntax highlighter
Change-Id: I66fc252e7ccc168fd32ed7100cc9af7f940dc3e0 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -146,6 +146,7 @@ private:
|
||||
void documentHasChanged();
|
||||
void toggleDescription();
|
||||
void updateDescription();
|
||||
void updateDescriptionHighlighter();
|
||||
void contextLineCountHasChanged(int lines);
|
||||
void ignoreWhitespaceHasChanged();
|
||||
void prepareForReload();
|
||||
@@ -298,6 +299,8 @@ void DiffEditor::setDocument(std::shared_ptr<DiffEditorDocument> doc)
|
||||
this, &DiffEditor::documentHasChanged);
|
||||
connect(m_document.get(), &DiffEditorDocument::descriptionChanged,
|
||||
this, &DiffEditor::updateDescription);
|
||||
connect(m_document.get(), &DiffEditorDocument::descriptionHighlighterChanged,
|
||||
this, &DiffEditor::updateDescriptionHighlighter);
|
||||
connect(m_document.get(), &DiffEditorDocument::aboutToReload,
|
||||
this, &DiffEditor::prepareForReload);
|
||||
connect(m_document.get(), &DiffEditorDocument::reloadFinished,
|
||||
@@ -451,6 +454,13 @@ void DiffEditor::updateDescription()
|
||||
m_toggleDescriptionAction->setVisible(!description.isEmpty());
|
||||
}
|
||||
|
||||
void DiffEditor::updateDescriptionHighlighter()
|
||||
{
|
||||
const auto creator = m_document->descriptionSyntaxHighlighterCreator();
|
||||
if (creator)
|
||||
m_descriptionWidget->textDocument()->resetSyntaxHighlighter(creator);
|
||||
}
|
||||
|
||||
void DiffEditor::contextLineCountHasChanged(int lines)
|
||||
{
|
||||
QTC_ASSERT(!m_document->isContextLineCountForced(), return);
|
||||
|
||||
@@ -87,6 +87,12 @@ void DiffEditorController::setDescription(const QString &description)
|
||||
m_document->setDescription(description);
|
||||
}
|
||||
|
||||
void DiffEditorController::setDescriptionSyntaxHighlighterCreator(
|
||||
const std::function<TextEditor::SyntaxHighlighter *()> &creator)
|
||||
{
|
||||
m_document->setDescriptionSyntaxHighlighterCreator(creator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Force the lines of context to the given number.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@ class QMenu;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class IDocument; }
|
||||
namespace TextEditor { class SyntaxHighlighter; }
|
||||
namespace Utils { class FilePath; }
|
||||
|
||||
namespace DiffEditor {
|
||||
@@ -63,6 +64,8 @@ protected:
|
||||
// Optional:
|
||||
void setDisplayName(const QString &name) { m_displayName = name; }
|
||||
void setDescription(const QString &description);
|
||||
void setDescriptionSyntaxHighlighterCreator(
|
||||
const std::function<TextEditor::SyntaxHighlighter *()> &creator);
|
||||
void setStartupFile(const QString &startupFile);
|
||||
void forceContextLineCount(int lines);
|
||||
|
||||
|
||||
@@ -179,6 +179,13 @@ void DiffEditorDocument::setDescription(const QString &description)
|
||||
emit descriptionChanged();
|
||||
}
|
||||
|
||||
void DiffEditorDocument::setDescriptionSyntaxHighlighterCreator(
|
||||
const std::function<TextEditor::SyntaxHighlighter *()> &creator)
|
||||
{
|
||||
m_descriptionHighlighter = creator;
|
||||
emit descriptionHighlighterChanged();
|
||||
}
|
||||
|
||||
QString DiffEditorDocument::description() const
|
||||
{
|
||||
return m_description;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <coreplugin/patchtool.h>
|
||||
#include <coreplugin/textdocument.h>
|
||||
|
||||
namespace TextEditor { class SyntaxHighlighter; }
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
class DiffEditorController;
|
||||
@@ -45,6 +47,11 @@ public:
|
||||
|
||||
void setDescription(const QString &description);
|
||||
QString description() const;
|
||||
void setDescriptionSyntaxHighlighterCreator(
|
||||
const std::function<TextEditor::SyntaxHighlighter *()> &creator);
|
||||
std::function<TextEditor::SyntaxHighlighter *()> descriptionSyntaxHighlighterCreator() const {
|
||||
return m_descriptionHighlighter;
|
||||
}
|
||||
|
||||
void setContextLineCount(int lines);
|
||||
int contextLineCount() const;
|
||||
@@ -71,6 +78,7 @@ signals:
|
||||
void temporaryStateChanged();
|
||||
void documentChanged();
|
||||
void descriptionChanged();
|
||||
void descriptionHighlighterChanged();
|
||||
|
||||
protected:
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
@@ -85,6 +93,7 @@ private:
|
||||
Utils::FilePath m_workingDirectory;
|
||||
QString m_startupFile;
|
||||
QString m_description;
|
||||
std::function<TextEditor::SyntaxHighlighter *()> m_descriptionHighlighter = {};
|
||||
int m_contextLineCount = 3;
|
||||
bool m_isContextLineCountForced = false;
|
||||
bool m_ignoreWhitespace = false;
|
||||
|
||||
Reference in New Issue
Block a user