forked from qt-creator/qt-creator
Mercurial: Emit version control changed() signals correctly.
Add a QVariant cookie to HgTask to be emitted on successful execution, wired to IVersionControl.
This commit is contained in:
@@ -48,9 +48,9 @@
|
|||||||
#include <QtCore/QtDebug>
|
#include <QtCore/QtDebug>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QByteArray>
|
#include <QtCore/QByteArray>
|
||||||
|
#include <QtCore/QMetaType>
|
||||||
|
|
||||||
using namespace Mercurial::Internal;
|
Q_DECLARE_METATYPE(QVariant)
|
||||||
using namespace Mercurial;
|
|
||||||
|
|
||||||
inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property, const QString &entry)
|
inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property, const QString &entry)
|
||||||
{
|
{
|
||||||
@@ -60,10 +60,14 @@ inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Mercurial {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
MercurialClient::MercurialClient() :
|
MercurialClient::MercurialClient() :
|
||||||
jobManager(0),
|
jobManager(0),
|
||||||
core(Core::ICore::instance())
|
core(Core::ICore::instance())
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType<QVariant>();
|
||||||
}
|
}
|
||||||
|
|
||||||
MercurialClient::~MercurialClient()
|
MercurialClient::~MercurialClient()
|
||||||
@@ -227,17 +231,18 @@ void MercurialClient::log(const QFileInfo &fileOrDir)
|
|||||||
|
|
||||||
void MercurialClient::revert(const QFileInfo &fileOrDir, const QString &revision)
|
void MercurialClient::revert(const QFileInfo &fileOrDir, const QString &revision)
|
||||||
{
|
{
|
||||||
QStringList args(QLatin1String("revert"));
|
const QString filePath = fileOrDir.absoluteFilePath();
|
||||||
|
const QString workingDir = fileOrDir.isDir() ? filePath : fileOrDir.absolutePath();
|
||||||
|
|
||||||
|
QStringList args(QLatin1String("revert"));
|
||||||
if (!revision.isEmpty())
|
if (!revision.isEmpty())
|
||||||
args << QLatin1String("-r") << revision;
|
args << QLatin1String("-r") << revision;
|
||||||
if (!fileOrDir.isDir())
|
args.append(fileOrDir.isDir() ? QString(QLatin1String("--all")) : filePath);
|
||||||
args.append(fileOrDir.absoluteFilePath());
|
|
||||||
else
|
|
||||||
args.append(QLatin1String("--all"));
|
|
||||||
|
|
||||||
QSharedPointer<HgTask> job(new HgTask(fileOrDir.isDir() ? fileOrDir.absoluteFilePath() :
|
// Indicate repository change or file list
|
||||||
fileOrDir.absolutePath(), args, false));
|
const QVariant cookie = fileOrDir.isDir() ? QVariant(filePath) : QVariant(QStringList(filePath));
|
||||||
|
QSharedPointer<HgTask> job(new HgTask(workingDir, args, false, cookie));
|
||||||
|
connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
|
||||||
enqueueJob(job);
|
enqueueJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +315,10 @@ void MercurialClient::pull(const QFileInfo &repositoryRoot, const QString &repos
|
|||||||
if (!repository.isEmpty())
|
if (!repository.isEmpty())
|
||||||
args.append(repository);
|
args.append(repository);
|
||||||
|
|
||||||
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, false));
|
const QString path = repositoryRoot.absoluteFilePath();
|
||||||
|
|
||||||
|
QSharedPointer<HgTask> job(new HgTask(path, args, false, QVariant(path)));
|
||||||
|
connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
|
||||||
enqueueJob(job);
|
enqueueJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +390,9 @@ void MercurialClient::update(const QFileInfo &repositoryRoot, const QString &rev
|
|||||||
if (!revision.isEmpty())
|
if (!revision.isEmpty())
|
||||||
args << revision;
|
args << revision;
|
||||||
|
|
||||||
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, false));
|
const QString path = repositoryRoot.absoluteFilePath();
|
||||||
|
QSharedPointer<HgTask> job(new HgTask(path, args, false, QVariant(path)));
|
||||||
|
connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
|
||||||
enqueueJob(job);
|
enqueueJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,3 +461,6 @@ void MercurialClient::enqueueJob(const QSharedPointer<HgTask> &job)
|
|||||||
}
|
}
|
||||||
jobManager->enqueueJob(job);
|
jobManager->enqueueJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Mercurial
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFileInfo;
|
class QFileInfo;
|
||||||
|
class QVariant;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -81,6 +82,8 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void parsedStatus(const QList<QPair<QString, QString> > &statusList);
|
void parsedStatus(const QList<QPair<QString, QString> > &statusList);
|
||||||
|
// Passes on changed signals from HgTask to Control.
|
||||||
|
void changed(const QVariant &v);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void view(const QString &source, const QString &id);
|
void view(const QString &source, const QString &id);
|
||||||
|
@@ -31,6 +31,8 @@
|
|||||||
#include "mercurialclient.h"
|
#include "mercurialclient.h"
|
||||||
|
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
using namespace Mercurial::Internal;
|
using namespace Mercurial::Internal;
|
||||||
|
|
||||||
@@ -107,3 +109,17 @@ bool MercurialControl::sccManaged(const QString &filename)
|
|||||||
{
|
{
|
||||||
return mercurialClient->manifestSync(filename);
|
return mercurialClient->manifestSync(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MercurialControl::changed(const QVariant &v)
|
||||||
|
{
|
||||||
|
switch (v.type()) {
|
||||||
|
case QVariant::String:
|
||||||
|
emit repositoryChanged(v.toString());
|
||||||
|
break;
|
||||||
|
case QVariant::StringList:
|
||||||
|
emit filesChanged(v.toStringList());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
#include <coreplugin/iversioncontrol.h>
|
#include <coreplugin/iversioncontrol.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QVariant;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Mercurial {
|
namespace Mercurial {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -56,6 +60,12 @@ public:
|
|||||||
bool vcsDelete(const QString &filename);
|
bool vcsDelete(const QString &filename);
|
||||||
bool sccManaged(const QString &filename);
|
bool sccManaged(const QString &filename);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
// To be connected to the HgTask's success signal to emit the repository/
|
||||||
|
// files changed signals according to the variant's type:
|
||||||
|
// String -> repository, StringList -> files
|
||||||
|
void changed(const QVariant&);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void enabledChanged(bool);
|
void enabledChanged(bool);
|
||||||
|
|
||||||
|
@@ -42,23 +42,36 @@
|
|||||||
using namespace Mercurial::Internal;
|
using namespace Mercurial::Internal;
|
||||||
using namespace Mercurial;
|
using namespace Mercurial;
|
||||||
|
|
||||||
HgTask::HgTask(const QString &repositoryRoot, const QStringList &arguments, bool emitRaw)
|
HgTask::HgTask(const QString &repositoryRoot,
|
||||||
: m_repositoryRoot(repositoryRoot),
|
const QStringList &arguments,
|
||||||
arguments(arguments),
|
bool emitRaw,
|
||||||
emitRaw(emitRaw),
|
const QVariant &cookie) :
|
||||||
editor(0)
|
m_repositoryRoot(repositoryRoot),
|
||||||
|
arguments(arguments),
|
||||||
|
emitRaw(emitRaw),
|
||||||
|
m_cookie(cookie),
|
||||||
|
editor(0)
|
||||||
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HgTask::HgTask(const QString &repositoryRoot, const QStringList &arguments, VCSBase::VCSBaseEditor *editor)
|
HgTask::HgTask(const QString &repositoryRoot,
|
||||||
: m_repositoryRoot(repositoryRoot),
|
const QStringList &arguments,
|
||||||
arguments(arguments),
|
VCSBase::VCSBaseEditor *editor,
|
||||||
emitRaw(false),
|
const QVariant &cookie) :
|
||||||
editor(editor)
|
m_repositoryRoot(repositoryRoot),
|
||||||
|
arguments(arguments),
|
||||||
|
emitRaw(false),
|
||||||
|
m_cookie(cookie),
|
||||||
|
editor(editor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HgTask::emitSucceeded()
|
||||||
|
{
|
||||||
|
emit succeeded(m_cookie);
|
||||||
|
}
|
||||||
|
|
||||||
MercurialJobRunner::MercurialJobRunner() :
|
MercurialJobRunner::MercurialJobRunner() :
|
||||||
plugin(MercurialPlugin::instance()),
|
plugin(MercurialPlugin::instance()),
|
||||||
keepRunning(true)
|
keepRunning(true)
|
||||||
@@ -206,6 +219,7 @@ void MercurialJobRunner::task(const QSharedPointer<HgTask> &job)
|
|||||||
if (stdOutput.isEmpty())
|
if (stdOutput.isEmpty())
|
||||||
stdOutput = hgProcess.readAllStandardError();
|
stdOutput = hgProcess.readAllStandardError();
|
||||||
emit output(stdOutput);
|
emit output(stdOutput);
|
||||||
|
taskData->emitSucceeded();
|
||||||
} else {
|
} else {
|
||||||
emit error(QString::fromLocal8Bit(hgProcess.readAllStandardError()));
|
emit error(QString::fromLocal8Bit(hgProcess.readAllStandardError()));
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include <QtCore/QWaitCondition>
|
#include <QtCore/QWaitCondition>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
|
#include <QtCore/QVariant>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
|
||||||
namespace VCSBase {
|
namespace VCSBase {
|
||||||
@@ -51,9 +52,13 @@ class HgTask : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
HgTask(const QString &workingDir, const QStringList &arguments, bool emitRaw=false);
|
explicit HgTask(const QString &workingDir,
|
||||||
HgTask(const QString &workingDir, const QStringList &arguments,
|
const QStringList &arguments,
|
||||||
VCSBase::VCSBaseEditor *editor);
|
bool emitRaw=false,
|
||||||
|
const QVariant &cookie = QVariant());
|
||||||
|
explicit HgTask(const QString &workingDir, const QStringList &arguments,
|
||||||
|
VCSBase::VCSBaseEditor *editor,
|
||||||
|
const QVariant &cookie = QVariant());
|
||||||
|
|
||||||
bool shouldEmit() { return emitRaw; }
|
bool shouldEmit() { return emitRaw; }
|
||||||
VCSBase::VCSBaseEditor* displayEditor() { return editor; }
|
VCSBase::VCSBaseEditor* displayEditor() { return editor; }
|
||||||
@@ -61,12 +66,17 @@ public:
|
|||||||
QString repositoryRoot() { return m_repositoryRoot; }
|
QString repositoryRoot() { return m_repositoryRoot; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void succeeded(const QVariant &cookie); // Use a queued connection
|
||||||
void rawData(const QByteArray &data);
|
void rawData(const QByteArray &data);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void emitSucceeded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_repositoryRoot;
|
const QString m_repositoryRoot;
|
||||||
const QStringList arguments;
|
const QStringList arguments;
|
||||||
const bool emitRaw;
|
const bool emitRaw;
|
||||||
|
const QVariant m_cookie;
|
||||||
VCSBase::VCSBaseEditor *editor;
|
VCSBase::VCSBaseEditor *editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -162,6 +162,7 @@ bool MercurialPlugin::initialize(const QStringList &arguments, QString *error_me
|
|||||||
|
|
||||||
mercurialVC = new MercurialControl(client);
|
mercurialVC = new MercurialControl(client);
|
||||||
addAutoReleasedObject(mercurialVC);
|
addAutoReleasedObject(mercurialVC);
|
||||||
|
connect(client, SIGNAL(changed(QVariant)), mercurialVC, SLOT(changed(QVariant)));
|
||||||
|
|
||||||
static const char *describeSlot = SLOT(view(QString,QString));
|
static const char *describeSlot = SLOT(view(QString,QString));
|
||||||
const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
|
const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
|
||||||
|
@@ -153,7 +153,7 @@ private:
|
|||||||
OptionsPage *optionsPage;
|
OptionsPage *optionsPage;
|
||||||
MercurialClient *client;
|
MercurialClient *client;
|
||||||
|
|
||||||
Core::IVersionControl *mercurialVC;
|
MercurialControl *mercurialVC;
|
||||||
Core::ICore *core;
|
Core::ICore *core;
|
||||||
Core::ActionManager *actionManager;
|
Core::ActionManager *actionManager;
|
||||||
Core::ActionContainer *mercurialContainer;
|
Core::ActionContainer *mercurialContainer;
|
||||||
|
Reference in New Issue
Block a user