summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@theqtcompany.com>2015-03-12 16:49:57 +0100
committerEike Ziller <eike.ziller@theqtcompany.com>2015-03-12 16:49:57 +0100
commit6433af534dee3ade44511ec3190425c03fb25ec5 (patch)
treee81017fb81f591aa1b4ef5f65296c4c0763a5b22 /src/plugins/diffeditor
parent23ec56516e02796fe22c5c84d59a309d90234908 (diff)
parentd108a54aabe1043afe3d2700ffa0b5afb3869292 (diff)
downloadqt-creator-6433af534dee3ade44511ec3190425c03fb25ec5.tar.gz
Merge remote-tracking branch 'origin/3.4'
Conflicts: qtcreator.pri Change-Id: Iacd9f2afb843f06d457914a3b842dfc606e3adf3
Diffstat (limited to 'src/plugins/diffeditor')
-rw-r--r--src/plugins/diffeditor/diffeditor.cpp272
-rw-r--r--src/plugins/diffeditor/diffeditor.h11
-rw-r--r--src/plugins/diffeditor/diffeditordocument.cpp3
-rw-r--r--src/plugins/diffeditor/sidebysidediffeditorwidget.cpp234
-rw-r--r--src/plugins/diffeditor/sidebysidediffeditorwidget.h3
5 files changed, 149 insertions, 374 deletions
diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp
index 8e2a073949..498945f8da 100644
--- a/src/plugins/diffeditor/diffeditor.cpp
+++ b/src/plugins/diffeditor/diffeditor.cpp
@@ -62,8 +62,7 @@
static const char settingsGroupC[] = "DiffEditor";
static const char descriptionVisibleKeyC[] = "DescriptionVisible";
-static const char horizontalScrollBarSynchronizationKeyC[] =
- "HorizontalScrollBarSynchronization";
+static const char horizontalScrollBarSynchronizationKeyC[] = "HorizontalScrollBarSynchronization";
static const char contextLineCountKeyC[] = "ContextLineNumbers";
static const char ignoreWhitespaceKeyC[] = "IgnoreWhitespace";
@@ -74,6 +73,19 @@ static const char useDiffEditorKeyC[] = "UseDiffEditor";
using namespace TextEditor;
+namespace {
+
+class Guard
+{
+public:
+ Guard(int *state) : m_state(state) { ++(*state); }
+ ~Guard() { --(*m_state); QTC_ASSERT(*m_state >= 0, return); }
+private:
+ int *m_state;
+};
+
+} // namespace
+
namespace DiffEditor {
namespace Internal {
@@ -210,19 +222,19 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
, m_stackedWidget(0)
, m_toolBar(0)
, m_entriesComboBox(0)
+ , m_contextSpinBox(0)
, m_toggleSyncAction(0)
, m_whitespaceButtonAction(0)
- , m_contextLabelAction(0)
- , m_contextSpinBoxAction(0)
, m_toggleDescriptionAction(0)
, m_reloadAction(0)
- , m_diffEditorSwitcher(0)
+ , m_viewSwitcherAction(0)
, m_currentViewIndex(-1)
, m_currentDiffFileIndex(-1)
+ , m_ignoreChanges(0)
, m_sync(false)
, m_showDescription(true)
- , m_ignoreChanges(true)
{
+ Guard guard(&m_ignoreChanges);
QTC_ASSERT(m_document, return);
setDuplicateSupported(true);
@@ -254,9 +266,7 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
toolBar();
loadSettings();
- updateDescription();
-
- m_ignoreChanges = false;
+ documentHasChanged();
}
DiffEditor::~DiffEditor()
@@ -314,58 +324,46 @@ QWidget *DiffEditor::toolBar()
this, &DiffEditor::setCurrentDiffFileIndex);
m_toolBar->addWidget(m_entriesComboBox);
- m_whitespaceButton = new QToolButton(m_toolBar);
- m_whitespaceButton->setText(tr("Ignore Whitespace"));
- m_whitespaceButton->setCheckable(true);
- m_whitespaceButton->setChecked(m_document->ignoreWhitespace());
- m_whitespaceButtonAction = m_toolBar->addWidget(m_whitespaceButton);
+ m_contextLabel = new QLabel(m_toolBar);
- QLabel *contextLabel = new QLabel(m_toolBar);
- contextLabel->setText(tr("Context Lines:"));
- contextLabel->setContentsMargins(6, 0, 6, 0);
- m_contextLabelAction = m_toolBar->addWidget(contextLabel);
+ m_contextLabel->setText(tr("Context Lines:"));
+ m_contextLabel->setContentsMargins(6, 0, 6, 0);
+ m_toolBar->addWidget(m_contextLabel);
m_contextSpinBox = new QSpinBox(m_toolBar);
m_contextSpinBox->setRange(1, 100);
m_contextSpinBox->setValue(m_document->contextLineCount());
m_contextSpinBox->setFrame(false);
- m_contextSpinBox->setSizePolicy(QSizePolicy::Minimum,
- QSizePolicy::Expanding); // Mac Qt5
- m_contextSpinBoxAction = m_toolBar->addWidget(m_contextSpinBox);
-
- QToolButton *toggleDescription = new QToolButton(m_toolBar);
- toggleDescription->setIcon(QIcon(QLatin1String(Constants::ICON_TOP_BAR)));
- toggleDescription->setCheckable(true);
- toggleDescription->setChecked(m_showDescription);
- m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription);
- updateDescription();
+ m_contextSpinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); // Mac Qt5
+ m_toolBar->addWidget(m_contextSpinBox);
+
+ m_whitespaceButtonAction = m_toolBar->addAction(tr("Ignore Whitespace"));
+ m_whitespaceButtonAction->setCheckable(true);
+ m_whitespaceButtonAction->setChecked(m_document->ignoreWhitespace());
+
+ m_toggleDescriptionAction = m_toolBar->addAction(QIcon(QLatin1String(Constants::ICON_TOP_BAR)),
+ QString());
+ m_toggleDescriptionAction->setCheckable(true);
- QToolButton *reloadButton = new QToolButton(m_toolBar);
- reloadButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RELOAD_GRAY)));
- reloadButton->setToolTip(tr("Reload Editor"));
- m_reloadAction = m_toolBar->addWidget(reloadButton);
+ m_reloadAction = m_toolBar->addAction(QIcon(QLatin1String(Core::Constants::ICON_RELOAD_GRAY)),
+ tr("Reload Diff"));
+ m_reloadAction->setToolTip(tr("Reload Diff"));
documentStateChanged();
- QToolButton *toggleSync = new QToolButton(m_toolBar);
- toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
- toggleSync->setCheckable(true);
- m_toggleSyncAction = m_toolBar->addWidget(toggleSync);
+ m_toggleSyncAction = m_toolBar->addAction(QIcon(QLatin1String(Core::Constants::ICON_LINK)),
+ QString());
+ m_toggleSyncAction->setCheckable(true);
- m_diffEditorSwitcher = new QToolButton(m_toolBar);
- m_toolBar->addWidget(m_diffEditorSwitcher);
+ m_viewSwitcherAction = m_toolBar->addAction(QIcon(), QString());
updateDiffEditorSwitcher();
- connect(m_whitespaceButton, &QToolButton::clicked,
- this, &DiffEditor::ignoreWhitespaceHasChanged);
+ connect(m_whitespaceButtonAction, &QAction::toggled, this, &DiffEditor::ignoreWhitespaceHasChanged);
connect(m_contextSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DiffEditor::contextLineCountHasChanged);
- connect(toggleSync, &QAbstractButton::clicked, this, &DiffEditor::toggleSync);
- connect(toggleDescription, &QAbstractButton::clicked,
- this, &DiffEditor::toggleDescription);
- connect(m_diffEditorSwitcher, &QAbstractButton::clicked,
- this, [this]() { showDiffView(nextView()); });
-
- connect(reloadButton, &QAbstractButton::clicked, this, [this]() { m_document->reload(); });
+ connect(m_toggleSyncAction, &QAction::toggled, this, &DiffEditor::toggleSync);
+ connect(m_toggleDescriptionAction, &QAction::toggled, this, &DiffEditor::toggleDescription);
+ connect(m_viewSwitcherAction, &QAction::triggered, this, [this]() { showDiffView(nextView()); });
+ connect(m_reloadAction, &QAction::triggered, this, [this]() { m_document->reload(); });
connect(m_document.data(), &DiffEditorDocument::temporaryStateChanged,
this, &DiffEditor::documentStateChanged);
@@ -374,72 +372,76 @@ QWidget *DiffEditor::toolBar()
void DiffEditor::documentHasChanged()
{
- m_ignoreChanges = true;
- const QList<FileData> diffFileList = m_document->diffFiles();
-
- currentView()->setDiff(diffFileList, m_document->baseDirectory());
-
- m_entriesComboBox->clear();
int index = 0;
- const int count = diffFileList.count();
- for (int i = 0; i < count; i++) {
- const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
- const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
- const QString leftShortFileName = Utils::FileName::fromString(leftEntry.fileName).fileName();
- const QString rightShortFileName = Utils::FileName::fromString(rightEntry.fileName).fileName();
- QString itemText;
- QString itemToolTip;
- if (leftEntry.fileName == rightEntry.fileName) {
- itemText = leftShortFileName;
-
- if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
- itemToolTip = leftEntry.fileName;
- } else {
- itemToolTip = tr("[%1] vs. [%2] %3")
- .arg(leftEntry.typeInfo,
- rightEntry.typeInfo,
- leftEntry.fileName);
- }
- } else {
- if (leftShortFileName == rightShortFileName) {
+ {
+ Guard guard(&m_ignoreChanges);
+ const QList<FileData> diffFileList = m_document->diffFiles();
+
+ updateDescription();
+ currentView()->setDiff(diffFileList, m_document->baseDirectory());
+
+ m_entriesComboBox->clear();
+ const int count = diffFileList.count();
+ for (int i = 0; i < count; i++) {
+ const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
+ const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
+ const QString leftShortFileName = Utils::FileName::fromString(leftEntry.fileName).fileName();
+ const QString rightShortFileName = Utils::FileName::fromString(rightEntry.fileName).fileName();
+ QString itemText;
+ QString itemToolTip;
+ if (leftEntry.fileName == rightEntry.fileName) {
itemText = leftShortFileName;
- } else {
- itemText = tr("%1 vs. %2")
- .arg(leftShortFileName,
- rightShortFileName);
- }
- if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
- itemToolTip = tr("%1 vs. %2")
- .arg(leftEntry.fileName,
- rightEntry.fileName);
+ if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
+ itemToolTip = leftEntry.fileName;
+ } else {
+ itemToolTip = tr("[%1] vs. [%2] %3")
+ .arg(leftEntry.typeInfo,
+ rightEntry.typeInfo,
+ leftEntry.fileName);
+ }
} else {
- itemToolTip = tr("[%1] %2 vs. [%3] %4")
- .arg(leftEntry.typeInfo,
- leftEntry.fileName,
- rightEntry.typeInfo,
- rightEntry.fileName);
+ if (leftShortFileName == rightShortFileName) {
+ itemText = leftShortFileName;
+ } else {
+ itemText = tr("%1 vs. %2")
+ .arg(leftShortFileName,
+ rightShortFileName);
+ }
+
+ if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
+ itemToolTip = tr("%1 vs. %2")
+ .arg(leftEntry.fileName,
+ rightEntry.fileName);
+ } else {
+ itemToolTip = tr("[%1] %2 vs. [%3] %4")
+ .arg(leftEntry.typeInfo,
+ leftEntry.fileName,
+ rightEntry.typeInfo,
+ rightEntry.fileName);
+ }
}
+ if (m_currentFileChunk.first == leftEntry.fileName
+ && m_currentFileChunk.second == rightEntry.fileName)
+ index = i;
+ m_entriesComboBox->addItem(itemText);
+ m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
+ leftEntry.fileName, Qt::UserRole);
+ m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
+ rightEntry.fileName, Qt::UserRole + 1);
+ m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
+ itemToolTip, Qt::ToolTipRole);
}
- if (m_currentFileChunk.first == leftEntry.fileName
- && m_currentFileChunk.second == rightEntry.fileName)
- index = i;
- m_entriesComboBox->addItem(itemText);
- m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
- leftEntry.fileName, Qt::UserRole);
- m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
- rightEntry.fileName, Qt::UserRole + 1);
- m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
- itemToolTip, Qt::ToolTipRole);
}
- m_ignoreChanges = false;
-
setCurrentDiffFileIndex(m_entriesComboBox->count() > 0 ? index : -1);
}
void DiffEditor::toggleDescription()
{
+ if (m_ignoreChanges > 0)
+ return;
+
m_showDescription = !m_showDescription;
saveSetting(QLatin1String(descriptionVisibleKeyC), m_showDescription);
updateDescription();
@@ -447,23 +449,25 @@ void DiffEditor::toggleDescription()
void DiffEditor::updateDescription()
{
+ QTC_ASSERT(m_toolBar, return);
+
QString description = m_document->description();
m_descriptionWidget->setPlainText(description);
m_descriptionWidget->setVisible(m_showDescription && !description.isEmpty());
- QTC_ASSERT(m_toolBar, return);
- QTC_ASSERT(m_toggleDescriptionAction, return);
-
- QWidget *toggle = m_toolBar->widgetForAction(m_toggleDescriptionAction);
- toggle->setToolTip(m_showDescription ? tr("Hide Change Description")
- : tr("Show Change Description"));
+ Guard guard(&m_ignoreChanges);
+ m_toggleDescriptionAction->setChecked(m_showDescription);
+ m_toggleDescriptionAction->setToolTip(m_showDescription ? tr("Hide Change Description")
+ : tr("Show Change Description"));
+ m_toggleDescriptionAction->setText(m_showDescription ? tr("Hide Change Description")
+ : tr("Show Change Description"));
m_toggleDescriptionAction->setVisible(!description.isEmpty());
}
void DiffEditor::contextLineCountHasChanged(int lines)
{
QTC_ASSERT(!m_document->isContextLineCountForced(), return);
- if (m_ignoreChanges || lines == m_document->contextLineCount())
+ if (m_ignoreChanges > 0 || lines == m_document->contextLineCount())
return;
m_document->setContextLineCount(lines);
@@ -472,13 +476,15 @@ void DiffEditor::contextLineCountHasChanged(int lines)
m_document->reload();
}
-void DiffEditor::ignoreWhitespaceHasChanged(bool ignore)
+void DiffEditor::ignoreWhitespaceHasChanged()
{
- if (m_ignoreChanges || ignore == m_document->ignoreWhitespace())
- return;
+ const bool ignore = m_whitespaceButtonAction->isChecked();
+ if (m_ignoreChanges > 0 || ignore == m_document->ignoreWhitespace())
+ return;
m_document->setIgnoreWhitespace(ignore);
saveSetting(QLatin1String(ignoreWhitespaceKeyC), ignore);
+
m_document->reload();
}
@@ -496,10 +502,11 @@ void DiffEditor::prepareForReload()
m_currentFileChunk = qMakePair(QString(), QString());
}
- m_ignoreChanges = true;
- m_contextSpinBox->setValue(m_document->contextLineCount());
- m_whitespaceButton->setChecked(m_document->ignoreWhitespace());
- m_ignoreChanges = false;
+ {
+ Guard guard(&m_ignoreChanges);
+ m_contextSpinBox->setValue(m_document->contextLineCount());
+ m_whitespaceButtonAction->setChecked(m_document->ignoreWhitespace());
+ }
currentView()->beginOperation();
}
@@ -522,20 +529,17 @@ void DiffEditor::updateEntryToolTip()
void DiffEditor::setCurrentDiffFileIndex(int index)
{
- if (m_ignoreChanges)
+ if (m_ignoreChanges > 0)
return;
QTC_ASSERT((index < 0) != (m_entriesComboBox->count() > 0), return);
- m_ignoreChanges = true;
-
+ Guard guard(&m_ignoreChanges);
m_currentDiffFileIndex = index;
currentView()->setCurrentDiffFileIndex(index);
m_entriesComboBox->setCurrentIndex(m_entriesComboBox->count() > 0 ? qMax(0, index) : -1);
updateEntryToolTip();
-
- m_ignoreChanges = false;
}
void DiffEditor::documentStateChanged()
@@ -544,22 +548,26 @@ void DiffEditor::documentStateChanged()
const bool contextVisible = !m_document->isContextLineCountForced();
m_whitespaceButtonAction->setVisible(canReload);
- m_contextLabelAction->setVisible(canReload && contextVisible);
- m_contextSpinBoxAction->setVisible(canReload && contextVisible);
+ m_contextLabel->setVisible(canReload && contextVisible);
+ m_contextSpinBox->setVisible(canReload && contextVisible);
m_reloadAction->setVisible(canReload);
}
void DiffEditor::updateDiffEditorSwitcher()
{
- if (!m_diffEditorSwitcher)
+ if (!m_viewSwitcherAction)
return;
IDiffView *next = nextView();
- m_diffEditorSwitcher->setIcon(next->icon());
- m_diffEditorSwitcher->setToolTip(next->toolTip());
+ m_viewSwitcherAction->setIcon(next->icon());
+ m_viewSwitcherAction->setToolTip(next->toolTip());
+ m_viewSwitcherAction->setText(next->toolTip());
}
void DiffEditor::toggleSync()
{
+ if (m_ignoreChanges > 0)
+ return;
+
QTC_ASSERT(currentView(), return);
m_sync = !m_sync;
saveSetting(QLatin1String(horizontalScrollBarSynchronizationKeyC), m_sync);
@@ -587,10 +595,8 @@ void DiffEditor::loadSettings()
// Read current settings:
s->beginGroup(QLatin1String(settingsGroupC));
- m_showDescription = s->value(QLatin1String(descriptionVisibleKeyC),
- true).toBool();
- m_sync = s->value(QLatin1String(horizontalScrollBarSynchronizationKeyC),
- true).toBool();
+ m_showDescription = s->value(QLatin1String(descriptionVisibleKeyC), true).toBool();
+ m_sync = s->value(QLatin1String(horizontalScrollBarSynchronizationKeyC), true).toBool();
m_document->setIgnoreWhitespace(s->value(QLatin1String(ignoreWhitespaceKeyC), false).toBool());
m_document->setContextLineCount(s->value(QLatin1String(contextLineCountKeyC), 3).toInt());
Core::Id id = Core::Id::fromSetting(s->value(QLatin1String(diffViewKeyC)));
@@ -651,9 +657,13 @@ void DiffEditor::setupView(IDiffView *view)
saveSetting(QLatin1String(diffViewKeyC), currentView()->id().toSetting());
- m_toggleSyncAction->setVisible(currentView()->supportsSync());
- m_toggleSyncAction->setToolTip(currentView()->syncToolTip());
- m_toggleSyncAction->setChecked(m_sync);
+ {
+ Guard guard(&m_ignoreChanges);
+ m_toggleSyncAction->setVisible(currentView()->supportsSync());
+ m_toggleSyncAction->setToolTip(currentView()->syncToolTip());
+ m_toggleSyncAction->setText(currentView()->syncToolTip());
+ m_toggleSyncAction->setChecked(m_sync);
+ }
view->setDocument(m_document.data());
view->setSync(m_sync);
diff --git a/src/plugins/diffeditor/diffeditor.h b/src/plugins/diffeditor/diffeditor.h
index 78134cc24c..3be67972e4 100644
--- a/src/plugins/diffeditor/diffeditor.h
+++ b/src/plugins/diffeditor/diffeditor.h
@@ -38,6 +38,7 @@
QT_BEGIN_NAMESPACE
class QComboBox;
+class QLabel;
class QSpinBox;
class QToolBar;
class QToolButton;
@@ -76,7 +77,7 @@ private slots:
void toggleDescription();
void updateDescription();
void contextLineCountHasChanged(int lines);
- void ignoreWhitespaceHasChanged(bool ignore);
+ void ignoreWhitespaceHasChanged();
void prepareForReload();
void reloadHasFinished(bool success);
void setCurrentDiffFileIndex(int index);
@@ -102,21 +103,19 @@ private:
QVector<IDiffView *> m_views;
QToolBar *m_toolBar;
QComboBox *m_entriesComboBox;
- QToolButton *m_whitespaceButton;
QSpinBox *m_contextSpinBox;
QAction *m_toggleSyncAction;
QAction *m_whitespaceButtonAction;
- QAction *m_contextLabelAction;
- QAction *m_contextSpinBoxAction;
QAction *m_toggleDescriptionAction;
QAction *m_reloadAction;
- QToolButton *m_diffEditorSwitcher;
+ QLabel *m_contextLabel;
+ QAction *m_viewSwitcherAction;
QPair<QString, QString> m_currentFileChunk;
int m_currentViewIndex;
int m_currentDiffFileIndex;
+ int m_ignoreChanges;
bool m_sync;
bool m_showDescription;
- bool m_ignoreChanges;
};
} // namespace Internal
diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp
index 0937a230e0..b091c3eece 100644
--- a/src/plugins/diffeditor/diffeditordocument.cpp
+++ b/src/plugins/diffeditor/diffeditordocument.cpp
@@ -160,6 +160,7 @@ QString DiffEditorDocument::description() const
void DiffEditorDocument::setContextLineCount(int lines)
{
+ QTC_ASSERT(!m_isContextLineCountForced, return);
m_contextLineCount = lines;
}
@@ -181,8 +182,6 @@ bool DiffEditorDocument::isContextLineCountForced() const
void DiffEditorDocument::setIgnoreWhitespace(bool ignore)
{
- if (m_isContextLineCountForced)
- return;
m_ignoreWhitespace = ignore;
}
diff --git a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp
index 76a989c42c..ffa5f48047 100644
--- a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp
+++ b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp
@@ -60,9 +60,6 @@
#include <utils/tooltip/tooltip.h>
-//static const int FILE_LEVEL = 1;
-//static const int CHUNK_LEVEL = 2;
-
using namespace Core;
using namespace TextEditor;
using namespace Utils;
@@ -70,30 +67,6 @@ using namespace Utils;
namespace DiffEditor {
namespace Internal {
-////////////////////////
-/*
-class MultiHighlighter : public SyntaxHighlighter
-{
- Q_OBJECT
-public:
- MultiHighlighter(SideDiffEditorWidget *editor, QTextDocument *document = 0);
- ~MultiHighlighter();
-
- virtual void setFontSettings(const FontSettings &fontSettings);
- void setDocuments(const QList<QPair<DiffFileInfo, QString> > &documents);
-
-protected:
- virtual void highlightBlock(const QString &text);
-
-private:
- SideDiffEditorWidget *m_editor;
- QMap<QString, HighlighterFactory *> m_mimeTypeToHighlighterFactory;
- QList<SyntaxHighlighter *> m_highlighters;
- QList<QTextDocument *> m_documents;
-};
-*/
-////////////////////////
-
class SideDiffEditorWidget : public SelectableTextEditorWidget
{
Q_OBJECT
@@ -127,7 +100,6 @@ public:
QTextBlock firstVisibleBlock() const {
return TextEditorWidget::firstVisibleBlock();
}
-// void setDocuments(const QList<QPair<DiffFileInfo, QString> > &documents);
void saveState();
void restoreState();
@@ -154,17 +126,12 @@ protected:
virtual bool replacementVisible(int blockNumber) const;
QColor replacementPenColor(int blockNumber) const;
virtual QString plainTextFromSelection(const QTextCursor &cursor) const;
-// virtual void drawCollapsedBlockPopup(QPainter &painter,
-// const QTextBlock &block,
-// QPointF offset,
-// const QRect &clip);
void mouseDoubleClickEvent(QMouseEvent *e);
void contextMenuEvent(QContextMenuEvent *e);
virtual void paintEvent(QPaintEvent *e);
virtual void scrollContentsBy(int dx, int dy);
private:
-// void paintCollapsedBlockPopup(QPainter &painter, const QRect &clipRect);
void paintSeparator(QPainter &painter, QColor &color, const QString &text,
const QTextBlock &block, int top);
void jumpToOriginalFile(const QTextCursor &cursor);
@@ -185,98 +152,8 @@ private:
QColor m_chunkLineForeground;
QColor m_textForeground;
QByteArray m_state;
-// MultiHighlighter *m_highlighter;
};
-////////////////////////
-/*
-MultiHighlighter::MultiHighlighter(SideDiffEditorWidget *editor, QTextDocument *document)
- : SyntaxHighlighter(document),
- m_editor(editor)
-{
- const QList<HighlighterFactory *> &factories =
- ExtensionSystem::PluginManager::getObjects<HighlighterFactory>();
- foreach (HighlighterFactory *factory, factories) {
- QStringList mimeTypes = factory->mimeTypes();
- foreach (const QString &mimeType, mimeTypes)
- m_mimeTypeToHighlighterFactory.insert(mimeType, factory);
- }
-}
-
-MultiHighlighter::~MultiHighlighter()
-{
- setDocuments(QList<QPair<DiffFileInfo, QString> >());
-}
-
-void MultiHighlighter::setFontSettings(const FontSettings &fontSettings)
-{
- foreach (SyntaxHighlighter *highlighter, m_highlighters) {
- if (highlighter) {
- highlighter->setFontSettings(fontSettings);
- highlighter->rehighlight();
- }
- }
-}
-
-void MultiHighlighter::setDocuments(const QList<QPair<DiffFileInfo, QString> > &documents)
-{
- // clear old documents
- qDeleteAll(m_documents);
- m_documents.clear();
- qDeleteAll(m_highlighters);
- m_highlighters.clear();
-
- // create new documents
- for (int i = 0; i < documents.count(); i++) {
- DiffFileInfo fileInfo = documents.at(i).first;
- const QString contents = documents.at(i).second;
- QTextDocument *document = new QTextDocument(contents);
- const MimeType mimeType = MimeDatabase::findByFile(QFileInfo(fileInfo.fileName));
- SyntaxHighlighter *highlighter = 0;
- if (const HighlighterFactory *factory = m_mimeTypeToHighlighterFactory.value(mimeType.type())) {
- highlighter = factory->createHighlighter();
- if (highlighter)
- highlighter->setDocument(document);
- }
- if (!highlighter) {
- highlighter = createGenericSyntaxHighlighter(mimeType);
- highlighter->setDocument(document);
- }
- m_documents.append(document);
- m_highlighters.append(highlighter);
- }
-}
-
-void MultiHighlighter::highlightBlock(const QString &text)
-{
- Q_UNUSED(text)
-
- QTextBlock block = currentBlock();
- const int fileIndex = m_editor->fileIndexForBlockNumber(block.blockNumber());
- if (fileIndex < 0)
- return;
-
- SyntaxHighlighter *currentHighlighter = m_highlighters.at(fileIndex);
- if (!currentHighlighter)
- return;
-
- // find block in document
- QTextDocument *currentDocument = m_documents.at(fileIndex);
- if (!currentDocument)
- return;
-
- QTextBlock documentBlock = currentDocument->findBlockByNumber(
- block.blockNumber() - m_editor->blockNumberForFileIndex(fileIndex));
-
- if (!documentBlock.isValid())
- return;
-
- QList<QTextLayout::FormatRange> formats = documentBlock.layout()->additionalFormats();
- setExtraAdditionalFormats(block, formats);
-}
-*/
-////////////////////////
-
SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
: SelectableTextEditorWidget("DiffEditor.SideDiffEditor", parent),
m_lineNumberDigits(1),
@@ -299,11 +176,6 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
else
ToolTip::hide();
});
-
-// setCodeFoldingSupported(true);
-
-// m_highlighter = new MultiHighlighter(this, baseTextDocument()->document());
-// baseTextDocument()->setSyntaxHighlighter(m_highlighter);
}
void SideDiffEditorWidget::saveState()
@@ -630,109 +502,7 @@ void SideDiffEditorWidget::paintEvent(QPaintEvent *e)
}
currentBlock = currentBlock.next();
}
-// paintCollapsedBlockPopup(painter, e->rect());
-}
-/*
-void SideDiffEditorWidget::paintCollapsedBlockPopup(QPainter &painter, const QRect &clipRect)
-{
- QPointF offset(contentOffset());
- QRect viewportRect = viewport()->rect();
- QTextBlock block = firstVisibleBlock();
- QTextBlock visibleCollapsedBlock;
- QPointF visibleCollapsedBlockOffset;
-
- while (block.isValid()) {
-
- QRectF r = blockBoundingRect(block).translated(offset);
-
- offset.ry() += r.height();
-
- if (offset.y() > viewportRect.height())
- break;
-
- block = block.next();
-
- if (!block.isVisible()) {
- if (block.blockNumber() == visibleFoldedBlockNumber()) {
- visibleCollapsedBlock = block;
- visibleCollapsedBlockOffset = offset + QPointF(0,1);
- break;
- }
-
- // invisible blocks do have zero line count
- block = document()->findBlockByLineNumber(block.firstLineNumber());
- }
- }
- if (visibleCollapsedBlock.isValid()) {
- drawCollapsedBlockPopup(painter,
- visibleCollapsedBlock,
- visibleCollapsedBlockOffset,
- clipRect);
- }
-}
-
-void SideDiffEditorWidget::drawCollapsedBlockPopup(QPainter &painter,
- const QTextBlock &block,
- QPointF offset,
- const QRect &clip)
-{
- // We ignore the call coming from the SelectableTextEditorWidget::paintEvent()
- // since we will draw it later, after custom drawings of this paintEvent.
- // We need to draw it after our custom drawings, otherwise custom
- // drawings will appear in front of block popup.
- if (m_inPaintEvent)
- return;
-
- int margin = block.document()->documentMargin();
- qreal maxWidth = 0;
- qreal blockHeight = 0;
- QTextBlock b = block;
-
- while (!b.isVisible()) {
- if (!m_separators.contains(b.blockNumber())) {
- b.setVisible(true); // make sure block bounding rect works
- QRectF r = blockBoundingRect(b).translated(offset);
-
- QTextLayout *layout = b.layout();
- for (int i = layout->lineCount()-1; i >= 0; --i)
- maxWidth = qMax(maxWidth, layout->lineAt(i).naturalTextWidth() + 2*margin);
-
- blockHeight += r.height();
-
- b.setVisible(false); // restore previous state
- b.setLineCount(0); // restore 0 line count for invisible block
- }
- b = b.next();
- }
-
- painter.save();
- painter.setRenderHint(QPainter::Antialiasing, true);
- painter.translate(.5, .5);
- QBrush brush = palette().base();
- painter.setBrush(brush);
- painter.drawRoundedRect(QRectF(offset.x(),
- offset.y(),
- maxWidth, blockHeight).adjusted(0, 0, 0, 0), 3, 3);
- painter.restore();
-
- QTextBlock end = b;
- b = block;
- while (b != end) {
- if (!m_separators.contains(b.blockNumber())) {
- b.setVisible(true); // make sure block bounding rect works
- QRectF r = blockBoundingRect(b).translated(offset);
- QTextLayout *layout = b.layout();
- QVector<QTextLayout::FormatRange> selections;
- layout->draw(&painter, offset, selections, clip);
-
- b.setVisible(false); // restore previous state
- b.setLineCount(0); // restore 0 line count for invisible block
- offset.ry() += r.height();
- }
- b = b.next();
- }
}
-*/
//////////////////
@@ -1196,8 +966,8 @@ void SideBySideDiffEditorWidget::slotSendChunkToCodePaster()
return;
// Retrieve service by soft dependency.
- QObject *pasteService= ExtensionSystem::PluginManager::getObjectByClassName(
- QLatin1String("CodePaster::CodePasterService"));
+ QObject *pasteService
+ = ExtensionSystem::PluginManager::getObjectByClassName(QLatin1String("CodePaster::CodePasterService"));
if (pasteService) {
QMetaObject::invokeMethod(pasteService, "postText",
Q_ARG(QString, patch),
diff --git a/src/plugins/diffeditor/sidebysidediffeditorwidget.h b/src/plugins/diffeditor/sidebysidediffeditorwidget.h
index 54386f8970..18341aac1f 100644
--- a/src/plugins/diffeditor/sidebysidediffeditorwidget.h
+++ b/src/plugins/diffeditor/sidebysidediffeditorwidget.h
@@ -93,12 +93,9 @@ private slots:
void rightHSliderChanged();
void leftCursorPositionChanged();
void rightCursorPositionChanged();
-// void leftDocumentSizeChanged();
-// void rightDocumentSizeChanged();
private:
void showDiff();
-// void synchronizeFoldings(SideDiffEditorWidget *source, SideDiffEditorWidget *destination);
void jumpToOriginalFile(const QString &fileName,
int lineNumber, int columnNumber);
void patch(bool revert);