Replace old svn diff editor with the new one

Change-Id: I4137b709be718603cdc221ac938e139326c88835
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
jkobus
2014-11-06 13:23:40 +01:00
committed by Jarek Kobus
parent 07e3a032ff
commit 8d1940a796
12 changed files with 347 additions and 185 deletions

View File

@@ -349,7 +349,7 @@ QWidget *DiffEditor::toolBar()
reloadButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RELOAD_GRAY)));
reloadButton->setToolTip(tr("Reload Editor"));
m_reloadAction = m_toolBar->addWidget(reloadButton);
slotReloaderChanged(m_controller->reloader());
slotReloaderChanged();
QToolButton *toggleSync = new QToolButton(m_toolBar);
toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
@@ -378,8 +378,10 @@ QWidget *DiffEditor::toolBar()
this, SLOT(slotDiffEditorSwitched()));
connect(reloadButton, SIGNAL(clicked()),
m_controller, SLOT(requestReload()));
connect(m_controller, SIGNAL(reloaderChanged(DiffEditorReloader*)),
this, SLOT(slotReloaderChanged(DiffEditorReloader*)));
connect(m_controller, SIGNAL(reloaderChanged()),
this, SLOT(slotReloaderChanged()));
connect(m_controller, SIGNAL(contextLinesNumberEnablementChanged(bool)),
this, SLOT(slotReloaderChanged()));
return m_toolBar;
}
@@ -495,11 +497,14 @@ void DiffEditor::slotDescriptionVisibilityChanged()
m_toggleDescriptionAction->setVisible(enabled);
}
void DiffEditor::slotReloaderChanged(DiffEditorReloader *reloader)
void DiffEditor::slotReloaderChanged()
{
const DiffEditorReloader *reloader = m_controller->reloader();
const bool contextVisible = m_controller->isContextLinesNumberEnabled();
m_whitespaceButtonAction->setVisible(reloader);
m_contextLabelAction->setVisible(reloader);
m_contextSpinBoxAction->setVisible(reloader);
m_contextLabelAction->setVisible(reloader && contextVisible);
m_contextSpinBoxAction->setVisible(reloader && contextVisible);
m_reloadAction->setVisible(reloader);
}

View File

@@ -83,7 +83,7 @@ private slots:
void entryActivated(int index);
void slotDescriptionChanged(const QString &description);
void slotDescriptionVisibilityChanged();
void slotReloaderChanged(DiffEditorReloader *reloader);
void slotReloaderChanged();
void slotDiffEditorSwitched();
private:

View File

@@ -48,6 +48,7 @@ DiffEditorController::DiffEditorController(QObject *parent)
m_chunkIndex(-1),
m_descriptionEnabled(false),
m_contextLinesNumber(3),
m_contextLinesNumberEnabled(true),
m_ignoreWhitespace(true),
m_reloader(0)
{
@@ -97,6 +98,11 @@ int DiffEditorController::contextLinesNumber() const
return m_contextLinesNumber;
}
bool DiffEditorController::isContextLinesNumberEnabled() const
{
return m_contextLinesNumberEnabled;
}
bool DiffEditorController::isIgnoreWhitespace() const
{
return m_ignoreWhitespace;
@@ -150,7 +156,7 @@ void DiffEditorController::setReloader(DiffEditorReloader *reloader)
if (m_reloader)
m_reloader->setController(this);
emit reloaderChanged(m_reloader);
emit reloaderChanged();
}
void DiffEditorController::clear()
@@ -180,10 +186,6 @@ void DiffEditorController::setDescription(const QString &description)
return;
m_description = description;
// Empty line before headers and commit message
const int emptyLine = m_description.indexOf(QLatin1String("\n\n"));
if (emptyLine != -1)
m_description.insert(emptyLine, QLatin1Char('\n') + QLatin1String(Constants::EXPAND_BRANCHES));
emit descriptionChanged(m_description);
}
@@ -250,6 +252,15 @@ void DiffEditorController::setContextLinesNumber(int lines)
emit contextLinesNumberChanged(l);
}
void DiffEditorController::setContextLinesNumberEnabled(bool on)
{
if (m_contextLinesNumberEnabled == on)
return;
m_contextLinesNumberEnabled = on;
emit contextLinesNumberEnablementChanged(on);
}
void DiffEditorController::setIgnoreWhitespace(bool ignore)
{
if (m_ignoreWhitespace == ignore)

View File

@@ -54,6 +54,7 @@ public:
QString description() const;
bool isDescriptionEnabled() const;
int contextLinesNumber() const;
bool isContextLinesNumberEnabled() const;
bool isIgnoreWhitespace() const;
QString makePatch(bool revert, bool addPrefix = false) const;
@@ -69,6 +70,7 @@ public slots:
void setDescription(const QString &description);
void setDescriptionEnabled(bool on);
void setContextLinesNumber(int lines);
void setContextLinesNumberEnabled(bool on);
void setIgnoreWhitespace(bool ignore);
void requestReload();
void requestChunkActions(QMenu *menu,
@@ -86,12 +88,13 @@ signals:
void descriptionChanged(const QString &description);
void descriptionEnablementChanged(bool on);
void contextLinesNumberChanged(int lines);
void contextLinesNumberEnablementChanged(bool on);
void ignoreWhitespaceChanged(bool ignore);
void chunkActionsRequested(QMenu *menu, bool isValid);
void saveStateRequested();
void restoreStateRequested();
void expandBranchesRequested(const QString &revision);
void reloaderChanged(DiffEditorReloader *reloader);
void reloaderChanged();
private:
QString prepareBranchesForCommit(const QString &output);
@@ -104,6 +107,7 @@ private:
QString m_description;
bool m_descriptionEnabled;
int m_contextLinesNumber;
bool m_contextLinesNumberEnabled;
bool m_ignoreWhitespace;
DiffEditorReloader *m_reloader;
};

View File

@@ -894,6 +894,66 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
fileDataList7 << fileData1;
QTest::newRow("Dirty submodule") << patch
<< fileDataList7;
//////////////
// Subversion New
patch = _("Index: src/plugins/subversion/subversioneditor.cpp\n"
"===================================================================\n"
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
"+++ src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
"@@ -0,0 +125 @@\n\n");
fileData1 = FileData();
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
chunkData1 = ChunkData();
chunkData1.leftStartingLineNumber = -1;
chunkData1.rightStartingLineNumber = 124;
fileData1.chunks << chunkData1;
QList<FileData> fileDataList8;
fileDataList8 << fileData1;
QTest::newRow("Subversion New") << patch
<< fileDataList8;
//////////////
// Subversion Deleted
patch = _("Index: src/plugins/subversion/subversioneditor.cpp\n"
"===================================================================\n"
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
"@@ -1,125 +0,0 @@\n\n");
fileData1 = FileData();
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
chunkData1 = ChunkData();
chunkData1.leftStartingLineNumber = 0;
chunkData1.rightStartingLineNumber = -1;
fileData1.chunks << chunkData1;
QList<FileData> fileDataList9;
fileDataList9 << fileData1;
QTest::newRow("Subversion Deleted") << patch
<< fileDataList9;
//////////////
// Subversion Normal
patch = _("Index: src/plugins/subversion/subversioneditor.cpp\n"
"===================================================================\n"
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
"@@ -120,7 +120,7 @@\n\n");
fileData1 = FileData();
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
chunkData1 = ChunkData();
chunkData1.leftStartingLineNumber = 119;
chunkData1.rightStartingLineNumber = 119;
fileData1.chunks << chunkData1;
QList<FileData> fileDataList10;
fileDataList10 << fileData1;
QTest::newRow("Subversion Normal") << patch
<< fileDataList10;
}
void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()

View File

@@ -540,8 +540,11 @@ static QList<RowData> readLines(const QString &patch,
int i;
for (i = 0; i < lines.count(); i++) {
const QString line = lines.at(i);
if (line.isEmpty())
break; // need to have at least one character (1 column)
if (line.isEmpty()) { // need to have at least one character (1 column)
if (lastChunk)
i = lines.count(); // pretend as we've read all the lines (we just ignore the rest)
break;
}
QChar firstCharacter = line.at(0);
if (firstCharacter == QLatin1Char('\\')) { // no new line marker
if (!lastChunk) // can only appear in last chunk of the file
@@ -567,14 +570,17 @@ static QList<RowData> readLines(const QString &patch,
}
} else {
Diff::Command command = Diff::Equal;
if (firstCharacter == QLatin1Char(' ')) // common line
if (firstCharacter == QLatin1Char(' ')) { // common line
command = Diff::Equal;
else if (firstCharacter == QLatin1Char('-')) // deleted line
} else if (firstCharacter == QLatin1Char('-')) { // deleted line
command = Diff::Delete;
else if (firstCharacter == QLatin1Char('+')) // inserted line
} else if (firstCharacter == QLatin1Char('+')) { // inserted line
command = Diff::Insert;
else
break; // no other character may exist as the first character
} else { // no other character may exist as the first character
if (lastChunk)
i = lines.count(); // pretend as we've read all the lines (we just ignore the rest)
break;
}
Diff diffToBeAdded(command, line.mid(1) + newLine);