Commit 83566c3c authored by cerf's avatar cerf Committed by Tobias Hunger
Browse files

vcsbase: simplify init of the diff editor in VCSBaseClient



Bazaar and Mercurial plugins are impacted, they benefit auto load/save
of the diff settings

Change-Id: I67327b231fd80eeb61bb859879f9eabdc56739e8
Merge-request: 345
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/463

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
parent 21c04836
......@@ -278,10 +278,17 @@ QPair<QString, QString> BazaarClient::parseStatusLine(const QString &line) const
return status;
}
// Collect all parameters required for a diff to be able to associate them
// with a diff editor and re-run the diff with parameters.
struct BazaarDiffParameters
// Collect all parameters required for a diff or log to be able to associate
// them with an editor and re-run the command with parameters.
struct BazaarCommandParameters
{
BazaarCommandParameters(const QString &workDir,
const QStringList &inFiles,
const QStringList &options) :
workingDir(workDir), files(inFiles), extraOptions(options)
{
}
QString workingDir;
QStringList files;
QStringList extraOptions;
......@@ -292,61 +299,44 @@ class BazaarDiffParameterWidget : public VCSBase::VCSBaseEditorParameterWidget
{
Q_OBJECT
public:
explicit BazaarDiffParameterWidget(const BazaarDiffParameters &p, QWidget *parent = 0);
BazaarDiffParameterWidget(BazaarClient *client,
const BazaarCommandParameters &p, QWidget *parent = 0) :
VCSBase::VCSBaseEditorParameterWidget(parent), m_client(client), m_params(p)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore whitespace")),
&client->settings()->diffIgnoreWhiteSpace);
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore blank lines")),
&client->settings()->diffIgnoreBlankLines);
}
signals:
void reRunDiff(const Bazaar::Internal::BazaarDiffParameters &);
QStringList arguments() const
{
QStringList args;
// Bazaar wants "--diff-options=-w -B.."
const QStringList formatArguments = VCSBaseEditorParameterWidget::arguments();
if (!formatArguments.isEmpty()) {
const QString a = QLatin1String("--diff-options=")
+ formatArguments.join(QString(QLatin1Char(' ')));
args.append(a);
}
return args;
}
private slots:
void triggerReRun();
void executeCommand()
{
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
}
private:
const BazaarDiffParameters m_parameters;
BazaarClient *m_client;
const BazaarCommandParameters m_params;
};
BazaarDiffParameterWidget::BazaarDiffParameterWidget(const BazaarDiffParameters &p, QWidget *parent) :
VCSBase::VCSBaseEditorParameterWidget(parent), m_parameters(p)
{
addToggleButton(QLatin1String("-w"), tr("Ignore whitespace"));
addToggleButton(QLatin1String("-B"), tr("Ignore blank lines"));
connect(this, SIGNAL(argumentsChanged()), this, SLOT(triggerReRun()));
}
void BazaarDiffParameterWidget::triggerReRun()
{
BazaarDiffParameters effectiveParameters = m_parameters;
// Bazaar wants "--diff-options=-w -B.."
const QStringList formatArguments = arguments();
if (!formatArguments.isEmpty()) {
const QString a = QLatin1String("--diff-options=")
+ formatArguments.join(QString(QLatin1Char(' ')));
effectiveParameters.extraOptions.append(a);
}
emit reRunDiff(effectiveParameters);
}
void BazaarClient::bazaarDiff(const Bazaar::Internal::BazaarDiffParameters &p)
{
diff(p.workingDir, p.files, p.extraOptions);
}
void BazaarClient::initializeDiffEditor(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *diffEditorWidget)
VCSBase::VCSBaseEditorParameterWidget *BazaarClient::createDiffEditor(
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
{
// Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor.
BazaarDiffParameters parameters;
parameters.workingDir = workingDir;
parameters.files = files;
parameters.extraOptions = extraOptions;
diffEditorWidget->setRevertDiffChunkEnabled(true);
BazaarDiffParameterWidget *pw = new BazaarDiffParameterWidget(parameters);
connect(pw, SIGNAL(reRunDiff(Bazaar::Internal::BazaarDiffParameters)),
this, SLOT(bazaarDiff(Bazaar::Internal::BazaarDiffParameters)));
connect(diffEditorWidget, SIGNAL(diffChunkReverted(VCSBase::DiffChunk)),
pw, SLOT(triggerReRun()));
diffEditorWidget->setConfigurationWidget(pw);
const BazaarCommandParameters parameters(workingDir, files, extraOptions);
return new BazaarDiffParameterWidget(this, parameters);
}
} //namespace Internal
......
......@@ -39,7 +39,6 @@
namespace Bazaar {
namespace Internal {
struct BazaarDiffParameters;
class BazaarSettings;
......@@ -55,9 +54,6 @@ public:
BranchInfo synchronousBranchQuery(const QString &repositoryRoot) const;
QString findTopLevelForFile(const QFileInfo &file) const;
private slots:
void bazaarDiff(const Bazaar::Internal::BazaarDiffParameters &p);
protected:
QString vcsEditorKind(VCSCommand cmd) const;
......@@ -79,9 +75,9 @@ protected:
const QString &revision, int lineNumber) const;
QStringList diffArguments(const QStringList &files,
const QStringList &extraOptions) const;
void initializeDiffEditor(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *diffEditorWidget);
VCSBase::VCSBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
QStringList logArguments(const QStringList &files,
const QStringList &extraOptions) const;
QStringList statusArguments(const QString &file) const;
......
......@@ -33,10 +33,17 @@
#include "bazaarsettings.h"
#include "constants.h"
#include <QtCore/QSettings>
namespace Bazaar {
namespace Internal {
BazaarSettings::BazaarSettings()
const QLatin1String diffIgnoreWhiteSpaceKey("diffIgnoreWhiteSpace");
const QLatin1String diffIgnoreBlankLinesKey("diffIgnoreBlankLines");
BazaarSettings::BazaarSettings() :
diffIgnoreWhiteSpace(false),
diffIgnoreBlankLines(false)
{
setBinary(QLatin1String(Constants::BAZAARDEFAULT));
}
......@@ -44,6 +51,10 @@ BazaarSettings::BazaarSettings()
BazaarSettings& BazaarSettings::operator=(const BazaarSettings& other)
{
VCSBase::VCSBaseClientSettings::operator=(other);
if (this != &other) {
diffIgnoreWhiteSpace = other.diffIgnoreWhiteSpace;
diffIgnoreBlankLines = other.diffIgnoreBlankLines;
}
return *this;
}
......@@ -52,5 +63,32 @@ bool BazaarSettings::sameUserId(const BazaarSettings& other) const
return userName() == other.userName() && email() == other.email();
}
void BazaarSettings::writeSettings(QSettings *settings, const QString &group) const
{
VCSBaseClientSettings::writeSettings(settings, group);
settings->beginGroup(group);
settings->setValue(diffIgnoreWhiteSpaceKey, diffIgnoreWhiteSpace);
settings->setValue(diffIgnoreBlankLinesKey, diffIgnoreBlankLines);
settings->endGroup();
}
void BazaarSettings::readSettings(const QSettings *settings, const QString &group)
{
VCSBaseClientSettings::readSettings(settings, group);
const QString keyRoot = group + QLatin1Char('/');
diffIgnoreWhiteSpace = settings->value(keyRoot + diffIgnoreWhiteSpaceKey, false).toBool();
diffIgnoreBlankLines = settings->value(keyRoot + diffIgnoreBlankLinesKey, false).toBool();
}
bool BazaarSettings::equals(const VCSBaseClientSettings &rhs) const
{
const BazaarSettings *bzrRhs = dynamic_cast<const BazaarSettings *>(&rhs);
if (bzrRhs == 0)
return false;
return VCSBaseClientSettings::equals(rhs)
&& diffIgnoreWhiteSpace == bzrRhs->diffIgnoreWhiteSpace
&& diffIgnoreBlankLines == bzrRhs->diffIgnoreBlankLines;
}
} // namespace Internal
} // namespace Bazaar
......@@ -44,6 +44,13 @@ public:
BazaarSettings();
BazaarSettings& operator=(const BazaarSettings& other);
bool sameUserId(const BazaarSettings& other) const;
virtual void writeSettings(QSettings *settings, const QString &group) const;
virtual void readSettings(const QSettings *settings, const QString &group);
virtual bool equals(const VCSBaseClientSettings &rhs) const;
bool diffIgnoreWhiteSpace;
bool diffIgnoreBlankLines;
};
} // namespace Internal
......
......@@ -51,11 +51,16 @@
namespace Mercurial {
namespace Internal {
MercurialClient::MercurialClient(VCSBase::VCSBaseClientSettings *settings) :
MercurialClient::MercurialClient(MercurialSettings *settings) :
VCSBase::VCSBaseClient(settings)
{
}
MercurialSettings *MercurialClient::settings() const
{
return dynamic_cast<MercurialSettings *>(VCSBase::VCSBaseClient::settings());
}
bool MercurialClient::manifestSync(const QString &repository, const QString &relativeFilename)
{
// This only works when called from the repo and outputs paths relative to it.
......@@ -486,55 +491,34 @@ class MercurialDiffParameterWidget : public VCSBase::VCSBaseEditorParameterWidge
{
Q_OBJECT
public:
explicit MercurialDiffParameterWidget(const MercurialDiffParameters &p, QWidget *parent = 0);
signals:
void reRunDiff(const Mercurial::Internal::MercurialDiffParameters &);
MercurialDiffParameterWidget(MercurialClient *client,
const MercurialDiffParameters &p, QWidget *parent = 0) :
VCSBase::VCSBaseEditorParameterWidget(parent), m_client(client), m_params(p)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore whitespace")),
&client->settings()->diffIgnoreWhiteSpace);
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore blank lines")),
&client->settings()->diffIgnoreBlankLines);
}
private slots:
void triggerReRun();
void executeCommand()
{
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
}
private:
const MercurialDiffParameters m_parameters;
MercurialClient *m_client;
const MercurialDiffParameters m_params;
};
MercurialDiffParameterWidget::MercurialDiffParameterWidget(const MercurialDiffParameters &p, QWidget *parent) :
VCSBase::VCSBaseEditorParameterWidget(parent), m_parameters(p)
{
addToggleButton(QLatin1String("-w"), tr("Ignore whitespace"));
addToggleButton(QLatin1String("-B"), tr("Ignore blank lines"));
connect(this, SIGNAL(argumentsChanged()), this, SLOT(triggerReRun()));
}
void MercurialDiffParameterWidget::triggerReRun()
{
MercurialDiffParameters effectiveParameters = m_parameters;
effectiveParameters.extraOptions += arguments();
emit reRunDiff(effectiveParameters);
}
void MercurialClient::mercurialDiff(const Mercurial::Internal::MercurialDiffParameters &p)
{
diff(p.workingDir, p.files, p.extraOptions);
}
void MercurialClient::initializeDiffEditor(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *diffEditorWidget)
VCSBase::VCSBaseEditorParameterWidget *MercurialClient::createDiffEditor(
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
{
// Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor.
MercurialDiffParameters parameters;
parameters.workingDir = workingDir;
parameters.files = files;
parameters.extraOptions = extraOptions;
diffEditorWidget->setRevertDiffChunkEnabled(true);
MercurialDiffParameterWidget *pw = new MercurialDiffParameterWidget(parameters);
connect(pw, SIGNAL(reRunDiff(Mercurial::Internal::MercurialDiffParameters)),
this, SLOT(mercurialDiff(Mercurial::Internal::MercurialDiffParameters)));
connect(diffEditorWidget, SIGNAL(diffChunkReverted(VCSBase::DiffChunk)),
pw, SLOT(triggerReRun()));
diffEditorWidget->setConfigurationWidget(pw);
return new MercurialDiffParameterWidget(this, parameters);
}
} // namespace Internal
......
......@@ -33,6 +33,7 @@
#ifndef MERCURIALCLIENT_H
#define MERCURIALCLIENT_H
#include "mercurialsettings.h"
#include <vcsbase/vcsbaseclient.h>
namespace Mercurial {
......@@ -43,7 +44,10 @@ class MercurialClient : public VCSBase::VCSBaseClient
{
Q_OBJECT
public:
MercurialClient(VCSBase::VCSBaseClientSettings *settings);
MercurialClient(MercurialSettings *settings);
MercurialSettings *settings() const;
virtual bool synchronousClone(const QString &workingDir,
const QString &srcLocation,
const QString &dstLocation,
......@@ -64,9 +68,6 @@ public:
void outgoing(const QString &repositoryRoot);
QString vcsGetRepositoryURL(const QString &directory);
private slots:
void mercurialDiff(const Mercurial::Internal::MercurialDiffParameters &);
public:
QString findTopLevelForFile(const QFileInfo &file) const;
......@@ -91,9 +92,9 @@ protected:
const QString &revision, int lineNumber) const;
QStringList diffArguments(const QStringList &files,
const QStringList &extraOptions) const;
void initializeDiffEditor(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *ed);
VCSBase::VCSBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
QStringList logArguments(const QStringList &files,
const QStringList &extraOptions) const;
QStringList statusArguments(const QString &file) const;
......
......@@ -33,15 +33,57 @@
#include "mercurialsettings.h"
#include "constants.h"
using namespace Mercurial::Internal;
MercurialSettings::MercurialSettings()
{
setBinary(QLatin1String(Constants::MERCURIALDEFAULT));
}
MercurialSettings& MercurialSettings::operator=(const MercurialSettings& other)
{
VCSBase::VCSBaseClientSettings::operator=(other);
return *this;
}
#include <QtCore/QSettings>
namespace Mercurial {
namespace Internal {
const QLatin1String diffIgnoreWhiteSpaceKey("diffIgnoreWhiteSpace");
const QLatin1String diffIgnoreBlankLinesKey("diffIgnoreBlankLines");
MercurialSettings::MercurialSettings() :
diffIgnoreWhiteSpace(false),
diffIgnoreBlankLines(false)
{
setBinary(QLatin1String(Constants::MERCURIALDEFAULT));
}
MercurialSettings& MercurialSettings::operator=(const MercurialSettings& other)
{
VCSBase::VCSBaseClientSettings::operator=(other);
if (this != &other) {
diffIgnoreWhiteSpace = other.diffIgnoreWhiteSpace;
diffIgnoreBlankLines = other.diffIgnoreBlankLines;
}
return *this;
}
void MercurialSettings::writeSettings(QSettings *settings, const QString &group) const
{
VCSBaseClientSettings::writeSettings(settings, group);
settings->beginGroup(group);
settings->setValue(diffIgnoreWhiteSpaceKey, diffIgnoreWhiteSpace);
settings->setValue(diffIgnoreBlankLinesKey, diffIgnoreBlankLines);
settings->endGroup();
}
void MercurialSettings::readSettings(const QSettings *settings, const QString &group)
{
VCSBaseClientSettings::readSettings(settings, group);
const QString keyRoot = group + QLatin1Char('/');
diffIgnoreWhiteSpace = settings->value(keyRoot + diffIgnoreWhiteSpaceKey, false).toBool();
diffIgnoreBlankLines = settings->value(keyRoot + diffIgnoreBlankLinesKey, false).toBool();
}
bool MercurialSettings::equals(const VCSBaseClientSettings &rhs) const
{
const MercurialSettings *hgRhs = dynamic_cast<const MercurialSettings *>(&rhs);
if (hgRhs == 0)
return false;
return VCSBaseClientSettings::equals(rhs)
&& diffIgnoreWhiteSpace == hgRhs->diffIgnoreWhiteSpace
&& diffIgnoreBlankLines == hgRhs->diffIgnoreBlankLines;
}
} // namespace Internal
} // namespace Mercurial
......@@ -43,6 +43,13 @@ class MercurialSettings : public VCSBase::VCSBaseClientSettings
public:
MercurialSettings();
MercurialSettings& operator=(const MercurialSettings& other);
virtual void writeSettings(QSettings *settings, const QString &group) const;
virtual void readSettings(const QSettings *settings, const QString &group);
virtual bool equals(const VCSBaseClientSettings &rhs) const;
bool diffIgnoreWhiteSpace;
bool diffIgnoreBlankLines;
};
} // namespace Internal
......
......@@ -33,6 +33,7 @@
#include "vcsbaseclient.h"
#include "vcsjobrunner.h"
#include "vcsbaseclientsettings.h"
#include "vcsbaseeditorparameterwidget.h"
#include <QtDebug>
......@@ -275,17 +276,25 @@ void VCSBaseClient::diff(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions)
{
const QString vcsCmdString = vcsCommandString(DiffCommand);
QStringList args;
args << vcsCmdString << diffArguments(files, extraOptions);
const QString kind = vcsEditorKind(DiffCommand);
const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files);
const QString title = vcsEditorTitle(vcsCmdString, id);
const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);
VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, source, true,
vcsCmdString.toLatin1().constData(), id);
editor->setRevertDiffChunkEnabled(true);
editor->setDiffBaseDirectory(workingDir);
initializeDiffEditor(workingDir, files, extraOptions, editor);
VCSBaseEditorParameterWidget *paramWidget = createDiffEditor(workingDir, files, extraOptions);
if (paramWidget != 0) {
connect(editor, SIGNAL(diffChunkReverted(VCSBase::DiffChunk)),
paramWidget, SLOT(executeCommand()));
editor->setConfigurationWidget(paramWidget);
}
QStringList args;
const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
args << vcsCmdString << diffArguments(files, extraOptions + paramArgs);
QSharedPointer<VCSJob> job(new VCSJob(workingDir, args, editor));
enqueueJob(job);
}
......@@ -456,12 +465,17 @@ void VCSBaseClient::settingsChanged()
}
}
void VCSBaseClient::initializeDiffEditor(const QString & /* workingDir */, const QStringList & /* files */,
const QStringList & /* extraOptions */,
VCSBaseEditorWidget *)
VCSBaseEditorParameterWidget *VCSBaseClient::createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions)
{
Q_UNUSED(workingDir);
Q_UNUSED(files);
Q_UNUSED(extraOptions);
return 0;
}
QString VCSBaseClient::vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const
{
return QFileInfo(settings()->binary()).baseName() +
......
......@@ -61,6 +61,7 @@ class VCSBaseEditorWidget;
class VCSBaseClientSettings;
class VCSJob;
class VCSBaseClientPrivate;
class VCSBaseEditorParameterWidget;
class VCSBASE_EXPORT VCSBaseClient : public QObject
{
......@@ -154,8 +155,9 @@ protected:
const QString &revision, int lineNumber) const = 0;
virtual QStringList diffArguments(const QStringList &files,
const QStringList &extraOptions) const = 0;
virtual void initializeDiffEditor(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions, VCSBaseEditorWidget *ed);
virtual VCSBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
virtual QStringList logArguments(const QStringList &files,
const QStringList &extraOptions) const = 0;
virtual QStringList statusArguments(const QString &file) const = 0;
......
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