Mercurial: Move plugin pimpl to .cpp

And remove a couple of singleton accesses and indirections.

Change-Id: Ib54a0e5c580b5354d2b700de02034cce506d8017
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2020-01-29 12:50:48 +01:00
parent 0f67026794
commit 0dadf19c91
9 changed files with 153 additions and 205 deletions

View File

@@ -58,15 +58,15 @@ namespace Internal {
class MercurialDiffEditorController : public VcsBaseDiffEditorController class MercurialDiffEditorController : public VcsBaseDiffEditorController
{ {
public: public:
MercurialDiffEditorController(IDocument *document, const QString &workingDirectory); MercurialDiffEditorController(IDocument *document, VcsBaseClientImpl *client, const QString &workingDirectory);
protected: protected:
void runCommand(const QList<QStringList> &args, QTextCodec *codec = nullptr); void runCommand(const QList<QStringList> &args, QTextCodec *codec = nullptr);
QStringList addConfigurationArguments(const QStringList &args) const; QStringList addConfigurationArguments(const QStringList &args) const;
}; };
MercurialDiffEditorController::MercurialDiffEditorController(IDocument *document, const QString &workingDirectory): MercurialDiffEditorController::MercurialDiffEditorController(IDocument *document, VcsBaseClientImpl *client, const QString &workingDirectory):
VcsBaseDiffEditorController(document, MercurialPluginPrivate::client(), workingDirectory) VcsBaseDiffEditorController(document, client, workingDirectory)
{ {
setDisplayName("Hg Diff"); setDisplayName("Hg Diff");
} }
@@ -90,8 +90,8 @@ QStringList MercurialDiffEditorController::addConfigurationArguments(const QStri
class FileDiffController : public MercurialDiffEditorController class FileDiffController : public MercurialDiffEditorController
{ {
public: public:
FileDiffController(IDocument *document, const QString &dir, const QString &fileName) : FileDiffController(IDocument *document, VcsBaseClient *client, const QString &dir, const QString &fileName) :
MercurialDiffEditorController(document, dir), MercurialDiffEditorController(document, client, dir),
m_fileName(fileName) m_fileName(fileName)
{ } { }
@@ -108,8 +108,8 @@ private:
class FileListDiffController : public MercurialDiffEditorController class FileListDiffController : public MercurialDiffEditorController
{ {
public: public:
FileListDiffController(IDocument *document, const QString &dir, const QStringList &fileNames) : FileListDiffController(IDocument *document, VcsBaseClient *client, const QString &dir, const QStringList &fileNames) :
MercurialDiffEditorController(document, dir), MercurialDiffEditorController(document, client, dir),
m_fileNames(fileNames) m_fileNames(fileNames)
{ } { }
@@ -128,8 +128,8 @@ private:
class RepositoryDiffController : public MercurialDiffEditorController class RepositoryDiffController : public MercurialDiffEditorController
{ {
public: public:
RepositoryDiffController(IDocument *document, const QString &dir) : RepositoryDiffController(IDocument *document, VcsBaseClient *client, const QString &dir) :
MercurialDiffEditorController(document, dir) MercurialDiffEditorController(document, client, dir)
{ } { }
void reload() override void reload() override
@@ -401,8 +401,8 @@ void MercurialClient::diff(const QString &workingDir, const QStringList &files,
const QString documentId = QString(Constants::MERCURIAL_PLUGIN) const QString documentId = QString(Constants::MERCURIAL_PLUGIN)
+ ".DiffRepo." + sourceFile; + ".DiffRepo." + sourceFile;
requestReload(documentId, sourceFile, title, requestReload(documentId, sourceFile, title,
[workingDir](IDocument *doc) { [this, workingDir](IDocument *doc) {
return new RepositoryDiffController(doc, workingDir); return new RepositoryDiffController(doc, this, workingDir);
}); });
} else if (files.size() == 1) { } else if (files.size() == 1) {
fileName = files.at(0); fileName = files.at(0);
@@ -411,8 +411,8 @@ void MercurialClient::diff(const QString &workingDir, const QStringList &files,
const QString documentId = QString(Constants::MERCURIAL_PLUGIN) const QString documentId = QString(Constants::MERCURIAL_PLUGIN)
+ ".DiffFile." + sourceFile; + ".DiffFile." + sourceFile;
requestReload(documentId, sourceFile, title, requestReload(documentId, sourceFile, title,
[workingDir, fileName](IDocument *doc) { [this, workingDir, fileName](IDocument *doc) {
return new FileDiffController(doc, workingDir, fileName); return new FileDiffController(doc, this, workingDir, fileName);
}); });
} else { } else {
const QString title = tr("Mercurial Diff \"%1\"").arg(workingDir); const QString title = tr("Mercurial Diff \"%1\"").arg(workingDir);
@@ -420,8 +420,8 @@ void MercurialClient::diff(const QString &workingDir, const QStringList &files,
const QString documentId = QString(Constants::MERCURIAL_PLUGIN) const QString documentId = QString(Constants::MERCURIAL_PLUGIN)
+ ".DiffFile." + workingDir; + ".DiffFile." + workingDir;
requestReload(documentId, sourceFile, title, requestReload(documentId, sourceFile, title,
[workingDir, files](IDocument *doc) { [this, workingDir, files](IDocument *doc) {
return new FileListDiffController(doc, workingDir, files); return new FileListDiffController(doc, this, workingDir, files);
}); });
} }
} }

View File

@@ -42,11 +42,12 @@
namespace Mercurial { namespace Mercurial {
namespace Internal { namespace Internal {
MercurialEditorWidget::MercurialEditorWidget() : MercurialEditorWidget::MercurialEditorWidget(MercurialClient *client) :
exactIdentifier12(QLatin1String(Constants::CHANGEIDEXACT12)), exactIdentifier12(QLatin1String(Constants::CHANGEIDEXACT12)),
exactIdentifier40(QLatin1String(Constants::CHANGEIDEXACT40)), exactIdentifier40(QLatin1String(Constants::CHANGEIDEXACT40)),
changesetIdentifier12(QLatin1String(Constants::CHANGESETID12)), changesetIdentifier12(QLatin1String(Constants::CHANGESETID12)),
changesetIdentifier40(QLatin1String(Constants::CHANGESETID40)) changesetIdentifier40(QLatin1String(Constants::CHANGESETID40)),
m_client(client)
{ {
setDiffFilePattern(QRegExp(QLatin1String(Constants::DIFFIDENTIFIER))); setDiffFilePattern(QRegExp(QLatin1String(Constants::DIFFIDENTIFIER)));
setLogEntryPattern(QRegExp(QLatin1String("^changeset:\\s+(\\S+)$"))); setLogEntryPattern(QRegExp(QLatin1String("^changeset:\\s+(\\S+)$")));
@@ -94,7 +95,7 @@ QString MercurialEditorWidget::decorateVersion(const QString &revision) const
const QFileInfo fi(source()); const QFileInfo fi(source());
const QString workingDirectory = fi.absolutePath(); const QString workingDirectory = fi.absolutePath();
// Format with short summary // Format with short summary
return MercurialPluginPrivate::client()->shortDescriptionSync(workingDirectory, revision); return m_client->shortDescriptionSync(workingDirectory, revision);
} }
QStringList MercurialEditorWidget::annotationPreviousVersions(const QString &revision) const QStringList MercurialEditorWidget::annotationPreviousVersions(const QString &revision) const
@@ -102,7 +103,7 @@ QStringList MercurialEditorWidget::annotationPreviousVersions(const QString &rev
const QFileInfo fi(source()); const QFileInfo fi(source());
const QString workingDirectory = fi.absolutePath(); const QString workingDirectory = fi.absolutePath();
// Retrieve parent revisions // Retrieve parent revisions
return MercurialPluginPrivate::client()->parentRevisionsSync(workingDirectory, fi.fileName(), revision); return m_client->parentRevisionsSync(workingDirectory, fi.fileName(), revision);
} }
} // namespace Internal } // namespace Internal

View File

@@ -32,11 +32,13 @@
namespace Mercurial { namespace Mercurial {
namespace Internal { namespace Internal {
class MercurialClient;
class MercurialEditorWidget : public VcsBase::VcsBaseEditorWidget class MercurialEditorWidget : public VcsBase::VcsBaseEditorWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
MercurialEditorWidget(); explicit MercurialEditorWidget(MercurialClient *client);
private: private:
QSet<QString> annotationChanges() const override; QSet<QString> annotationChanges() const override;
@@ -50,6 +52,8 @@ private:
mutable QRegExp exactIdentifier40; mutable QRegExp exactIdentifier40;
mutable QRegExp changesetIdentifier12; mutable QRegExp changesetIdentifier12;
const QRegExp changesetIdentifier40; const QRegExp changesetIdentifier40;
MercurialClient *m_client;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -100,13 +100,78 @@ static const VcsBaseSubmitEditorParameters submitEditorParameters = {
VcsBaseSubmitEditorParameters::DiffFiles VcsBaseSubmitEditorParameters::DiffFiles
}; };
static MercurialPluginPrivate *dd = nullptr; class MercurialPluginPrivate final : public VcsBase::VcsBasePluginPrivate
MercurialPluginPrivate::~MercurialPluginPrivate()
{ {
delete m_client; Q_DECLARE_TR_FUNCTIONS(Mercurial::Internal::MercurialPlugin)
m_client = nullptr;
} public:
MercurialPluginPrivate();
private:
void updateActions(VcsBase::VcsBasePluginPrivate::ActionState) final;
bool submitEditorAboutToClose() final;
// File menu action slots
void addCurrentFile();
void annotateCurrentFile();
void diffCurrentFile();
void logCurrentFile();
void revertCurrentFile();
void statusCurrentFile();
// Directory menu action slots
void diffRepository();
void logRepository();
void revertMulti();
void statusMulti();
// Repository menu action slots
void pull();
void push();
void update();
void import();
void incoming();
void outgoing();
void commit();
void showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusItem> &status);
void commitFromEditor() override;
void diffFromEditorSelected(const QStringList &files);
void createMenu(const Core::Context &context);
void createFileActions(const Core::Context &context);
void createDirectoryActions(const Core::Context &context);
void createRepositoryActions(const Core::Context &context);
// Variables
MercurialSettings m_settings;
MercurialClient m_client{&m_settings};
MercurialControl m_control{&m_client};
OptionsPage m_optionsPage{[this] { m_control.configurationChanged(); }, &m_settings};
Core::CommandLocator *m_commandLocator = nullptr;
Core::ActionContainer *m_mercurialContainer = nullptr;
QList<QAction *> m_repositoryActionList;
// Menu items (file actions)
ParameterAction *m_addAction = nullptr;
ParameterAction *m_deleteAction = nullptr;
ParameterAction *annotateFile = nullptr;
ParameterAction *diffFile = nullptr;
ParameterAction *logFile = nullptr;
ParameterAction *revertFile = nullptr;
ParameterAction *statusFile = nullptr;
QAction *m_createRepositoryAction = nullptr;
QAction *m_menuAction = nullptr;
QString m_submitRepository;
bool m_submitActionTriggered = false;
};
static MercurialPluginPrivate *dd = nullptr;
MercurialPlugin::~MercurialPlugin() MercurialPlugin::~MercurialPlugin()
{ {
@@ -114,16 +179,6 @@ MercurialPlugin::~MercurialPlugin()
dd = nullptr; dd = nullptr;
} }
MercurialPluginPrivate *MercurialPluginPrivate::instance()
{
return dd;
}
MercurialClient *MercurialPluginPrivate::client()
{
return dd->m_client;
}
bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString * /*errorMessage */) bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString * /*errorMessage */)
{ {
dd = new MercurialPluginPrivate; dd = new MercurialPluginPrivate;
@@ -140,19 +195,15 @@ MercurialPluginPrivate::MercurialPluginPrivate()
dd = this; dd = this;
Core::Context context(Constants::MERCURIAL_CONTEXT); Core::Context context(Constants::MERCURIAL_CONTEXT);
m_client = new MercurialClient(&m_settings); initializeVcs(&m_control, context);
auto vc = new MercurialControl(m_client);
initializeVcs(vc, context);
new OptionsPage(vc, this); connect(&m_client, &VcsBaseClient::changed, &m_control, &MercurialControl::changed);
connect(&m_client, &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update);
connect(m_client, &VcsBaseClient::changed, vc, &MercurialControl::changed);
connect(m_client, &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update);
const auto describeFunc = [this](const QString &source, const QString &id) { const auto describeFunc = [this](const QString &source, const QString &id) {
m_client->view(source, id); m_client.view(source, id);
}; };
const auto widgetCreator = []() { return new MercurialEditorWidget; }; const auto widgetCreator = [this] { return new MercurialEditorWidget(&m_client); };
for (auto &editor : editorParameters) for (auto &editor : editorParameters)
new VcsEditorFactory(&editor, widgetCreator, describeFunc, this); new VcsEditorFactory(&editor, widgetCreator, describeFunc, this);
@@ -248,7 +299,7 @@ void MercurialPluginPrivate::addCurrentFile()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile()); m_client.synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
} }
void MercurialPluginPrivate::annotateCurrentFile() void MercurialPluginPrivate::annotateCurrentFile()
@@ -258,21 +309,21 @@ void MercurialPluginPrivate::annotateCurrentFile()
currentLine = editor->currentLine(); currentLine = editor->currentLine();
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->annotate(state.currentFileTopLevel(), state.relativeCurrentFile(), QString(), currentLine); m_client.annotate(state.currentFileTopLevel(), state.relativeCurrentFile(), QString(), currentLine);
} }
void MercurialPluginPrivate::diffCurrentFile() void MercurialPluginPrivate::diffCurrentFile()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile())); m_client.diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
} }
void MercurialPluginPrivate::logCurrentFile() void MercurialPluginPrivate::logCurrentFile()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), m_client.log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()),
QStringList(), true); QStringList(), true);
} }
@@ -284,14 +335,14 @@ void MercurialPluginPrivate::revertCurrentFile()
RevertDialog reverter(Core::ICore::dialogParent()); RevertDialog reverter(Core::ICore::dialogParent());
if (reverter.exec() != QDialog::Accepted) if (reverter.exec() != QDialog::Accepted)
return; return;
m_client->revertFile(state.currentFileTopLevel(), state.relativeCurrentFile(), reverter.revision()); m_client.revertFile(state.currentFileTopLevel(), state.relativeCurrentFile(), reverter.revision());
} }
void MercurialPluginPrivate::statusCurrentFile() void MercurialPluginPrivate::statusCurrentFile()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->status(state.currentFileTopLevel(), state.relativeCurrentFile()); m_client.status(state.currentFileTopLevel(), state.relativeCurrentFile());
} }
void MercurialPluginPrivate::createDirectoryActions(const Core::Context &context) void MercurialPluginPrivate::createDirectoryActions(const Core::Context &context)
@@ -329,14 +380,14 @@ void MercurialPluginPrivate::diffRepository()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_client->diff(state.topLevel()); m_client.diff(state.topLevel());
} }
void MercurialPluginPrivate::logRepository() void MercurialPluginPrivate::logRepository()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_client->log(state.topLevel()); m_client.log(state.topLevel());
} }
void MercurialPluginPrivate::revertMulti() void MercurialPluginPrivate::revertMulti()
@@ -347,7 +398,7 @@ void MercurialPluginPrivate::revertMulti()
RevertDialog reverter(Core::ICore::dialogParent()); RevertDialog reverter(Core::ICore::dialogParent());
if (reverter.exec() != QDialog::Accepted) if (reverter.exec() != QDialog::Accepted)
return; return;
m_client->revertAll(state.topLevel(), reverter.revision()); m_client.revertAll(state.topLevel(), reverter.revision());
} }
void MercurialPluginPrivate::statusMulti() void MercurialPluginPrivate::statusMulti()
@@ -355,7 +406,7 @@ void MercurialPluginPrivate::statusMulti()
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_client->status(state.topLevel()); m_client.status(state.topLevel());
} }
void MercurialPluginPrivate::createRepositoryActions(const Core::Context &context) void MercurialPluginPrivate::createRepositoryActions(const Core::Context &context)
@@ -421,11 +472,11 @@ void MercurialPluginPrivate::pull()
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
SrcDestDialog dialog(SrcDestDialog::incoming, Core::ICore::dialogParent()); SrcDestDialog dialog(state, SrcDestDialog::incoming, Core::ICore::dialogParent());
dialog.setWindowTitle(tr("Pull Source")); dialog.setWindowTitle(tr("Pull Source"));
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return;
m_client->synchronousPull(dialog.workingDir(), dialog.getRepositoryString()); m_client.synchronousPull(dialog.workingDir(), dialog.getRepositoryString());
} }
void MercurialPluginPrivate::push() void MercurialPluginPrivate::push()
@@ -433,11 +484,11 @@ void MercurialPluginPrivate::push()
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
SrcDestDialog dialog(SrcDestDialog::outgoing, Core::ICore::dialogParent()); SrcDestDialog dialog(state, SrcDestDialog::outgoing, Core::ICore::dialogParent());
dialog.setWindowTitle(tr("Push Destination")); dialog.setWindowTitle(tr("Push Destination"));
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return;
m_client->synchronousPush(dialog.workingDir(), dialog.getRepositoryString()); m_client.synchronousPush(dialog.workingDir(), dialog.getRepositoryString());
} }
void MercurialPluginPrivate::update() void MercurialPluginPrivate::update()
@@ -449,7 +500,7 @@ void MercurialPluginPrivate::update()
updateDialog.setWindowTitle(tr("Update")); updateDialog.setWindowTitle(tr("Update"));
if (updateDialog.exec() != QDialog::Accepted) if (updateDialog.exec() != QDialog::Accepted)
return; return;
m_client->update(state.topLevel(), updateDialog.revision()); m_client.update(state.topLevel(), updateDialog.revision());
} }
void MercurialPluginPrivate::import() void MercurialPluginPrivate::import()
@@ -465,7 +516,7 @@ void MercurialPluginPrivate::import()
return; return;
const QStringList fileNames = importDialog.selectedFiles(); const QStringList fileNames = importDialog.selectedFiles();
m_client->import(state.topLevel(), fileNames); m_client.import(state.topLevel(), fileNames);
} }
void MercurialPluginPrivate::incoming() void MercurialPluginPrivate::incoming()
@@ -473,18 +524,18 @@ void MercurialPluginPrivate::incoming()
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
SrcDestDialog dialog(SrcDestDialog::incoming, Core::ICore::dialogParent()); SrcDestDialog dialog(state, SrcDestDialog::incoming, Core::ICore::dialogParent());
dialog.setWindowTitle(tr("Incoming Source")); dialog.setWindowTitle(tr("Incoming Source"));
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return;
m_client->incoming(state.topLevel(), dialog.getRepositoryString()); m_client.incoming(state.topLevel(), dialog.getRepositoryString());
} }
void MercurialPluginPrivate::outgoing() void MercurialPluginPrivate::outgoing()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_client->outgoing(state.topLevel()); m_client.outgoing(state.topLevel());
} }
void MercurialPluginPrivate::commit() void MercurialPluginPrivate::commit()
@@ -500,14 +551,14 @@ void MercurialPluginPrivate::commit()
m_submitRepository = state.topLevel(); m_submitRepository = state.topLevel();
connect(m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget); connect(&m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget);
m_client->emitParsedStatus(m_submitRepository); m_client.emitParsedStatus(m_submitRepository);
} }
void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status) void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status)
{ {
//Once we receive our data release the connection so it can be reused elsewhere //Once we receive our data release the connection so it can be reused elsewhere
disconnect(m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget); disconnect(&m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget);
if (status.isEmpty()) { if (status.isEmpty()) {
VcsOutputWindow::appendError(tr("There are no changes to commit.")); VcsOutputWindow::appendError(tr("There are no changes to commit."));
@@ -542,15 +593,15 @@ void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusI
arg(QDir::toNativeSeparators(m_submitRepository)); arg(QDir::toNativeSeparators(m_submitRepository));
commitEditor->document()->setPreferredDisplayName(msg); commitEditor->document()->setPreferredDisplayName(msg);
QString branch = versionControl()->vcsTopic(m_submitRepository); QString branch = m_control.vcsTopic(m_submitRepository);
commitEditor->setFields(m_submitRepository, branch, commitEditor->setFields(m_submitRepository, branch,
m_client->settings().stringValue(MercurialSettings::userNameKey), m_settings.stringValue(MercurialSettings::userNameKey),
m_client->settings().stringValue(MercurialSettings::userEmailKey), status); m_settings.stringValue(MercurialSettings::userEmailKey), status);
} }
void MercurialPluginPrivate::diffFromEditorSelected(const QStringList &files) void MercurialPluginPrivate::diffFromEditorSelected(const QStringList &files)
{ {
m_client->diff(m_submitRepository, files); m_client.diff(m_submitRepository, files);
} }
void MercurialPluginPrivate::commitFromEditor() void MercurialPluginPrivate::commitFromEditor()
@@ -590,7 +641,7 @@ bool MercurialPluginPrivate::submitEditorAboutToClose()
QStringList extraOptions; QStringList extraOptions;
if (!commitEditor->committerInfo().isEmpty()) if (!commitEditor->committerInfo().isEmpty())
extraOptions << QLatin1String("-u") << commitEditor->committerInfo(); extraOptions << QLatin1String("-u") << commitEditor->committerInfo();
m_client->commit(m_submitRepository, files, editorFile->filePath().toString(), m_client.commit(m_submitRepository, files, editorFile->filePath().toString(),
extraOptions); extraOptions);
} }
return true; return true;

View File

@@ -25,119 +25,11 @@
#pragma once #pragma once
#include "mercurialsettings.h" #include <extensionsystem/iplugin.h>
#include <vcsbase/vcsbaseclient.h>
#include <vcsbase/vcsbaseplugin.h>
#include <coreplugin/icontext.h>
QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
namespace Core {
class ActionContainer;
class CommandLocator;
} // namespace Core
namespace Utils { class ParameterAction; }
namespace VcsBase { class VcsBaseSubmitEditor; }
namespace Mercurial { namespace Mercurial {
namespace Internal { namespace Internal {
class OptionsPage;
class MercurialClient;
class MercurialPluginPrivate final : public VcsBase::VcsBasePluginPrivate
{
Q_OBJECT
public:
MercurialPluginPrivate();
~MercurialPluginPrivate() final;
static MercurialPluginPrivate *instance();
static MercurialClient *client();
protected:
void updateActions(VcsBase::VcsBasePluginPrivate::ActionState) override;
bool submitEditorAboutToClose() override;
private:
// File menu action slots
void addCurrentFile();
void annotateCurrentFile();
void diffCurrentFile();
void logCurrentFile();
void revertCurrentFile();
void statusCurrentFile();
// Directory menu action slots
void diffRepository();
void logRepository();
void revertMulti();
void statusMulti();
// Repository menu action slots
void pull();
void push();
void update();
void import();
void incoming();
void outgoing();
void commit();
void showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusItem> &status);
void commitFromEditor() override;
void diffFromEditorSelected(const QStringList &files);
//TODO implement
/* //repository management action slots
void merge();
void branch();
void heads();
void parents();
void tags();
void tip();
void paths();
//less used repository action
void init();
void serve();*/
void createMenu(const Core::Context &context);
void createFileActions(const Core::Context &context);
void createDirectoryActions(const Core::Context &context);
void createRepositoryActions(const Core::Context &context);
// Variables
MercurialSettings m_settings;
OptionsPage *optionsPage = nullptr;
MercurialClient *m_client = nullptr;
Core::CommandLocator *m_commandLocator = nullptr;
Core::ActionContainer *m_mercurialContainer = nullptr;
QList<QAction *> m_repositoryActionList;
// Menu items (file actions)
Utils::ParameterAction *m_addAction = nullptr;
Utils::ParameterAction *m_deleteAction = nullptr;
Utils::ParameterAction *annotateFile = nullptr;
Utils::ParameterAction *diffFile = nullptr;
Utils::ParameterAction *logFile = nullptr;
Utils::ParameterAction *renameFile = nullptr;
Utils::ParameterAction *revertFile = nullptr;
Utils::ParameterAction *statusFile = nullptr;
QAction *m_createRepositoryAction = nullptr;
QAction *m_menuAction = nullptr;
QString m_submitRepository;
bool m_submitActionTriggered = false;
};
class MercurialPlugin final : public ExtensionSystem::IPlugin class MercurialPlugin final : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT

View File

@@ -45,23 +45,24 @@ class OptionsPageWidget final : public Core::IOptionsPageWidget
Q_DECLARE_TR_FUNCTIONS(Mercurial::Internal::OptionsPageWidget) Q_DECLARE_TR_FUNCTIONS(Mercurial::Internal::OptionsPageWidget)
public: public:
explicit OptionsPageWidget(Core::IVersionControl *control); OptionsPageWidget(const std::function<void()> &onApply, MercurialSettings *settings);
void apply() final; void apply() final;
private: private:
Ui::OptionsPage m_ui; Ui::OptionsPage m_ui;
Core::IVersionControl *m_control; std::function<void()> m_onApply;
MercurialSettings *m_settings;
}; };
OptionsPageWidget::OptionsPageWidget(Core::IVersionControl *control) OptionsPageWidget::OptionsPageWidget(const std::function<void()> &onApply, MercurialSettings *settings)
: m_control(control) : m_onApply(onApply), m_settings(settings)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand); m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_ui.commandChooser->setHistoryCompleter(QLatin1String("Mercurial.Command.History")); m_ui.commandChooser->setHistoryCompleter(QLatin1String("Mercurial.Command.History"));
m_ui.commandChooser->setPromptDialogTitle(tr("Mercurial Command")); m_ui.commandChooser->setPromptDialogTitle(tr("Mercurial Command"));
const VcsBaseClientSettings &s = MercurialPluginPrivate::client()->settings(); const VcsBaseClientSettings &s = *settings;
m_ui.commandChooser->setPath(s.stringValue(MercurialSettings::binaryPathKey)); m_ui.commandChooser->setPath(s.stringValue(MercurialSettings::binaryPathKey));
m_ui.defaultUsernameLineEdit->setText(s.stringValue(MercurialSettings::userNameKey)); m_ui.defaultUsernameLineEdit->setText(s.stringValue(MercurialSettings::userNameKey));
@@ -79,20 +80,18 @@ void OptionsPageWidget::apply()
ms.setValue(MercurialSettings::logCountKey, m_ui.logEntriesCount->value()); ms.setValue(MercurialSettings::logCountKey, m_ui.logEntriesCount->value());
ms.setValue(MercurialSettings::timeoutKey, m_ui.timeout->value()); ms.setValue(MercurialSettings::timeoutKey, m_ui.timeout->value());
VcsBaseClientSettings &s = MercurialPluginPrivate::client()->settings(); if (*m_settings != ms) {
if (s != ms) { *m_settings = ms;
s = ms; m_onApply();
m_control->configurationChanged();
} }
} }
OptionsPage::OptionsPage(Core::IVersionControl *control, QObject *parent) OptionsPage::OptionsPage(const std::function<void()> &onApply, MercurialSettings *settings)
: Core::IOptionsPage(parent)
{ {
setId(VcsBase::Constants::VCS_ID_MERCURIAL); setId(VcsBase::Constants::VCS_ID_MERCURIAL);
setDisplayName(OptionsPageWidget::tr("Mercurial")); setDisplayName(OptionsPageWidget::tr("Mercurial"));
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY); setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
setWidgetCreator([control] { return new OptionsPageWidget(control); }); setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); });
} }
} // namespace Internal } // namespace Internal

View File

@@ -27,15 +27,15 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
namespace Core { class IVersionControl; }
namespace Mercurial { namespace Mercurial {
namespace Internal { namespace Internal {
class MercurialSettings;
class OptionsPage final : public Core::IOptionsPage class OptionsPage final : public Core::IOptionsPage
{ {
public: public:
OptionsPage(Core::IVersionControl *control, QObject *parent); OptionsPage(const std::function<void()> &onApply, MercurialSettings *settings);
}; };
} // namespace Internal } // namespace Internal

View File

@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "authenticationdialog.h" #include "authenticationdialog.h"
#include "mercurialplugin.h"
#include "srcdestdialog.h" #include "srcdestdialog.h"
#include "ui_srcdestdialog.h" #include "ui_srcdestdialog.h"
@@ -36,10 +35,11 @@ using namespace VcsBase;
namespace Mercurial { namespace Mercurial {
namespace Internal { namespace Internal {
SrcDestDialog::SrcDestDialog(Direction dir, QWidget *parent) : SrcDestDialog::SrcDestDialog(const VcsBasePluginState &state, Direction dir, QWidget *parent) :
QDialog(parent), QDialog(parent),
m_ui(new Ui::SrcDestDialog), m_ui(new Ui::SrcDestDialog),
m_direction(dir) m_direction(dir),
m_state(state)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->localPathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory); m_ui->localPathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
@@ -97,10 +97,9 @@ QString SrcDestDialog::workingDir() const
QUrl SrcDestDialog::getRepoUrl() const QUrl SrcDestDialog::getRepoUrl() const
{ {
const VcsBasePluginState state = MercurialPluginPrivate::instance()->currentState();
// Repo to use: Default to the project repo, but use the current // Repo to use: Default to the project repo, but use the current
const QString projectLoc = state.currentProjectPath(); const QString projectLoc = m_state.currentProjectPath();
const QString fileLoc = state.currentFileTopLevel(); const QString fileLoc = m_state.currentFileTopLevel();
m_workingdir = projectLoc; m_workingdir = projectLoc;
if (!fileLoc.isEmpty()) if (!fileLoc.isEmpty())
m_workingdir = fileLoc; m_workingdir = fileLoc;

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <vcsbase/vcsbaseplugin.h>
#include <QDialog> #include <QDialog>
namespace Mercurial { namespace Mercurial {
@@ -39,7 +40,7 @@ class SrcDestDialog : public QDialog
public: public:
enum Direction { outgoing, incoming }; enum Direction { outgoing, incoming };
explicit SrcDestDialog(Direction dir, QWidget *parent = nullptr); explicit SrcDestDialog(const VcsBase::VcsBasePluginState &state, Direction dir, QWidget *parent = nullptr);
~SrcDestDialog() override; ~SrcDestDialog() override;
void setPathChooserKind(Utils::PathChooser::Kind kind); void setPathChooserKind(Utils::PathChooser::Kind kind);
@@ -53,6 +54,7 @@ private:
Ui::SrcDestDialog *m_ui; Ui::SrcDestDialog *m_ui;
Direction m_direction; Direction m_direction;
mutable QString m_workingdir; mutable QString m_workingdir;
VcsBase::VcsBasePluginState m_state;
}; };
} // namespace Internal } // namespace Internal