Commit 8d1940a7 authored by jkobus's avatar jkobus Committed by Jarek Kobus

Replace old svn diff editor with the new one

Change-Id: I4137b709be718603cdc221ac938e139326c88835
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 07e3a032
......@@ -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);
}
......
......@@ -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:
......
......@@ -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)
......
......@@ -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;
};
......
......@@ -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()
......
......@@ -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);
......
......@@ -828,6 +828,7 @@ GitDiffEditorReloader *GitClient::findOrCreateDiffEditor(const QString &document
reloader->setWorkingDirectory(workingDirectory);
}
QTC_ASSERT(reloader, return 0);
VcsBasePlugin::setSource(diffEditorDocument, source);
EditorManager::activateEditorForDocument(diffEditorDocument);
......@@ -2464,6 +2465,12 @@ QString GitClient::extendedShowDescription(const QString &workingDirectory, cons
modText.insert(lastHeaderLine, QLatin1String("Precedes: ") + precedes + QLatin1Char('\n'));
if (!follows.isEmpty())
modText.insert(lastHeaderLine, QLatin1String("Follows: ") + follows + QLatin1Char('\n'));
// Empty line before headers and commit message
const int emptyLine = modText.indexOf(QLatin1String("\n\n"));
if (emptyLine != -1)
modText.insert(emptyLine, QLatin1Char('\n') + QLatin1String(DiffEditor::Constants::EXPAND_BRANCHES));
return modText;
}
......
......@@ -4,4 +4,5 @@ QTC_LIB_DEPENDS += \
QTC_PLUGIN_DEPENDS += \
texteditor \
coreplugin \
vcsbase
vcsbase \
diffeditor
This diff is collapsed.
......@@ -41,6 +41,7 @@ namespace Subversion {
namespace Internal {
class SubversionSettings;
class SubversionDiffEditorReloader;
class SubversionClient : public VcsBase::VcsBaseClient
{
......@@ -60,8 +61,8 @@ public:
const QString &commitMessageFile,
const QStringList &extraOptions = QStringList());
void diff(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions = QStringList());
void diff(const QString &workingDirectory, const QStringList &files);
void describe(const QString &workingDirectory, int changeNumber, const QString &title);
QString findTopLevelForFile(const QFileInfo &file) const;
QStringList revisionSpec(const QString &revision) const;
StatusItem parseStatusLine(const QString &line) const;
......@@ -73,12 +74,15 @@ public:
protected:
Core::Id vcsEditorKind(VcsCommandTag cmd) const;
VcsBase::VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
private:
Utils::FileName m_svnVersionBinary;
QString m_svnVersion;
SubversionDiffEditorReloader *findOrCreateDiffEditor(const QString &documentId,
const QString &source,
const QString &title,
const QString &workingDirectory) const;
mutable Utils::FileName m_svnVersionBinary;
mutable QString m_svnVersion;
};
} // namespace Internal
......
......@@ -128,11 +128,7 @@ const VcsBaseEditorParameters editorParameters[] = {
{ AnnotateOutput,
"Subversion Annotation Editor", // id
QT_TRANSLATE_NOOP("VCS", "Subversion Annotation Editor"), // display_name
"text/vnd.qtcreator.svn.annotation"},
{ DiffOutput,
"Subversion Diff Editor", // id
QT_TRANSLATE_NOOP("VCS", "Subversion Diff Editor"), // display_name
"text/x-patch"}
"text/vnd.qtcreator.svn.annotation"}
};
// Utility to find a parameter set by type
......@@ -912,49 +908,14 @@ void SubversionPlugin::describe(const QString &source, const QString &changeNr)
qDebug() << Q_FUNC_INFO << source << topLevel << changeNr;
// Number must be >= 1
bool ok;
const int number = changeNr.toInt(&ok);
if (!ok || number < 1)
return;
// Run log to obtain message (local utf8)
QString description;
QStringList args(QLatin1String("log"));
args << SubversionClient::addAuthenticationOptions(settings());
args.push_back(QLatin1String("-r"));
args.push_back(changeNr);
const SubversionResponse logResponse =
runSvn(topLevel, args, m_settings.timeOutMs(), SshPasswordPrompt);
if (logResponse.error)
return;
description = logResponse.stdOut;
// Run diff (encoding via source codec)
args.clear();
args.push_back(QLatin1String("diff"));
args << SubversionClient::addAuthenticationOptions(settings());
args.push_back(QLatin1String("-r"));
QString diffArg;
QTextStream(&diffArg) << (number - 1) << ':' << number;
args.push_back(diffArg);
QTextCodec *codec = VcsBaseEditor::getCodec(source);
const SubversionResponse response =
runSvn(topLevel, args, m_settings.timeOutMs(),
SshPasswordPrompt, codec);
if (response.error)
return;
description += response.stdOut;
const QString title = QString::fromLatin1("svn describe %1#%2").arg(fi.fileName(), changeNr);
// Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
const QString tag = VcsBaseEditor::editorTag(DiffOutput, source, QStringList(), changeNr);
if (IEditor *editor = VcsBaseEditor::locateEditorByTag(tag)) {
editor->document()->setContents(description.toUtf8());
EditorManager::activateEditor(editor);
} else {
const QString title = QString::fromLatin1("svn describe %1#%2").arg(fi.fileName(), changeNr);
IEditor *newEditor = showOutputInEditor(title, description, DiffOutput, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag);
}
m_client->describe(topLevel, number, title);
}
void SubversionPlugin::slotDescribe()
......@@ -1233,39 +1194,6 @@ SubversionControl *SubversionPlugin::subVersionControl() const
}
#ifdef WITH_TESTS
void SubversionPlugin::testDiffFileResolving_data()
{
QTest::addColumn<QByteArray>("header");
QTest::addColumn<QByteArray>("fileName");
QTest::newRow("New") << QByteArray(
"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")
<< QByteArray("src/plugins/subversion/subversioneditor.cpp");
QTest::newRow("Deleted") << QByteArray(
"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")
<< QByteArray("src/plugins/subversion/subversioneditor.cpp");
QTest::newRow("Normal") << QByteArray(
"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")
<< QByteArray("src/plugins/subversion/subversioneditor.cpp");
}
void SubversionPlugin::testDiffFileResolving()
{
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id);
}
void SubversionPlugin::testLogResolving()
{
QByteArray data(
......
......@@ -93,6 +93,9 @@ public:
QString monitorFile(const QString &repository) const;
QString synchronousTopic(const QString &repository) const;
SubversionResponse runSvn(const QString &workingDir,
const QStringList &arguments, int timeOut,
unsigned flags, QTextCodec *outputCodec = 0) const;
public slots:
void vcsAnnotate(const QString &workingDir, const QString &file,
......@@ -123,8 +126,6 @@ private slots:
void statusRepository();
void updateRepository();
#ifdef WITH_TESTS
void testDiffFileResolving_data();
void testDiffFileResolving();
void testLogResolving();
#endif
......@@ -137,9 +138,6 @@ private:
Core::IEditor * showOutputInEditor(const QString& title, const QString &output,
int editorType, const QString &source,
QTextCodec *codec);
SubversionResponse runSvn(const QString &workingDir,
const QStringList &arguments, int timeOut,
unsigned flags, QTextCodec *outputCodec = 0) const;
void filelog(const QString &workingDir,
const QString &file = QString(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment