forked from qt-creator/qt-creator
Git: Allow for pretty format selection in git show
Allow for pretty format selection in git show. Save selected value and default to "email". Task-number: QTCREATORBUG-3341
This commit is contained in:
@@ -63,6 +63,7 @@
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QSignalMapper>
|
||||
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QMainWindow> // for msg box parent
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QToolButton>
|
||||
@@ -121,19 +122,42 @@ public:
|
||||
m_ignoreSpaces->setCheckable(true);
|
||||
m_ignoreSpaces->setChecked(m_settings->ignoreSpaceChangesInDiff);
|
||||
connect(m_ignoreSpaces, SIGNAL(toggled(bool)), this, SLOT(testForArgumentsChanged()));
|
||||
|
||||
m_prettyFormat = new QComboBox;
|
||||
m_prettyFormat->setToolTip(tr("Select the pretty printing format"));
|
||||
m_prettyFormat->addItem(tr("oneline"), QLatin1String("oneline"));
|
||||
m_prettyFormat->addItem(tr("short"), QLatin1String("short"));
|
||||
m_prettyFormat->addItem(tr("medium"), QLatin1String("medium"));
|
||||
m_prettyFormat->addItem(tr("full"), QLatin1String("full"));
|
||||
m_prettyFormat->addItem(tr("fuller"), QLatin1String("fuller"));
|
||||
m_prettyFormat->addItem(tr("email"), QLatin1String("email"));
|
||||
m_prettyFormat->addItem(tr("raw"), QLatin1String("raw"));
|
||||
layout->addWidget(m_prettyFormat);
|
||||
m_prettyFormat->setCurrentIndex(m_settings->showPrettyFormat);
|
||||
m_prettyFormat->setVisible(false);
|
||||
connect(m_prettyFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(testForArgumentsChanged()));
|
||||
}
|
||||
|
||||
QStringList arguments() const
|
||||
{
|
||||
QStringList args = m_diffArgs;
|
||||
QStringList args;
|
||||
foreach (const QString &arg, m_diffArgs) {
|
||||
if (arg == QLatin1String("--patience")
|
||||
|| arg == QLatin1String("--ignore-space-change")
|
||||
|| arg.startsWith(QLatin1String("--pretty="))
|
||||
|| arg.startsWith(QLatin1String("--format=")))
|
||||
continue;
|
||||
args.append(arg);
|
||||
}
|
||||
|
||||
args.removeAll(QLatin1String("--patience"));
|
||||
args.removeAll(QLatin1String("--ignore-space-change"));
|
||||
|
||||
if (m_patience->isChecked())
|
||||
if (m_patience->isChecked() && m_patience->isVisible())
|
||||
args.prepend(QLatin1String("--patience"));
|
||||
if (m_ignoreSpaces->isChecked())
|
||||
if (m_ignoreSpaces->isChecked() && m_ignoreSpaces->isVisible())
|
||||
args.prepend(QLatin1String("--ignore-space-change"));
|
||||
if (m_prettyFormat->isVisible()) {
|
||||
args.prepend(QString::fromLatin1("--pretty=")
|
||||
+ m_prettyFormat->itemData(m_prettyFormat->currentIndex()).toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
@@ -141,6 +165,7 @@ public:
|
||||
void testForArgumentsChanged() {
|
||||
m_settings->diffPatience = m_patience->isChecked();
|
||||
m_settings->ignoreSpaceChangesInDiff = m_ignoreSpaces->isChecked();
|
||||
m_settings->showPrettyFormat = m_prettyFormat->currentIndex();
|
||||
|
||||
QStringList newArguments = arguments();
|
||||
|
||||
@@ -151,9 +176,10 @@ public:
|
||||
redoCommand();
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
QToolButton *m_patience;
|
||||
QToolButton *m_ignoreSpaces;
|
||||
QComboBox *m_prettyFormat;
|
||||
};
|
||||
|
||||
class GitCommitDiffArgumentsWidget : public BaseGitDiffArgumentsWidget
|
||||
@@ -216,6 +242,30 @@ private:
|
||||
const QString m_branchName;
|
||||
};
|
||||
|
||||
class GitShowArgumentsWidget : public BaseGitDiffArgumentsWidget
|
||||
{
|
||||
public:
|
||||
GitShowArgumentsWidget(Git::Internal::GitSettings *settings,
|
||||
Git::Internal::GitClient *client, const QString &directory,
|
||||
const QStringList &args, const QString &id) :
|
||||
BaseGitDiffArgumentsWidget(settings, client, directory, args),
|
||||
m_id(id)
|
||||
{
|
||||
m_patience->setVisible(false);
|
||||
m_ignoreSpaces->setVisible(false);
|
||||
m_prettyFormat->setVisible(true);
|
||||
}
|
||||
|
||||
void redoCommand()
|
||||
{
|
||||
m_client->show(m_workingDirectory, m_id, m_diffArgs);
|
||||
}
|
||||
|
||||
private:
|
||||
const QString m_id;
|
||||
};
|
||||
|
||||
|
||||
class GitBlameArgumentsWidget : public Git::Internal::BaseGitArgumentsWidget
|
||||
{
|
||||
public:
|
||||
@@ -631,7 +681,7 @@ static inline QString msgCannotShow(const QString &sha)
|
||||
return GitClient::tr("Cannot describe '%1'.").arg(sha);
|
||||
}
|
||||
|
||||
void GitClient::show(const QString &source, const QString &id)
|
||||
void GitClient::show(const QString &source, const QString &id, const QStringList &args)
|
||||
{
|
||||
if (Git::Constants::debug)
|
||||
qDebug() << "show" << source << id;
|
||||
@@ -640,14 +690,22 @@ void GitClient::show(const QString &source, const QString &id)
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("show") << QLatin1String(noColorOption) << id;
|
||||
|
||||
QStringList userArgs = args;
|
||||
const QString title = tr("Git Show %1").arg(id);
|
||||
const QString editorId = QLatin1String(Git::Constants::GIT_DIFF_EDITOR_ID);
|
||||
VCSBase::VCSBaseEditor *editor = findExistingVCSEditor("show", id);
|
||||
if (!editor)
|
||||
editor = createVCSEditor(editorId, title, source, true, "show", id, 0);
|
||||
if (!editor) {
|
||||
GitShowArgumentsWidget *argWidget =
|
||||
new GitShowArgumentsWidget(&m_settings, this, source,
|
||||
QStringList(), id);
|
||||
userArgs = argWidget->arguments();
|
||||
editor = createVCSEditor(editorId, title, source, true, "show", id, argWidget);
|
||||
}
|
||||
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("show") << QLatin1String(noColorOption);
|
||||
arguments.append(userArgs);
|
||||
arguments << id;
|
||||
|
||||
const QFileInfo sourceFi(source);
|
||||
const QString workDir = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath();
|
||||
|
||||
Reference in New Issue
Block a user