Commit 95da4190 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

VCS[vcs,p4,svn,hg]: Use VCManager for delete operations.

...and its dialog prompt consistently. Rename method and
introduce overload taking IVersionControl. Add convenience slot to
VCSBasePlugin.
parent 66131474
......@@ -33,6 +33,7 @@
#include "filemanager.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <QtCore/QString>
#include <QtCore/QList>
......@@ -133,10 +134,17 @@ IVersionControl* VCSManager::findVersionControlForDirectory(const QString &direc
return 0;
}
bool VCSManager::showDeleteDialog(const QString &fileName)
bool VCSManager::promptToDelete(const QString &fileName)
{
IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath());
if (!vc || !vc->supportsOperation(IVersionControl::DeleteOperation))
if (IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath()))
return promptToDelete(vc, fileName);
return true;
}
bool VCSManager::promptToDelete(IVersionControl *vc, const QString &fileName)
{
QTC_ASSERT(vc, return true)
if (!vc->supportsOperation(IVersionControl::DeleteOperation))
return true;
const QString title = QCoreApplication::translate("VCSManager", "Version Control");
const QString msg = QCoreApplication::translate("VCSManager",
......
......@@ -72,7 +72,8 @@ public:
// Shows a confirmation dialog, whether the file should also be deleted
// from revision control Calls sccDelete on the file. Returns false
// if a failure occurs
bool showDeleteDialog(const QString &fileName);
bool promptToDelete(const QString &fileName);
bool promptToDelete(IVersionControl *versionControl, const QString &fileName);
friend CORE_EXPORT QDebug operator<<(QDebug in, const VCSManager &);
......
......@@ -261,14 +261,14 @@ bool CVSPlugin::initialize(const QStringList & /*arguments */, QString *errorMes
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
cvsMenu->addAction(command);
m_deleteAction = new Utils::ParameterAction(tr("Delete"), tr("Delete \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_deleteAction, CMD_ID_DELETE_FILE,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteCurrentFile()));
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
cvsMenu->addAction(command);
m_revertAction = new Utils::ParameterAction(tr("Revert"), tr("Revert \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
m_revertAction = new Utils::ParameterAction(tr("Revert..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_revertAction, CMD_ID_REVERT,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
......@@ -524,14 +524,6 @@ void CVSPlugin::addCurrentFile()
vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void CVSPlugin::deleteCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
if (!Core::ICore::instance()->vcsManager()->showDeleteDialog(state.currentFile()))
QMessageBox::warning(0, QLatin1String("CVS remove"), tr("The file '%1' could not be deleted.").arg(state.currentFile()), QMessageBox::Ok);
}
void CVSPlugin::revertCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
......
......@@ -99,7 +99,6 @@ public:
private slots:
void addCurrentFile();
void deleteCurrentFile();
void revertCurrentFile();
void diffProject();
void diffCurrentFile();
......
......@@ -85,6 +85,8 @@ const char * const COMMITMIMETYPE = "application/vnd.nokia.text.scs_mercurial_co
//menu items
//File menu actions
const char * const ADD = "Mercurial.AddSingleFile";
const char * const DELETE = "Mercurial.DeleteSingleFile";
const char * const ANNOTATE = "Mercurial.Annotate";
const char * const DIFF = "Mercurial.DiffSingleFile";
const char * const LOG = "Mercurial.LogSingleFile";
......
......@@ -38,8 +38,7 @@
using namespace Mercurial::Internal;
MercurialControl::MercurialControl(MercurialClient *client)
: mercurialClient(client),
mercurialEnabled(true)
: mercurialClient(client)
{
}
......
......@@ -66,7 +66,6 @@ public slots:
private:
MercurialClient *mercurialClient;
bool mercurialEnabled;
};
} //namespace Internal
......
......@@ -41,6 +41,7 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/basemode.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/modemanager.h>
......@@ -124,6 +125,8 @@ MercurialPlugin::MercurialPlugin() :
optionsPage(0),
m_client(0),
changeLog(0),
m_addAction(0),
m_deleteAction(0),
m_menuAction(0)
{
m_instance = this;
......@@ -225,38 +228,59 @@ void MercurialPlugin::createFileActions(const QList<int> &context)
{
Core::Command *command;
annotateFile = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
annotateFile = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(annotateFile, QLatin1String(Constants::ANNOTATE), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(annotateFile, SIGNAL(triggered()), this, SLOT(annotateCurrentFile()));
mercurialContainer->addAction(command);
diffFile = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
diffFile = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(diffFile, QLatin1String(Constants::DIFF), context);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+D")));
connect(diffFile, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
mercurialContainer->addAction(command);
logFile = new Utils::ParameterAction(tr("Log Current File"), tr("Log \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
logFile = new Utils::ParameterAction(tr("Log Current File"), tr("Log \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(logFile, QLatin1String(Constants::LOG), context);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+L")));
connect(logFile, SIGNAL(triggered()), this, SLOT(logCurrentFile()));
mercurialContainer->addAction(command);
revertFile = new Utils::ParameterAction(tr("Revert Current File"), tr("Revert \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
command = actionManager->registerAction(revertFile, QLatin1String(Constants::REVERT), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
mercurialContainer->addAction(command);
statusFile = new Utils::ParameterAction(tr("Status Current File"), tr("Status \"%1\""), Utils::ParameterAction::AlwaysEnabled, this);
statusFile = new Utils::ParameterAction(tr("Status Current File"), tr("Status \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(statusFile, QLatin1String(Constants::STATUS), context);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+S")));
connect(statusFile, SIGNAL(triggered()), this, SLOT(statusCurrentFile()));
mercurialContainer->addAction(command);
createSeparator(context, QLatin1String("FileDirSeperator1"));
m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(m_addAction, QLatin1String(Constants::ADD), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
mercurialContainer->addAction(command);
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(m_deleteAction, QLatin1String(Constants::DELETE), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
mercurialContainer->addAction(command);
revertFile = new Utils::ParameterAction(tr("Revert Current File..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = actionManager->registerAction(revertFile, QLatin1String(Constants::REVERT), context);
command->setAttribute(Core::Command::CA_UpdateText);
connect(revertFile, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
mercurialContainer->addAction(command);
}
void MercurialPlugin::addCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
m_client->add(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void MercurialPlugin::annotateCurrentFile()
......@@ -655,19 +679,15 @@ void MercurialPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
return;
const QString filename = currentState().currentFileName();
const bool fileEnabled = !filename.isEmpty();
const bool repoEnabled = currentState().hasTopLevel();
annotateFile->setParameter(filename);
annotateFile->setEnabled(fileEnabled);
diffFile->setParameter(filename);
diffFile->setEnabled(fileEnabled);
logFile->setParameter(filename);
logFile->setEnabled(fileEnabled);
m_addAction->setParameter(filename);
m_deleteAction->setParameter(filename);
revertFile->setParameter(filename);
revertFile->setEnabled(fileEnabled);
statusFile->setParameter(filename);
statusFile->setEnabled(fileEnabled);
foreach (QAction *repoAction, m_repositoryActionList)
repoAction->setEnabled(repoEnabled);
......
......@@ -88,6 +88,7 @@ public:
private slots:
// File menu action Slots
void addCurrentFile();
void annotateCurrentFile();
void diffCurrentFile();
void logCurrentFile();
......@@ -156,6 +157,8 @@ private:
QTemporaryFile *changeLog;
//Menu Items (file actions)
Utils::ParameterAction *m_addAction;
Utils::ParameterAction *m_deleteAction;
Utils::ParameterAction *annotateFile;
Utils::ParameterAction *diffFile;
Utils::ParameterAction *logFile;
......
......@@ -276,11 +276,11 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString * e
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
mperforce->addAction(command);
m_deleteAction = new Utils::ParameterAction(tr("Delete"), tr("Delete \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = am->registerAction(m_deleteAction, CMD_ID_DELETE_FILE, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultText(tr("Delete File"));
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteCurrentFile()));
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
mperforce->addAction(command);
m_revertFileAction = new Utils::ParameterAction(tr("Revert"), tr("Revert \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
......@@ -451,13 +451,6 @@ void PerforcePlugin::addCurrentFile()
vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void PerforcePlugin::deleteCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
vcsDelete(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void PerforcePlugin::revertCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
......
......@@ -106,7 +106,6 @@ public slots:
private slots:
void openCurrentFile();
void addCurrentFile();
void deleteCurrentFile();
void revertCurrentFile();
void printOpenedFileList();
void diffCurrentFile();
......
......@@ -1946,7 +1946,7 @@ void ProjectExplorerPlugin::removeFile()
}
// remove from version control
core->vcsManager()->showDeleteDialog(filePath);
core->vcsManager()->promptToDelete(filePath);
// remove from file system
if (deleteFile) {
......
......@@ -292,14 +292,14 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *e
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
subversionMenu->addAction(command);
m_deleteAction = new Utils::ParameterAction(tr("Delete"), tr("Delete \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_deleteAction, CMD_ID_DELETE_FILE,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteCurrentFile()));
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
subversionMenu->addAction(command);
m_revertAction = new Utils::ParameterAction(tr("Revert"), tr("Revert \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
m_revertAction = new Utils::ParameterAction(tr("Revert..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_revertAction, CMD_ID_REVERT,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
......@@ -556,13 +556,6 @@ void SubversionPlugin::addCurrentFile()
vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void SubversionPlugin::deleteCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
vcsDelete(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void SubversionPlugin::revertCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
......
......@@ -98,7 +98,6 @@ public:
private slots:
void addCurrentFile();
void deleteCurrentFile();
void revertCurrentFile();
void diffProject();
void diffCurrentFile();
......
......@@ -46,6 +46,7 @@
#include <QtCore/QSharedData>
#include <QtGui/QAction>
#include <QtGui/QMessageBox>
enum { debug = 0 };
......@@ -446,6 +447,15 @@ bool VCSBasePlugin::enableMenuAction(ActionState as, QAction *menuAction)
return true;
}
void VCSBasePlugin::promptToDeleteCurrentFile()
{
const VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
const bool rc = Core::ICore::instance()->vcsManager()->promptToDelete(versionControl(), state.currentFile());
if (!rc)
QMessageBox::warning(0, tr("Version Control"), tr("The file '%1' could not be deleted.").arg(state.currentFile()), QMessageBox::Ok);
}
} // namespace VCSBase
#include "vcsbaseplugin.moc"
......@@ -149,6 +149,11 @@ public:
const VCSBasePluginState &currentState() const;
Core::IVersionControl *versionControl() const;
public slots:
// Convenience slot for "Delete current file" action. Prompts to
// delete the file via VCSManager.
void promptToDeleteCurrentFile();
protected:
enum ActionState { NoVCSEnabled, OtherVCSEnabled, VCSEnabled };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment