Bazaar: Code style

Change-Id: I0c2281703d4708bf07702d9d2fc148842489bb04
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2014-07-19 16:04:46 +02:00
parent 4b82817391
commit 2bf4d7c3da
2 changed files with 105 additions and 102 deletions

View File

@@ -26,6 +26,7 @@
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
** **
****************************************************************************/ ****************************************************************************/
#include "bazaarplugin.h" #include "bazaarplugin.h"
#include "constants.h" #include "constants.h"
#include "bazaarclient.h" #include "bazaarclient.h"
@@ -66,35 +67,43 @@
#include <QDir> #include <QDir>
#include <QDialog> #include <QDialog>
using namespace Bazaar::Internal; #ifdef WITH_TESTS
using namespace Bazaar; #include <QTest>
#endif
static const VcsBase::VcsBaseEditorParameters editorParameters[] = { using namespace Core;
{ VcsBase::LogOutput, // type using namespace Utils;
using namespace VcsBase;
namespace Bazaar {
namespace Internal {
static const VcsBaseEditorParameters editorParameters[] = {
{ LogOutput, // type
Constants::FILELOG_ID, // id Constants::FILELOG_ID, // id
Constants::FILELOG_DISPLAY_NAME, // display name Constants::FILELOG_DISPLAY_NAME, // display name
Constants::FILELOG, // context Constants::FILELOG, // context
Constants::LOGAPP}, // mime type Constants::LOGAPP}, // mime type
{ VcsBase::AnnotateOutput, { AnnotateOutput,
Constants::ANNOTATELOG_ID, Constants::ANNOTATELOG_ID,
Constants::ANNOTATELOG_DISPLAY_NAME, Constants::ANNOTATELOG_DISPLAY_NAME,
Constants::ANNOTATELOG, Constants::ANNOTATELOG,
Constants::ANNOTATEAPP}, Constants::ANNOTATEAPP},
{ VcsBase::DiffOutput, { DiffOutput,
Constants::DIFFLOG_ID, Constants::DIFFLOG_ID,
Constants::DIFFLOG_DISPLAY_NAME, Constants::DIFFLOG_DISPLAY_NAME,
Constants::DIFFLOG, Constants::DIFFLOG,
Constants::DIFFAPP} Constants::DIFFAPP}
}; };
static const VcsBase::VcsBaseSubmitEditorParameters submitEditorParameters = { static const VcsBaseSubmitEditorParameters submitEditorParameters = {
Constants::COMMITMIMETYPE, Constants::COMMITMIMETYPE,
Constants::COMMIT_ID, Constants::COMMIT_ID,
Constants::COMMIT_DISPLAY_NAME, Constants::COMMIT_DISPLAY_NAME,
Constants::COMMIT_ID, Constants::COMMIT_ID,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles VcsBaseSubmitEditorParameters::DiffFiles
}; };
@@ -114,11 +123,8 @@ BazaarPlugin::BazaarPlugin()
BazaarPlugin::~BazaarPlugin() BazaarPlugin::~BazaarPlugin()
{ {
if (m_client) { delete m_client;
delete m_client; m_client = 0;
m_client = 0;
}
m_instance = 0; m_instance = 0;
} }
@@ -127,28 +133,28 @@ bool BazaarPlugin::initialize(const QStringList &arguments, QString *errorMessag
Q_UNUSED(arguments); Q_UNUSED(arguments);
Q_UNUSED(errorMessage); Q_UNUSED(errorMessage);
typedef VcsBase::VcsEditorFactory<BazaarEditor> BazaarEditorFactory; typedef VcsEditorFactory<BazaarEditor> BazaarEditorFactory;
m_client = new BazaarClient(&m_bazaarSettings); m_client = new BazaarClient(&m_bazaarSettings);
initializeVcs(new BazaarControl(m_client)); initializeVcs(new BazaarControl(m_client));
m_optionsPage = new OptionsPage(); m_optionsPage = new OptionsPage();
addAutoReleasedObject(m_optionsPage); addAutoReleasedObject(m_optionsPage);
m_bazaarSettings.readSettings(Core::ICore::settings()); m_bazaarSettings.readSettings(ICore::settings());
connect(m_client, SIGNAL(changed(QVariant)), versionControl(), SLOT(changed(QVariant))); connect(m_client, SIGNAL(changed(QVariant)), versionControl(), SLOT(changed(QVariant)));
static const char *describeSlot = SLOT(view(QString,QString)); static const char *describeSlot = SLOT(view(QString,QString));
const int editorCount = sizeof(editorParameters) / sizeof(VcsBase::VcsBaseEditorParameters); const int editorCount = sizeof(editorParameters) / sizeof(VcsBaseEditorParameters);
for (int i = 0; i < editorCount; i++) for (int i = 0; i < editorCount; i++)
addAutoReleasedObject(new BazaarEditorFactory(editorParameters + i, m_client, describeSlot)); addAutoReleasedObject(new BazaarEditorFactory(editorParameters + i, m_client, describeSlot));
addAutoReleasedObject(new VcsBase::VcsSubmitEditorFactory<CommitEditor>(&submitEditorParameters)); addAutoReleasedObject(new VcsSubmitEditorFactory<CommitEditor>(&submitEditorParameters));
addAutoReleasedObject(new CloneWizardFactory); addAutoReleasedObject(new CloneWizardFactory);
const QString prefix = QLatin1String("bzr"); const QString prefix = QLatin1String("bzr");
m_commandLocator = new Core::CommandLocator("Bazaar", prefix, prefix); m_commandLocator = new CommandLocator("Bazaar", prefix, prefix);
addAutoReleasedObject(m_commandLocator); addAutoReleasedObject(m_commandLocator);
createMenu(); createMenu();
@@ -186,10 +192,10 @@ void BazaarPlugin::setSettings(const BazaarSettings &settings)
void BazaarPlugin::createMenu() void BazaarPlugin::createMenu()
{ {
Core::Context context(Core::Constants::C_GLOBAL); Context context(Core::Constants::C_GLOBAL);
// Create menu item for Bazaar // Create menu item for Bazaar
m_bazaarContainer = Core::ActionManager::createMenu(Core::Id("Bazaar.BazaarMenu")); m_bazaarContainer = ActionManager::createMenu("Bazaar.BazaarMenu");
QMenu *menu = m_bazaarContainer->menu(); QMenu *menu = m_bazaarContainer->menu();
menu->setTitle(tr("Bazaar")); menu->setTitle(tr("Bazaar"));
@@ -201,64 +207,64 @@ void BazaarPlugin::createMenu()
m_bazaarContainer->addSeparator(context); m_bazaarContainer->addSeparator(context);
// Request the Tools menu and add the Bazaar menu to it // Request the Tools menu and add the Bazaar menu to it
Core::ActionContainer *toolsMenu = Core::ActionManager::actionContainer(Core::Id(Core::Constants::M_TOOLS)); ActionContainer *toolsMenu = ActionManager::actionContainer(Core::Constants::M_TOOLS);
toolsMenu->addMenu(m_bazaarContainer); toolsMenu->addMenu(m_bazaarContainer);
m_menuAction = m_bazaarContainer->menu()->menuAction(); m_menuAction = m_bazaarContainer->menu()->menuAction();
} }
void BazaarPlugin::createFileActions(const Core::Context &context) void BazaarPlugin::createFileActions(const Context &context)
{ {
Core::Command *command; Core::Command *command;
m_annotateFile = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this); m_annotateFile = new ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_annotateFile, Core::Id(Constants::ANNOTATE), context); command = ActionManager::registerAction(m_annotateFile, Constants::ANNOTATE, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
connect(m_annotateFile, SIGNAL(triggered()), this, SLOT(annotateCurrentFile())); connect(m_annotateFile, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
m_diffFile = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this); m_diffFile = new ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_diffFile, Core::Id(Constants::DIFF), context); command = ActionManager::registerAction(m_diffFile, Constants::DIFF, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Z,Meta+D") : tr("ALT+Z,Alt+D"))); command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Z,Meta+D") : tr("ALT+Z,Alt+D")));
connect(m_diffFile, SIGNAL(triggered()), this, SLOT(diffCurrentFile())); connect(m_diffFile, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
m_logFile = new Utils::ParameterAction(tr("Log Current File"), tr("Log \"%1\""), Utils::ParameterAction::EnabledWithParameter, this); m_logFile = new ParameterAction(tr("Log Current File"), tr("Log \"%1\""), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_logFile, Core::Id(Constants::LOG), context); command = ActionManager::registerAction(m_logFile, Constants::LOG, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Z,Meta+L") : tr("ALT+Z,Alt+L"))); command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Z,Meta+L") : tr("ALT+Z,Alt+L")));
connect(m_logFile, SIGNAL(triggered()), this, SLOT(logCurrentFile())); connect(m_logFile, SIGNAL(triggered()), this, SLOT(logCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
m_statusFile = new Utils::ParameterAction(tr("Status Current File"), tr("Status \"%1\""), Utils::ParameterAction::EnabledWithParameter, this); m_statusFile = new ParameterAction(tr("Status Current File"), tr("Status \"%1\""), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_statusFile, Core::Id(Constants::STATUS), context); command = ActionManager::registerAction(m_statusFile, Constants::STATUS, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Z,Meta+S") : tr("ALT+Z,Alt+S"))); command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Z,Meta+S") : tr("ALT+Z,Alt+S")));
connect(m_statusFile, SIGNAL(triggered()), this, SLOT(statusCurrentFile())); connect(m_statusFile, SIGNAL(triggered()), this, SLOT(statusCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
m_bazaarContainer->addSeparator(context); m_bazaarContainer->addSeparator(context);
m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this); m_addAction = new ParameterAction(tr("Add"), tr("Add \"%1\""), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_addAction, Core::Id(Constants::ADD), context); command = ActionManager::registerAction(m_addAction, Constants::ADD, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile())); connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this); m_deleteAction = new ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_deleteAction, Core::Id(Constants::DELETE), context); command = ActionManager::registerAction(m_deleteAction, Constants::DELETE, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile())); connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
m_revertFile = new Utils::ParameterAction(tr("Revert Current File..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this); m_revertFile = new ParameterAction(tr("Revert Current File..."), tr("Revert \"%1\"..."), ParameterAction::EnabledWithParameter, this);
command = Core::ActionManager::registerAction(m_revertFile, Core::Id(Constants::REVERT), context); command = ActionManager::registerAction(m_revertFile, Constants::REVERT, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
connect(m_revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile())); connect(m_revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
@@ -267,28 +273,28 @@ void BazaarPlugin::createFileActions(const Core::Context &context)
void BazaarPlugin::addCurrentFile() void BazaarPlugin::addCurrentFile()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile()); m_client->synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
} }
void BazaarPlugin::annotateCurrentFile() void BazaarPlugin::annotateCurrentFile()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->annotate(state.currentFileTopLevel(), state.relativeCurrentFile()); m_client->annotate(state.currentFileTopLevel(), state.relativeCurrentFile());
} }
void BazaarPlugin::diffCurrentFile() void BazaarPlugin::diffCurrentFile()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile())); m_client->diff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
} }
void BazaarPlugin::logCurrentFile() void BazaarPlugin::logCurrentFile()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), m_client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()),
QStringList(), true); QStringList(), true);
@@ -296,10 +302,10 @@ void BazaarPlugin::logCurrentFile()
void BazaarPlugin::revertCurrentFile() void BazaarPlugin::revertCurrentFile()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
QDialog dialog(Core::ICore::dialogParent()); QDialog dialog(ICore::dialogParent());
Ui::RevertDialog revertUi; Ui::RevertDialog revertUi;
revertUi.setupUi(&dialog); revertUi.setupUi(&dialog);
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
@@ -311,40 +317,40 @@ void BazaarPlugin::revertCurrentFile()
void BazaarPlugin::statusCurrentFile() void BazaarPlugin::statusCurrentFile()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
m_client->status(state.currentFileTopLevel(), state.relativeCurrentFile()); m_client->status(state.currentFileTopLevel(), state.relativeCurrentFile());
} }
void BazaarPlugin::createDirectoryActions(const Core::Context &context) void BazaarPlugin::createDirectoryActions(const Context &context)
{ {
QAction *action; QAction *action;
Core::Command *command; Core::Command *command;
action = new QAction(tr("Diff"), this); action = new QAction(tr("Diff"), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::DIFFMULTI), context); command = ActionManager::registerAction(action, Constants::DIFFMULTI, context);
connect(action, SIGNAL(triggered()), this, SLOT(diffRepository())); connect(action, SIGNAL(triggered()), this, SLOT(diffRepository()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Log"), this); action = new QAction(tr("Log"), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::LOGMULTI), context); command = ActionManager::registerAction(action, Constants::LOGMULTI, context);
connect(action, SIGNAL(triggered()), this, SLOT(logRepository())); connect(action, SIGNAL(triggered()), this, SLOT(logRepository()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Revert..."), this); action = new QAction(tr("Revert..."), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::REVERTMULTI), context); command = ActionManager::registerAction(action, Constants::REVERTMULTI, context);
connect(action, SIGNAL(triggered()), this, SLOT(revertAll())); connect(action, SIGNAL(triggered()), this, SLOT(revertAll()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Status"), this); action = new QAction(tr("Status"), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::STATUSMULTI), context); command = ActionManager::registerAction(action, Constants::STATUSMULTI, context);
connect(action, SIGNAL(triggered()), this, SLOT(statusMulti())); connect(action, SIGNAL(triggered()), this, SLOT(statusMulti()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
@@ -353,14 +359,14 @@ void BazaarPlugin::createDirectoryActions(const Core::Context &context)
void BazaarPlugin::diffRepository() void BazaarPlugin::diffRepository()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_client->diff(state.topLevel()); m_client->diff(state.topLevel());
} }
void BazaarPlugin::logRepository() void BazaarPlugin::logRepository()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
QStringList extraOptions; QStringList extraOptions;
extraOptions += QLatin1String("--limit=") + QString::number(settings().intValue(BazaarSettings::logCountKey)); extraOptions += QLatin1String("--limit=") + QString::number(settings().intValue(BazaarSettings::logCountKey));
@@ -369,10 +375,10 @@ void BazaarPlugin::logRepository()
void BazaarPlugin::revertAll() void BazaarPlugin::revertAll()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
QDialog dialog(Core::ICore::dialogParent()); QDialog dialog(ICore::dialogParent());
Ui::RevertDialog revertUi; Ui::RevertDialog revertUi;
revertUi.setupUi(&dialog); revertUi.setupUi(&dialog);
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
@@ -382,64 +388,64 @@ void BazaarPlugin::revertAll()
void BazaarPlugin::statusMulti() void BazaarPlugin::statusMulti()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_client->status(state.topLevel()); m_client->status(state.topLevel());
} }
void BazaarPlugin::createRepositoryActions(const Core::Context &context) void BazaarPlugin::createRepositoryActions(const Context &context)
{ {
QAction *action = 0; QAction *action = 0;
Core::Command *command = 0; Core::Command *command = 0;
action = new QAction(tr("Pull..."), this); action = new QAction(tr("Pull..."), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::PULL), context); command = ActionManager::registerAction(action, Constants::PULL, context);
connect(action, SIGNAL(triggered()), this, SLOT(pull())); connect(action, SIGNAL(triggered()), this, SLOT(pull()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Push..."), this); action = new QAction(tr("Push..."), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::PUSH), context); command = ActionManager::registerAction(action, Constants::PUSH, context);
connect(action, SIGNAL(triggered()), this, SLOT(push())); connect(action, SIGNAL(triggered()), this, SLOT(push()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Update..."), this); action = new QAction(tr("Update..."), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::UPDATE), context); command = ActionManager::registerAction(action, Constants::UPDATE, context);
connect(action, SIGNAL(triggered()), this, SLOT(update())); connect(action, SIGNAL(triggered()), this, SLOT(update()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Commit..."), this); action = new QAction(tr("Commit..."), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::COMMIT), context); command = ActionManager::registerAction(action, Constants::COMMIT, context);
command->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Z,Meta+C") : tr("ALT+Z,Alt+C"))); command->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Z,Meta+C") : tr("ALT+Z,Alt+C")));
connect(action, SIGNAL(triggered()), this, SLOT(commit())); connect(action, SIGNAL(triggered()), this, SLOT(commit()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
action = new QAction(tr("Uncommit..."), this); action = new QAction(tr("Uncommit..."), this);
m_repositoryActionList.append(action); m_repositoryActionList.append(action);
command = Core::ActionManager::registerAction(action, Core::Id(Constants::UNCOMMIT), context); command = ActionManager::registerAction(action, Constants::UNCOMMIT, context);
connect(action, SIGNAL(triggered()), this, SLOT(uncommit())); connect(action, SIGNAL(triggered()), this, SLOT(uncommit()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
m_commandLocator->appendCommand(command); m_commandLocator->appendCommand(command);
QAction *createRepositoryAction = new QAction(tr("Create Repository..."), this); QAction *createRepositoryAction = new QAction(tr("Create Repository..."), this);
command = Core::ActionManager::registerAction(createRepositoryAction, Core::Id(Constants::CREATE_REPOSITORY), context); command = ActionManager::registerAction(createRepositoryAction, Constants::CREATE_REPOSITORY, context);
connect(createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository())); connect(createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository()));
m_bazaarContainer->addAction(command); m_bazaarContainer->addAction(command);
} }
void BazaarPlugin::pull() void BazaarPlugin::pull()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
PullOrPushDialog dialog(PullOrPushDialog::PullMode, Core::ICore::dialogParent()); PullOrPushDialog dialog(PullOrPushDialog::PullMode, ICore::dialogParent());
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return;
QStringList extraOptions; QStringList extraOptions;
@@ -456,10 +462,10 @@ void BazaarPlugin::pull()
void BazaarPlugin::push() void BazaarPlugin::push()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
PullOrPushDialog dialog(PullOrPushDialog::PushMode, Core::ICore::dialogParent()); PullOrPushDialog dialog(PullOrPushDialog::PushMode, ICore::dialogParent());
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return;
QStringList extraOptions; QStringList extraOptions;
@@ -478,10 +484,10 @@ void BazaarPlugin::push()
void BazaarPlugin::update() void BazaarPlugin::update()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
QDialog dialog(Core::ICore::dialogParent()); QDialog dialog(ICore::dialogParent());
Ui::RevertDialog revertUi; Ui::RevertDialog revertUi;
revertUi.setupUi(&dialog); revertUi.setupUi(&dialog);
dialog.setWindowTitle(tr("Update")); dialog.setWindowTitle(tr("Update"));
@@ -492,22 +498,22 @@ void BazaarPlugin::update()
void BazaarPlugin::createSubmitEditorActions() void BazaarPlugin::createSubmitEditorActions()
{ {
Core::Context context(Constants::COMMIT_ID); Context context(Constants::COMMIT_ID);
Core::Command *command; Core::Command *command;
m_editorCommit = new QAction(VcsBase::VcsBaseSubmitEditor::submitIcon(), tr("Commit"), this); m_editorCommit = new QAction(VcsBaseSubmitEditor::submitIcon(), tr("Commit"), this);
command = Core::ActionManager::registerAction(m_editorCommit, Core::Id(Constants::COMMIT), context); command = ActionManager::registerAction(m_editorCommit, Constants::COMMIT, context);
command->setAttribute(Core::Command::CA_UpdateText); command->setAttribute(Core::Command::CA_UpdateText);
connect(m_editorCommit, SIGNAL(triggered()), this, SLOT(commitFromEditor())); connect(m_editorCommit, SIGNAL(triggered()), this, SLOT(commitFromEditor()));
m_editorDiff = new QAction(VcsBase::VcsBaseSubmitEditor::diffIcon(), tr("Diff &Selected Files"), this); m_editorDiff = new QAction(VcsBaseSubmitEditor::diffIcon(), tr("Diff &Selected Files"), this);
command = Core::ActionManager::registerAction(m_editorDiff, Core::Id(Constants::DIFFEDITOR), context); command = ActionManager::registerAction(m_editorDiff, Constants::DIFFEDITOR, context);
m_editorUndo = new QAction(tr("&Undo"), this); m_editorUndo = new QAction(tr("&Undo"), this);
command = Core::ActionManager::registerAction(m_editorUndo, Core::Id(Core::Constants::UNDO), context); command = ActionManager::registerAction(m_editorUndo, Core::Constants::UNDO, context);
m_editorRedo = new QAction(tr("&Redo"), this); m_editorRedo = new QAction(tr("&Redo"), this);
command = Core::ActionManager::registerAction(m_editorRedo, Core::Id(Core::Constants::REDO), context); command = ActionManager::registerAction(m_editorRedo, Core::Constants::REDO, context);
} }
void BazaarPlugin::commit() void BazaarPlugin::commit()
@@ -515,23 +521,23 @@ void BazaarPlugin::commit()
if (raiseSubmitEditor()) if (raiseSubmitEditor())
return; return;
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
m_submitRepository = state.topLevel(); m_submitRepository = state.topLevel();
connect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)), connect(m_client, SIGNAL(parsedStatus(QList<VcsBaseClient::StatusItem>)),
this, SLOT(showCommitWidget(QList<VcsBase::VcsBaseClient::StatusItem>))); this, SLOT(showCommitWidget(QList<VcsBaseClient::StatusItem>)));
// The "--short" option allows to easily parse status output // The "--short" option allows to easily parse status output
m_client->emitParsedStatus(m_submitRepository, QStringList(QLatin1String("--short"))); m_client->emitParsedStatus(m_submitRepository, QStringList(QLatin1String("--short")));
} }
void BazaarPlugin::showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusItem> &status) void BazaarPlugin::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status)
{ {
VcsBase::VcsBaseOutputWindow *outputWindow = VcsBase::VcsBaseOutputWindow::instance(); VcsBaseOutputWindow *outputWindow = VcsBaseOutputWindow::instance();
//Once we receive our data release the connection so it can be reused elsewhere //Once we receive our data release the connection so it can be reused elsewhere
disconnect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)), disconnect(m_client, SIGNAL(parsedStatus(QList<VcsBaseClient::StatusItem>)),
this, SLOT(showCommitWidget(QList<VcsBase::VcsBaseClient::StatusItem>))); this, SLOT(showCommitWidget(QList<VcsBaseClient::StatusItem>)));
if (status.isEmpty()) { if (status.isEmpty()) {
outputWindow->appendError(tr("There are no changes to commit.")); outputWindow->appendError(tr("There are no changes to commit."));
@@ -539,15 +545,15 @@ void BazaarPlugin::showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusIt
} }
// Start new temp file // Start new temp file
Utils::TempFileSaver saver; TempFileSaver saver;
// Keep the file alive, else it removes self and forgets its name // Keep the file alive, else it removes self and forgets its name
saver.setAutoRemove(false); saver.setAutoRemove(false);
if (!saver.finalize()) { if (!saver.finalize()) {
VcsBase::VcsBaseOutputWindow::instance()->appendError(saver.errorString()); VcsBaseOutputWindow::instance()->appendError(saver.errorString());
return; return;
} }
Core::IEditor *editor = Core::EditorManager::openEditor(saver.fileName(), Constants::COMMIT_ID); IEditor *editor = EditorManager::openEditor(saver.fileName(), Constants::COMMIT_ID);
if (!editor) { if (!editor) {
outputWindow->appendError(tr("Unable to create an editor for the commit.")); outputWindow->appendError(tr("Unable to create an editor for the commit."));
return; return;
@@ -582,7 +588,6 @@ void BazaarPlugin::diffFromEditorSelected(const QStringList &files)
} }
#ifdef WITH_TESTS #ifdef WITH_TESTS
#include <QTest>
void BazaarPlugin::testDiffFileResolving_data() void BazaarPlugin::testDiffFileResolving_data()
{ {
@@ -644,15 +649,15 @@ void BazaarPlugin::commitFromEditor()
{ {
// Close the submit editor // Close the submit editor
m_submitActionTriggered = true; m_submitActionTriggered = true;
Core::EditorManager::closeEditor(); EditorManager::closeEditor();
} }
void BazaarPlugin::uncommit() void BazaarPlugin::uncommit()
{ {
const VcsBase::VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
UnCommitDialog dialog(Core::ICore::dialogParent()); UnCommitDialog dialog(ICore::dialogParent());
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
m_client->synchronousUncommit(state.topLevel(), dialog.revision(), dialog.extraOptions()); m_client->synchronousUncommit(state.topLevel(), dialog.revision(), dialog.extraOptions());
} }
@@ -661,20 +666,20 @@ bool BazaarPlugin::submitEditorAboutToClose()
{ {
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor()); CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor());
QTC_ASSERT(commitEditor, return true); QTC_ASSERT(commitEditor, return true);
Core::IDocument *editorDocument = commitEditor->document(); IDocument *editorDocument = commitEditor->document();
QTC_ASSERT(editorDocument, return true); QTC_ASSERT(editorDocument, return true);
bool dummyPrompt = false; bool dummyPrompt = false;
const VcsBase::VcsBaseSubmitEditor::PromptSubmitResult response = const VcsBaseSubmitEditor::PromptSubmitResult response =
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"), commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
tr("Message check failed. Do you want to proceed?"), tr("Message check failed. Do you want to proceed?"),
&dummyPrompt, !m_submitActionTriggered); &dummyPrompt, !m_submitActionTriggered);
m_submitActionTriggered = false; m_submitActionTriggered = false;
switch (response) { switch (response) {
case VcsBase::VcsBaseSubmitEditor::SubmitCanceled: case VcsBaseSubmitEditor::SubmitCanceled:
return false; return false;
case VcsBase::VcsBaseSubmitEditor::SubmitDiscarded: case VcsBaseSubmitEditor::SubmitDiscarded:
return true; return true;
default: default:
break; break;
@@ -734,4 +739,7 @@ void BazaarPlugin::updateActions(VcsBase::VcsBasePlugin::ActionState as)
repoAction->setEnabled(repoEnabled); repoAction->setEnabled(repoEnabled);
} }
Q_EXPORT_PLUGIN(BazaarPlugin) } // namespace Internal
} // namespace Bazaar
Q_EXPORT_PLUGIN(Bazaar::Internal::BazaarPlugin)

View File

@@ -26,6 +26,7 @@
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
** **
****************************************************************************/ ****************************************************************************/
#ifndef BAZAARPLUGIN_H #ifndef BAZAARPLUGIN_H
#define BAZAARPLUGIN_H #define BAZAARPLUGIN_H
@@ -40,19 +41,13 @@ class QAction;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { namespace Core {
class ActionManager;
class ActionContainer; class ActionContainer;
class CommandLocator; class CommandLocator;
class Id; class Id;
class IVersionControl;
class IEditorFactory;
class IEditor;
} // namespace Core } // namespace Core
namespace Utils { class ParameterAction; } namespace Utils { class ParameterAction; }
namespace VcsBase { class VcsBaseSubmitEditor; }
namespace Bazaar { namespace Bazaar {
namespace Internal { namespace Internal {