Merge branch '0.9.1-beta' of git@scm.dev.nokia.troll.no:creator/mainline into 0.9.1-beta

This commit is contained in:
hjk
2008-12-03 15:35:15 +01:00
21 changed files with 283 additions and 138 deletions

View File

@@ -1003,29 +1003,32 @@ bool EditorManager::saveFile(IEditor *editor)
return success; return success;
} }
namespace { EditorManager::ReadOnlyAction
enum ReadOnlyAction { RO_Cancel, RO_OpenSCC, RO_MakeWriteable, RO_SaveAs }; EditorManager::promptReadOnlyFile(const QString &fileName,
} const IVersionControl *versionControl,
QWidget *parent,
static ReadOnlyAction promptReadOnly(const QString &fileName, bool hasSCC, QWidget *parent) bool displaySaveAsButton)
{ {
QMessageBox msgBox(QMessageBox::Question, QObject::tr("File is Read Only"), QMessageBox msgBox(QMessageBox::Question, QObject::tr("File is Read Only"),
QObject::tr("The file %1 is read only.").arg(fileName), QObject::tr("The file %1 is read only.").arg(fileName),
QMessageBox::Cancel, parent); QMessageBox::Cancel, parent);
QPushButton *sccButton = 0; QPushButton *sccButton = 0;
if (hasSCC) if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation))
sccButton = msgBox.addButton(QObject::tr("Open with SCC"), QMessageBox::AcceptRole); 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 *makeWritableButton = msgBox.addButton(QObject::tr("Make writable"), QMessageBox::AcceptRole);
QPushButton *saveAsButton = msgBox.addButton(QObject::tr("Save as ..."), QMessageBox::ActionRole);
if (hasSCC) QPushButton *saveAsButton = 0;
msgBox.setDefaultButton(sccButton); if (displaySaveAsButton)
else msgBox.addButton(QObject::tr("Save as ..."), QMessageBox::ActionRole);
msgBox.setDefaultButton(makeWritableButton);
msgBox.setDefaultButton(sccButton ? sccButton : makeWritableButton);
msgBox.exec(); msgBox.exec();
QAbstractButton *clickedButton = msgBox.clickedButton(); QAbstractButton *clickedButton = msgBox.clickedButton();
if (clickedButton == sccButton) if (clickedButton == sccButton)
return RO_OpenSCC; return RO_OpenVCS;
if (clickedButton == makeWritableButton) if (clickedButton == makeWritableButton)
return RO_MakeWriteable; return RO_MakeWriteable;
if (clickedButton == saveAsButton) if (clickedButton == saveAsButton)
@@ -1042,8 +1045,8 @@ EditorManager::makeEditorWritable(IEditor *editor)
IFile *file = editor->file(); IFile *file = editor->file();
const QString &fileName = file->fileName(); const QString &fileName = file->fileName();
switch (promptReadOnly(fileName, versionControl, m_d->m_core->mainWindow())) { switch (promptReadOnlyFile(fileName, versionControl, m_d->m_core->mainWindow(), true)) {
case RO_OpenSCC: case RO_OpenVCS:
if (!versionControl->vcsOpen(fileName)) { if (!versionControl->vcsOpen(fileName)) {
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC.")); QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC."));
return Failed; return Failed;

View File

@@ -55,6 +55,7 @@ class IEditorFactory;
class MimeType; class MimeType;
class IFile; class IFile;
class IMode; class IMode;
class IVersionControl;
enum MakeWritableResult { enum MakeWritableResult {
OpenedWithVersionControl, OpenedWithVersionControl,
@@ -159,6 +160,16 @@ public:
QString defaultExternalEditor() const; QString defaultExternalEditor() const;
QString externalEditorHelpText() 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: signals:
void currentEditorChanged(Core::IEditor *editor); void currentEditorChanged(Core::IEditor *editor);
void editorCreated(Core::IEditor *editor, const QString &fileName); void editorCreated(Core::IEditor *editor, const QString &fileName);

View File

@@ -45,51 +45,53 @@ class CORE_EXPORT IVersionControl : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Operation { AddOperation, DeleteOperation, OpenOperation };
IVersionControl(QObject *parent = 0) : QObject(parent) {} IVersionControl(QObject *parent = 0) : QObject(parent) {}
virtual ~IVersionControl() {} 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. // version control.
virtual bool managesDirectory(const QString &filename) const = 0; virtual bool managesDirectory(const QString &filename) const = 0;
// This function should return the topmost directory, for // This function should return the topmost directory, for which this
// which this IVersionControl should be used. // IVersionControl should be used. The VCSManager assumes that all files
// The VCSManager assumes that all files in the returned directory // in the returned directory are managed by the same IVersionControl
// are managed by the same IVersionControl
// Note that this is used as an optimization, so that the VCSManager // Note that this is used as an optimization, so that the VCSManager
// doesn't need to call managesDirectory(..) for each directory // doesn't need to call managesDirectory(..) for each directory
// This function is called after finding out that the directory is managed by // This function is called after finding out that the directory is managed
// a specific version control // by a specific version control.
virtual QString findTopLevelForDirectory(const QString &directory) const = 0; virtual QString findTopLevelForDirectory(const QString &directory) const = 0;
// Called prior to save, if the file is read only. // Called to query whether a VCS supports the respective operations.
// Should be implemented if the scc requires a operation before editing the file virtual bool supportsOperation(Operation operation) const = 0;
// E.g. p4 edit
// Note: The EditorManager calls this for the editors // 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; virtual bool vcsOpen(const QString &fileName) = 0;
// Called after a file has been added to a project // Called after a file has been added to a project If the version control
// If the version control needs to know which files it needs to track // needs to know which files it needs to track you should reimplement this
// you should reimplement this function // function, e.g. 'p4 add', 'cvs add', 'svn add'.
// E.g. p4 add, cvs add, svn add // Note: This function should be called from IProject subclasses after
// Note: This function should be called from IProject subclasses after files // files are added to the project
// are added to the project
virtual bool vcsAdd(const QString &filename) = 0; virtual bool vcsAdd(const QString &filename) = 0;
// Called after a file has been removed from the project (if the user wants) // Called after a file has been removed from the project (if the user
// E.g. p4 delete, svn delete // wants), e.g. 'p4 delete', 'svn delete'.
// You probably want to call SccManager::showDeleteDialog, which asks the user to // You probably want to call VcsManager::showDeleteDialog, which asks the
// confirm the deletion // user to confirm the deletion
virtual bool vcsDelete(const QString &filename) = 0; virtual bool vcsDelete(const QString &filename) = 0;
// TODO: ADD A WAY TO DETECT WHETHER A FILE IS MANAGED, e.g // TODO: ADD A WAY TO DETECT WHETHER A FILE IS MANAGED, e.g
// virtual bool sccManaged(const QStryng &filename) = 0; // 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 } // namespace Core

View File

@@ -45,8 +45,18 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
enum { debug = 0 };
namespace Core { namespace Core {
typedef QList<IVersionControl *> VersionControlList;
static inline VersionControlList allVersionControls()
{
return ExtensionSystem::PluginManager::instance()->getObjects<IVersionControl>();
}
// ---- VCSManagerPrivate
struct VCSManagerPrivate { struct VCSManagerPrivate {
QMap<QString, IVersionControl *> m_cachedMatches; QMap<QString, IVersionControl *> m_cachedMatches;
}; };
@@ -61,31 +71,54 @@ VCSManager::~VCSManager()
delete m_d; 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) IVersionControl* VCSManager::findVersionControlForDirectory(const QString &directory)
{ {
// first look into the cache // first look into the cache, check the whole name
int pos = 0;
{ // First try the whole name {
QMap<QString, IVersionControl *>::const_iterator it = m_d->m_cachedMatches.constFind(directory); const QMap<QString, IVersionControl *>::const_iterator it = m_d->m_cachedMatches.constFind(directory);
if (it != m_d->m_cachedMatches.constEnd()) { if (it != m_d->m_cachedMatches.constEnd())
return it.value(); return it.value();
}
} }
int pos = 0;
const QChar slash = QLatin1Char('/');
while(true) { while(true) {
int index = directory.indexOf('/', pos); int index = directory.indexOf(slash, pos);
if (index == -1) if (index == -1)
break; break;
QString directoryPart = directory.left(index); const QString directoryPart = directory.left(index);
QMap<QString, IVersionControl *>::const_iterator it = m_d->m_cachedMatches.constFind(directoryPart); 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(); return it.value();
}
pos = index+1; pos = index+1;
} }
// ah nothing so ask the IVersionControls directly // ah nothing so ask the IVersionControls directly
QList<IVersionControl *> versionControls = ExtensionSystem::PluginManager::instance()->getObjects<IVersionControl>(); const VersionControlList versionControls = allVersionControls();
foreach(IVersionControl * versionControl, versionControls) { foreach(IVersionControl * versionControl, versionControls) {
if (versionControl->managesDirectory(directory)) { if (versionControl->managesDirectory(directory)) {
m_d->m_cachedMatches.insert(versionControl->findTopLevelForDirectory(directory), versionControl); m_d->m_cachedMatches.insert(versionControl->findTopLevelForDirectory(directory), versionControl);
@@ -95,20 +128,20 @@ IVersionControl* VCSManager::findVersionControlForDirectory(const QString &direc
return 0; return 0;
} }
void VCSManager::showDeleteDialog(const QString &fileName) bool VCSManager::showDeleteDialog(const QString &fileName)
{ {
IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath()); IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath());
if (!vc) if (!vc || !vc->supportsOperation(IVersionControl::DeleteOperation))
return; return true;
const QString title = QCoreApplication::translate("VCSManager", "Version Control"); const QString title = QCoreApplication::translate("VCSManager", "Version Control");
const QString msg = QCoreApplication::translate("VCSManager", const QString msg = QCoreApplication::translate("VCSManager",
"Would you like to remove this file from the version control system?\n" "Would you like to remove this file from the version control system (%1)?\n"
"Note: This might remove the local file."); "Note: This might remove the local file.").arg(vc->name());
const QMessageBox::StandardButton button = const QMessageBox::StandardButton button =
QMessageBox::question(0, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::question(0, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button == QMessageBox::Yes) { if (button != QMessageBox::Yes)
vc->vcsDelete(fileName); return true;
} return vc->vcsDelete(fileName);
} }
} // namespace Core } // namespace Core

View File

@@ -62,10 +62,16 @@ public:
IVersionControl *findVersionControlForDirectory(const QString &directory); IVersionControl *findVersionControlForDirectory(const QString &directory);
// Shows a confirmation dialog, // Enable the VCS managing a certain directory only. This should
// wheter the file should also be deleted from revision control // be used by project manager classes.
// Calls sccDelete on the file void setVCSEnabled(const QString &directory);
void showDeleteDialog(const QString &fileName); // 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: private:
VCSManagerPrivate *m_d; VCSManagerPrivate *m_d;

View File

@@ -17,7 +17,8 @@ HEADERS += gitplugin.h \
giteditor.h \ giteditor.h \
annotationhighlighter.h \ annotationhighlighter.h \
gitsubmiteditorwidget.h \ gitsubmiteditorwidget.h \
gitsubmiteditor.h gitsubmiteditor.h \
gitversioncontrol.h
SOURCES += gitplugin.cpp \ SOURCES += gitplugin.cpp \
gitoutputwindow.cpp \ gitoutputwindow.cpp \
@@ -28,7 +29,8 @@ SOURCES += gitplugin.cpp \
giteditor.cpp \ giteditor.cpp \
annotationhighlighter.cpp \ annotationhighlighter.cpp \
gitsubmiteditorwidget.cpp \ gitsubmiteditorwidget.cpp \
gitsubmiteditor.cpp gitsubmiteditor.cpp \
gitversioncontrol.cpp
FORMS += changeselectiondialog.ui \ FORMS += changeselectiondialog.ui \
settingspage.ui \ settingspage.ui \

View File

@@ -87,11 +87,6 @@ GitClient::~GitClient()
{ {
} }
bool GitClient::vcsOpen(const QString &fileName)
{
return m_plugin->vcsOpen(fileName);
}
QString GitClient::findRepositoryForFile(const QString &fileName) QString GitClient::findRepositoryForFile(const QString &fileName)
{ {
const QString gitDirectory = QLatin1String(kGitDirectoryC); const QString gitDirectory = QLatin1String(kGitDirectoryC);

View File

@@ -62,17 +62,14 @@ class GitCommand;
struct CommitData; struct CommitData;
struct GitSubmitEditorPanelData; struct GitSubmitEditorPanelData;
class GitClient : public Core::IVersionControl class GitClient : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
GitClient(GitPlugin *plugin, Core::ICore *core); explicit GitClient(GitPlugin *plugin, Core::ICore *core);
~GitClient(); ~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; } bool managesDirectory(const QString &) const { return false; }
QString findTopLevelForDirectory(const QString &) const { return QString(); } QString findTopLevelForDirectory(const QString &) const { return QString(); }

View File

@@ -33,6 +33,7 @@
#include "gitplugin.h" #include "gitplugin.h"
#include "gitclient.h" #include "gitclient.h"
#include "gitversioncontrol.h"
#include "giteditor.h" #include "giteditor.h"
#include "gitconstants.h" #include "gitconstants.h"
#include "changeselectiondialog.h" #include "changeselectiondialog.h"
@@ -132,6 +133,7 @@ GitPlugin::GitPlugin() :
m_settingsPage(0), m_settingsPage(0),
m_coreListener(0), m_coreListener(0),
m_submitEditorFactory(0), m_submitEditorFactory(0),
m_versionControl(0),
m_changeTmpFile(0) m_changeTmpFile(0)
{ {
Q_ASSERT(m_instance == 0); Q_ASSERT(m_instance == 0);
@@ -170,6 +172,12 @@ GitPlugin::~GitPlugin()
m_submitEditorFactory = 0; m_submitEditorFactory = 0;
} }
if (m_versionControl) {
removeObject(m_versionControl);
delete m_versionControl;
m_versionControl = 0;
}
cleanChangeTmpFile(); cleanChangeTmpFile();
delete m_gitClient; delete m_gitClient;
m_instance = 0; m_instance = 0;
@@ -235,6 +243,9 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *error_message)
m_submitEditorFactory = new GitSubmitEditorFactory(&submitParameters); m_submitEditorFactory = new GitSubmitEditorFactory(&submitParameters);
addObject(m_submitEditorFactory); addObject(m_submitEditorFactory);
m_versionControl = new GitVersionControl(m_gitClient);
addObject(m_versionControl);
//register actions //register actions
Core::ActionManagerInterface *actionManager = m_core->actionManager(); Core::ActionManagerInterface *actionManager = m_core->actionManager();
@@ -245,6 +256,10 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *error_message)
actionManager->createMenu(QLatin1String("Git")); actionManager->createMenu(QLatin1String("Git"));
gitContainer->menu()->setTitle(tr("&Git")); gitContainer->menu()->setTitle(tr("&Git"));
toolsContainer->addMenu(gitContainer); 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; Core::ICommand *command;
QAction *tmpaction; QAction *tmpaction;
@@ -383,12 +398,6 @@ void GitPlugin::extensionsInitialized()
m_projectExplorer = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::ProjectExplorerPlugin>(); 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) void GitPlugin::submitEditorDiff(const QStringList &files)
{ {
if (files.empty()) if (files.empty())

View File

@@ -55,6 +55,7 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
class IEditorFactory; class IEditorFactory;
class ICore; class ICore;
class IVersionControl;
} }
namespace Git { namespace Git {
@@ -87,8 +88,6 @@ public:
~GitPlugin(); ~GitPlugin();
static GitPlugin *instance(); static GitPlugin *instance();
bool vcsOpen(const QString &fileName);
bool initialize(const QStringList &arguments bool initialize(const QStringList &arguments
, QString *error_message); , QString *error_message);
void extensionsInitialized(); void extensionsInitialized();
@@ -154,6 +153,7 @@ private:
QList<Core::IEditorFactory*> m_editorFactories; QList<Core::IEditorFactory*> m_editorFactories;
CoreListener *m_coreListener; CoreListener *m_coreListener;
Core::IEditorFactory *m_submitEditorFactory; Core::IEditorFactory *m_submitEditorFactory;
Core::IVersionControl *m_versionControl;
QString m_submitRepository; QString m_submitRepository;
QStringList m_submitOrigCommitFiles; QStringList m_submitOrigCommitFiles;
QTemporaryFile *m_changeTmpFile; QTemporaryFile *m_changeTmpFile;

View File

@@ -235,6 +235,10 @@ bool PerforcePlugin::initialize(const QStringList & /*arguments*/, QString *erro
am->createMenu(QLatin1String(PERFORCE_MENU)); am->createMenu(QLatin1String(PERFORCE_MENU));
mperforce->menu()->setTitle(tr("&Perforce")); mperforce->menu()->setTitle(tr("&Perforce"));
mtools->addMenu(mperforce); 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; QList<int> globalcontext;
globalcontext << Core::Constants::C_GLOBAL_ID; globalcontext << Core::Constants::C_GLOBAL_ID;

View File

@@ -38,10 +38,41 @@ namespace Perforce {
namespace Internal { namespace Internal {
PerforceVersionControl::PerforceVersionControl(PerforcePlugin *plugin) : PerforceVersionControl::PerforceVersionControl(PerforcePlugin *plugin) :
m_enabled(true),
m_plugin(plugin) 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) bool PerforceVersionControl::vcsOpen(const QString &fileName)
{ {
return m_plugin->vcsOpen(fileName); return m_plugin->vcsOpen(fileName);

View File

@@ -46,13 +46,25 @@ class PerforceVersionControl : public Core::IVersionControl
Q_OBJECT Q_OBJECT
public: public:
explicit PerforceVersionControl(PerforcePlugin *plugin); explicit PerforceVersionControl(PerforcePlugin *plugin);
virtual QString name() const;
virtual bool isEnabled() const;
virtual void setEnabled(bool enabled);
bool managesDirectory(const QString &directory) const; bool managesDirectory(const QString &directory) const;
virtual QString findTopLevelForDirectory(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 vcsOpen(const QString &fileName);
virtual bool vcsAdd(const QString &fileName); virtual bool vcsAdd(const QString &fileName);
virtual bool vcsDelete(const QString &filename); virtual bool vcsDelete(const QString &filename);
signals:
void enabledChanged(bool);
private: private:
bool m_enabled;
PerforcePlugin *m_plugin; PerforcePlugin *m_plugin;
}; };

View File

@@ -76,6 +76,7 @@
#include <coreplugin/welcomemode.h> #include <coreplugin/welcomemode.h>
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h> #include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
#include <utils/listutils.h> #include <utils/listutils.h>
#include <QtCore/qplugin.h> #include <QtCore/qplugin.h>
@@ -1153,6 +1154,13 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
if (projectChanged) { if (projectChanged) {
if (debug) if (debug)
qDebug() << "ProjectExplorer - currentProjectChanged(" << (project ? project->name() : "0") << ")"; 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); emit currentProjectChanged(project);
updateActions(); updateActions();
} }
@@ -1565,27 +1573,28 @@ void ProjectExplorerPlugin::addExistingFiles()
fileNames.removeOne(file); fileNames.removeOne(file);
} }
if (Core::IVersionControl *vcManager = m_core->vcsManager()->findVersionControlForDirectory(dir)) { if (Core::IVersionControl *vcManager = m_core->vcsManager()->findVersionControlForDirectory(dir))
const QString files = fileNames.join("\n"); if (vcManager->supportsOperation(Core::IVersionControl::AddOperation)) {
QMessageBox::StandardButton button = const QString files = fileNames.join(QString(QLatin1Char('\n')));
QMessageBox::StandardButton button =
QMessageBox::question(m_core->mainWindow(), tr("Add to Version Control"), 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); QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) { if (button == QMessageBox::Yes) {
QStringList notAddedToVc; QStringList notAddedToVc;
foreach (const QString file, fileNames) { foreach (const QString &file, fileNames) {
if (!vcManager->vcsAdd(file)) if (!vcManager->vcsAdd(file))
notAddedToVc << file; notAddedToVc << file;
} }
if (!notAddedToVc.isEmpty()) { if (!notAddedToVc.isEmpty()) {
const QString message = tr("Could not add following files to version control\n"); const QString message = tr("Could not add following files to version control (%1)\n").arg(vcManager->name());
const QString filesNotAdded = notAddedToVc.join("\n"); const QString filesNotAdded = notAddedToVc.join(QString(QLatin1Char('\n')));
QMessageBox::warning(m_core->mainWindow(), tr("Add files to version control failed"), QMessageBox::warning(m_core->mainWindow(), tr("Add files to version control failed"),
message + filesNotAdded); message + filesNotAdded);
}
} }
} }
}
} }
void ProjectExplorerPlugin::openFile() void ProjectExplorerPlugin::openFile()

View File

@@ -118,7 +118,11 @@ void ProjectFileWizardExtension::firstExtensionPageShown(const QList<Core::Gener
m_context->versionControl = m_core->vcsManager()->findVersionControlForDirectory(directory); m_context->versionControl = m_core->vcsManager()->findVersionControlForDirectory(directory);
m_context->page->setFilesDisplay(fileNames); 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() static ProjectNode *currentProject()

View File

@@ -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) void ProjectWizardPage::setFilesDisplay(const QStringList &files)
{ {
QString fileMessage; { QString fileMessage; {

View File

@@ -69,6 +69,7 @@ public:
bool addToVersionControl() const; bool addToVersionControl() const;
void setAddToVersionControlEnabled(bool b); void setAddToVersionControlEnabled(bool b);
void setVCSDisplay(const QString &vcsName);
void setFilesDisplay(const QStringList &files); void setFilesDisplay(const QStringList &files);
protected: protected:

View File

@@ -265,46 +265,18 @@ bool Qt4PriFileNode::changeIncludes(ProFile *includeFile, const QStringList &pro
return false; 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) bool Qt4PriFileNode::priFileWritable(const QString &path)
{ {
const QString dir = QFileInfo(path).dir().path(); const QString dir = QFileInfo(path).dir().path();
Core::IVersionControl *versionControl = m_core->vcsManager()->findVersionControlForDirectory(dir); Core::IVersionControl *versionControl = m_core->vcsManager()->findVersionControlForDirectory(dir);
switch (promptReadOnly(path, versionControl != 0, m_core->mainWindow())) { switch (Core::EditorManager::promptReadOnlyFile(path, versionControl, m_core->mainWindow(), false)) {
case RO_OpenSCC: case Core::EditorManager::RO_OpenVCS:
if (!versionControl->vcsOpen(path)) { if (!versionControl->vcsOpen(path)) {
QMessageBox::warning(m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC.")); QMessageBox::warning(m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC."));
return false; return false;
} }
break; break;
case RO_MakeWriteable: { case Core::EditorManager::RO_MakeWriteable: {
const bool permsOk = QFile::setPermissions(path, QFile::permissions(path) | QFile::WriteUser); const bool permsOk = QFile::setPermissions(path, QFile::permissions(path) | QFile::WriteUser);
if (!permsOk) { if (!permsOk) {
QMessageBox::warning(m_core->mainWindow(), tr("Failed!"), tr("Could not set permissions to writable.")); 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; break;
} }
case RO_Cancel: { case Core::EditorManager::RO_SaveAs:
case Core::EditorManager::RO_Cancel:
return false; return false;
} }
}
return true; return true;
} }
@@ -457,7 +429,8 @@ void Qt4PriFileNode::save()
if (modifiedFileHandle) if (modifiedFileHandle)
fileManager->blockFileChange(modifiedFileHandle); fileManager->blockFileChange(modifiedFileHandle);
ProWriter pw; 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_includeFile->setModified(false);
m_project->qt4ProjectManager()->notifyChanged(m_includeFile->fileName()); m_project->qt4ProjectManager()->notifyChanged(m_includeFile->fileName());
if (modifiedFileHandle) if (modifiedFileHandle)

View File

@@ -38,10 +38,43 @@ using namespace Subversion;
using namespace Subversion::Internal; using namespace Subversion::Internal;
SubversionControl::SubversionControl(SubversionPlugin *plugin) : SubversionControl::SubversionControl(SubversionPlugin *plugin) :
m_enabled(true),
m_plugin(plugin) 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 */) bool SubversionControl::vcsOpen(const QString & /* fileName */)
{ {
// Open for edit: N/A // Open for edit: N/A

View File

@@ -47,13 +47,24 @@ class SubversionControl : public Core::IVersionControl
Q_OBJECT Q_OBJECT
public: public:
explicit SubversionControl(SubversionPlugin *plugin); 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 bool managesDirectory(const QString &directory) const;
virtual QString findTopLevelForDirectory(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 vcsOpen(const QString &fileName);
virtual bool vcsAdd(const QString &fileName); virtual bool vcsAdd(const QString &fileName);
virtual bool vcsDelete(const QString &filename); virtual bool vcsDelete(const QString &filename);
signals:
void enabledChanged(bool);
private: private:
bool m_enabled;
SubversionPlugin *m_plugin; SubversionPlugin *m_plugin;
}; };

View File

@@ -276,6 +276,10 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments*/, QString *er
ami->createMenu(QLatin1String(SUBVERSION_MENU)); ami->createMenu(QLatin1String(SUBVERSION_MENU));
subversionMenu->menu()->setTitle(tr("&Subversion")); subversionMenu->menu()->setTitle(tr("&Subversion"));
toolsContainer->addMenu(subversionMenu); 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; QList<int> globalcontext;
globalcontext << m_coreInstance->uniqueIDManager()->uniqueIdentifier(C_GLOBAL); globalcontext << m_coreInstance->uniqueIDManager()->uniqueIdentifier(C_GLOBAL);