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