diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 0092513693b467b42690e2c86e5157e932c827fa..ddfe984a8d226d16ce8f44a7ad401dcda3a40a2c 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1003,29 +1003,32 @@ bool EditorManager::saveFile(IEditor *editor) return success; } -namespace { - enum ReadOnlyAction { RO_Cancel, RO_OpenSCC, RO_MakeWriteable, RO_SaveAs }; -} - -static ReadOnlyAction promptReadOnly(const QString &fileName, bool hasSCC, QWidget *parent) +EditorManager::ReadOnlyAction + EditorManager::promptReadOnlyFile(const QString &fileName, + const IVersionControl *versionControl, + QWidget *parent, + bool displaySaveAsButton) { QMessageBox msgBox(QMessageBox::Question, QObject::tr("File is Read Only"), QObject::tr("The file %1 is read only.").arg(fileName), QMessageBox::Cancel, parent); QPushButton *sccButton = 0; - if (hasSCC) - sccButton = msgBox.addButton(QObject::tr("Open with SCC"), QMessageBox::AcceptRole); + if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation)) + sccButton = msgBox.addButton(QObject::tr("Open with VCS (%1)").arg(versionControl->name()), QMessageBox::AcceptRole); + QPushButton *makeWritableButton = msgBox.addButton(QObject::tr("Make writable"), QMessageBox::AcceptRole); - QPushButton *saveAsButton = msgBox.addButton(QObject::tr("Save as ..."), QMessageBox::ActionRole); - if (hasSCC) - msgBox.setDefaultButton(sccButton); - else - msgBox.setDefaultButton(makeWritableButton); + + QPushButton *saveAsButton = 0; + if (displaySaveAsButton) + msgBox.addButton(QObject::tr("Save as ..."), QMessageBox::ActionRole); + + msgBox.setDefaultButton(sccButton ? sccButton : makeWritableButton); msgBox.exec(); + QAbstractButton *clickedButton = msgBox.clickedButton(); if (clickedButton == sccButton) - return RO_OpenSCC; + return RO_OpenVCS; if (clickedButton == makeWritableButton) return RO_MakeWriteable; if (clickedButton == saveAsButton) @@ -1042,8 +1045,8 @@ EditorManager::makeEditorWritable(IEditor *editor) IFile *file = editor->file(); const QString &fileName = file->fileName(); - switch (promptReadOnly(fileName, versionControl, m_d->m_core->mainWindow())) { - case RO_OpenSCC: + switch (promptReadOnlyFile(fileName, versionControl, m_d->m_core->mainWindow(), true)) { + case RO_OpenVCS: if (!versionControl->vcsOpen(fileName)) { QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC.")); return Failed; diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index b71791f36bfaae03145b5eda8dd2804f48cfa1b2..b9da2e055ff2478a83487564c9593792d7199903 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -55,6 +55,7 @@ class IEditorFactory; class MimeType; class IFile; class IMode; +class IVersionControl; enum MakeWritableResult { OpenedWithVersionControl, @@ -159,6 +160,16 @@ public: QString defaultExternalEditor() const; QString externalEditorHelpText() const; + + // Helper to display a message dialog when encountering a read-only + // file, prompting the user about how to make it writeable. + enum ReadOnlyAction { RO_Cancel, RO_OpenVCS, RO_MakeWriteable, RO_SaveAs }; + + static ReadOnlyAction promptReadOnlyFile(const QString &fileName, + const IVersionControl *versionControl, + QWidget *parent, + bool displaySaveAsButton = false); + signals: void currentEditorChanged(Core::IEditor *editor); void editorCreated(Core::IEditor *editor, const QString &fileName); diff --git a/src/plugins/coreplugin/iversioncontrol.h b/src/plugins/coreplugin/iversioncontrol.h index b90f9d79c659536d31be68d962c5c12794ab6282..0962c5537e8cf6b1594fdcd84b1b4ff449fc955f 100644 --- a/src/plugins/coreplugin/iversioncontrol.h +++ b/src/plugins/coreplugin/iversioncontrol.h @@ -45,51 +45,53 @@ class CORE_EXPORT IVersionControl : public QObject { Q_OBJECT public: + enum Operation { AddOperation, DeleteOperation, OpenOperation }; + IVersionControl(QObject *parent = 0) : QObject(parent) {} virtual ~IVersionControl() {} - // Returns wheter files in this directory should be managed with this + virtual QString name() const = 0; + + // Enable the VCS, that is, make its menu actions visible. + virtual bool isEnabled() const = 0; + virtual void setEnabled(bool enabled) = 0; + + // Returns whether files in this directory should be managed with this // version control. virtual bool managesDirectory(const QString &filename) const = 0; - // This function should return the topmost directory, for - // which this IVersionControl should be used. - // The VCSManager assumes that all files in the returned directory - // are managed by the same IVersionControl + // This function should return the topmost directory, for which this + // IVersionControl should be used. The VCSManager assumes that all files + // in the returned directory are managed by the same IVersionControl // Note that this is used as an optimization, so that the VCSManager // doesn't need to call managesDirectory(..) for each directory - // This function is called after finding out that the directory is managed by - // a specific version control + // This function is called after finding out that the directory is managed + // by a specific version control. virtual QString findTopLevelForDirectory(const QString &directory) const = 0; - // Called prior to save, if the file is read only. - // Should be implemented if the scc requires a operation before editing the file - // E.g. p4 edit - // Note: The EditorManager calls this for the editors + // Called to query whether a VCS supports the respective operations. + virtual bool supportsOperation(Operation operation) const = 0; + + // Called prior to save, if the file is read only. Should be implemented + // if the scc requires a operation before editing the file, e.g. 'p4 edit' + // Note: The EditorManager calls this for the editors. virtual bool vcsOpen(const QString &fileName) = 0; - // Called after a file has been added to a project - // If the version control needs to know which files it needs to track - // you should reimplement this function - // E.g. p4 add, cvs add, svn add - // Note: This function should be called from IProject subclasses after files - // are added to the project + // Called after a file has been added to a project If the version control + // needs to know which files it needs to track you should reimplement this + // function, e.g. 'p4 add', 'cvs add', 'svn add'. + // Note: This function should be called from IProject subclasses after + // files are added to the project virtual bool vcsAdd(const QString &filename) = 0; - // Called after a file has been removed from the project (if the user wants) - // E.g. p4 delete, svn delete - // You probably want to call SccManager::showDeleteDialog, which asks the user to - // confirm the deletion + // Called after a file has been removed from the project (if the user + // wants), e.g. 'p4 delete', 'svn delete'. + // You probably want to call VcsManager::showDeleteDialog, which asks the + // user to confirm the deletion virtual bool vcsDelete(const QString &filename) = 0; // TODO: ADD A WAY TO DETECT WHETHER A FILE IS MANAGED, e.g // virtual bool sccManaged(const QStryng &filename) = 0; - - // TODO - // we probably want to have a function supports( enum Operation ) or - // something which describes which "kind" of revision control system it is. - // That is to check wheter a given operation is needed. - // But well I don't know yet how all different version control systems work }; } // namespace Core diff --git a/src/plugins/coreplugin/vcsmanager.cpp b/src/plugins/coreplugin/vcsmanager.cpp index a0e1cc19c0ad2663899efcf53a566deeeba574da..02475a0d0e66cfb5369327ec1c5f2827f43aa167 100644 --- a/src/plugins/coreplugin/vcsmanager.cpp +++ b/src/plugins/coreplugin/vcsmanager.cpp @@ -45,8 +45,18 @@ #include <QtCore/QFileInfo> #include <QtGui/QMessageBox> +enum { debug = 0 }; + namespace Core { +typedef QList<IVersionControl *> VersionControlList; + +static inline VersionControlList allVersionControls() +{ + return ExtensionSystem::PluginManager::instance()->getObjects<IVersionControl>(); +} + +// ---- VCSManagerPrivate struct VCSManagerPrivate { QMap<QString, IVersionControl *> m_cachedMatches; }; @@ -61,31 +71,54 @@ VCSManager::~VCSManager() delete m_d; } +void VCSManager::setVCSEnabled(const QString &directory) +{ + if (debug) + qDebug() << Q_FUNC_INFO << directory; + IVersionControl* managingVCS = findVersionControlForDirectory(directory); + const VersionControlList versionControls = allVersionControls(); + foreach(IVersionControl *versionControl, versionControls) { + const bool newEnabled = versionControl == managingVCS; + if (newEnabled != versionControl->isEnabled()) + versionControl->setEnabled(newEnabled); + } +} + +void VCSManager::setAllVCSEnabled() +{ + if (debug) + qDebug() << Q_FUNC_INFO; + const VersionControlList versionControls = allVersionControls(); + foreach(IVersionControl *versionControl, versionControls) + if (!versionControl->isEnabled()) + versionControl->setEnabled(true); +} + IVersionControl* VCSManager::findVersionControlForDirectory(const QString &directory) { - // first look into the cache - int pos = 0; - { // First try the whole name - QMap<QString, IVersionControl *>::const_iterator it = m_d->m_cachedMatches.constFind(directory); - if (it != m_d->m_cachedMatches.constEnd()) { + // first look into the cache, check the whole name + + { + const QMap<QString, IVersionControl *>::const_iterator it = m_d->m_cachedMatches.constFind(directory); + if (it != m_d->m_cachedMatches.constEnd()) return it.value(); - } } + int pos = 0; + const QChar slash = QLatin1Char('/'); while(true) { - int index = directory.indexOf('/', pos); + int index = directory.indexOf(slash, pos); if (index == -1) break; - QString directoryPart = directory.left(index); + const QString directoryPart = directory.left(index); QMap<QString, IVersionControl *>::const_iterator it = m_d->m_cachedMatches.constFind(directoryPart); - if (it != m_d->m_cachedMatches.constEnd()) { + if (it != m_d->m_cachedMatches.constEnd()) return it.value(); - } pos = index+1; } // ah nothing so ask the IVersionControls directly - QList<IVersionControl *> versionControls = ExtensionSystem::PluginManager::instance()->getObjects<IVersionControl>(); + const VersionControlList versionControls = allVersionControls(); foreach(IVersionControl * versionControl, versionControls) { if (versionControl->managesDirectory(directory)) { m_d->m_cachedMatches.insert(versionControl->findTopLevelForDirectory(directory), versionControl); @@ -95,20 +128,20 @@ IVersionControl* VCSManager::findVersionControlForDirectory(const QString &direc return 0; } -void VCSManager::showDeleteDialog(const QString &fileName) +bool VCSManager::showDeleteDialog(const QString &fileName) { IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath()); - if (!vc) - return; + if (!vc || !vc->supportsOperation(IVersionControl::DeleteOperation)) + return true; const QString title = QCoreApplication::translate("VCSManager", "Version Control"); const QString msg = QCoreApplication::translate("VCSManager", - "Would you like to remove this file from the version control system?\n" - "Note: This might remove the local file."); + "Would you like to remove this file from the version control system (%1)?\n" + "Note: This might remove the local file.").arg(vc->name()); const QMessageBox::StandardButton button = QMessageBox::question(0, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - if (button == QMessageBox::Yes) { - vc->vcsDelete(fileName); - } + if (button != QMessageBox::Yes) + return true; + return vc->vcsDelete(fileName); } } // namespace Core diff --git a/src/plugins/coreplugin/vcsmanager.h b/src/plugins/coreplugin/vcsmanager.h index 92e4f35d1540a2a2282b1fb361ae35ea231a75ef..a3afca96d6adef219ad847fcc7427d8818b92814 100644 --- a/src/plugins/coreplugin/vcsmanager.h +++ b/src/plugins/coreplugin/vcsmanager.h @@ -45,12 +45,12 @@ class IVersionControl; // The VCSManager has only one notable function: // findVersionControlFor(), which returns the IVersionControl * for a given -// filename. Note that the VCSManager assumes that if a IVersionControl * +// filename. Note that the VCSManager assumes that if a IVersionControl * // manages a directory, then it also manages all the files and all the // subdirectories. // // It works by asking all IVersionControl * if they manage the file, and ask -// for the topmost directory it manages. This information is cached and +// for the topmost directory it manages. This information is cached and // VCSManager thus knows pretty fast which IVersionControl * is responsible. class CORE_EXPORT VCSManager @@ -62,10 +62,16 @@ public: IVersionControl *findVersionControlForDirectory(const QString &directory); - // Shows a confirmation dialog, - // wheter the file should also be deleted from revision control - // Calls sccDelete on the file - void showDeleteDialog(const QString &fileName); + // Enable the VCS managing a certain directory only. This should + // be used by project manager classes. + void setVCSEnabled(const QString &directory); + // Enable all VCS. + void setAllVCSEnabled(); + + // 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); private: VCSManagerPrivate *m_d; diff --git a/src/plugins/git/git.pro b/src/plugins/git/git.pro index 258639dcbe3416cce70579750af6d0b4dd600c12..160f8792695c54eea0d6d15a060d5852f07f6ff7 100644 --- a/src/plugins/git/git.pro +++ b/src/plugins/git/git.pro @@ -17,7 +17,8 @@ HEADERS += gitplugin.h \ giteditor.h \ annotationhighlighter.h \ gitsubmiteditorwidget.h \ - gitsubmiteditor.h + gitsubmiteditor.h \ + gitversioncontrol.h SOURCES += gitplugin.cpp \ gitoutputwindow.cpp \ @@ -28,7 +29,8 @@ SOURCES += gitplugin.cpp \ giteditor.cpp \ annotationhighlighter.cpp \ gitsubmiteditorwidget.cpp \ - gitsubmiteditor.cpp + gitsubmiteditor.cpp \ + gitversioncontrol.cpp FORMS += changeselectiondialog.ui \ settingspage.ui \ diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index fb73d4fe5e2b41a2a750f4ab656d3966baab951c..0abdb630bdace3d576496db20227e1b0c266a25f 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -87,11 +87,6 @@ GitClient::~GitClient() { } -bool GitClient::vcsOpen(const QString &fileName) -{ - return m_plugin->vcsOpen(fileName); -} - QString GitClient::findRepositoryForFile(const QString &fileName) { const QString gitDirectory = QLatin1String(kGitDirectoryC); diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index 1a7ebe8c983a8f83dd970e1019b02ca4c2e8286b..69649ea786f3ea0e640bfb3c8dd68ec9a4c66407 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -62,17 +62,14 @@ class GitCommand; struct CommitData; struct GitSubmitEditorPanelData; -class GitClient : public Core::IVersionControl +class GitClient : public QObject { Q_OBJECT public: - GitClient(GitPlugin *plugin, Core::ICore *core); + explicit GitClient(GitPlugin *plugin, Core::ICore *core); ~GitClient(); - bool vcsOpen(const QString &fileName); - bool vcsAdd(const QString &) { return false; } - bool vcsDelete(const QString &) { return false; } bool managesDirectory(const QString &) const { return false; } QString findTopLevelForDirectory(const QString &) const { return QString(); } diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 6209996edc141052ff75a4571df052fdb3d85144..e0d1bd6a4afc52c48b06c52fa0c45136a5dd2711 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -33,6 +33,7 @@ #include "gitplugin.h" #include "gitclient.h" +#include "gitversioncontrol.h" #include "giteditor.h" #include "gitconstants.h" #include "changeselectiondialog.h" @@ -132,6 +133,7 @@ GitPlugin::GitPlugin() : m_settingsPage(0), m_coreListener(0), m_submitEditorFactory(0), + m_versionControl(0), m_changeTmpFile(0) { Q_ASSERT(m_instance == 0); @@ -170,6 +172,12 @@ GitPlugin::~GitPlugin() m_submitEditorFactory = 0; } + if (m_versionControl) { + removeObject(m_versionControl); + delete m_versionControl; + m_versionControl = 0; + } + cleanChangeTmpFile(); delete m_gitClient; m_instance = 0; @@ -235,6 +243,9 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *error_message) m_submitEditorFactory = new GitSubmitEditorFactory(&submitParameters); addObject(m_submitEditorFactory); + m_versionControl = new GitVersionControl(m_gitClient); + addObject(m_versionControl); + //register actions Core::ActionManagerInterface *actionManager = m_core->actionManager(); @@ -245,6 +256,10 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *error_message) actionManager->createMenu(QLatin1String("Git")); gitContainer->menu()->setTitle(tr("&Git")); toolsContainer->addMenu(gitContainer); + if (QAction *ma = gitContainer->menu()->menuAction()) { + ma->setEnabled(m_versionControl->isEnabled()); + connect(m_versionControl, SIGNAL(enabledChanged(bool)), ma, SLOT(setVisible(bool))); + } Core::ICommand *command; QAction *tmpaction; @@ -383,12 +398,6 @@ void GitPlugin::extensionsInitialized() m_projectExplorer = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::ProjectExplorerPlugin>(); } -bool GitPlugin::vcsOpen(const QString &fileName) -{ - Q_UNUSED(fileName); - return false; -} - void GitPlugin::submitEditorDiff(const QStringList &files) { if (files.empty()) diff --git a/src/plugins/git/gitplugin.h b/src/plugins/git/gitplugin.h index 51846c71d66650bb197b63ae58e0769b62d9289a..bf3c5328f041de00e1046cb535d67a4009deab26 100644 --- a/src/plugins/git/gitplugin.h +++ b/src/plugins/git/gitplugin.h @@ -55,6 +55,7 @@ QT_END_NAMESPACE namespace Core { class IEditorFactory; class ICore; + class IVersionControl; } namespace Git { @@ -87,8 +88,6 @@ public: ~GitPlugin(); static GitPlugin *instance(); - bool vcsOpen(const QString &fileName); - bool initialize(const QStringList &arguments , QString *error_message); void extensionsInitialized(); @@ -154,6 +153,7 @@ private: QList<Core::IEditorFactory*> m_editorFactories; CoreListener *m_coreListener; Core::IEditorFactory *m_submitEditorFactory; + Core::IVersionControl *m_versionControl; QString m_submitRepository; QStringList m_submitOrigCommitFiles; QTemporaryFile *m_changeTmpFile; diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 7f71282fbbf71df8d7ea6d6bcef2e50c41073ce2..2de31700a867462dba9d8a17017cf8d81e990096 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -235,6 +235,10 @@ bool PerforcePlugin::initialize(const QStringList & /*arguments*/, QString *erro am->createMenu(QLatin1String(PERFORCE_MENU)); mperforce->menu()->setTitle(tr("&Perforce")); mtools->addMenu(mperforce); + if (QAction *ma = mperforce->menu()->menuAction()) { + ma->setEnabled(m_versionControl->isEnabled()); + connect(m_versionControl, SIGNAL(enabledChanged(bool)), ma, SLOT(setVisible(bool))); + } QList<int> globalcontext; globalcontext << Core::Constants::C_GLOBAL_ID; diff --git a/src/plugins/perforce/perforceversioncontrol.cpp b/src/plugins/perforce/perforceversioncontrol.cpp index a51930c1e6daf254994442a27bfd9e25d3007d1e..98379024bc04858b349778ae904133d3b5d62c23 100644 --- a/src/plugins/perforce/perforceversioncontrol.cpp +++ b/src/plugins/perforce/perforceversioncontrol.cpp @@ -38,10 +38,41 @@ namespace Perforce { namespace Internal { PerforceVersionControl::PerforceVersionControl(PerforcePlugin *plugin) : + m_enabled(true), m_plugin(plugin) { } +QString PerforceVersionControl::name() const +{ + return QLatin1String("perforce"); +} + +bool PerforceVersionControl::isEnabled() const +{ + return m_enabled; +} + +void PerforceVersionControl::setEnabled(bool enabled) +{ + if (m_enabled != enabled) { + m_enabled = enabled; + emit enabledChanged(m_enabled); + } +} + +bool PerforceVersionControl::supportsOperation(Operation operation) const +{ + bool rc = true; + switch (operation) { + case AddOperation: + case DeleteOperation: + case OpenOperation: + break; + } + return rc; +} + bool PerforceVersionControl::vcsOpen(const QString &fileName) { return m_plugin->vcsOpen(fileName); diff --git a/src/plugins/perforce/perforceversioncontrol.h b/src/plugins/perforce/perforceversioncontrol.h index d87a7f15ae4ef86de7870d1662d062965d331b95..0e8a1ea6539d6aaaa1465bbca2be2d25ba96cc83 100644 --- a/src/plugins/perforce/perforceversioncontrol.h +++ b/src/plugins/perforce/perforceversioncontrol.h @@ -46,13 +46,25 @@ class PerforceVersionControl : public Core::IVersionControl Q_OBJECT public: explicit PerforceVersionControl(PerforcePlugin *plugin); + + virtual QString name() const; + + virtual bool isEnabled() const; + virtual void setEnabled(bool enabled); + bool managesDirectory(const QString &directory) const; virtual QString findTopLevelForDirectory(const QString &directory) const; + + virtual bool supportsOperation(Operation operation) const; virtual bool vcsOpen(const QString &fileName); virtual bool vcsAdd(const QString &fileName); virtual bool vcsDelete(const QString &filename); +signals: + void enabledChanged(bool); + private: + bool m_enabled; PerforcePlugin *m_plugin; }; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index e04553763a36e1194fc9a2cffd5dc707afa6486e..9e41e3703f610f6fc65f82c921174dbf06f9a2f6 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -76,6 +76,7 @@ #include <coreplugin/welcomemode.h> #include <coreplugin/vcsmanager.h> #include <coreplugin/iversioncontrol.h> +#include <coreplugin/vcsmanager.h> #include <utils/listutils.h> #include <QtCore/qplugin.h> @@ -1172,6 +1173,13 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node if (projectChanged) { if (debug) qDebug() << "ProjectExplorer - currentProjectChanged(" << (project ? project->name() : "0") << ")"; + // Enable the right VCS + if (const Core::IFile *projectFile = project ? project->file() : static_cast<const Core::IFile *>(0)) { + m_core->vcsManager()->setVCSEnabled(QFileInfo(projectFile->fileName()).absolutePath()); + } else { + m_core->vcsManager()->setAllVCSEnabled(); + } + emit currentProjectChanged(project); updateActions(); } @@ -1584,27 +1592,28 @@ void ProjectExplorerPlugin::addExistingFiles() fileNames.removeOne(file); } - if (Core::IVersionControl *vcManager = m_core->vcsManager()->findVersionControlForDirectory(dir)) { - const QString files = fileNames.join("\n"); - QMessageBox::StandardButton button = + if (Core::IVersionControl *vcManager = m_core->vcsManager()->findVersionControlForDirectory(dir)) + if (vcManager->supportsOperation(Core::IVersionControl::AddOperation)) { + const QString files = fileNames.join(QString(QLatin1Char('\n'))); + QMessageBox::StandardButton button = QMessageBox::question(m_core->mainWindow(), tr("Add to Version Control"), - tr("Add files\n%1\nto version control?").arg(files), + tr("Add files\n%1\nto version control (%2)?").arg(files, vcManager->name()), QMessageBox::Yes | QMessageBox::No); - if (button == QMessageBox::Yes) { - QStringList notAddedToVc; - foreach (const QString file, fileNames) { - if (!vcManager->vcsAdd(file)) - notAddedToVc << file; - } + if (button == QMessageBox::Yes) { + QStringList notAddedToVc; + foreach (const QString &file, fileNames) { + if (!vcManager->vcsAdd(file)) + notAddedToVc << file; + } - if (!notAddedToVc.isEmpty()) { - const QString message = tr("Could not add following files to version control\n"); - const QString filesNotAdded = notAddedToVc.join("\n"); - QMessageBox::warning(m_core->mainWindow(), tr("Add files to version control failed"), - message + filesNotAdded); + if (!notAddedToVc.isEmpty()) { + const QString message = tr("Could not add following files to version control (%1)\n").arg(vcManager->name()); + const QString filesNotAdded = notAddedToVc.join(QString(QLatin1Char('\n'))); + QMessageBox::warning(m_core->mainWindow(), tr("Add files to version control failed"), + message + filesNotAdded); + } } } - } } void ProjectExplorerPlugin::openFile() diff --git a/src/plugins/projectexplorer/projectfilewizardextension.cpp b/src/plugins/projectexplorer/projectfilewizardextension.cpp index 2cd220ef58e3e9c1eb4cf7b39699871d92098718..7445d4799c7e7a304d421f6ce4545e2bf084eaaf 100644 --- a/src/plugins/projectexplorer/projectfilewizardextension.cpp +++ b/src/plugins/projectexplorer/projectfilewizardextension.cpp @@ -118,7 +118,11 @@ void ProjectFileWizardExtension::firstExtensionPageShown(const QList<Core::Gener m_context->versionControl = m_core->vcsManager()->findVersionControlForDirectory(directory); m_context->page->setFilesDisplay(fileNames); - m_context->page->setAddToVersionControlEnabled(m_context->versionControl != 0); + + const bool canAddToVCS = m_context->versionControl && m_context->versionControl->supportsOperation(Core::IVersionControl::AddOperation); + if (m_context->versionControl) + m_context->page->setVCSDisplay(m_context->versionControl->name()); + m_context->page->setAddToVersionControlEnabled(canAddToVCS); } static ProjectNode *currentProject() diff --git a/src/plugins/projectexplorer/projectwizardpage.cpp b/src/plugins/projectexplorer/projectwizardpage.cpp index 8a2873c336db953bbfc3e2eac0a00938683f5518..8912fbb9e948e02c1c505fd56b8ca699cb8f9aab 100644 --- a/src/plugins/projectexplorer/projectwizardpage.cpp +++ b/src/plugins/projectexplorer/projectwizardpage.cpp @@ -108,6 +108,11 @@ void ProjectWizardPage::changeEvent(QEvent *e) } } +void ProjectWizardPage::setVCSDisplay(const QString &vcsName) +{ + m_ui->addToVersionControlLabel->setText(tr("Add to &VCS (%1)").arg(vcsName)); +} + void ProjectWizardPage::setFilesDisplay(const QStringList &files) { QString fileMessage; { diff --git a/src/plugins/projectexplorer/projectwizardpage.h b/src/plugins/projectexplorer/projectwizardpage.h index 2031923d37c8a3c7adf4404c321f931f7e490463..bc86bb6fa7eccc52ca0af34bf910a78077a29f2a 100644 --- a/src/plugins/projectexplorer/projectwizardpage.h +++ b/src/plugins/projectexplorer/projectwizardpage.h @@ -69,6 +69,7 @@ public: bool addToVersionControl() const; void setAddToVersionControlEnabled(bool b); + void setVCSDisplay(const QString &vcsName); void setFilesDisplay(const QStringList &files); protected: diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index 672ce8b835b9077fd5ae28c743231979b39b1304..24302df0df5eeb994e68c32fa3b5d63bf5080162 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -265,46 +265,18 @@ bool Qt4PriFileNode::changeIncludes(ProFile *includeFile, const QStringList &pro return false; } - -namespace { - enum ReadOnlyAction { RO_Cancel, RO_OpenSCC, RO_MakeWriteable }; -} - -static ReadOnlyAction promptReadOnly(const QString &fileName, bool hasSCC, QWidget *parent) -{ - QMessageBox msgBox(QMessageBox::Question, QObject::tr("File is Read Only"), - QObject::tr("The file %1 is read only.").arg(fileName), - QMessageBox::Cancel, parent); - - QPushButton *sccButton = 0; - if (hasSCC) - sccButton = msgBox.addButton(QObject::tr("Open with SCC"), QMessageBox::AcceptRole); - QPushButton *makeWritableButton = msgBox.addButton(QObject::tr("Make writable"), QMessageBox::AcceptRole); - if (hasSCC) - msgBox.setDefaultButton(sccButton); - else - msgBox.setDefaultButton(makeWritableButton); - msgBox.exec(); - QAbstractButton *clickedButton = msgBox.clickedButton(); - if (clickedButton == sccButton) - return RO_OpenSCC; - if (clickedButton == makeWritableButton) - return RO_MakeWriteable; - return RO_Cancel; -} - bool Qt4PriFileNode::priFileWritable(const QString &path) { const QString dir = QFileInfo(path).dir().path(); Core::IVersionControl *versionControl = m_core->vcsManager()->findVersionControlForDirectory(dir); - switch (promptReadOnly(path, versionControl != 0, m_core->mainWindow())) { - case RO_OpenSCC: + switch (Core::EditorManager::promptReadOnlyFile(path, versionControl, m_core->mainWindow(), false)) { + case Core::EditorManager::RO_OpenVCS: if (!versionControl->vcsOpen(path)) { QMessageBox::warning(m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC.")); return false; } break; - case RO_MakeWriteable: { + case Core::EditorManager::RO_MakeWriteable: { const bool permsOk = QFile::setPermissions(path, QFile::permissions(path) | QFile::WriteUser); if (!permsOk) { QMessageBox::warning(m_core->mainWindow(), tr("Failed!"), tr("Could not set permissions to writable.")); @@ -312,10 +284,10 @@ bool Qt4PriFileNode::priFileWritable(const QString &path) } break; } - case RO_Cancel: { + case Core::EditorManager::RO_SaveAs: + case Core::EditorManager::RO_Cancel: return false; } - } return true; } @@ -457,7 +429,8 @@ void Qt4PriFileNode::save() if (modifiedFileHandle) fileManager->blockFileChange(modifiedFileHandle); ProWriter pw; - bool ok = pw.write(m_includeFile, m_includeFile->fileName()); + const bool ok = pw.write(m_includeFile, m_includeFile->fileName()); + Q_UNUSED(ok) m_includeFile->setModified(false); m_project->qt4ProjectManager()->notifyChanged(m_includeFile->fileName()); if (modifiedFileHandle) diff --git a/src/plugins/subversion/subversioncontrol.cpp b/src/plugins/subversion/subversioncontrol.cpp index ba2a2f2e8e92dcfa8b5af88c36b308418aa05f32..56ad229954743e3719088985e4eecc15be726919 100644 --- a/src/plugins/subversion/subversioncontrol.cpp +++ b/src/plugins/subversion/subversioncontrol.cpp @@ -38,10 +38,43 @@ using namespace Subversion; using namespace Subversion::Internal; SubversionControl::SubversionControl(SubversionPlugin *plugin) : + m_enabled(true), m_plugin(plugin) { } +QString SubversionControl::name() const +{ + return QLatin1String("subversion"); +} + +bool SubversionControl::isEnabled() const +{ + return m_enabled; +} + +void SubversionControl::setEnabled(bool enabled) +{ + if (m_enabled != enabled) { + m_enabled = enabled; + emit enabledChanged(m_enabled); + } +} + +bool SubversionControl::supportsOperation(Operation operation) const +{ + bool rc = true; + switch (operation) { + case AddOperation: + case DeleteOperation: + break; + case OpenOperation: + rc = false; + break; + } + return rc; +} + bool SubversionControl::vcsOpen(const QString & /* fileName */) { // Open for edit: N/A diff --git a/src/plugins/subversion/subversioncontrol.h b/src/plugins/subversion/subversioncontrol.h index f293852a3a11e4917dd912d1d767ef324ef8afd4..c4a2f8aa79c69d5145438a9182fd6737821e1443 100644 --- a/src/plugins/subversion/subversioncontrol.h +++ b/src/plugins/subversion/subversioncontrol.h @@ -47,13 +47,24 @@ class SubversionControl : public Core::IVersionControl Q_OBJECT public: explicit SubversionControl(SubversionPlugin *plugin); + virtual QString name() const; + + virtual bool isEnabled() const; + virtual void setEnabled(bool enabled); + virtual bool managesDirectory(const QString &directory) const; virtual QString findTopLevelForDirectory(const QString &directory) const; + + virtual bool supportsOperation(Operation operation) const; virtual bool vcsOpen(const QString &fileName); virtual bool vcsAdd(const QString &fileName); virtual bool vcsDelete(const QString &filename); +signals: + void enabledChanged(bool); + private: + bool m_enabled; SubversionPlugin *m_plugin; }; diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp index 6532a9d43357775f8de4e8ba199f447c60039979..a24bb7d3d06bbb0e652143e6a73cc134332f97a1 100644 --- a/src/plugins/subversion/subversionplugin.cpp +++ b/src/plugins/subversion/subversionplugin.cpp @@ -276,6 +276,10 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments*/, QString *er ami->createMenu(QLatin1String(SUBVERSION_MENU)); subversionMenu->menu()->setTitle(tr("&Subversion")); toolsContainer->addMenu(subversionMenu); + if (QAction *ma = subversionMenu->menu()->menuAction()) { + ma->setEnabled(m_versionControl->isEnabled()); + connect(m_versionControl, SIGNAL(enabledChanged(bool)), ma, SLOT(setVisible(bool))); + } QList<int> globalcontext; globalcontext << m_coreInstance->uniqueIDManager()->uniqueIdentifier(C_GLOBAL);