2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Brian McGillion
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-11-02 18:50:06 +01:00
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "mercurialplugin.h"
|
|
|
|
|
#include "optionspage.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "mercurialclient.h"
|
|
|
|
|
#include "mercurialeditor.h"
|
|
|
|
|
#include "revertdialog.h"
|
|
|
|
|
#include "srcdestdialog.h"
|
|
|
|
|
#include "commiteditor.h"
|
|
|
|
|
#include "mercurialsettings.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2017-09-08 12:52:35 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-01-11 15:22:17 +01:00
|
|
|
#include <coreplugin/vcsmanager.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/locator/commandlocator.h>
|
2010-02-12 16:03:08 +01:00
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include <utils/parameteraction.h>
|
2009-12-08 14:28:00 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
#include <vcsbase/basevcseditorfactory.h>
|
|
|
|
|
#include <vcsbase/basevcssubmiteditorfactory.h>
|
|
|
|
|
#include <vcsbase/vcsbaseeditor.h>
|
2014-07-28 18:46:34 +02:00
|
|
|
#include <vcsbase/vcsbaseconstants.h>
|
2014-08-26 00:02:47 +02:00
|
|
|
#include <vcsbase/vcsoutputwindow.h>
|
2020-01-30 12:31:47 +01:00
|
|
|
#include <vcsbase/vcscommand.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QMenu>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
#include <QFileDialog>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2014-07-28 18:46:34 +02:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
#include <QTest>
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
using namespace VcsBase;
|
|
|
|
|
using namespace Utils;
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2014-07-28 18:46:34 +02:00
|
|
|
namespace Mercurial {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
class MercurialTopicCache : public Core::IVersionControl::TopicCache
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MercurialTopicCache(MercurialClient *client) : m_client(client) {}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
QString trackFile(const QString &repository) override
|
|
|
|
|
{
|
|
|
|
|
return repository + QLatin1String("/.hg/branch");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString refreshTopic(const QString &repository) override
|
|
|
|
|
{
|
|
|
|
|
return m_client->branchQuerySync(repository);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MercurialClient *m_client;
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
static const VcsBaseEditorParameters editorParameters[] = {
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2013-05-22 21:03:37 +03:00
|
|
|
LogOutput,
|
2014-08-27 18:55:41 +02:00
|
|
|
Constants::FILELOG_ID,
|
|
|
|
|
Constants::FILELOG_DISPLAY_NAME,
|
|
|
|
|
Constants::LOGAPP},
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
{ AnnotateOutput,
|
|
|
|
|
Constants::ANNOTATELOG_ID,
|
|
|
|
|
Constants::ANNOTATELOG_DISPLAY_NAME,
|
2013-05-21 20:54:26 +03:00
|
|
|
Constants::ANNOTATEAPP},
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
{ DiffOutput,
|
2010-01-08 09:48:54 +01:00
|
|
|
Constants::DIFFLOG_ID,
|
|
|
|
|
Constants::DIFFLOG_DISPLAY_NAME,
|
2013-05-21 20:54:26 +03:00
|
|
|
Constants::DIFFAPP}
|
2009-09-15 13:03:13 +03:00
|
|
|
};
|
|
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
static const VcsBaseSubmitEditorParameters submitEditorParameters = {
|
2009-09-15 13:03:13 +03:00
|
|
|
Constants::COMMITMIMETYPE,
|
2010-01-08 09:48:54 +01:00
|
|
|
Constants::COMMIT_ID,
|
|
|
|
|
Constants::COMMIT_DISPLAY_NAME,
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsBaseSubmitEditorParameters::DiffFiles
|
2009-09-15 13:03:13 +03:00
|
|
|
};
|
|
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
class MercurialPluginPrivate final : public VcsBase::VcsBasePluginPrivate
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Mercurial::Internal::MercurialPlugin)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
MercurialPluginPrivate();
|
|
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
// IVersionControl
|
|
|
|
|
QString displayName() const final;
|
|
|
|
|
Core::Id id() const final;
|
|
|
|
|
bool isVcsFileOrDirectory(const Utils::FilePath &fileName) const final;
|
|
|
|
|
|
|
|
|
|
bool managesDirectory(const QString &filename, QString *topLevel = nullptr) const final;
|
|
|
|
|
bool managesFile(const QString &workingDirectory, const QString &fileName) const final;
|
|
|
|
|
bool isConfigured() const final;
|
|
|
|
|
bool supportsOperation(Operation operation) const final;
|
|
|
|
|
bool vcsOpen(const QString &fileName) final;
|
|
|
|
|
bool vcsAdd(const QString &filename) final;
|
|
|
|
|
bool vcsDelete(const QString &filename) final;
|
|
|
|
|
bool vcsMove(const QString &from, const QString &to) final;
|
|
|
|
|
bool vcsCreateRepository(const QString &directory) final;
|
|
|
|
|
bool vcsAnnotate(const QString &file, int line) final;
|
|
|
|
|
|
|
|
|
|
Core::ShellCommand *createInitialCheckoutCommand(const QString &url,
|
|
|
|
|
const Utils::FilePath &baseDirectory,
|
|
|
|
|
const QString &localName,
|
|
|
|
|
const QStringList &extraArgs) final;
|
|
|
|
|
|
|
|
|
|
bool sccManaged(const QString &filename);
|
|
|
|
|
|
|
|
|
|
// 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&);
|
|
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
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};
|
|
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
OptionsPage m_optionsPage{[this] { configurationChanged(); }, &m_settings};
|
2020-01-29 12:50:48 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
static MercurialPluginPrivate *dd = nullptr;
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
MercurialPlugin::~MercurialPlugin()
|
|
|
|
|
{
|
2020-01-23 17:22:05 +01:00
|
|
|
delete dd;
|
|
|
|
|
dd = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString * /*errorMessage */)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2020-01-23 17:22:05 +01:00
|
|
|
dd = new MercurialPluginPrivate;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
dd->extensionsInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MercurialPluginPrivate::MercurialPluginPrivate()
|
2020-01-30 12:31:47 +01:00
|
|
|
: VcsBase::VcsBasePluginPrivate(Core::Context(Constants::MERCURIAL_CONTEXT))
|
2020-01-23 17:22:05 +01:00
|
|
|
{
|
|
|
|
|
dd = this;
|
2014-11-16 12:05:34 +02:00
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
setTopicCache(new MercurialTopicCache(&m_client));
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
Core::Context context(Constants::MERCURIAL_CONTEXT);
|
|
|
|
|
|
|
|
|
|
connect(&m_client, &VcsBaseClient::changed, this, &MercurialPluginPrivate::changed);
|
2020-01-29 12:50:48 +01:00
|
|
|
connect(&m_client, &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2016-11-26 21:52:49 +02:00
|
|
|
const auto describeFunc = [this](const QString &source, const QString &id) {
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.view(source, id);
|
2016-11-26 21:52:49 +02:00
|
|
|
};
|
2020-01-29 12:50:48 +01:00
|
|
|
const auto widgetCreator = [this] { return new MercurialEditorWidget(&m_client); };
|
2018-11-15 14:50:43 +01:00
|
|
|
for (auto &editor : editorParameters)
|
2018-11-14 01:58:25 +01:00
|
|
|
new VcsEditorFactory(&editor, widgetCreator, describeFunc, this);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2018-02-02 10:08:21 +01:00
|
|
|
new VcsSubmitEditorFactory(&submitEditorParameters,
|
|
|
|
|
[]() { return new CommitEditor(&submitEditorParameters); }, this);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2010-02-12 16:03:08 +01:00
|
|
|
const QString prefix = QLatin1String("hg");
|
2018-02-02 10:08:21 +01:00
|
|
|
m_commandLocator = new Core::CommandLocator("Mercurial", prefix, prefix, this);
|
2010-02-12 16:03:08 +01:00
|
|
|
|
2014-11-16 12:05:34 +02:00
|
|
|
createMenu(context);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::createMenu(const Core::Context &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
// Create menu item for Mercurial
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer = Core::ActionManager::createMenu("Mercurial.MercurialMenu");
|
|
|
|
|
QMenu *menu = m_mercurialContainer->menu();
|
2013-06-13 20:41:27 +03:00
|
|
|
menu->setTitle(tr("Me&rcurial"));
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
createFileActions(context);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addSeparator(context);
|
2009-09-15 13:03:13 +03:00
|
|
|
createDirectoryActions(context);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addSeparator(context);
|
2009-09-15 13:03:13 +03:00
|
|
|
createRepositoryActions(context);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addSeparator(context);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
// Request the Tools menu and add the Mercurial menu to it
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionContainer *toolsMenu = Core::ActionManager::actionContainer(Core::Id(Core::Constants::M_TOOLS));
|
2014-11-09 10:15:46 +02:00
|
|
|
toolsMenu->addMenu(m_mercurialContainer);
|
|
|
|
|
m_menuAction = m_mercurialContainer->menu()->menuAction();
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::createFileActions(const Core::Context &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
Core::Command *command;
|
|
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
annotateFile = new ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(annotateFile, Core::Id(Constants::ANNOTATE), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(annotateFile, &QAction::triggered, this, &MercurialPluginPrivate::annotateCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
diffFile = new ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(diffFile, Core::Id(Constants::DIFF), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2018-02-02 13:39:18 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+H,Meta+D") : tr("Alt+G,Alt+D")));
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(diffFile, &QAction::triggered, this, &MercurialPluginPrivate::diffCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
logFile = new ParameterAction(tr("Log Current File"), tr("Log \"%1\""), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(logFile, Core::Id(Constants::LOG), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2018-02-02 13:39:18 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+H,Meta+L") : tr("Alt+G,Alt+L")));
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(logFile, &QAction::triggered, this, &MercurialPluginPrivate::logCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
statusFile = new ParameterAction(tr("Status Current File"), tr("Status \"%1\""), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(statusFile, Core::Id(Constants::STATUS), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2018-02-02 13:39:18 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+H,Meta+S") : tr("Alt+G,Alt+S")));
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(statusFile, &QAction::triggered, this, &MercurialPluginPrivate::statusCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2010-01-11 15:22:17 +01:00
|
|
|
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addSeparator(context);
|
2010-01-11 15:22:17 +01:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
m_addAction = new ParameterAction(tr("Add"), tr("Add \"%1\""), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(m_addAction, Core::Id(Constants::ADD), context);
|
2010-01-11 15:22:17 +01:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(m_addAction, &QAction::triggered, this, &MercurialPluginPrivate::addCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2010-01-11 15:22:17 +01:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
m_deleteAction = new ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(m_deleteAction, Core::Id(Constants::DELETE), context);
|
2010-01-11 15:22:17 +01:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(m_deleteAction, &QAction::triggered, this, &MercurialPluginPrivate::promptToDeleteCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2010-01-11 15:22:17 +01:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
revertFile = new ParameterAction(tr("Revert Current File..."), tr("Revert \"%1\"..."), ParameterAction::EnabledWithParameter, this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(revertFile, Core::Id(Constants::REVERT), context);
|
2010-01-11 15:22:17 +01:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(revertFile, &QAction::triggered, this, &MercurialPluginPrivate::revertCurrentFile);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2010-01-11 15:22:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::addCurrentFile()
|
2010-01-11 15:22:17 +01:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::annotateCurrentFile()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2013-06-13 14:33:43 +03:00
|
|
|
int currentLine = -1;
|
|
|
|
|
if (Core::IEditor *editor = Core::EditorManager::currentEditor())
|
|
|
|
|
currentLine = editor->currentLine();
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.annotate(state.currentFileTopLevel(), state.relativeCurrentFile(), QString(), currentLine);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::diffCurrentFile()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::logCurrentFile()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()),
|
|
|
|
|
QStringList(), true);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::revertCurrentFile()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2014-06-18 21:42:46 +02:00
|
|
|
RevertDialog reverter(Core::ICore::dialogParent());
|
2009-09-15 13:03:13 +03:00
|
|
|
if (reverter.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.revertFile(state.currentFileTopLevel(), state.relativeCurrentFile(), reverter.revision());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::statusCurrentFile()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.status(state.currentFileTopLevel(), state.relativeCurrentFile());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::createDirectoryActions(const Core::Context &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2015-01-22 13:53:03 +01:00
|
|
|
auto action = new QAction(tr("Diff"), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2015-01-22 13:53:03 +01:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(action, Core::Id(Constants::DIFFMULTI), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::diffRepository);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
action = new QAction(tr("Log"), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::LOGMULTI), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::logRepository);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Revert..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::REVERTMULTI), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::revertMulti);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
action = new QAction(tr("Status"), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::STATUSMULTI), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::statusMulti);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::diffRepository()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.diff(state.topLevel());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::logRepository()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.log(state.topLevel());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::revertMulti()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2014-06-18 21:42:46 +02:00
|
|
|
RevertDialog reverter(Core::ICore::dialogParent());
|
2009-09-15 13:03:13 +03:00
|
|
|
if (reverter.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.revertAll(state.topLevel(), reverter.revision());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::statusMulti()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.status(state.topLevel());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::createRepositoryActions(const Core::Context &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2015-01-22 13:53:03 +01:00
|
|
|
auto action = new QAction(tr("Pull..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(action, Core::Id(Constants::PULL), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::pull);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Push..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::PUSH), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::push);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Update..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::UPDATE), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::update);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Import..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::IMPORT), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::import);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Incoming..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::INCOMING), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::incoming);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Outgoing..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::OUTGOING), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::outgoing);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Commit..."), this);
|
2009-12-08 14:28:00 +01:00
|
|
|
m_repositoryActionList.append(action);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(action, Core::Id(Constants::COMMIT), context);
|
2018-02-02 13:39:18 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+H,Meta+C") : tr("Alt+G,Alt+C")));
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(action, &QAction::triggered, this, &MercurialPluginPrivate::commit);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2010-02-12 16:03:08 +01:00
|
|
|
m_commandLocator->appendCommand(command);
|
2010-01-12 16:45:21 +01:00
|
|
|
|
|
|
|
|
m_createRepositoryAction = new QAction(tr("Create Repository..."), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(m_createRepositoryAction, Core::Id(Constants::CREATE_REPOSITORY), context);
|
2020-01-23 17:22:05 +01:00
|
|
|
connect(m_createRepositoryAction, &QAction::triggered, this, &MercurialPluginPrivate::createRepository);
|
2014-11-09 10:15:46 +02:00
|
|
|
m_mercurialContainer->addAction(command);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::pull()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
SrcDestDialog dialog(state, SrcDestDialog::incoming, Core::ICore::dialogParent());
|
2009-11-03 16:38:39 +01:00
|
|
|
dialog.setWindowTitle(tr("Pull Source"));
|
2009-09-15 13:03:13 +03:00
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.synchronousPull(dialog.workingDir(), dialog.getRepositoryString());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::push()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
SrcDestDialog dialog(state, SrcDestDialog::outgoing, Core::ICore::dialogParent());
|
2009-11-03 16:38:39 +01:00
|
|
|
dialog.setWindowTitle(tr("Push Destination"));
|
2009-09-15 13:03:13 +03:00
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.synchronousPush(dialog.workingDir(), dialog.getRepositoryString());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::update()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2014-06-18 21:42:46 +02:00
|
|
|
RevertDialog updateDialog(Core::ICore::dialogParent());
|
2009-11-03 16:38:39 +01:00
|
|
|
updateDialog.setWindowTitle(tr("Update"));
|
2009-09-15 13:03:13 +03:00
|
|
|
if (updateDialog.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.update(state.topLevel(), updateDialog.revision());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::import()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2014-06-18 21:42:46 +02:00
|
|
|
QFileDialog importDialog(Core::ICore::dialogParent());
|
2009-09-15 13:03:13 +03:00
|
|
|
importDialog.setFileMode(QFileDialog::ExistingFiles);
|
|
|
|
|
importDialog.setViewMode(QFileDialog::Detail);
|
|
|
|
|
|
|
|
|
|
if (importDialog.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QStringList fileNames = importDialog.selectedFiles();
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.import(state.topLevel(), fileNames);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::incoming()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
SrcDestDialog dialog(state, SrcDestDialog::incoming, Core::ICore::dialogParent());
|
2009-11-03 16:38:39 +01:00
|
|
|
dialog.setWindowTitle(tr("Incoming Source"));
|
2009-09-15 13:03:13 +03:00
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.incoming(state.topLevel(), dialog.getRepositoryString());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::outgoing()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.outgoing(state.topLevel());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::commit()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2017-09-08 12:52:35 +02:00
|
|
|
if (!promptBeforeCommit())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-04-18 12:06:43 +02:00
|
|
|
if (raiseSubmitEditor())
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBasePluginState state = currentState();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
|
|
|
|
m_submitRepository = state.topLevel();
|
|
|
|
|
|
2020-01-29 12:50:48 +01:00
|
|
|
connect(&m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget);
|
|
|
|
|
m_client.emitParsedStatus(m_submitRepository);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
//Once we receive our data release the connection so it can be reused elsewhere
|
2020-01-29 12:50:48 +01:00
|
|
|
disconnect(&m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
if (status.isEmpty()) {
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::appendError(tr("There are no changes to commit."));
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 15:18:44 +02:00
|
|
|
// Start new temp file
|
2015-02-03 23:52:10 +02:00
|
|
|
TempFileSaver saver;
|
2012-09-26 15:18:44 +02:00
|
|
|
// Keep the file alive, else it removes self and forgets its name
|
|
|
|
|
saver.setAutoRemove(false);
|
|
|
|
|
if (!saver.finalize()) {
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsOutputWindow::appendError(saver.errorString());
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 15:18:44 +02:00
|
|
|
Core::IEditor *editor = Core::EditorManager::openEditor(saver.fileName(),
|
2013-05-31 12:52:53 +02:00
|
|
|
Constants::COMMIT_ID);
|
2009-09-15 13:03:13 +03:00
|
|
|
if (!editor) {
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::appendError(tr("Unable to create an editor for the commit."));
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(qobject_cast<CommitEditor *>(editor), return);
|
2018-11-14 01:58:25 +01:00
|
|
|
auto commitEditor = static_cast<CommitEditor *>(editor);
|
2013-04-18 12:06:43 +02:00
|
|
|
setSubmitEditor(commitEditor);
|
2009-12-08 14:28:00 +01:00
|
|
|
|
2015-03-04 14:56:56 +01:00
|
|
|
connect(commitEditor, &VcsBaseSubmitEditor::diffSelectedFiles,
|
2020-01-23 17:22:05 +01:00
|
|
|
this, &MercurialPluginPrivate::diffFromEditorSelected);
|
2011-11-22 15:11:58 +01:00
|
|
|
commitEditor->setCheckScriptWorkingDirectory(m_submitRepository);
|
|
|
|
|
|
2010-07-05 09:52:32 +02:00
|
|
|
const QString msg = tr("Commit changes for \"%1\".").
|
|
|
|
|
arg(QDir::toNativeSeparators(m_submitRepository));
|
2015-02-25 14:36:03 +02:00
|
|
|
commitEditor->document()->setPreferredDisplayName(msg);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
const QString branch = vcsTopic(m_submitRepository);
|
2011-09-14 09:13:44 +00:00
|
|
|
commitEditor->setFields(m_submitRepository, branch,
|
2020-01-29 12:50:48 +01:00
|
|
|
m_settings.stringValue(MercurialSettings::userNameKey),
|
|
|
|
|
m_settings.stringValue(MercurialSettings::userEmailKey), status);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::diffFromEditorSelected(const QStringList &files)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.diff(m_submitRepository, files);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::commitFromEditor()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2012-09-26 15:18:44 +02:00
|
|
|
// Close the submit editor
|
|
|
|
|
m_submitActionTriggered = true;
|
2014-08-19 16:15:57 +02:00
|
|
|
QTC_ASSERT(submitEditor(), return);
|
|
|
|
|
Core::EditorManager::closeDocument(submitEditor()->document());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
bool MercurialPluginPrivate::submitEditorAboutToClose()
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2018-11-14 01:58:25 +01:00
|
|
|
auto commitEditor = qobject_cast<CommitEditor *>(submitEditor());
|
2013-04-18 12:06:43 +02:00
|
|
|
QTC_ASSERT(commitEditor, return true);
|
|
|
|
|
Core::IDocument *editorFile = commitEditor->document();
|
|
|
|
|
QTC_ASSERT(editorFile, return true);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-01-07 14:32:59 +01:00
|
|
|
const VcsBaseSubmitEditor::PromptSubmitResult response =
|
2018-11-09 09:59:40 +02:00
|
|
|
commitEditor->promptSubmit(this, nullptr, !m_submitActionTriggered);
|
2012-09-26 15:18:44 +02:00
|
|
|
m_submitActionTriggered = false;
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
switch (response) {
|
2012-01-07 14:32:59 +01:00
|
|
|
case VcsBaseSubmitEditor::SubmitCanceled:
|
2009-09-15 13:03:13 +03:00
|
|
|
return false;
|
2012-01-07 14:32:59 +01:00
|
|
|
case VcsBaseSubmitEditor::SubmitDiscarded:
|
2009-09-15 13:03:13 +03:00
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList files = commitEditor->checkedFiles();
|
|
|
|
|
if (!files.empty()) {
|
|
|
|
|
//save the commit message
|
2012-02-14 16:43:51 +01:00
|
|
|
if (!Core::DocumentManager::saveDocument(editorFile))
|
2011-03-30 12:43:17 +02:00
|
|
|
return false;
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-05-12 14:48:10 +02:00
|
|
|
QStringList extraOptions;
|
|
|
|
|
if (!commitEditor->committerInfo().isEmpty())
|
|
|
|
|
extraOptions << QLatin1String("-u") << commitEditor->committerInfo();
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client.commit(m_submitRepository, files, editorFile->filePath().toString(),
|
|
|
|
|
extraOptions);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-02-28 13:40:04 +01:00
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
void MercurialPluginPrivate::updateActions(VcsBasePluginPrivate::ActionState as)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2010-02-15 13:55:11 +01:00
|
|
|
if (!enableMenuAction(as, m_menuAction)) {
|
|
|
|
|
m_commandLocator->setEnabled(false);
|
2009-12-08 14:28:00 +01:00
|
|
|
return;
|
2010-02-15 13:55:11 +01:00
|
|
|
}
|
2009-12-08 14:28:00 +01:00
|
|
|
const QString filename = currentState().currentFileName();
|
|
|
|
|
const bool repoEnabled = currentState().hasTopLevel();
|
2010-02-15 13:55:11 +01:00
|
|
|
m_commandLocator->setEnabled(repoEnabled);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
annotateFile->setParameter(filename);
|
|
|
|
|
diffFile->setParameter(filename);
|
|
|
|
|
logFile->setParameter(filename);
|
2010-01-11 15:22:17 +01:00
|
|
|
m_addAction->setParameter(filename);
|
|
|
|
|
m_deleteAction->setParameter(filename);
|
2009-09-15 13:03:13 +03:00
|
|
|
revertFile->setParameter(filename);
|
|
|
|
|
statusFile->setParameter(filename);
|
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
foreach (QAction *repoAction, m_repositoryActionList)
|
|
|
|
|
repoAction->setEnabled(repoEnabled);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
QString MercurialPluginPrivate::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr("Mercurial");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Id MercurialPluginPrivate::id() const
|
|
|
|
|
{
|
|
|
|
|
return {VcsBase::Constants::VCS_ID_MERCURIAL};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::isVcsFileOrDirectory(const Utils::FilePath &fileName) const
|
|
|
|
|
{
|
|
|
|
|
return m_client.isVcsDirectory(fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::managesDirectory(const QString &directory, QString *topLevel) const
|
|
|
|
|
{
|
|
|
|
|
QFileInfo dir(directory);
|
|
|
|
|
const QString topLevelFound = m_client.findTopLevelForFile(dir);
|
|
|
|
|
if (topLevel)
|
|
|
|
|
*topLevel = topLevelFound;
|
|
|
|
|
return !topLevelFound.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::managesFile(const QString &workingDirectory, const QString &fileName) const
|
|
|
|
|
{
|
|
|
|
|
return m_client.managesFile(workingDirectory, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::isConfigured() const
|
|
|
|
|
{
|
2020-02-03 17:54:41 +01:00
|
|
|
const Utils::FilePath binary = m_settings.binaryPath();
|
2020-01-30 12:31:47 +01:00
|
|
|
if (binary.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
QFileInfo fi = binary.toFileInfo();
|
|
|
|
|
return fi.exists() && fi.isFile() && fi.isExecutable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::supportsOperation(Operation operation) const
|
|
|
|
|
{
|
|
|
|
|
bool supported = isConfigured();
|
|
|
|
|
switch (operation) {
|
|
|
|
|
case Core::IVersionControl::AddOperation:
|
|
|
|
|
case Core::IVersionControl::DeleteOperation:
|
|
|
|
|
case Core::IVersionControl::MoveOperation:
|
|
|
|
|
case Core::IVersionControl::CreateRepositoryOperation:
|
|
|
|
|
case Core::IVersionControl::AnnotateOperation:
|
|
|
|
|
case Core::IVersionControl::InitialCheckoutOperation:
|
|
|
|
|
break;
|
|
|
|
|
case Core::IVersionControl::SnapshotOperations:
|
|
|
|
|
supported = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return supported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::vcsOpen(const QString &filename)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(filename)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::vcsAdd(const QString &filename)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fi(filename);
|
|
|
|
|
return m_client.synchronousAdd(fi.absolutePath(), fi.fileName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::vcsDelete(const QString &filename)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fi(filename);
|
|
|
|
|
return m_client.synchronousRemove(fi.absolutePath(), fi.fileName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::vcsMove(const QString &from, const QString &to)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fromInfo(from);
|
|
|
|
|
const QFileInfo toInfo(to);
|
|
|
|
|
return m_client.synchronousMove(fromInfo.absolutePath(),
|
|
|
|
|
fromInfo.absoluteFilePath(),
|
|
|
|
|
toInfo.absoluteFilePath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::vcsCreateRepository(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
return m_client.synchronousCreateRepository(directory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::vcsAnnotate(const QString &file, int line)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fi(file);
|
|
|
|
|
m_client.annotate(fi.absolutePath(), fi.fileName(), QString(), line);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::ShellCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &url,
|
|
|
|
|
const Utils::FilePath &baseDirectory,
|
|
|
|
|
const QString &localName,
|
|
|
|
|
const QStringList &extraArgs)
|
|
|
|
|
{
|
|
|
|
|
QStringList args;
|
|
|
|
|
args << QLatin1String("clone") << extraArgs << url << localName;
|
|
|
|
|
auto command = new VcsBase::VcsCommand(baseDirectory.toString(),
|
|
|
|
|
m_client.processEnvironment());
|
2020-02-03 17:54:41 +01:00
|
|
|
command->addJob({m_settings.binaryPath(), args}, -1);
|
2020-01-30 12:31:47 +01:00
|
|
|
return command;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPluginPrivate::sccManaged(const QString &filename)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fi(filename);
|
|
|
|
|
QString topLevel;
|
|
|
|
|
const bool managed = managesDirectory(fi.absolutePath(), &topLevel);
|
|
|
|
|
if (!managed || topLevel.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
const QDir topLevelDir(topLevel);
|
|
|
|
|
return m_client.manifestSync(topLevel, topLevelDir.relativeFilePath(filename));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPluginPrivate::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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 22:56:01 +02:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::testDiffFileResolving_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QByteArray>("header");
|
|
|
|
|
QTest::addColumn<QByteArray>("fileName");
|
|
|
|
|
|
|
|
|
|
QTest::newRow("New") << QByteArray(
|
|
|
|
|
"diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"new file mode 100644\n"
|
|
|
|
|
"--- /dev/null\n"
|
|
|
|
|
"+++ b/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"@@ -0,0 +1,112 @@\n\n")
|
|
|
|
|
<< QByteArray("src/plugins/mercurial/mercurialeditor.cpp");
|
|
|
|
|
QTest::newRow("Deleted") << QByteArray(
|
|
|
|
|
"diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"deleted file mode 100644\n"
|
|
|
|
|
"--- a/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"+++ /dev/null\n"
|
|
|
|
|
"@@ -1,112 +0,0 @@\n\n")
|
|
|
|
|
<< QByteArray("src/plugins/mercurial/mercurialeditor.cpp");
|
|
|
|
|
QTest::newRow("Normal") << QByteArray(
|
|
|
|
|
"diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"--- a/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"+++ b/src/plugins/mercurial/mercurialeditor.cpp\n"
|
|
|
|
|
"@@ -49,6 +49,8 @@\n\n")
|
|
|
|
|
<< QByteArray("src/plugins/mercurial/mercurialeditor.cpp");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::testDiffFileResolving()
|
|
|
|
|
{
|
2014-08-28 13:45:42 +02:00
|
|
|
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id);
|
2013-01-21 22:56:01 +02:00
|
|
|
}
|
2013-01-28 22:02:35 +02:00
|
|
|
|
|
|
|
|
void MercurialPlugin::testLogResolving()
|
|
|
|
|
{
|
|
|
|
|
QByteArray data(
|
|
|
|
|
"changeset: 18473:692cbda1eb50\n"
|
|
|
|
|
"branch: stable\n"
|
|
|
|
|
"bookmark: @\n"
|
|
|
|
|
"tag: tip\n"
|
|
|
|
|
"user: FUJIWARA Katsunori <foozy@lares.dti.ne.jp>\n"
|
|
|
|
|
"date: Wed Jan 23 22:52:55 2013 +0900\n"
|
|
|
|
|
"summary: revset: evaluate sub expressions correctly (issue3775)\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"changeset: 18472:37100f30590f\n"
|
|
|
|
|
"branch: stable\n"
|
|
|
|
|
"user: Pierre-Yves David <pierre-yves.david@ens-lyon.org>\n"
|
|
|
|
|
"date: Sat Jan 19 04:08:16 2013 +0100\n"
|
|
|
|
|
"summary: test-rebase: add another test for rebase with multiple roots\n"
|
|
|
|
|
);
|
2014-08-28 13:45:42 +02:00
|
|
|
VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "18473:692cbda1eb50", "18472:37100f30590f");
|
2013-01-28 22:02:35 +02:00
|
|
|
}
|
2013-01-21 22:56:01 +02:00
|
|
|
#endif
|
|
|
|
|
|
2014-07-28 18:46:34 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Mercurial
|