2011-02-28 13:40:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2010 Hugues Delorme
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-02-28 13:40:06 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2011-02-28 13:40:06 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "bazaarplugin.h"
|
|
|
|
#include "constants.h"
|
|
|
|
#include "bazaarclient.h"
|
|
|
|
#include "bazaarcontrol.h"
|
|
|
|
#include "optionspage.h"
|
|
|
|
#include "bazaarcommitwidget.h"
|
|
|
|
#include "bazaareditor.h"
|
|
|
|
#include "pullorpushdialog.h"
|
|
|
|
#include "commiteditor.h"
|
|
|
|
#include "clonewizard.h"
|
|
|
|
|
|
|
|
#include "ui_revertdialog.h"
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2011-02-28 13:40:06 +01:00
|
|
|
#include <coreplugin/vcsmanager.h>
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/filemanager.h>
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
|
|
#include <locator/commandlocator.h>
|
|
|
|
|
|
|
|
#include <utils/parameteraction.h>
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
#include <vcsbase/basevcseditorfactory.h>
|
|
|
|
#include <vcsbase/basevcssubmiteditorfactory.h>
|
|
|
|
#include <vcsbase/vcsbasesubmiteditor.h>
|
|
|
|
#include <vcsbase/vcsbaseeditor.h>
|
|
|
|
#include <vcsbase/vcsbaseoutputwindow.h>
|
|
|
|
|
|
|
|
#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 Bazaar::Internal;
|
|
|
|
using namespace Bazaar;
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
static const VcsBase::VcsBaseEditorParameters editorParameters[] = {
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::RegularCommandOutput, //type
|
2011-02-28 13:40:06 +01:00
|
|
|
Constants::COMMANDLOG_ID, // id
|
|
|
|
Constants::COMMANDLOG_DISPLAY_NAME, // display name
|
|
|
|
Constants::COMMANDLOG, // context
|
|
|
|
Constants::COMMANDAPP, // mime type
|
|
|
|
Constants::COMMANDEXT}, //extension
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
{ VcsBase::LogOutput,
|
2011-02-28 13:40:06 +01:00
|
|
|
Constants::FILELOG_ID,
|
|
|
|
Constants::FILELOG_DISPLAY_NAME,
|
|
|
|
Constants::FILELOG,
|
|
|
|
Constants::LOGAPP,
|
|
|
|
Constants::LOGEXT},
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
{ VcsBase::AnnotateOutput,
|
2011-02-28 13:40:06 +01:00
|
|
|
Constants::ANNOTATELOG_ID,
|
|
|
|
Constants::ANNOTATELOG_DISPLAY_NAME,
|
|
|
|
Constants::ANNOTATELOG,
|
|
|
|
Constants::ANNOTATEAPP,
|
|
|
|
Constants::ANNOTATEEXT},
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
{ VcsBase::DiffOutput,
|
2011-02-28 13:40:06 +01:00
|
|
|
Constants::DIFFLOG_ID,
|
|
|
|
Constants::DIFFLOG_DISPLAY_NAME,
|
|
|
|
Constants::DIFFLOG,
|
|
|
|
Constants::DIFFAPP,
|
|
|
|
Constants::DIFFEXT}
|
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
static const VcsBase::VcsBaseSubmitEditorParameters submitEditorParameters = {
|
2011-02-28 13:40:06 +01:00
|
|
|
Constants::COMMITMIMETYPE,
|
|
|
|
Constants::COMMIT_ID,
|
|
|
|
Constants::COMMIT_DISPLAY_NAME,
|
|
|
|
Constants::COMMIT_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BazaarPlugin *BazaarPlugin::m_instance = 0;
|
|
|
|
|
2011-11-10 16:06:19 +01:00
|
|
|
BazaarPlugin::BazaarPlugin()
|
2012-01-07 12:31:48 +01:00
|
|
|
: VcsBase::VcsBasePlugin(QLatin1String(Constants::COMMIT_ID)),
|
2011-11-10 16:06:19 +01:00
|
|
|
m_optionsPage(0),
|
|
|
|
m_client(0),
|
|
|
|
m_commandLocator(0),
|
|
|
|
m_changeLog(0),
|
|
|
|
m_addAction(0),
|
|
|
|
m_deleteAction(0),
|
|
|
|
m_menuAction(0)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
|
|
|
m_instance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BazaarPlugin::~BazaarPlugin()
|
|
|
|
{
|
|
|
|
if (m_client) {
|
|
|
|
delete m_client;
|
|
|
|
m_client = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteCommitLog();
|
|
|
|
|
|
|
|
m_instance = 0;
|
|
|
|
}
|
|
|
|
|
2011-03-14 15:37:30 +01:00
|
|
|
bool BazaarPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2011-03-14 15:37:30 +01:00
|
|
|
Q_UNUSED(arguments);
|
|
|
|
Q_UNUSED(errorMessage);
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
typedef VcsBase::VcsEditorFactory<BazaarEditor> BazaarEditorFactory;
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2011-06-10 14:02:46 +00:00
|
|
|
m_client = new BazaarClient(&m_bazaarSettings);
|
2011-06-04 21:07:34 +02:00
|
|
|
initializeVcs(new BazaarControl(m_client));
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
m_actionManager = Core::ICore::actionManager();
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
m_optionsPage = new OptionsPage();
|
|
|
|
addAutoReleasedObject(m_optionsPage);
|
2012-01-24 15:36:40 +01:00
|
|
|
m_bazaarSettings.readSettings(Core::ICore::settings());
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
connect(m_client, SIGNAL(changed(QVariant)), versionControl(), SLOT(changed(QVariant)));
|
|
|
|
|
|
|
|
static const char *describeSlot = SLOT(view(QString,QString));
|
2012-01-07 12:31:48 +01:00
|
|
|
const int editorCount = sizeof(editorParameters) / sizeof(VcsBase::VcsBaseEditorParameters);
|
2011-02-28 13:40:06 +01:00
|
|
|
for (int i = 0; i < editorCount; i++)
|
|
|
|
addAutoReleasedObject(new BazaarEditorFactory(editorParameters + i, m_client, describeSlot));
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
addAutoReleasedObject(new VcsBase::VcsSubmitEditorFactory<CommitEditor>(&submitEditorParameters));
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
addAutoReleasedObject(new CloneWizard);
|
|
|
|
|
|
|
|
const QString prefix = QLatin1String("bzr");
|
|
|
|
m_commandLocator = new Locator::CommandLocator(QLatin1String("Bazaar"), prefix, prefix);
|
|
|
|
addAutoReleasedObject(m_commandLocator);
|
|
|
|
|
|
|
|
createMenu();
|
|
|
|
|
|
|
|
createSubmitEditorActions();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BazaarPlugin *BazaarPlugin::instance()
|
|
|
|
{
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
BazaarClient *BazaarPlugin::client() const
|
|
|
|
{
|
|
|
|
return m_client;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BazaarSettings &BazaarPlugin::settings() const
|
|
|
|
{
|
|
|
|
return m_bazaarSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::setSettings(const BazaarSettings &settings)
|
|
|
|
{
|
|
|
|
if (settings != m_bazaarSettings) {
|
2011-03-18 09:55:33 +01:00
|
|
|
const bool userIdChanged = !m_bazaarSettings.sameUserId(settings);
|
|
|
|
m_bazaarSettings = settings;
|
|
|
|
if (userIdChanged)
|
|
|
|
client()->synchronousSetUserId();
|
2011-04-15 17:43:44 +02:00
|
|
|
static_cast<BazaarControl *>(versionControl())->emitConfigurationChanged();
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::createMenu()
|
|
|
|
{
|
|
|
|
Core::Context context(Core::Constants::C_GLOBAL);
|
|
|
|
|
|
|
|
// Create menu item for Bazaar
|
|
|
|
m_bazaarContainer = m_actionManager->createMenu(Core::Id("Bazaar.BazaarMenu"));
|
|
|
|
QMenu *menu = m_bazaarContainer->menu();
|
|
|
|
menu->setTitle(tr("Bazaar"));
|
|
|
|
|
|
|
|
createFileActions(context);
|
2011-02-28 17:28:41 +01:00
|
|
|
createSeparator(context, Core::Id("Bazaar.FileDirSeperator"));
|
2011-02-28 13:40:06 +01:00
|
|
|
createDirectoryActions(context);
|
2011-02-28 17:28:41 +01:00
|
|
|
createSeparator(context, Core::Id("Bazaar.DirRepoSeperator"));
|
2011-02-28 13:40:06 +01:00
|
|
|
createRepositoryActions(context);
|
2011-02-28 17:28:41 +01:00
|
|
|
createSeparator(context, Core::Id("Bazaar.Repository Management"));
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
// Request the Tools menu and add the Bazaar menu to it
|
|
|
|
Core::ActionContainer *toolsMenu = m_actionManager->actionContainer(Core::Id(Core::Constants::M_TOOLS));
|
|
|
|
toolsMenu->addMenu(m_bazaarContainer);
|
|
|
|
m_menuAction = m_bazaarContainer->menu()->menuAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::createFileActions(const Core::Context &context)
|
|
|
|
{
|
|
|
|
Core::Command *command;
|
|
|
|
|
|
|
|
m_annotateFile = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_annotateFile, Core::Id(Constants::ANNOTATE), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
connect(m_annotateFile, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
m_diffFile = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_diffFile, Core::Id(Constants::DIFF), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2011-03-21 11:35:10 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("ALT+Z,Alt+D")));
|
2011-02-28 13:40:06 +01:00
|
|
|
connect(m_diffFile, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
m_logFile = new Utils::ParameterAction(tr("Log Current File"), tr("Log \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_logFile, Core::Id(Constants::LOG), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2011-03-21 11:35:10 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("ALT+Z,Alt+L")));
|
2011-02-28 13:40:06 +01:00
|
|
|
connect(m_logFile, SIGNAL(triggered()), this, SLOT(logCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
m_statusFile = new Utils::ParameterAction(tr("Status Current File"), tr("Status \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_statusFile, Core::Id(Constants::STATUS), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
2011-03-21 11:35:10 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("ALT+Z,Alt+S")));
|
2011-02-28 13:40:06 +01:00
|
|
|
connect(m_statusFile, SIGNAL(triggered()), this, SLOT(statusCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
2011-02-28 17:28:41 +01:00
|
|
|
createSeparator(context, Core::Id("Bazaar.FileDirSeperator1"));
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_addAction, Core::Id(Constants::ADD), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_deleteAction, Core::Id(Constants::DELETE), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
m_revertFile = new Utils::ParameterAction(tr("Revert Current File..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
command = m_actionManager->registerAction(m_revertFile, Core::Id(Constants::REVERT), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
connect(m_revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::addCurrentFile()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
|
|
|
m_client->synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::annotateCurrentFile()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
|
|
|
m_client->annotate(state.currentFileTopLevel(), state.relativeCurrentFile());
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::diffCurrentFile()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
|
|
|
m_client->diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::logCurrentFile()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
2011-05-03 14:44:38 +02:00
|
|
|
m_client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()),
|
2011-05-12 14:48:10 +02:00
|
|
|
QStringList(), true);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::revertCurrentFile()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
|
|
|
|
|
|
|
QDialog dialog;
|
|
|
|
Ui::RevertDialog revertUi;
|
|
|
|
revertUi.setupUi(&dialog);
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
|
|
|
m_client->revertFile(state.currentFileTopLevel(),
|
|
|
|
state.relativeCurrentFile(),
|
|
|
|
revertUi.revisionLineEdit->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::statusCurrentFile()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasFile(), return);
|
|
|
|
m_client->status(state.currentFileTopLevel(), state.relativeCurrentFile());
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::createDirectoryActions(const Core::Context &context)
|
|
|
|
{
|
|
|
|
QAction *action;
|
|
|
|
Core::Command *command;
|
|
|
|
|
|
|
|
action = new QAction(tr("Diff"), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::DIFFMULTI), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(diffRepository()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
action = new QAction(tr("Log"), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::LOGMULTI), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(logRepository()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
action = new QAction(tr("Revert..."), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::REVERTMULTI), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(revertAll()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
action = new QAction(tr("Status"), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::STATUSMULTI), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(statusMulti()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BazaarPlugin::diffRepository()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
m_client->diff(state.topLevel());
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::logRepository()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 15:05:40 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
2011-05-12 16:37:20 +02:00
|
|
|
QStringList extraOptions;
|
2011-09-14 09:13:44 +00:00
|
|
|
extraOptions += QString("--limit=%1").arg(settings().intValue(BazaarSettings::logCountKey));
|
2011-05-12 16:37:20 +02:00
|
|
|
m_client->log(state.topLevel(), QStringList(), extraOptions);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::revertAll()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
|
|
|
|
QDialog dialog;
|
|
|
|
Ui::RevertDialog revertUi;
|
|
|
|
revertUi.setupUi(&dialog);
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
|
|
|
m_client->revertAll(state.topLevel(), revertUi.revisionLineEdit->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::statusMulti()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
m_client->status(state.topLevel());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::createRepositoryActions(const Core::Context &context)
|
|
|
|
{
|
|
|
|
QAction *action = 0;
|
|
|
|
Core::Command *command = 0;
|
|
|
|
|
|
|
|
action = new QAction(tr("Pull..."), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::PULL), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(pull()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
action = new QAction(tr("Push..."), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::PUSH), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(push()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
action = new QAction(tr("Update..."), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::UPDATE), context);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(update()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
|
|
|
action = new QAction(tr("Commit..."), this);
|
|
|
|
m_repositoryActionList.append(action);
|
|
|
|
command = m_actionManager->registerAction(action, Core::Id(Constants::COMMIT), context);
|
2011-03-21 11:35:10 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("ALT+Z,Alt+C")));
|
2011-02-28 13:40:06 +01:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(commit()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
m_commandLocator->appendCommand(command);
|
|
|
|
|
2011-09-21 11:43:58 +02:00
|
|
|
QAction *createRepositoryAction = new QAction(tr("Create Repository..."), this);
|
2011-02-28 13:40:06 +01:00
|
|
|
command = m_actionManager->registerAction(createRepositoryAction, Core::Id(Constants::CREATE_REPOSITORY), context);
|
|
|
|
connect(createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository()));
|
|
|
|
m_bazaarContainer->addAction(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::pull()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
|
|
|
|
PullOrPushDialog dialog(PullOrPushDialog::PullMode);
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
2011-05-12 14:48:10 +02:00
|
|
|
QStringList extraOptions;
|
|
|
|
if (dialog.isRememberOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--remember");
|
|
|
|
if (dialog.isOverwriteOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--overwrite");
|
|
|
|
if (dialog.isLocalOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--local");
|
|
|
|
if (!dialog.revision().isEmpty())
|
|
|
|
extraOptions << QLatin1String("-r") << dialog.revision();
|
2011-02-28 13:40:06 +01:00
|
|
|
m_client->synchronousPull(state.topLevel(), dialog.branchLocation(), extraOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::push()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
|
|
|
|
PullOrPushDialog dialog(PullOrPushDialog::PushMode);
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
2011-05-12 14:48:10 +02:00
|
|
|
QStringList extraOptions;
|
|
|
|
if (dialog.isRememberOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--remember");
|
|
|
|
if (dialog.isOverwriteOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--overwrite");
|
|
|
|
if (dialog.isUseExistingDirectoryOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--use-existing-dir");
|
|
|
|
if (dialog.isCreatePrefixOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--create-prefix");
|
|
|
|
if (!dialog.revision().isEmpty())
|
|
|
|
extraOptions << QLatin1String("-r") << dialog.revision();
|
2011-02-28 13:40:06 +01:00
|
|
|
m_client->synchronousPush(state.topLevel(), dialog.branchLocation(), extraOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::update()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
|
|
|
|
QDialog dialog;
|
|
|
|
Ui::RevertDialog revertUi;
|
|
|
|
revertUi.setupUi(&dialog);
|
|
|
|
dialog.setWindowTitle(tr("Update"));
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
|
|
|
m_client->update(state.topLevel(), revertUi.revisionLineEdit->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::createSubmitEditorActions()
|
|
|
|
{
|
|
|
|
Core::Context context(Constants::COMMIT_ID);
|
|
|
|
Core::Command *command;
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
m_editorCommit = new QAction(VcsBase::VcsBaseSubmitEditor::submitIcon(), tr("Commit"), this);
|
2011-02-28 13:40:06 +01:00
|
|
|
command = m_actionManager->registerAction(m_editorCommit, Core::Id(Constants::COMMIT), context);
|
|
|
|
command->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
connect(m_editorCommit, SIGNAL(triggered()), this, SLOT(commitFromEditor()));
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
m_editorDiff = new QAction(VcsBase::VcsBaseSubmitEditor::diffIcon(), tr("Diff &Selected Files"), this);
|
2011-02-28 13:40:06 +01:00
|
|
|
command = m_actionManager->registerAction(m_editorDiff, Core::Id(Constants::DIFFEDITOR), context);
|
|
|
|
|
|
|
|
m_editorUndo = new QAction(tr("&Undo"), this);
|
|
|
|
command = m_actionManager->registerAction(m_editorUndo, Core::Id(Core::Constants::UNDO), context);
|
|
|
|
|
|
|
|
m_editorRedo = new QAction(tr("&Redo"), this);
|
|
|
|
command = m_actionManager->registerAction(m_editorRedo, Core::Id(Core::Constants::REDO), context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::commit()
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
if (VcsBase::VcsBaseSubmitEditor::raiseSubmitEditor())
|
2011-02-28 13:40:06 +01:00
|
|
|
return;
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBasePluginState state = currentState();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTC_ASSERT(state.hasTopLevel(), return);
|
|
|
|
|
|
|
|
m_submitRepository = state.topLevel();
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
connect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)),
|
|
|
|
this, SLOT(showCommitWidget(QList<VcsBase::VcsBaseClient::StatusItem>)));
|
2011-08-22 15:33:03 +00:00
|
|
|
// The "--short" option allows to easily parse status output
|
|
|
|
m_client->emitParsedStatus(m_submitRepository, QStringList(QLatin1String("--short")));
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void BazaarPlugin::showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusItem> &status)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBaseOutputWindow *outputWindow = VcsBase::VcsBaseOutputWindow::instance();
|
2011-02-28 13:40:06 +01:00
|
|
|
//Once we receive our data release the connection so it can be reused elsewhere
|
2012-01-07 12:31:48 +01:00
|
|
|
disconnect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)),
|
|
|
|
this, SLOT(showCommitWidget(QList<VcsBase::VcsBaseClient::StatusItem>)));
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
if (status.isEmpty()) {
|
|
|
|
outputWindow->appendError(tr("There are no changes to commit."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteCommitLog();
|
|
|
|
|
|
|
|
// Open commit log
|
2011-11-10 15:48:58 +01:00
|
|
|
QString changeLogPattern = QDir::tempPath();
|
|
|
|
if (!changeLogPattern.endsWith(QLatin1Char('/')))
|
|
|
|
changeLogPattern += QLatin1Char('/');
|
|
|
|
changeLogPattern += QLatin1String("qtcreator-bzr-XXXXXX.msg");
|
|
|
|
m_changeLog = new QTemporaryFile(changeLogPattern, this);
|
2011-02-28 13:40:06 +01:00
|
|
|
if (!m_changeLog->open()) {
|
|
|
|
outputWindow->appendError(tr("Unable to generate a temporary file for the commit editor."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::IEditor *editor = Core::ICore::editorManager()->openEditor(m_changeLog->fileName(),
|
2011-09-07 09:26:29 +02:00
|
|
|
Constants::COMMIT_ID,
|
2011-02-28 13:40:06 +01:00
|
|
|
Core::EditorManager::ModeSwitch);
|
|
|
|
if (!editor) {
|
|
|
|
outputWindow->appendError(tr("Unable to create an editor for the commit."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(editor);
|
|
|
|
|
|
|
|
if (!commitEditor) {
|
|
|
|
outputWindow->appendError(tr("Unable to create a commit editor."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:11:58 +01:00
|
|
|
commitEditor->registerActions(m_editorUndo, m_editorRedo, m_editorCommit, m_editorDiff);
|
|
|
|
connect(commitEditor, SIGNAL(diffSelectedFiles(QStringList)),
|
|
|
|
this, SLOT(diffFromEditorSelected(QStringList)));
|
|
|
|
commitEditor->setCheckScriptWorkingDirectory(m_submitRepository);
|
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
const QString msg = tr("Commit changes for \"%1\".").
|
|
|
|
arg(QDir::toNativeSeparators(m_submitRepository));
|
|
|
|
commitEditor->setDisplayName(msg);
|
|
|
|
|
|
|
|
const BranchInfo branch = m_client->synchronousBranchQuery(m_submitRepository);
|
2011-12-05 15:37:19 +01:00
|
|
|
commitEditor->setFields(m_submitRepository, branch,
|
|
|
|
m_bazaarSettings.stringValue(BazaarSettings::userNameKey),
|
2011-09-14 09:13:44 +00:00
|
|
|
m_bazaarSettings.stringValue(BazaarSettings::userEmailKey), status);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::diffFromEditorSelected(const QStringList &files)
|
|
|
|
{
|
|
|
|
m_client->diff(m_submitRepository, files);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::commitFromEditor()
|
|
|
|
{
|
|
|
|
if (!m_changeLog)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//use the same functionality than if the user closes the file without completing the commit
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::ICore::editorManager()->closeEditors(Core::ICore::editorManager()->editorsForFileName(m_changeLog->fileName()));
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submitEditor)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
|
|
|
if (!m_changeLog)
|
|
|
|
return true;
|
|
|
|
Core::IFile *editorFile = submitEditor->file();
|
|
|
|
const CommitEditor *commitEditor = qobject_cast<const CommitEditor *>(submitEditor);
|
|
|
|
if (!editorFile || !commitEditor)
|
|
|
|
return true;
|
|
|
|
|
2011-09-14 09:13:44 +00:00
|
|
|
bool dummyPrompt = m_bazaarSettings.boolValue(BazaarSettings::promptOnSubmitKey);
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBase::VcsBaseSubmitEditor::PromptSubmitResult response =
|
2011-02-28 13:40:06 +01:00
|
|
|
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
|
|
|
tr("Message check failed. Do you want to proceed?"),
|
2011-09-14 09:13:44 +00:00
|
|
|
&dummyPrompt, dummyPrompt);
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
switch (response) {
|
2012-01-07 12:31:48 +01:00
|
|
|
case VcsBase::VcsBaseSubmitEditor::SubmitCanceled:
|
2011-02-28 13:40:06 +01:00
|
|
|
return false;
|
2012-01-07 12:31:48 +01:00
|
|
|
case VcsBase::VcsBaseSubmitEditor::SubmitDiscarded:
|
2011-02-28 13:40:06 +01:00
|
|
|
deleteCommitLog();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-18 09:55:36 +01:00
|
|
|
QStringList files = commitEditor->checkedFiles();
|
2011-02-28 13:40:06 +01:00
|
|
|
if (!files.empty()) {
|
|
|
|
//save the commit message
|
2012-01-19 23:23:43 +01:00
|
|
|
if (!Core::FileManager::saveFile(editorFile))
|
2011-03-30 12:43:17 +02:00
|
|
|
return false;
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2011-03-18 09:55:36 +01:00
|
|
|
//rewrite entries of the form 'file => newfile' to 'newfile' because
|
|
|
|
//this would mess the commit command
|
|
|
|
for (QStringList::iterator iFile = files.begin(); iFile != files.end(); ++iFile) {
|
|
|
|
const QStringList parts = iFile->split(" => ", QString::SkipEmptyParts);
|
|
|
|
if (!parts.isEmpty())
|
|
|
|
*iFile = parts.last();
|
|
|
|
}
|
|
|
|
|
2011-09-21 11:43:58 +02:00
|
|
|
const BazaarCommitWidget *commitWidget = commitEditor->commitWidget();
|
2011-05-12 14:48:10 +02:00
|
|
|
QStringList extraOptions;
|
|
|
|
// Author
|
|
|
|
if (!commitWidget->committer().isEmpty())
|
|
|
|
extraOptions.append(QLatin1String("--author=") + commitWidget->committer());
|
|
|
|
// Fixed bugs
|
|
|
|
foreach (const QString &fix, commitWidget->fixedBugs()) {
|
|
|
|
if (!fix.isEmpty())
|
|
|
|
extraOptions << QLatin1String("--fixes") << fix;
|
|
|
|
}
|
|
|
|
// Whether local commit or not
|
|
|
|
if (commitWidget->isLocalOptionEnabled())
|
|
|
|
extraOptions += QLatin1String("--local");
|
2011-02-28 13:40:06 +01:00
|
|
|
m_client->commit(m_submitRepository, files, editorFile->fileName(), extraOptions);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::deleteCommitLog()
|
|
|
|
{
|
|
|
|
if (m_changeLog) {
|
|
|
|
delete m_changeLog;
|
|
|
|
m_changeLog = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarPlugin::createSeparator(const Core::Context &context, const Core::Id &id)
|
|
|
|
{
|
|
|
|
QAction *action = new QAction(this);
|
|
|
|
action->setSeparator(true);
|
|
|
|
m_bazaarContainer->addAction(m_actionManager->registerAction(action, id, context));
|
|
|
|
}
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void BazaarPlugin::updateActions(VcsBase::VcsBasePlugin::ActionState as)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
|
|
|
if (!enableMenuAction(as, m_menuAction)) {
|
|
|
|
m_commandLocator->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QString filename = currentState().currentFileName();
|
|
|
|
const bool repoEnabled = currentState().hasTopLevel();
|
|
|
|
m_commandLocator->setEnabled(repoEnabled);
|
|
|
|
|
|
|
|
m_annotateFile->setParameter(filename);
|
|
|
|
m_diffFile->setParameter(filename);
|
|
|
|
m_logFile->setParameter(filename);
|
|
|
|
m_addAction->setParameter(filename);
|
|
|
|
m_deleteAction->setParameter(filename);
|
|
|
|
m_revertFile->setParameter(filename);
|
|
|
|
m_statusFile->setParameter(filename);
|
|
|
|
|
|
|
|
foreach (QAction *repoAction, m_repositoryActionList)
|
|
|
|
repoAction->setEnabled(repoEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(BazaarPlugin)
|