Commit 7dc2760f authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

VCS[git]: Add menu option to launch gitk.

Task-number: QTCREATORBUG-1577
parent 019ff9d0
...@@ -1141,7 +1141,7 @@ bool GitClient::fullySynchronousGit(const QString &workingDirectory, ...@@ -1141,7 +1141,7 @@ bool GitClient::fullySynchronousGit(const QString &workingDirectory,
if (!Utils::SynchronousProcess::readDataFromProcess(process, m_settings.timeoutSeconds * 1000, if (!Utils::SynchronousProcess::readDataFromProcess(process, m_settings.timeoutSeconds * 1000,
outputText, errorText, true)) { outputText, errorText, true)) {
*errorText->append(GitCommand::msgTimeout(m_settings.timeoutSeconds).toLocal8Bit()); errorText->append(GitCommand::msgTimeout(m_settings.timeoutSeconds).toLocal8Bit());
Utils::SynchronousProcess::stopProcess(process); Utils::SynchronousProcess::stopProcess(process);
return false; return false;
} }
...@@ -1254,6 +1254,45 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory, ...@@ -1254,6 +1254,45 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
return StatusChanged; return StatusChanged;
} }
void GitClient::launchGitK(const QString &workingDirectory)
{
VCSBase::VCSBaseOutputWindow *outwin = VCSBase::VCSBaseOutputWindow::instance();
// Locate git in (potentially) custom path. m_binaryPath can be absolute,
// which will be handled correctly.
QTC_ASSERT(!m_binaryPath.isEmpty(), return);
const QString gitBinary = QLatin1String(Constants::GIT_BINARY);
const QProcessEnvironment env = processEnvironment();
const QString path = env.value(QLatin1String("PATH"));
const QString fullGitBinary = Utils::SynchronousProcess::locateBinary(path, m_binaryPath);
if (fullGitBinary.isEmpty()) {
outwin->appendError(tr("Cannot locate %1.").arg(gitBinary));
return;
}
const QString gitBinDirectory = QFileInfo(fullGitBinary).absolutePath();
#ifdef Q_OS_WIN
// Launch 'wish' shell from git binary directory with the gitk located there
const QString binary = gitBinDirectory + QLatin1String("/wish");
const QStringList arguments(gitBinDirectory + QLatin1String("/gitk"));
#else
// Simple: Run gitk from binary path
const QString binary = gitBinDirectory + QLatin1String("/gitk");
const QStringList arguments;
#endif
outwin->appendCommand(workingDirectory, binary, arguments);
// This should use QProcess::startDetached ideally, but that does not have
// an environment parameter.
QProcess *process = new QProcess(this);
process->setWorkingDirectory(workingDirectory);
process->setProcessEnvironment(env);
process->start(binary, arguments);
if (!process->waitForStarted()) {
outwin->appendError(tr("Unable to launch %1.").arg(binary));
delete process;
return;
}
connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
}
bool GitClient::getCommitData(const QString &workingDirectory, bool GitClient::getCommitData(const QString &workingDirectory,
QString *commitTemplate, QString *commitTemplate,
CommitData *d, CommitData *d,
......
...@@ -203,6 +203,8 @@ public: ...@@ -203,6 +203,8 @@ public:
QString *errorMessage = 0, QString *errorMessage = 0,
bool *onBranch = 0); bool *onBranch = 0);
void launchGitK(const QString &workingDirectory);
GitSettings settings() const; GitSettings settings() const;
void setSettings(const GitSettings &s); void setSettings(const GitSettings &s);
......
...@@ -416,6 +416,10 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) ...@@ -416,6 +416,10 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
tr("Clean Repository..."), QLatin1String("Git.CleanRepository"), tr("Clean Repository..."), QLatin1String("Git.CleanRepository"),
globalcontext, true, SLOT(cleanRepository())); globalcontext, true, SLOT(cleanRepository()));
createRepositoryAction(actionManager, gitContainer,
tr("Launch gitk"), QLatin1String("Git.LaunchGitK"),
globalcontext, false, &GitClient::launchGitK);
gitContainer->addAction(createSeparator(actionManager, globalcontext, QLatin1String("Git.Sep.Global"), this)); gitContainer->addAction(createSeparator(actionManager, globalcontext, QLatin1String("Git.Sep.Global"), this));
ActionCommandPair actionCommand = ActionCommandPair actionCommand =
......
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