forked from qt-creator/qt-creator
Git: Refactoring ChangeSelectionDialog
- added ability to fix working directory in constructor - show tooltip for commit Change-Id: Ife69bed696960b8ce0b929a24f45bc8bba85df49 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
4a6a13d30b
commit
75f10ab1dd
@@ -33,17 +33,38 @@
|
|||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ChangeSelectionDialog::ChangeSelectionDialog(QWidget *parent)
|
ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
, m_process(0)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
if (!workingDirectory.isEmpty()) {
|
||||||
|
setWorkingDirectory(workingDirectory);
|
||||||
|
m_ui.workingDirectoryButton->setEnabled(false);
|
||||||
|
m_ui.workingDirectoryEdit->setEnabled(false);
|
||||||
|
}
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
connect(m_ui.workingDirectoryButton, SIGNAL(clicked()), this, SLOT(selectWorkingDirectory()));
|
connect(m_ui.workingDirectoryButton, SIGNAL(clicked()), this, SLOT(selectWorkingDirectory()));
|
||||||
setWindowTitle(tr("Select a Git Commit"));
|
setWindowTitle(tr("Select a Git Commit"));
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
m_gitBinaryPath = GitPlugin::instance()->gitClient()->gitBinaryPath(&ok);
|
||||||
|
if (!ok)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_gitEnvironment = GitPlugin::instance()->gitClient()->processEnvironment();
|
||||||
|
connect(m_ui.changeNumberEdit, SIGNAL(textChanged(QString)),
|
||||||
|
this, SLOT(recalculateToolTip(QString)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeSelectionDialog::~ChangeSelectionDialog()
|
||||||
|
{
|
||||||
|
delete m_process;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChangeSelectionDialog::change() const
|
QString ChangeSelectionDialog::change() const
|
||||||
@@ -82,5 +103,39 @@ void ChangeSelectionDialog::selectWorkingDirectory()
|
|||||||
tr("Selected directory is not a Git repository"));
|
tr("Selected directory is not a Git repository"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Set commit message as toolTip
|
||||||
|
void ChangeSelectionDialog::setToolTip(int exitCode)
|
||||||
|
{
|
||||||
|
if (exitCode == 0)
|
||||||
|
m_ui.changeNumberEdit->setToolTip(QString::fromUtf8(m_process->readAllStandardOutput()));
|
||||||
|
else
|
||||||
|
m_ui.changeNumberEdit->setToolTip(tr("Error: unknown reference"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChangeSelectionDialog::recalculateToolTip(const QString &ref)
|
||||||
|
{
|
||||||
|
if (m_process) {
|
||||||
|
m_process->kill();
|
||||||
|
m_process->waitForFinished();
|
||||||
|
delete m_process;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList args;
|
||||||
|
args << QLatin1String("log") << QLatin1String("-n1") << ref;
|
||||||
|
|
||||||
|
m_process = new QProcess(this);
|
||||||
|
m_process->setWorkingDirectory(workingDirectory());
|
||||||
|
m_process->setProcessEnvironment(m_gitEnvironment);
|
||||||
|
|
||||||
|
connect(m_process, SIGNAL(finished(int)), this, SLOT(setToolTip(int)));
|
||||||
|
|
||||||
|
m_process->start(m_gitBinaryPath, args);
|
||||||
|
m_process->closeWriteChannel();
|
||||||
|
if (!m_process->waitForStarted())
|
||||||
|
m_ui.changeNumberEdit->setToolTip(tr("Error: could not start git"));
|
||||||
|
else
|
||||||
|
m_ui.changeNumberEdit->setToolTip(tr("Fetching commit data..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
} // Git
|
||||||
|
@@ -31,6 +31,8 @@
|
|||||||
#define CHANGESELECTIONDIALOG_H
|
#define CHANGESELECTIONDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QProcess)
|
||||||
|
|
||||||
#include "ui_changeselectiondialog.h"
|
#include "ui_changeselectiondialog.h"
|
||||||
|
|
||||||
@@ -41,7 +43,8 @@ class ChangeSelectionDialog : public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ChangeSelectionDialog(QWidget *parent = 0);
|
ChangeSelectionDialog(const QString &workingDirectory = QString(), QWidget *parent = 0);
|
||||||
|
~ChangeSelectionDialog();
|
||||||
|
|
||||||
QString change() const;
|
QString change() const;
|
||||||
|
|
||||||
@@ -51,8 +54,15 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void selectWorkingDirectory();
|
void selectWorkingDirectory();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void setToolTip(int exitCode);
|
||||||
|
void recalculateToolTip(const QString &ref);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_ChangeSelectionDialog m_ui;
|
Ui_ChangeSelectionDialog m_ui;
|
||||||
|
QProcess* m_process;
|
||||||
|
QString m_gitBinaryPath;
|
||||||
|
QProcessEnvironment m_gitEnvironment;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user