2009-11-02 18:50:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2009 Brian McGillion
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "mercurialplugin.h"
|
|
|
|
|
#include "optionspage.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "mercurialclient.h"
|
|
|
|
|
#include "mercurialcontrol.h"
|
|
|
|
|
#include "mercurialeditor.h"
|
|
|
|
|
#include "revertdialog.h"
|
|
|
|
|
#include "srcdestdialog.h"
|
|
|
|
|
#include "commiteditor.h"
|
|
|
|
|
#include "clonewizard.h"
|
|
|
|
|
#include "mercurialsettings.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/basemode.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
#include <coreplugin/filemanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2009-11-02 19:52:28 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
#include <utils/parameteraction.h>
|
|
|
|
|
|
|
|
|
|
#include <vcsbase/basevcseditorfactory.h>
|
|
|
|
|
#include <vcsbase/basevcssubmiteditorfactory.h>
|
|
|
|
|
#include <vcsbase/vcsbaseeditor.h>
|
2009-11-03 14:21:48 +01:00
|
|
|
#include <vcsbase/vcsbaseoutputwindow.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
#include <QtCore/QtPlugin>
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
|
#include <QtCore/QtDebug>
|
|
|
|
|
#include <QtCore/QtGlobal>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtGui/QDialog>
|
|
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
|
#include <QtCore/QTemporaryFile>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Mercurial::Internal;
|
|
|
|
|
using namespace Mercurial;
|
|
|
|
|
|
|
|
|
|
bool ListenForClose::editorAboutToClose(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
return MercurialPlugin::instance()->closeEditor(editor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
|
|
|
|
|
{
|
|
|
|
|
VCSBase::RegularCommandOutput, //type
|
|
|
|
|
Constants::COMMANDLOG, // kind
|
|
|
|
|
Constants::COMMANDLOG, // context
|
|
|
|
|
Constants::COMMANDAPP, // mime type
|
|
|
|
|
Constants::COMMANDEXT}, //extension
|
|
|
|
|
|
|
|
|
|
{ VCSBase::LogOutput,
|
|
|
|
|
Constants::FILELOG,
|
|
|
|
|
Constants::FILELOG,
|
|
|
|
|
Constants::LOGAPP,
|
|
|
|
|
Constants::LOGEXT},
|
|
|
|
|
|
|
|
|
|
{ VCSBase::AnnotateOutput,
|
|
|
|
|
Constants::ANNOTATELOG,
|
|
|
|
|
Constants::ANNOTATELOG,
|
|
|
|
|
Constants::ANNOTATEAPP,
|
|
|
|
|
Constants::ANNOTATEEXT},
|
|
|
|
|
|
|
|
|
|
{ VCSBase::DiffOutput,
|
|
|
|
|
Constants::DIFFLOG,
|
|
|
|
|
Constants::DIFFLOG,
|
|
|
|
|
Constants::DIFFAPP,
|
|
|
|
|
Constants::DIFFEXT}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const VCSBase::VCSBaseSubmitEditorParameters submitEditorParameters = {
|
|
|
|
|
Constants::COMMITMIMETYPE,
|
|
|
|
|
Constants::COMMITKIND,
|
|
|
|
|
Constants::COMMITKIND
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Utility to find a parameter set by type
|
|
|
|
|
static inline const VCSBase::VCSBaseEditorParameters *findType(int ie)
|
|
|
|
|
{
|
|
|
|
|
const VCSBase::EditorContentType et = static_cast<VCSBase::EditorContentType>(ie);
|
|
|
|
|
return VCSBase::VCSBaseEditor::findType(editorParameters,
|
|
|
|
|
sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters), et);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MercurialPlugin *MercurialPlugin::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
MercurialPlugin::MercurialPlugin()
|
|
|
|
|
: mercurialSettings(new MercurialSettings),
|
|
|
|
|
optionsPage(0),
|
|
|
|
|
client(0),
|
|
|
|
|
mercurialVC(0),
|
|
|
|
|
projectExplorer(0),
|
|
|
|
|
changeLog(0)
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MercurialPlugin::~MercurialPlugin()
|
|
|
|
|
{
|
|
|
|
|
if (client) {
|
|
|
|
|
delete client;
|
|
|
|
|
client = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mercurialSettings) {
|
|
|
|
|
delete mercurialSettings;
|
|
|
|
|
mercurialSettings = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteCommitLog();
|
|
|
|
|
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPlugin::initialize(const QStringList &arguments, QString *error_message)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(error_message)
|
|
|
|
|
|
|
|
|
|
typedef VCSBase::VCSEditorFactory<MercurialEditor> MercurialEditorFactory;
|
|
|
|
|
|
|
|
|
|
core = Core::ICore::instance();
|
|
|
|
|
actionManager = core->actionManager();
|
|
|
|
|
|
|
|
|
|
optionsPage = new OptionsPage();
|
|
|
|
|
addAutoReleasedObject(optionsPage);
|
|
|
|
|
|
|
|
|
|
client = new MercurialClient();
|
|
|
|
|
connect(optionsPage, SIGNAL(settingsChanged()), client, SLOT(settingsChanged()));
|
|
|
|
|
|
|
|
|
|
mercurialVC = new MercurialControl(client);
|
|
|
|
|
addAutoReleasedObject(mercurialVC);
|
|
|
|
|
|
|
|
|
|
static const char *describeSlot = SLOT(view(QString,QString));
|
|
|
|
|
const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
|
|
|
|
|
for (int i = 0; i < editorCount; i++)
|
|
|
|
|
addAutoReleasedObject(new MercurialEditorFactory(editorParameters + i, client, describeSlot));
|
|
|
|
|
|
|
|
|
|
addAutoReleasedObject(new VCSBase::VCSSubmitEditorFactory<CommitEditor>(&submitEditorParameters));
|
|
|
|
|
|
|
|
|
|
addAutoReleasedObject(new CloneWizard);
|
|
|
|
|
|
|
|
|
|
addAutoReleasedObject(new ListenForClose);
|
|
|
|
|
|
|
|
|
|
createMenu();
|
|
|
|
|
|
|
|
|
|
createSubmitEditorActions();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
|
|
|
|
|
if (projectExplorer)
|
|
|
|
|
connect(projectExplorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project *)),
|
|
|
|
|
this, SLOT(currentProjectChanged(ProjectExplorer::Project *)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MercurialSettings *MercurialPlugin::settings()
|
|
|
|
|
{
|
|
|
|
|
return mercurialSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
QStringList MercurialPlugin::standardArguments() const
|
|
|
|
|
{
|
|
|
|
|
return mercurialSettings->standardArguments();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
void MercurialPlugin::createMenu()
|
|
|
|
|
{
|
2009-11-03 16:38:39 +01:00
|
|
|
QList<int> context = QList<int>()<< core->uniqueIDManager()->uniqueIdentifier(QLatin1String(Core::Constants::C_GLOBAL));
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
// Create menu item for Mercurial
|
2009-11-03 16:38:39 +01:00
|
|
|
mercurialContainer = actionManager->createMenu(QLatin1String("Mercurial.MercurialMenu"));
|
2009-09-15 13:03:13 +03:00
|
|
|
QMenu *menu = mercurialContainer->menu();
|
|
|
|
|
menu->setTitle(tr("Mercurial"));
|
|
|
|
|
|
|
|
|
|
if (QAction *visibleAction = menu->menuAction()) {
|
|
|
|
|
visibleAction->setEnabled(mercurialVC->isEnabled());
|
|
|
|
|
connect(mercurialVC, SIGNAL(enabledChanged(bool)), visibleAction, SLOT(setVisible(bool)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createFileActions(context);
|
2009-11-03 16:38:39 +01:00
|
|
|
createSeparator(context, QLatin1String("FileDirSeperator"));
|
2009-09-15 13:03:13 +03:00
|
|
|
createDirectoryActions(context);
|
2009-11-03 16:38:39 +01:00
|
|
|
createSeparator(context, QLatin1String("DirRepoSeperator"));
|
2009-09-15 13:03:13 +03:00
|
|
|
createRepositoryActions(context);
|
2009-11-03 16:38:39 +01:00
|
|
|
createSeparator(context, QLatin1String("Repository Management"));
|
2009-09-15 13:03:13 +03:00
|
|
|
createRepositoryManagementActions(context);
|
2009-11-03 16:38:39 +01:00
|
|
|
createSeparator(context, QLatin1String("LessUsedfunctionality"));
|
2009-09-15 13:03:13 +03:00
|
|
|
createLessUsedActions(context);
|
|
|
|
|
|
|
|
|
|
// Request the Tools menu and add the Mercurial menu to it
|
2009-11-03 16:38:39 +01:00
|
|
|
Core::ActionContainer *toolsMenu = actionManager->actionContainer(QLatin1String(Core::Constants::M_TOOLS));
|
2009-09-15 13:03:13 +03:00
|
|
|
toolsMenu->addMenu(mercurialContainer);
|
|
|
|
|
|
|
|
|
|
connect(core, SIGNAL(contextChanged(Core::IContext *)), this, SLOT(updateActions()));
|
|
|
|
|
connect(core->fileManager(), SIGNAL(currentFileChanged(const QString &)),
|
|
|
|
|
this, SLOT(updateActions()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
void MercurialPlugin::createFileActions(const QList<int> &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
Core::Command *command;
|
|
|
|
|
|
2009-11-02 19:52:28 +01:00
|
|
|
annotateFile = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(annotateFile, QLatin1String(Constants::ANNOTATE), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
|
connect(annotateFile, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-02 19:52:28 +01:00
|
|
|
diffFile = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(diffFile, QLatin1String(Constants::DIFF), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2009-11-03 16:38:39 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+D")));
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(diffFile, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-02 19:52:28 +01:00
|
|
|
logFile = new Utils::ParameterAction(tr("Log Current File"), tr("Log \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(logFile, QLatin1String(Constants::LOG), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2009-11-03 16:38:39 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+L")));
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(logFile, SIGNAL(triggered()), this, SLOT(logCurrentFile()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-02 19:52:28 +01:00
|
|
|
revertFile = new Utils::ParameterAction(tr("Revert Current File"), tr("Revert \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(revertFile, QLatin1String(Constants::REVERT), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
|
connect(revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-02 19:52:28 +01:00
|
|
|
statusFile = new Utils::ParameterAction(tr("Status Current File"), tr("Status \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(statusFile, QLatin1String(Constants::STATUS), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2009-11-03 16:38:39 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+S")));
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(statusFile, SIGNAL(triggered()), this, SLOT(statusCurrentFile()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::annotateCurrentFile()
|
|
|
|
|
{
|
|
|
|
|
client->annotate(currentFile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::diffCurrentFile()
|
|
|
|
|
{
|
|
|
|
|
client->diff(currentFile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::logCurrentFile()
|
|
|
|
|
{
|
|
|
|
|
client->log(currentFile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::revertCurrentFile()
|
|
|
|
|
{
|
|
|
|
|
RevertDialog reverter;
|
|
|
|
|
if (reverter.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2009-11-03 14:21:48 +01:00
|
|
|
client->revert(currentFile(), reverter.revision());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::statusCurrentFile()
|
|
|
|
|
{
|
|
|
|
|
client->status(currentFile());
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
void MercurialPlugin::createDirectoryActions(const QList<int> &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
QAction *action;
|
|
|
|
|
Core::Command *command;
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("Diff"), this);
|
|
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::DIFFMULTI), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(diffRepository()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("Log"), this);
|
|
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::LOGMULTI), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(logRepository()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Revert..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::REVERTMULTI), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(revertMulti()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("Status"), this);
|
|
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::STATUSMULTI), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(statusMulti()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::diffRepository()
|
|
|
|
|
{
|
|
|
|
|
client->diff(currentProjectRoot());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::logRepository()
|
|
|
|
|
{
|
|
|
|
|
client->log(currentProjectRoot());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::revertMulti()
|
|
|
|
|
{
|
|
|
|
|
RevertDialog reverter;
|
|
|
|
|
if (reverter.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2009-11-03 14:21:48 +01:00
|
|
|
client->revert(currentProjectRoot(), reverter.revision());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::statusMulti()
|
|
|
|
|
{
|
|
|
|
|
client->status(currentProjectRoot());
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
void MercurialPlugin::createRepositoryActions(const QList<int> &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2009-11-05 12:45:02 +01:00
|
|
|
QAction *action = new QAction(tr("Pull..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
Core::Command *command = actionManager->registerAction(action, QLatin1String(Constants::PULL), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(pull()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Push..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::PUSH), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(push()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Update..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::UPDATE), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(update()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Import..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::IMPORT), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(import()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Incoming..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::INCOMING), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(incoming()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Outgoing..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::OUTGOING), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(outgoing()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
action = new QAction(tr("Commit..."), this);
|
2009-09-15 13:03:13 +03:00
|
|
|
actionList.append(action);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(action, QLatin1String(Constants::COMMIT), context);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+C")));
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(commit()));
|
|
|
|
|
mercurialContainer->addAction(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::pull()
|
|
|
|
|
{
|
|
|
|
|
SrcDestDialog dialog;
|
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;
|
|
|
|
|
QString repository = dialog.getRepositoryString();
|
|
|
|
|
client->pull(currentProjectRoot(), repository);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::push()
|
|
|
|
|
{
|
|
|
|
|
SrcDestDialog dialog;
|
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;
|
|
|
|
|
QString repository = dialog.getRepositoryString();
|
|
|
|
|
client->push(currentProjectRoot(), repository);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::update()
|
|
|
|
|
{
|
|
|
|
|
RevertDialog updateDialog;
|
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;
|
2009-11-03 14:21:48 +01:00
|
|
|
client->update(currentProjectRoot(), updateDialog.revision());
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::import()
|
|
|
|
|
{
|
|
|
|
|
QFileDialog importDialog;
|
|
|
|
|
importDialog.setFileMode(QFileDialog::ExistingFiles);
|
|
|
|
|
importDialog.setViewMode(QFileDialog::Detail);
|
|
|
|
|
|
|
|
|
|
if (importDialog.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QStringList fileNames = importDialog.selectedFiles();
|
|
|
|
|
client->import(currentProjectRoot(), fileNames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::incoming()
|
|
|
|
|
{
|
|
|
|
|
SrcDestDialog dialog;
|
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;
|
|
|
|
|
QString repository = dialog.getRepositoryString();
|
|
|
|
|
client->incoming(currentProjectRoot(), repository);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::outgoing()
|
|
|
|
|
{
|
|
|
|
|
client->outgoing(currentProjectRoot());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::createSubmitEditorActions()
|
|
|
|
|
{
|
2009-11-03 16:38:39 +01:00
|
|
|
QList<int> context = QList<int>()<< core->uniqueIDManager()->uniqueIdentifier(QLatin1String(Constants::COMMITKIND));
|
2009-09-15 13:03:13 +03:00
|
|
|
Core::Command *command;
|
|
|
|
|
|
|
|
|
|
editorCommit = new QAction(VCSBase::VCSBaseSubmitEditor::submitIcon(), tr("Commit"), this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(editorCommit, QLatin1String(Constants::COMMIT), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
connect(editorCommit, SIGNAL(triggered()), this, SLOT(commitFromEditor()));
|
|
|
|
|
|
|
|
|
|
editorDiff = new QAction(VCSBase::VCSBaseSubmitEditor::diffIcon(), tr("Diff Selected Files"), this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(editorDiff, QLatin1String(Constants::DIFFEDITOR), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
editorUndo = new QAction(tr("&Undo"), this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(editorUndo, QLatin1String(Core::Constants::UNDO), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
editorRedo = new QAction(tr("&Redo"), this);
|
2009-11-03 16:38:39 +01:00
|
|
|
command = actionManager->registerAction(editorRedo, QLatin1String(Core::Constants::REDO), context);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::commit()
|
|
|
|
|
{
|
|
|
|
|
if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
|
|
|
|
|
return;
|
|
|
|
|
|
2009-11-03 14:21:48 +01:00
|
|
|
connect(client, SIGNAL(parsedStatus(QList<QPair<QString,QString> >)),
|
|
|
|
|
this, SLOT(showCommitWidget(QList<QPair<QString,QString> >)));
|
2009-09-15 13:03:13 +03:00
|
|
|
client->statusWithSignal(currentProjectRoot());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::showCommitWidget(const QList<QPair<QString, QString> > &status)
|
|
|
|
|
{
|
2009-11-03 14:21:48 +01:00
|
|
|
|
|
|
|
|
VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
|
2009-09-15 13:03:13 +03:00
|
|
|
//Once we receive our data release the connection so it can be reused elsewhere
|
2009-11-03 14:21:48 +01:00
|
|
|
disconnect(client, SIGNAL(parsedStatus(QList<QPair<QString,QString> >)),
|
|
|
|
|
this, SLOT(showCommitWidget(QList<QPair<QString,QString> >)));
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
if (status.isEmpty()) {
|
2009-11-03 14:21:48 +01:00
|
|
|
outputWindow->appendError(tr("There are no changes to commit."));
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteCommitLog();
|
|
|
|
|
|
|
|
|
|
changeLog = new QTemporaryFile(this);
|
|
|
|
|
if (!changeLog->open()) {
|
2009-11-03 14:21:48 +01:00
|
|
|
outputWindow->appendError(tr("Unable to generate a temporary file for the commit editor."));
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IEditor *editor = core->editorManager()->openEditor(changeLog->fileName(),
|
2009-11-03 16:38:39 +01:00
|
|
|
QLatin1String(Constants::COMMITKIND));
|
2009-09-15 13:03:13 +03:00
|
|
|
if (!editor) {
|
2009-11-03 14:21:48 +01:00
|
|
|
outputWindow->appendError(tr("Unable to create an editor for the commit."));
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
core->editorManager()->ensureEditorManagerVisible();
|
|
|
|
|
|
|
|
|
|
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(editor);
|
|
|
|
|
|
|
|
|
|
if (!commitEditor) {
|
2009-11-03 14:21:48 +01:00
|
|
|
outputWindow->appendError(tr("Unable to create a commit editor."));
|
2009-09-15 13:03:13 +03:00
|
|
|
return;
|
|
|
|
|
}
|
2009-11-03 14:21:48 +01:00
|
|
|
const QString msg = tr("Commit changes for \"%1\".").arg(currentProjectName());
|
|
|
|
|
commitEditor->setDisplayName(msg);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
QString branch = client->branchQuerySync(currentProjectRoot());
|
|
|
|
|
|
|
|
|
|
commitEditor->setFields(currentProjectRoot(), branch, mercurialSettings->userName(),
|
|
|
|
|
mercurialSettings->email(), status);
|
|
|
|
|
|
|
|
|
|
commitEditor->registerActions(editorUndo, editorRedo, editorCommit, editorDiff);
|
|
|
|
|
connect(commitEditor, SIGNAL(diffSelectedFiles(const QStringList &)),
|
|
|
|
|
this, SLOT(diffFromEditorSelected(const QStringList &)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::diffFromEditorSelected(const QStringList &files)
|
|
|
|
|
{
|
2009-11-03 16:38:39 +01:00
|
|
|
foreach (const QString &file, files) {
|
|
|
|
|
const QFileInfo toDiff(QDir(currentProjectRoot().absoluteFilePath()).absoluteFilePath(file));
|
2009-09-15 13:03:13 +03:00
|
|
|
client->diff(toDiff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::commitFromEditor()
|
|
|
|
|
{
|
|
|
|
|
if (!changeLog)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//use the same functionality than if the user closes the file without completing the commit
|
|
|
|
|
core->editorManager()->closeEditors(core->editorManager()->editorsForFileName(changeLog->fileName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MercurialPlugin::closeEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (!changeLog || !editor || qstrcmp(editor->kind(), Constants::COMMITKIND))
|
|
|
|
|
return true;
|
|
|
|
|
Core::IFile *editorFile = editor->file();
|
|
|
|
|
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(editor);
|
|
|
|
|
if (!editorFile || !commitEditor)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool dummyPrompt = settings()->prompt();
|
|
|
|
|
const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult response =
|
|
|
|
|
commitEditor->promptSubmit(tr("Close commit editor"), tr("Do you want to commit the changes?"),
|
|
|
|
|
tr("Message check failed. Do you want to proceed?"),
|
|
|
|
|
&dummyPrompt, settings()->prompt());
|
|
|
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
|
case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
|
|
|
|
|
return false;
|
|
|
|
|
case VCSBase::VCSBaseSubmitEditor::SubmitDiscarded:
|
|
|
|
|
deleteCommitLog();
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList files = commitEditor->checkedFiles();
|
|
|
|
|
if (!files.empty()) {
|
|
|
|
|
//save the commit message
|
|
|
|
|
core->fileManager()->blockFileChange(editorFile);
|
|
|
|
|
editorFile->save();
|
|
|
|
|
core->fileManager()->unblockFileChange(editorFile);
|
|
|
|
|
|
|
|
|
|
const QFileInfo repoRoot(commitEditor->repoRoot());
|
|
|
|
|
client->commit(repoRoot, files, commitEditor->committerInfo(),
|
|
|
|
|
editorFile->fileName());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
void MercurialPlugin::deleteCommitLog()
|
|
|
|
|
{
|
|
|
|
|
if (changeLog) {
|
|
|
|
|
delete changeLog;
|
|
|
|
|
changeLog = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
void MercurialPlugin::createRepositoryManagementActions(const QList<int> &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
//TODO create menu for these options
|
|
|
|
|
Q_UNUSED(context);
|
|
|
|
|
return;
|
|
|
|
|
// QAction *action = new QAction(tr("Branch"), this);
|
|
|
|
|
// actionList.append(action);
|
|
|
|
|
// Core::Command *command = actionManager->registerAction(action, Constants::BRANCH, context);
|
|
|
|
|
// // connect(action, SIGNAL(triggered()), this, SLOT(branch()));
|
|
|
|
|
// mercurialContainer->addAction(command);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
void MercurialPlugin::createLessUsedActions(const QList<int> &context)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
//TODO create menue for these options
|
|
|
|
|
Q_UNUSED(context);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::createSeparator(const QList<int> &context, const QString &id)
|
|
|
|
|
{
|
|
|
|
|
QAction *action = new QAction(this);
|
|
|
|
|
action->setSeparator(true);
|
|
|
|
|
mercurialContainer->addAction(actionManager->registerAction(action, id, context));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::updateActions()
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo file = currentFile();
|
|
|
|
|
const QString filename = file.fileName();
|
|
|
|
|
const QString repoRoot = client->findTopLevelForFile(file);
|
|
|
|
|
bool enable = false;
|
|
|
|
|
|
|
|
|
|
//File menu Items should only be enabled for files that are below a mercurial repository
|
|
|
|
|
enable = !repoRoot.isEmpty();
|
|
|
|
|
annotateFile->setParameter(filename);
|
|
|
|
|
annotateFile->setEnabled(enable);
|
|
|
|
|
diffFile->setParameter(filename);
|
|
|
|
|
diffFile->setEnabled(enable);
|
|
|
|
|
logFile->setParameter(filename);
|
|
|
|
|
logFile->setEnabled(enable);
|
|
|
|
|
revertFile->setParameter(filename);
|
|
|
|
|
revertFile->setEnabled(enable);
|
|
|
|
|
statusFile->setParameter(filename);
|
|
|
|
|
statusFile->setEnabled(enable);
|
|
|
|
|
|
|
|
|
|
//repository actions
|
|
|
|
|
if (projectMapper.contains(currentProjectName()))
|
|
|
|
|
enable = true;
|
|
|
|
|
else
|
|
|
|
|
enable = false;
|
|
|
|
|
|
|
|
|
|
foreach (QAction *action, actionList)
|
|
|
|
|
action->setEnabled(enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFileInfo MercurialPlugin::currentFile()
|
|
|
|
|
{
|
|
|
|
|
QString fileName = core->fileManager()->currentFile();
|
|
|
|
|
QFileInfo fileInfo(fileName);
|
|
|
|
|
return fileInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MercurialPlugin::currentProjectName()
|
|
|
|
|
{
|
|
|
|
|
if (projectExplorer)
|
|
|
|
|
if (projectExplorer->currentProject())
|
|
|
|
|
return projectExplorer->currentProject()->name();
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MercurialPlugin::currentProjectChanged(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
if (!project)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (projectMapper.contains(project->name()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString repoRoot = client->findTopLevelForFile(QFileInfo(project->file()->fileName()));
|
|
|
|
|
|
|
|
|
|
if (!repoRoot.isEmpty())
|
|
|
|
|
projectMapper.insert(project->name(), QFileInfo(repoRoot));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFileInfo MercurialPlugin::currentProjectRoot()
|
|
|
|
|
{
|
|
|
|
|
return projectMapper.value(currentProjectName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(MercurialPlugin)
|