Commit 7019a51f authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Tobias Hunger
Browse files

Git: Enable difference display in Log



Task-number: QTCREATORBUG-5726

Change-Id: Ide3f66de3bbccf86f4a044f8aa3f2fa0fe3d7c36
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent e7a23272
......@@ -96,18 +96,20 @@ public:
Q_ASSERT(!directory.isEmpty());
Q_ASSERT(m_client);
mapSetting(addToggleButton(QLatin1String("--patience"), tr("Patience"),
tr("Use the patience algorithm for calculating the differences.")),
client->settings()->boolPointer(GitSettings::diffPatienceKey));
mapSetting(addToggleButton("--ignore-space-change", tr("Ignore Whitespace"),
tr("Ignore whitespace only changes.")),
m_client->settings()->boolPointer(GitSettings::ignoreSpaceChangesInDiffKey));
m_patienceButton = addToggleButton(QLatin1String("--patience"), tr("Patience"),
tr("Use the patience algorithm for calculating the differences."));
mapSetting(m_patienceButton, client->settings()->boolPointer(GitSettings::diffPatienceKey));
m_ignoreWSButton = addToggleButton("--ignore-space-change", tr("Ignore Whitespace"),
tr("Ignore whitespace only changes."));
mapSetting(m_ignoreWSButton, m_client->settings()->boolPointer(GitSettings::ignoreSpaceChangesInDiffKey));
}
protected:
QString m_workingDirectory;
GitClient *m_client;
QStringList m_args;
QToolButton *m_patienceButton;
QToolButton *m_ignoreWSButton;
};
class GitCommitDiffArgumentsWidget : public BaseGitDiffArgumentsWidget
......@@ -257,6 +259,46 @@ private:
QString m_fileName;
};
class GitLogArgumentsWidget : public BaseGitDiffArgumentsWidget
{
Q_OBJECT
public:
GitLogArgumentsWidget(Git::Internal::GitClient *client,
const QString &directory,
bool enableAnnotationContextMenu,
const QStringList &args,
const QStringList &fileNames) :
BaseGitDiffArgumentsWidget(client, directory, args),
m_client(client),
m_workingDirectory(directory),
m_enableAnnotationContextMenu(enableAnnotationContextMenu),
m_args(args),
m_fileNames(fileNames)
{
QToolButton *button = addToggleButton(QLatin1String("--patch"), tr("Show Diff"),
tr("Show difference."));
mapSetting(button, m_client->settings()->boolPointer(GitSettings::logDiffKey));
connect(button, SIGNAL(toggled(bool)), m_patienceButton, SLOT(setEnabled(bool)));
connect(button, SIGNAL(toggled(bool)), m_ignoreWSButton, SLOT(setEnabled(bool)));
m_patienceButton->setEnabled(button->isChecked());
m_ignoreWSButton->setEnabled(button->isChecked());
}
void executeCommand()
{
m_client->log(m_workingDirectory, m_fileNames, m_enableAnnotationContextMenu, m_args);
}
private:
GitClient *m_client;
QString m_workingDirectory;
bool m_enableAnnotationContextMenu;
QStringList m_args;
QStringList m_fileNames;
};
inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property, const QString &entry)
{
foreach (Core::IEditor *ed, core->editorManager()->openedEditors())
......@@ -545,8 +587,21 @@ void GitClient::graphLog(const QString &workingDirectory, const QString & branch
}
void GitClient::log(const QString &workingDirectory, const QStringList &fileNames,
bool enableAnnotationContextMenu)
bool enableAnnotationContextMenu, const QStringList &args)
{
const QString msgArg = fileNames.empty() ? workingDirectory :
fileNames.join(QString(", "));
const QString title = tr("Git Log \"%1\"").arg(msgArg);
const Core::Id editorId = Git::Constants::GIT_LOG_EDITOR_ID;
const QString sourceFile = VCSBase::VCSBaseEditorWidget::getSource(workingDirectory, fileNames);
VCSBase::VCSBaseEditorWidget *editor = findExistingVCSEditor("logFileName", sourceFile);
if (!editor)
editor = createVCSEditor(editorId, title, sourceFile, CodecLogOutput, "logFileName", sourceFile,
new GitLogArgumentsWidget(this, workingDirectory,
enableAnnotationContextMenu,
args, fileNames));
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
QStringList arguments;
arguments << QLatin1String("log") << QLatin1String(noColorOption)
<< QLatin1String(decorateOption);
......@@ -555,18 +610,14 @@ void GitClient::log(const QString &workingDirectory, const QStringList &fileName
if (logCount > 0)
arguments << QLatin1String("-n") << QString::number(logCount);
GitLogArgumentsWidget *argWidget = qobject_cast<GitLogArgumentsWidget *>(editor->configurationWidget());
QStringList userArgs = argWidget->arguments();
arguments.append(userArgs);
if (!fileNames.isEmpty())
arguments.append(fileNames);
const QString msgArg = fileNames.empty() ? workingDirectory :
fileNames.join(QString(", "));
const QString title = tr("Git Log \"%1\"").arg(msgArg);
const Core::Id editorId = Git::Constants::GIT_LOG_EDITOR_ID;
const QString sourceFile = VCSBase::VCSBaseEditorWidget::getSource(workingDirectory, fileNames);
VCSBase::VCSBaseEditorWidget *editor = findExistingVCSEditor("logFileName", sourceFile);
if (!editor)
editor = createVCSEditor(editorId, title, sourceFile, CodecLogOutput, "logFileName", sourceFile, 0);
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
executeGit(workingDirectory, arguments, editor);
}
......
......@@ -100,7 +100,7 @@ public:
void graphLog(const QString &workingDirectory) { graphLog(workingDirectory, QString()); }
void graphLog(const QString &workingDirectory, const QString &branch);
void log(const QString &workingDirectory, const QStringList &fileNames = QStringList(),
bool enableAnnotationContextMenu = false);
bool enableAnnotationContextMenu = false, const QStringList &args = QStringList());
void blame(const QString &workingDirectory, const QStringList &args, const QString &fileName,
const QString &revision = QString(), int lineNumber = -1);
void checkout(const QString &workingDirectory, const QString &file);
......
......@@ -49,6 +49,7 @@ const QLatin1String GitSettings::diffPatienceKey("DiffPatience");
const QLatin1String GitSettings::winSetHomeEnvironmentKey("WinSetHomeEnvironment");
const QLatin1String GitSettings::showPrettyFormatKey("DiffPrettyFormat");
const QLatin1String GitSettings::gitkOptionsKey("GitKOptions");
const QLatin1String GitSettings::logDiffKey("LogDiff");
GitSettings::GitSettings()
{
......@@ -70,6 +71,7 @@ GitSettings::GitSettings()
declareKey(winSetHomeEnvironmentKey, false);
declareKey(gitkOptionsKey, QString());
declareKey(showPrettyFormatKey, 2);
declareKey(logDiffKey, false);
}
QString GitSettings::gitBinaryPath(bool *ok, QString *errorMessage) const
......
......@@ -56,6 +56,7 @@ public:
static const QLatin1String winSetHomeEnvironmentKey;
static const QLatin1String showPrettyFormatKey;
static const QLatin1String gitkOptionsKey;
static const QLatin1String logDiffKey;
QString gitBinaryPath(bool *ok = 0, QString *errorMessage = 0) const;
......
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