forked from qt-creator/qt-creator
Vcs: in VcsBaseClient use functors to create log/diff parameter widgets
Also API of VcsBaseEditorParameterWidget was changed to take benefit of C++11 lambdas. Slot executeCommand() is no longer virtual and only fires signal commandExecutionRequested(). The Vcs client just has to bind a lambda to this signal instead of some boiler-plate code like keeping track of the arguments of diff/log with "struct XxxDiffParameters", etc. Change-Id: I347c97d84a8324e9c661df4e6d9a6075980b020f Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -61,9 +61,66 @@ SynchronousProcessResponse::Result BazaarDiffExitCodeInterpreter::interpretExitC
|
||||
return SynchronousProcessResponse::Finished;
|
||||
}
|
||||
|
||||
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
||||
class BazaarDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BazaarDiffParameterWidget(BazaarSettings *settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
settings->boolPointer(BazaarSettings::diffIgnoreWhiteSpaceKey));
|
||||
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
|
||||
settings->boolPointer(BazaarSettings::diffIgnoreBlankLinesKey));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
class BazaarLogParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BazaarLogParameterWidget(BazaarSettings *settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
|
||||
tr("Show files changed in each revision")),
|
||||
settings->boolPointer(BazaarSettings::logVerboseKey));
|
||||
mapSetting(addToggleButton(QLatin1String("--forward"), tr("Forward"),
|
||||
tr("Show from oldest to newest")),
|
||||
settings->boolPointer(BazaarSettings::logForwardKey));
|
||||
mapSetting(addToggleButton(QLatin1String("--include-merges"), tr("Include merges"),
|
||||
tr("Show merged revisions")),
|
||||
settings->boolPointer(BazaarSettings::logIncludeMergesKey));
|
||||
|
||||
QList<ComboBoxItem> logChoices;
|
||||
logChoices << ComboBoxItem(tr("Detailed"), QLatin1String("long"))
|
||||
<< ComboBoxItem(tr("Moderately short"), QLatin1String("short"))
|
||||
<< ComboBoxItem(tr("One line"), QLatin1String("line"))
|
||||
<< ComboBoxItem(tr("GNU ChangeLog"), QLatin1String("gnu-changelog"));
|
||||
mapSetting(addComboBox(QStringList(QLatin1String("--log-format=%1")), logChoices),
|
||||
settings->stringPointer(BazaarSettings::logFormatKey));
|
||||
}
|
||||
};
|
||||
|
||||
BazaarClient::BazaarClient(BazaarSettings *settings) :
|
||||
VcsBaseClient(settings)
|
||||
{
|
||||
setDiffParameterWidgetCreator([=] { return new BazaarDiffParameterWidget(settings); });
|
||||
setLogParameterWidgetCreator([=] { return new BazaarLogParameterWidget(settings); });
|
||||
}
|
||||
|
||||
BazaarSettings *BazaarClient::settings() const
|
||||
@@ -253,112 +310,6 @@ BazaarClient::StatusItem BazaarClient::parseStatusLine(const QString &line) cons
|
||||
return item;
|
||||
}
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
||||
class BazaarDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BazaarDiffParameterWidget(BazaarClient *client,
|
||||
const BazaarCommandParameters &p, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
client->settings()->boolPointer(BazaarSettings::diffIgnoreWhiteSpaceKey));
|
||||
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
|
||||
client->settings()->boolPointer(BazaarSettings::diffIgnoreBlankLinesKey));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void executeCommand()
|
||||
{
|
||||
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
|
||||
}
|
||||
|
||||
private:
|
||||
BazaarClient *m_client;
|
||||
const BazaarCommandParameters m_params;
|
||||
};
|
||||
|
||||
VcsBaseEditorParameterWidget *BazaarClient::createDiffEditor(
|
||||
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
||||
{
|
||||
const BazaarCommandParameters parameters(workingDir, files, extraOptions);
|
||||
return new BazaarDiffParameterWidget(this, parameters);
|
||||
}
|
||||
|
||||
class BazaarLogParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BazaarLogParameterWidget(BazaarClient *client,
|
||||
const BazaarCommandParameters &p, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
||||
{
|
||||
BazaarSettings *settings = m_client->settings();
|
||||
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
|
||||
tr("Show files changed in each revision")),
|
||||
settings->boolPointer(BazaarSettings::logVerboseKey));
|
||||
mapSetting(addToggleButton(QLatin1String("--forward"), tr("Forward"),
|
||||
tr("Show from oldest to newest")),
|
||||
settings->boolPointer(BazaarSettings::logForwardKey));
|
||||
mapSetting(addToggleButton(QLatin1String("--include-merges"), tr("Include merges"),
|
||||
tr("Show merged revisions")),
|
||||
settings->boolPointer(BazaarSettings::logIncludeMergesKey));
|
||||
|
||||
QList<ComboBoxItem> logChoices;
|
||||
logChoices << ComboBoxItem(tr("Detailed"), QLatin1String("long"))
|
||||
<< ComboBoxItem(tr("Moderately short"), QLatin1String("short"))
|
||||
<< ComboBoxItem(tr("One line"), QLatin1String("line"))
|
||||
<< ComboBoxItem(tr("GNU ChangeLog"), QLatin1String("gnu-changelog"));
|
||||
mapSetting(addComboBox(QStringList(QLatin1String("--log-format=%1")), logChoices),
|
||||
settings->stringPointer(BazaarSettings::logFormatKey));
|
||||
}
|
||||
|
||||
void executeCommand()
|
||||
{
|
||||
m_client->log(m_params.workingDir, m_params.files, m_params.extraOptions);
|
||||
}
|
||||
|
||||
private:
|
||||
BazaarClient *m_client;
|
||||
const BazaarCommandParameters m_params;
|
||||
};
|
||||
|
||||
VcsBaseEditorParameterWidget *BazaarClient::createLogEditor(
|
||||
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
||||
{
|
||||
const BazaarCommandParameters parameters(workingDir, files, extraOptions);
|
||||
return new BazaarLogParameterWidget(this, parameters);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Bazaar
|
||||
|
||||
|
@@ -68,12 +68,6 @@ protected:
|
||||
QString vcsCommandString(VcsCommandTag cmd) const;
|
||||
Utils::ExitCodeInterpreter *exitCodeInterpreter(VcsCommandTag cmd, QObject *parent) const;
|
||||
QStringList revisionSpec(const QString &revision) const;
|
||||
VcsBase::VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions);
|
||||
VcsBase::VcsBaseEditorParameterWidget *createLogEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions);
|
||||
StatusItem parseStatusLine(const QString &line) const;
|
||||
|
||||
private:
|
||||
|
@@ -65,59 +65,40 @@ SynchronousProcessResponse::Result CvsDiffExitCodeInterpreter::interpretExitCode
|
||||
return SynchronousProcessResponse::Finished;
|
||||
}
|
||||
|
||||
// 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 CvsDiffParameters
|
||||
{
|
||||
QString workingDir;
|
||||
QStringList extraOptions;
|
||||
QStringList files;
|
||||
};
|
||||
|
||||
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
||||
class CvsDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CvsDiffParameterWidget(CvsClient *client,
|
||||
const CvsDiffParameters &p,
|
||||
QWidget *parent = 0);
|
||||
explicit CvsDiffParameterWidget(CvsSettings *settings, QWidget *parent = 0);
|
||||
QStringList arguments() const;
|
||||
void executeCommand();
|
||||
|
||||
private:
|
||||
|
||||
CvsClient *m_client;
|
||||
const CvsDiffParameters m_params;
|
||||
const CvsSettings *m_settings;
|
||||
};
|
||||
|
||||
CvsDiffParameterWidget::CvsDiffParameterWidget(CvsClient *client,
|
||||
const CvsDiffParameters &p,
|
||||
QWidget *parent)
|
||||
: VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
||||
CvsDiffParameterWidget::CvsDiffParameterWidget(CvsSettings *settings, QWidget *parent)
|
||||
: VcsBaseEditorParameterWidget(parent),
|
||||
m_settings(settings)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
client->settings()->boolPointer(CvsSettings::diffIgnoreWhiteSpaceKey));
|
||||
settings->boolPointer(CvsSettings::diffIgnoreWhiteSpaceKey));
|
||||
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
|
||||
client->settings()->boolPointer(CvsSettings::diffIgnoreBlankLinesKey));
|
||||
settings->boolPointer(CvsSettings::diffIgnoreBlankLinesKey));
|
||||
}
|
||||
|
||||
QStringList CvsDiffParameterWidget::arguments() const
|
||||
{
|
||||
QStringList args;
|
||||
args = m_client->settings()->stringValue(CvsSettings::diffOptionsKey).split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
args = m_settings->stringValue(CvsSettings::diffOptionsKey).split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
args += VcsBaseEditorParameterWidget::arguments();
|
||||
return args;
|
||||
}
|
||||
|
||||
void CvsDiffParameterWidget::executeCommand()
|
||||
{
|
||||
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
|
||||
}
|
||||
|
||||
CvsClient::CvsClient(CvsSettings *settings) :
|
||||
VcsBaseClient(settings)
|
||||
{
|
||||
setDiffParameterWidgetCreator([=] { return new CvsDiffParameterWidget(settings); });
|
||||
}
|
||||
|
||||
CvsSettings *CvsClient::settings() const
|
||||
@@ -169,17 +150,6 @@ VcsBaseClient::StatusItem CvsClient::parseStatusLine(const QString &line) const
|
||||
return VcsBaseClient::StatusItem();
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *CvsClient::createDiffEditor(
|
||||
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
||||
{
|
||||
Q_UNUSED(extraOptions)
|
||||
CvsDiffParameters p;
|
||||
p.workingDir = workingDir;
|
||||
p.files = files;
|
||||
p.extraOptions = extraOptions;
|
||||
return new CvsDiffParameterWidget(this, p);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Cvs
|
||||
|
||||
|
@@ -53,14 +53,9 @@ public:
|
||||
QStringList revisionSpec(const QString &revision) const;
|
||||
StatusItem parseStatusLine(const QString &line) const;
|
||||
|
||||
|
||||
protected:
|
||||
Utils::ExitCodeInterpreter *exitCodeInterpreter(VcsCommandTag cmd, QObject *parent) const;
|
||||
Core::Id vcsEditorKind(VcsCommandTag cmd) const;
|
||||
VcsBase::VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions);
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -449,32 +449,24 @@ class BaseGitDiffArgumentsWidget : public VcsBaseEditorParameterWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BaseGitDiffArgumentsWidget(GitClient *client, const QString &directory,
|
||||
const QStringList &args) :
|
||||
m_workingDirectory(directory),
|
||||
m_client(client)
|
||||
BaseGitDiffArgumentsWidget(GitSettings *settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
{
|
||||
QTC_ASSERT(!directory.isEmpty(), return);
|
||||
QTC_ASSERT(m_client, return);
|
||||
QTC_ASSERT(settings, return);
|
||||
|
||||
m_patienceButton = addToggleButton(
|
||||
QLatin1String("--patience"),
|
||||
tr("Patience"),
|
||||
tr("Use the patience algorithm for calculating the differences."));
|
||||
mapSetting(m_patienceButton, client->settings()->boolPointer(
|
||||
GitSettings::diffPatienceKey));
|
||||
mapSetting(m_patienceButton, settings->boolPointer(GitSettings::diffPatienceKey));
|
||||
m_ignoreWSButton = addToggleButton(
|
||||
QLatin1String("--ignore-space-change"), tr("Ignore Whitespace"),
|
||||
tr("Ignore whitespace only changes."));
|
||||
mapSetting(m_ignoreWSButton,
|
||||
m_client->settings()->boolPointer(GitSettings::ignoreSpaceChangesInDiffKey));
|
||||
|
||||
setBaseArguments(args);
|
||||
settings->boolPointer(GitSettings::ignoreSpaceChangesInDiffKey));
|
||||
}
|
||||
|
||||
protected:
|
||||
QString m_workingDirectory;
|
||||
GitClient *m_client;
|
||||
QToolButton *m_patienceButton;
|
||||
QToolButton *m_ignoreWSButton;
|
||||
};
|
||||
@@ -484,44 +476,16 @@ class GitBlameArgumentsWidget : public VcsBaseEditorParameterWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GitBlameArgumentsWidget(Git::Internal::GitClient *client,
|
||||
const QString &directory,
|
||||
const QStringList &args,
|
||||
const QString &revision, const QString &fileName) :
|
||||
m_editor(0),
|
||||
m_client(client),
|
||||
m_workingDirectory(directory),
|
||||
m_revision(revision),
|
||||
m_fileName(fileName)
|
||||
GitBlameArgumentsWidget(GitSettings *settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
{
|
||||
mapSetting(addToggleButton(QString(), tr("Omit Date"),
|
||||
tr("Hide the date of a change from the output.")),
|
||||
m_client->settings()->boolPointer(GitSettings::omitAnnotationDateKey));
|
||||
settings->boolPointer(GitSettings::omitAnnotationDateKey));
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace"),
|
||||
tr("Ignore whitespace only changes.")),
|
||||
m_client->settings()->boolPointer(GitSettings::ignoreSpaceChangesInBlameKey));
|
||||
|
||||
setBaseArguments(args);
|
||||
settings->boolPointer(GitSettings::ignoreSpaceChangesInBlameKey));
|
||||
}
|
||||
|
||||
void setEditor(VcsBaseEditorWidget *editor)
|
||||
{
|
||||
QTC_ASSERT(editor, return);
|
||||
m_editor = editor;
|
||||
}
|
||||
|
||||
void executeCommand()
|
||||
{
|
||||
int line = VcsBaseEditor::lineNumberOfCurrentEditor();
|
||||
m_client->blame(m_workingDirectory, baseArguments(), m_fileName, m_revision, line);
|
||||
}
|
||||
|
||||
private:
|
||||
VcsBaseEditorWidget *m_editor;
|
||||
GitClient *m_client;
|
||||
QString m_workingDirectory;
|
||||
QString m_revision;
|
||||
QString m_fileName;
|
||||
};
|
||||
|
||||
class GitLogArgumentsWidget : public BaseGitDiffArgumentsWidget
|
||||
@@ -529,20 +493,12 @@ class GitLogArgumentsWidget : public BaseGitDiffArgumentsWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GitLogArgumentsWidget(Git::Internal::GitClient *client,
|
||||
const QString &directory,
|
||||
bool enableAnnotationContextMenu,
|
||||
const QStringList &args,
|
||||
const QString &fileName) :
|
||||
BaseGitDiffArgumentsWidget(client, directory, args),
|
||||
m_client(client),
|
||||
m_workingDirectory(directory),
|
||||
m_enableAnnotationContextMenu(enableAnnotationContextMenu)
|
||||
GitLogArgumentsWidget(GitSettings *settings, QWidget *parent = 0) :
|
||||
BaseGitDiffArgumentsWidget(settings, parent)
|
||||
{
|
||||
QTC_ASSERT(!directory.isEmpty(), return);
|
||||
QToolButton *diffButton = addToggleButton(QLatin1String("--patch"), tr("Show Diff"),
|
||||
tr("Show difference."));
|
||||
mapSetting(diffButton, m_client->settings()->boolPointer(GitSettings::logDiffKey));
|
||||
mapSetting(diffButton, settings->boolPointer(GitSettings::logDiffKey));
|
||||
connect(diffButton, SIGNAL(toggled(bool)), m_patienceButton, SLOT(setVisible(bool)));
|
||||
connect(diffButton, SIGNAL(toggled(bool)), m_ignoreWSButton, SLOT(setVisible(bool)));
|
||||
m_patienceButton->setVisible(diffButton->isChecked());
|
||||
@@ -552,25 +508,8 @@ public:
|
||||
graphArguments << (QLatin1String("--pretty=format:") + QLatin1String(graphLogFormatC));
|
||||
QToolButton *graphButton = addToggleButton(graphArguments, tr("Graph"),
|
||||
tr("Show textual graph log."));
|
||||
mapSetting(graphButton, m_client->settings()->boolPointer(GitSettings::graphLogKey));
|
||||
setFileName(fileName);
|
||||
mapSetting(graphButton, settings->boolPointer(GitSettings::graphLogKey));
|
||||
}
|
||||
|
||||
void setFileName(const QString &fileNames)
|
||||
{
|
||||
m_fileName = fileNames;
|
||||
}
|
||||
|
||||
void executeCommand()
|
||||
{
|
||||
m_client->log(m_workingDirectory, m_fileName, m_enableAnnotationContextMenu, baseArguments());
|
||||
}
|
||||
|
||||
private:
|
||||
GitClient *m_client;
|
||||
QString m_workingDirectory;
|
||||
bool m_enableAnnotationContextMenu;
|
||||
QString m_fileName;
|
||||
};
|
||||
|
||||
class ConflictHandler : public QObject
|
||||
@@ -1033,11 +972,13 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
const Id editorId = Git::Constants::GIT_LOG_EDITOR_ID;
|
||||
const QString sourceFile = VcsBaseEditor::getSource(workingDirectory, fileName);
|
||||
VcsBaseEditorWidget *editor = findExistingVCSEditor("logFileName", sourceFile);
|
||||
if (!editor)
|
||||
if (!editor) {
|
||||
auto *argWidget = new GitLogArgumentsWidget(settings());
|
||||
QObject::connect(argWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] { log(workingDirectory, fileName, enableAnnotationContextMenu, args); });
|
||||
editor = createVcsEditor(editorId, title, sourceFile, CodecLogOutput, "logFileName", sourceFile,
|
||||
new GitLogArgumentsWidget(this, workingDirectory,
|
||||
enableAnnotationContextMenu,
|
||||
args, fileName));
|
||||
argWidget);
|
||||
}
|
||||
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
||||
editor->setWorkingDirectory(workingDirectory);
|
||||
|
||||
@@ -1049,9 +990,8 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
if (logCount > 0)
|
||||
arguments << QLatin1String("-n") << QString::number(logCount);
|
||||
|
||||
GitLogArgumentsWidget *argWidget = qobject_cast<GitLogArgumentsWidget *>(editor->configurationWidget());
|
||||
auto *argWidget = editor->configurationWidget();
|
||||
argWidget->setBaseArguments(args);
|
||||
argWidget->setFileName(fileName);
|
||||
QStringList userArgs = argWidget->arguments();
|
||||
|
||||
arguments.append(userArgs);
|
||||
@@ -1158,11 +1098,14 @@ void GitClient::blame(const QString &workingDirectory,
|
||||
|
||||
VcsBaseEditorWidget *editor = findExistingVCSEditor("blameFileName", id);
|
||||
if (!editor) {
|
||||
GitBlameArgumentsWidget *argWidget =
|
||||
new GitBlameArgumentsWidget(this, workingDirectory, args,
|
||||
revision, fileName);
|
||||
auto *argWidget = new GitBlameArgumentsWidget(settings());
|
||||
argWidget->setBaseArguments(args);
|
||||
QObject::connect(argWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] {
|
||||
const int line = VcsBaseEditor::lineNumberOfCurrentEditor();
|
||||
blame(workingDirectory, args, fileName, revision, line);
|
||||
} );
|
||||
editor = createVcsEditor(editorId, title, sourceFile, CodecSource, "blameFileName", id, argWidget);
|
||||
argWidget->setEditor(editor);
|
||||
}
|
||||
|
||||
editor->setWorkingDirectory(workingDirectory);
|
||||
|
@@ -53,9 +53,25 @@ using namespace VcsBase;
|
||||
namespace Mercurial {
|
||||
namespace Internal {
|
||||
|
||||
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
||||
class MercurialDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MercurialDiffParameterWidget(MercurialSettings *settings, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
settings->boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
|
||||
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
|
||||
settings->boolPointer(MercurialSettings::diffIgnoreBlankLinesKey));
|
||||
}
|
||||
};
|
||||
|
||||
MercurialClient::MercurialClient(MercurialSettings *settings) :
|
||||
VcsBaseClient(settings)
|
||||
{
|
||||
setDiffParameterWidgetCreator([=] { return new MercurialDiffParameterWidget(settings); });
|
||||
}
|
||||
|
||||
MercurialSettings *MercurialClient::settings() const
|
||||
@@ -414,50 +430,6 @@ void MercurialClient::parsePullOutput(const QString &output)
|
||||
emit needMerge();
|
||||
}
|
||||
|
||||
// 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 MercurialDiffParameters
|
||||
{
|
||||
QString workingDir;
|
||||
QStringList files;
|
||||
QStringList extraOptions;
|
||||
};
|
||||
|
||||
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
||||
class MercurialDiffParameterWidget : public VcsBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MercurialDiffParameterWidget(MercurialClient *client,
|
||||
const MercurialDiffParameters &p, QWidget *parent = 0) :
|
||||
VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
||||
{
|
||||
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
||||
client->settings()->boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
|
||||
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
|
||||
client->settings()->boolPointer(MercurialSettings::diffIgnoreBlankLinesKey));
|
||||
}
|
||||
|
||||
void executeCommand()
|
||||
{
|
||||
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
|
||||
}
|
||||
|
||||
private:
|
||||
MercurialClient *m_client;
|
||||
const MercurialDiffParameters m_params;
|
||||
};
|
||||
|
||||
VcsBaseEditorParameterWidget *MercurialClient::createDiffEditor(
|
||||
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
||||
{
|
||||
MercurialDiffParameters parameters;
|
||||
parameters.workingDir = workingDir;
|
||||
parameters.files = files;
|
||||
parameters.extraOptions = extraOptions;
|
||||
return new MercurialDiffParameterWidget(this, parameters);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Mercurial
|
||||
|
||||
|
@@ -86,9 +86,6 @@ public:
|
||||
protected:
|
||||
Core::Id vcsEditorKind(VcsCommandTag cmd) const;
|
||||
QStringList revisionSpec(const QString &revision) const;
|
||||
VcsBase::VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions);
|
||||
StatusItem parseStatusLine(const QString &line) const;
|
||||
|
||||
signals:
|
||||
|
@@ -89,9 +89,15 @@ public:
|
||||
void bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor);
|
||||
void commandFinishedGotoLine(QWidget *editorObject);
|
||||
|
||||
VcsBaseEditorParameterWidget *createDiffEditor();
|
||||
VcsBaseEditorParameterWidget *createLogEditor();
|
||||
|
||||
VcsBaseClientSettings *m_clientSettings;
|
||||
QSignalMapper *m_cmdFinishedMapper;
|
||||
|
||||
VcsBaseClient::ParameterWidgetCreator m_diffParamWidgetCreator;
|
||||
VcsBaseClient::ParameterWidgetCreator m_logParamWidgetCreator;
|
||||
|
||||
private:
|
||||
VcsBaseClient *m_client;
|
||||
};
|
||||
@@ -157,6 +163,16 @@ void VcsBaseClientPrivate::commandFinishedGotoLine(QWidget *editorObject)
|
||||
}
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createDiffEditor()
|
||||
{
|
||||
return m_diffParamWidgetCreator ? m_diffParamWidgetCreator() : 0;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createLogEditor()
|
||||
{
|
||||
return m_logParamWidgetCreator ? m_logParamWidgetCreator() : 0;
|
||||
}
|
||||
|
||||
VcsBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
|
||||
flags(s), file(f)
|
||||
{
|
||||
@@ -350,10 +366,12 @@ void VcsBaseClient::diff(const QString &workingDir, const QStringList &files,
|
||||
editor->setWorkingDirectory(workingDir);
|
||||
|
||||
VcsBaseEditorParameterWidget *paramWidget = editor->configurationWidget();
|
||||
if (!paramWidget && (paramWidget = createDiffEditor(workingDir, files, extraOptions))) {
|
||||
if (!paramWidget && (paramWidget = d->createDiffEditor())) {
|
||||
// editor has been just created, createVcsEditor() didn't set a configuration widget yet
|
||||
connect(editor, &VcsBaseEditorWidget::diffChunkReverted,
|
||||
paramWidget, &VcsBaseEditorParameterWidget::executeCommand);
|
||||
connect(paramWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] { diff(workingDir, files, extraOptions); } );
|
||||
editor->setConfigurationWidget(paramWidget);
|
||||
}
|
||||
|
||||
@@ -380,8 +398,10 @@ void VcsBaseClient::log(const QString &workingDir, const QStringList &files,
|
||||
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
||||
|
||||
VcsBaseEditorParameterWidget *paramWidget = editor->configurationWidget();
|
||||
if (!paramWidget && (paramWidget = createLogEditor(workingDir, files, extraOptions))) {
|
||||
if (!paramWidget && (paramWidget = d->createLogEditor())) {
|
||||
// editor has been just created, createVcsEditor() didn't set a configuration widget yet
|
||||
connect(paramWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] { log(workingDir, files, extraOptions, enableAnnotationContextMenu); } );
|
||||
editor->setConfigurationWidget(paramWidget);
|
||||
}
|
||||
|
||||
@@ -467,6 +487,16 @@ Utils::ExitCodeInterpreter *VcsBaseClient::exitCodeInterpreter(VcsCommandTag cmd
|
||||
return 0;
|
||||
}
|
||||
|
||||
void VcsBaseClient::setDiffParameterWidgetCreator(ParameterWidgetCreator creator)
|
||||
{
|
||||
d->m_diffParamWidgetCreator = std::move(creator);
|
||||
}
|
||||
|
||||
void VcsBaseClient::setLogParameterWidgetCreator(ParameterWidgetCreator creator)
|
||||
{
|
||||
d->m_logParamWidgetCreator = std::move(creator);
|
||||
}
|
||||
|
||||
void VcsBaseClient::import(const QString &repositoryRoot, const QStringList &files,
|
||||
const QStringList &extraOptions)
|
||||
{
|
||||
@@ -527,26 +557,6 @@ VcsBaseClientSettings *VcsBaseClient::settings() const
|
||||
return d->m_clientSettings;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClient::createDiffEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions)
|
||||
{
|
||||
Q_UNUSED(workingDir);
|
||||
Q_UNUSED(files);
|
||||
Q_UNUSED(extraOptions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClient::createLogEditor(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
|
||||
{
|
||||
const Utils::FileName binary = settings()->binaryPath();
|
||||
|
@@ -37,6 +37,8 @@
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QFileInfo;
|
||||
class QVariant;
|
||||
@@ -155,12 +157,11 @@ protected:
|
||||
virtual Utils::ExitCodeInterpreter *exitCodeInterpreter(VcsCommandTag cmd, QObject *parent) const;
|
||||
|
||||
virtual QStringList revisionSpec(const QString &revision) const = 0;
|
||||
virtual VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions);
|
||||
virtual VcsBaseEditorParameterWidget *createLogEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions);
|
||||
|
||||
typedef std::function<VcsBaseEditorParameterWidget *()> ParameterWidgetCreator;
|
||||
void setDiffParameterWidgetCreator(ParameterWidgetCreator creator);
|
||||
void setLogParameterWidgetCreator(ParameterWidgetCreator creator);
|
||||
|
||||
virtual StatusItem parseStatusLine(const QString &line) const = 0;
|
||||
|
||||
QString vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const;
|
||||
|
@@ -218,16 +218,17 @@ void VcsBaseEditorParameterWidget::mapSetting(QComboBox *comboBox, int *setting)
|
||||
comboBox->blockSignals(false);
|
||||
}
|
||||
|
||||
void VcsBaseEditorParameterWidget::executeCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void VcsBaseEditorParameterWidget::handleArgumentsChanged()
|
||||
{
|
||||
updateMappedSettings();
|
||||
executeCommand();
|
||||
}
|
||||
|
||||
void VcsBaseEditorParameterWidget::executeCommand()
|
||||
{
|
||||
emit commandExecutionRequested();
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping() :
|
||||
widget(0)
|
||||
{
|
||||
|
@@ -80,10 +80,12 @@ public:
|
||||
virtual QStringList arguments() const;
|
||||
|
||||
public slots:
|
||||
virtual void executeCommand();
|
||||
virtual void handleArgumentsChanged();
|
||||
void handleArgumentsChanged();
|
||||
void executeCommand();
|
||||
|
||||
signals:
|
||||
void commandExecutionRequested();
|
||||
|
||||
// Trigger a re-run to show changed output according to new argument list.
|
||||
void argumentsChanged();
|
||||
|
||||
|
Reference in New Issue
Block a user