Commit 267e441a authored by hjk's avatar hjk Committed by Tobias Hunger

Apply 'static' pattern to VcsManager

Adapt user and surrounding code.

Change-Id: Id2648f82a9cbbd0ad0bfb91f6958b8cee7ea29cc
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent d18b61b8
......@@ -377,7 +377,7 @@ void ReadOnlyFilesDialog::initDialog(const QStringList &fileNames)
// Add a button for opening the file with a version control system
// if the file is managed by an version control system which allows opening files.
IVersionControl *versionControlForFile =
ICore::vcsManager()->findVersionControlForDirectory(directory);
VcsManager::findVersionControlForDirectory(directory);
const bool fileManagedByVCS = versionControlForFile
&& versionControlForFile->openSupportMode() != IVersionControl::NoOpen;
if (fileManagedByVCS) {
......
......@@ -1850,7 +1850,7 @@ void EditorManager::vcsOpenCurrentEditor()
return;
const QString directory = QFileInfo(document->filePath()).absolutePath();
IVersionControl *versionControl = ICore::vcsManager()->findVersionControlForDirectory(directory);
IVersionControl *versionControl = VcsManager::findVersionControlForDirectory(directory);
if (!versionControl || versionControl->openSupportMode() == IVersionControl::NoOpen)
return;
......@@ -1912,7 +1912,7 @@ void EditorManager::updateMakeWritableWarning()
// if we do not really show a warning.
bool promptVCS = false;
const QString directory = QFileInfo(document->filePath()).absolutePath();
IVersionControl *versionControl = ICore::vcsManager()->findVersionControlForDirectory(directory);
IVersionControl *versionControl = VcsManager::findVersionControlForDirectory(directory);
if (versionControl && versionControl->openSupportMode() != IVersionControl::NoOpen) {
if (versionControl->settingsFlags() & IVersionControl::AutoOpen) {
vcsOpenCurrentEditor();
......
......@@ -159,7 +159,7 @@ QString FileUtils::msgTerminalAction()
void FileUtils::removeFile(const QString &filePath, bool deleteFromFS)
{
// remove from version control
ICore::vcsManager()->promptToDelete(filePath);
VcsManager::promptToDelete(filePath);
// remove from file system
if (deleteFromFS) {
......@@ -194,7 +194,7 @@ bool FileUtils::renameFile(const QString &orgFilePath, const QString &newFilePat
return false;
QString dir = QFileInfo(orgFilePath).absolutePath();
IVersionControl *vc = ICore::vcsManager()->findVersionControlForDirectory(dir);
IVersionControl *vc = VcsManager::findVersionControlForDirectory(dir);
bool result = false;
if (vc && vc->supportsOperation(IVersionControl::MoveOperation))
......
......@@ -349,11 +349,6 @@ bool ICore::showWarningWithOptions(const QString &title, const QString &text,
settingsId, parent);
}
VcsManager *ICore::vcsManager()
{
return m_mainwindow->vcsManager();
}
QSettings *ICore::settings(QSettings::Scope scope)
{
return m_mainwindow->settings(scope);
......
......@@ -80,8 +80,6 @@ public:
Id settingsId = Id(),
QWidget *parent = 0);
static VcsManager *vcsManager();
static QSettings *settings(QSettings::Scope scope = QSettings::UserScope);
static SettingsDatabase *settingsDatabase();
static QPrinter *printer();
......
......@@ -178,11 +178,13 @@ public:
IVersionControl *m_unconfiguredVcs;
};
static VcsManagerPrivate *d;
static VcsManagerPrivate *d = 0;
static VcsManager *m_instance = 0;
VcsManager::VcsManager(QObject *parent) :
QObject(parent)
{
m_instance = this;
d = new VcsManagerPrivate;
}
......@@ -190,9 +192,15 @@ VcsManager::VcsManager(QObject *parent) :
VcsManager::~VcsManager()
{
m_instance = 0;
delete d;
}
QObject *VcsManager::instance()
{
return m_instance;
}
void VcsManager::extensionsInitialized()
{
// Change signal connections
......@@ -200,7 +208,7 @@ void VcsManager::extensionsInitialized()
connect(versionControl, SIGNAL(filesChanged(QStringList)),
DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)));
connect(versionControl, SIGNAL(repositoryChanged(QString)),
this, SIGNAL(repositoryChanged(QString)));
m_instance, SIGNAL(repositoryChanged(QString)));
}
}
......@@ -217,7 +225,7 @@ void VcsManager::resetVersionControlForDirectory(const QString &inputDirectory)
const QString directory = QDir(inputDirectory).absolutePath();
d->resetCache(directory);
emit repositoryChanged(directory);
emit m_instance->repositoryChanged(directory);
}
IVersionControl* VcsManager::findVersionControlForDirectory(const QString &inputDirectory,
......@@ -295,7 +303,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
.arg(versionControl->displayName()),
InfoBarEntry::GlobalSuppressionEnabled);
d->m_unconfiguredVcs = versionControl;
info.setCustomButtonInfo(tr("Configure"), this, SLOT(configureVcs()));
info.setCustomButtonInfo(tr("Configure"), m_instance, SLOT(configureVcs()));
infoBar->addInfo(info);
}
return 0;
......@@ -304,7 +312,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
return versionControl;
}
QStringList VcsManager::repositories(const IVersionControl *vc) const
QStringList VcsManager::repositories(const IVersionControl *vc)
{
QStringList result;
foreach (const VcsManagerPrivate::VcsInfo *vi, d->m_vcsInfoList)
......@@ -422,7 +430,7 @@ void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNa
void VcsManager::emitRepositoryChanged(const QString &repository)
{
emit repositoryChanged(repository);
emit m_instance->repositoryChanged(repository);
}
void VcsManager::clearVersionControlCache()
......@@ -430,7 +438,7 @@ void VcsManager::clearVersionControlCache()
QStringList repoList = d->m_cachedMatches.keys();
d->clearCache();
foreach (const QString &repo, repoList)
emit repositoryChanged(repo);
emit m_instance->repositoryChanged(repo);
}
void VcsManager::configureVcs()
......
......@@ -58,33 +58,35 @@ class CORE_EXPORT VcsManager : public QObject
Q_OBJECT
public:
void extensionsInitialized();
static QObject *instance();
void resetVersionControlForDirectory(const QString &inputDirectory);
IVersionControl *findVersionControlForDirectory(const QString &directory,
static void extensionsInitialized();
static void resetVersionControlForDirectory(const QString &inputDirectory);
static IVersionControl *findVersionControlForDirectory(const QString &directory,
QString *topLevelDirectory = 0);
QStringList repositories(const IVersionControl *) const;
static QStringList repositories(const IVersionControl *);
IVersionControl *checkout(const QString &versionControlType,
static IVersionControl *checkout(const QString &versionControlType,
const QString &directory,
const QByteArray &url);
// Used only by Trac plugin.
bool findVersionControl(const QString &versionControl);
// Used only by Trac plugin.
QString repositoryUrl(const QString &directory);
static QString repositoryUrl(const QString &directory);
// Shows a confirmation dialog, whether the file should also be deleted
// from revision control. Calls vcsDelete on the file. Returns false
// if a failure occurs
bool promptToDelete(const QString &fileName);
bool promptToDelete(IVersionControl *versionControl, const QString &fileName);
static bool promptToDelete(const QString &fileName);
static bool promptToDelete(IVersionControl *versionControl, const QString &fileName);
// Shows a confirmation dialog, whether the files in the list should be
// added to revision control. Calls vcsAdd for each file.
void promptToAdd(const QString &directory, const QStringList &fileNames);
static void promptToAdd(const QString &directory, const QStringList &fileNames);
void emitRepositoryChanged(const QString &repository);
static void emitRepositoryChanged(const QString &repository);
// Utility messages for adding files
static QString msgAddToVcsTitle();
......@@ -96,14 +98,14 @@ signals:
void repositoryChanged(const QString &repository);
public slots:
void clearVersionControlCache();
static void clearVersionControlCache();
private slots:
void configureVcs();
static void configureVcs();
private:
explicit VcsManager(QObject *parent = 0);
virtual ~VcsManager();
~VcsManager();
friend class Core::Internal::MainWindow;
};
......
......@@ -97,8 +97,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
// Objects
CppModelManager *modelManager = CppModelManager::instance();
VcsManager *vcsManager = ICore::vcsManager();
connect(vcsManager, SIGNAL(repositoryChanged(QString)),
connect(VcsManager::instance(), SIGNAL(repositoryChanged(QString)),
modelManager, SLOT(updateModifiedSourceFiles()));
connect(DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
modelManager, SLOT(updateSourceFiles(QStringList)));
......
......@@ -512,8 +512,7 @@ void GerritPlugin::fetch(const QSharedPointer<Gerrit::Internal::GerritChange> &c
// Try to find a matching repository for a project by asking the VcsManager.
QString GerritPlugin::findLocalRepository(QString project, const QString &branch) const
{
const Core::VcsManager *vcsManager = ICore::instance()->vcsManager();
const QStringList gitRepositories = vcsManager->repositories(Git::Internal::GitPlugin::instance()->gitVersionControl());
const QStringList gitRepositories = VcsManager::repositories(Git::Internal::GitPlugin::instance()->gitVersionControl());
// Determine key (file name) to look for (qt/qtbase->'qtbase').
const int slashPos = project.lastIndexOf(QLatin1Char('/'));
if (slashPos != -1)
......
......@@ -1714,7 +1714,7 @@ bool GitClient::synchronousInit(const QString &workingDirectory)
outputWindow()->appendError(commandOutputFromLocal8Bit(errorText));
} else {
// TODO: Turn this into a VcsBaseClient and use resetCachedVcsInfo(...)
Core::ICore::vcsManager()->resetVersionControlForDirectory(workingDirectory);
Core::VcsManager::resetVersionControlForDirectory(workingDirectory);
}
return rc;
}
......@@ -3760,7 +3760,7 @@ bool GitClient::cloneRepository(const QString &directory,const QByteArray &url)
const Utils::SynchronousProcessResponse resp =
synchronousGit(workingDirectory.path(), arguments, flags);
// TODO: Turn this into a VcsBaseClient and use resetCachedVcsInfo(...)
Core::ICore::vcsManager()->resetVersionControlForDirectory(workingDirectory.absolutePath());
Core::VcsManager::resetVersionControlForDirectory(workingDirectory.absolutePath());
return (resp.result == Utils::SynchronousProcessResponse::Finished);
}
}
......
......@@ -697,9 +697,9 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
m_redoAction = new QAction(tr("&Redo"), this);
command = Core::ActionManager::registerAction(m_redoAction, Core::Constants::REDO, submitContext);
connect(Core::ICore::vcsManager(), SIGNAL(repositoryChanged(QString)),
connect(Core::VcsManager::instance(), SIGNAL(repositoryChanged(QString)),
this, SLOT(updateContinueAndAbortCommands()));
connect(Core::ICore::vcsManager(), SIGNAL(repositoryChanged(QString)),
connect(Core::VcsManager::instance(), SIGNAL(repositoryChanged(QString)),
this, SLOT(updateBranches(QString)), Qt::QueuedConnection);
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(RC_GIT_MIME_XML), errorMessage))
......
......@@ -1761,7 +1761,7 @@ void ProjectExplorerPlugin::updateExternalFileWarning()
return;
// External file. Test if it under the same VCS
QString topLevel;
if (Core::ICore::vcsManager()->findVersionControlForDirectory(projectDir.toString(), &topLevel)
if (Core::VcsManager::findVersionControlForDirectory(projectDir.toString(), &topLevel)
&& fileName.isChildOf(Utils::FileName::fromString(topLevel))) {
return;
}
......@@ -2841,7 +2841,7 @@ void ProjectExplorerPlugin::addExistingFiles(ProjectNode *projectNode, const QSt
fileNames.removeOne(file);
}
Core::ICore::vcsManager()->promptToAdd(dir, fileNames);
Core::VcsManager::promptToAdd(dir, fileNames);
}
void ProjectExplorerPlugin::removeProject()
......@@ -2929,7 +2929,7 @@ void ProjectExplorerPlugin::deleteFile()
Core::DocumentManager::expectFileChange(filePath);
if (Core::IVersionControl *vc =
Core::ICore::vcsManager()->findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) {
Core::VcsManager::findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) {
vc->vcsDelete(filePath);
}
QFile file(filePath);
......
......@@ -349,7 +349,7 @@ void ProjectFileWizardExtension::initializeVersionControlChoices()
QStringList versionControlChoices = QStringList(tr("<None>"));
if (!m_context->commonDirectory.isEmpty()) {
Core::IVersionControl *managingControl = Core::ICore::vcsManager()->findVersionControlForDirectory(m_context->commonDirectory);
Core::IVersionControl *managingControl = Core::VcsManager::findVersionControlForDirectory(m_context->commonDirectory);
if (managingControl) {
// Under VCS
if (managingControl->supportsOperation(Core::IVersionControl::AddOperation)) {
......
......@@ -348,11 +348,12 @@ ProjectNode::ProjectNode(const QString &projectFilePath)
setDisplayName(QFileInfo(projectFilePath).fileName());
}
QString ProjectNode::vcsTopic() const {
QString ProjectNode::vcsTopic() const
{
const QString dir = QFileInfo(path()).absolutePath();
if (Core::IVersionControl *const vc =
Core::ICore::vcsManager()->findVersionControlForDirectory(dir))
Core::VcsManager::findVersionControlForDirectory(dir))
return vc->vcsTopic(dir);
return QString();
......
......@@ -31,33 +31,35 @@
#include "task.h"
#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
#include <utils/qtcassert.h>
#include <QAction>
#include <QFileInfo>
#include <QAction>
using namespace Core;
using namespace ProjectExplorer::Internal;
namespace ProjectExplorer {
namespace Internal {
bool VcsAnnotateTaskHandler::canHandle(const ProjectExplorer::Task &task) const
bool VcsAnnotateTaskHandler::canHandle(const Task &task) const
{
QFileInfo fi(task.file.toFileInfo());
if (!fi.exists() || !fi.isFile() || !fi.isReadable())
return false;
Core::IVersionControl *vc = Core::ICore::vcsManager()->findVersionControlForDirectory(fi.absolutePath());
IVersionControl *vc = VcsManager::findVersionControlForDirectory(fi.absolutePath());
if (!vc)
return false;
return vc->supportsOperation(Core::IVersionControl::AnnotateOperation);
return vc->supportsOperation(IVersionControl::AnnotateOperation);
}
void VcsAnnotateTaskHandler::handle(const ProjectExplorer::Task &task)
void VcsAnnotateTaskHandler::handle(const Task &task)
{
QFileInfo fi(task.file.toFileInfo());
Core::IVersionControl *vc = Core::ICore::vcsManager()->findVersionControlForDirectory(fi.absolutePath());
Q_ASSERT(vc);
Q_ASSERT(vc->supportsOperation(Core::IVersionControl::AnnotateOperation));
IVersionControl *vc = VcsManager::findVersionControlForDirectory(fi.absolutePath());
QTC_ASSERT(vc, return);
QTC_ASSERT(vc->supportsOperation(IVersionControl::AnnotateOperation), return);
vc->vcsAnnotate(fi.absoluteFilePath(), task.movedLine);
}
......@@ -67,3 +69,6 @@ QAction *VcsAnnotateTaskHandler::createAction(QObject *parent) const
vcsannotateAction->setToolTip(tr("Annotate using version control system"));
return vcsannotateAction;
}
} // namespace Internal
} // namespace ProjectExplorer
......@@ -108,7 +108,7 @@ public:
if (!refactoring.createFile(newFileName, txt))
return;
Core::IVersionControl *versionControl = Core::ICore::vcsManager()->findVersionControlForDirectory(path);
Core::IVersionControl *versionControl = Core::VcsManager::findVersionControlForDirectory(path);
if (versionControl
&& versionControl->supportsOperation(Core::IVersionControl::AddOperation)) {
const QMessageBox::StandardButton button =
......
......@@ -1117,8 +1117,7 @@ void Qt4PriFileNode::changeFiles(const QString &mimeType,
QFileInfo fi(m_projectFilePath);
if (!fi.isWritable()) {
// Try via vcs manager
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
Core::IVersionControl *versionControl = vcsManager->findVersionControlForDirectory(fi.absolutePath());
Core::IVersionControl *versionControl = Core::VcsManager::findVersionControlForDirectory(fi.absolutePath());
if (!versionControl || versionControl->vcsOpen(m_projectFilePath)) {
bool makeWritable = QFile::setPermissions(m_projectFilePath, fi.permissions() | QFile::WriteUser);
if (!makeWritable) {
......
......@@ -968,8 +968,7 @@ void ResourceModel::addFiles(int prefixIndex, const QStringList &fileNames, int
firstFile = cnt;
lastFile = cnt + unique_list.count() - 1;
Core::ICore::vcsManager()->promptToAdd(QFileInfo(m_resource_file.fileName()).absolutePath(),
fileNames);
Core::VcsManager::promptToAdd(QFileInfo(m_resource_file.fileName()).absolutePath(), fileNames);
}
......
......@@ -405,7 +405,7 @@ Utils::SynchronousProcessResponse Command::runVcs(const QStringList &arguments,
if (d->m_flags & VcsBasePlugin::ExpectRepoChanges) {
// TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
Core::ICore::vcsManager()->emitRepositoryChanged(d->m_workingDirectory);
Core::VcsManager::emitRepositoryChanged(d->m_workingDirectory);
}
return response;
......@@ -515,7 +515,7 @@ bool Command::runFullySynchronous(const QStringList &arguments, int timeoutMS,
if (d->m_flags & VcsBasePlugin::ExpectRepoChanges) {
// TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(workingDirectory);
Core::ICore::vcsManager()->emitRepositoryChanged(d->m_workingDirectory);
Core::VcsManager::emitRepositoryChanged(d->m_workingDirectory);
}
return process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0;
......
......@@ -613,7 +613,7 @@ void VcsBaseClient::enqueueJob(Command *cmd, const QStringList &args)
void VcsBaseClient::resetCachedVcsInfo(const QString &workingDir)
{
Core::ICore::vcsManager()->resetVersionControlForDirectory(workingDir);
Core::VcsManager::resetVersionControlForDirectory(workingDir);
}
} // namespace VcsBase
......
......@@ -1366,8 +1366,7 @@ QString VcsBaseEditorWidget::findDiffFile(const QString &f) const
return sourceFileInfo.absoluteFilePath();
QString topLevel;
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
vcsManager->findVersionControlForDirectory(sourceDir, &topLevel); //
Core::VcsManager::findVersionControlForDirectory(sourceDir, &topLevel); //
if (topLevel.isEmpty())
return QString();
......
......@@ -210,7 +210,7 @@ StateListener::StateListener(QObject *parent) :
this, SLOT(slotStateChanged()));
connect(Core::EditorManager::instance(), SIGNAL(currentDocumentStateChanged()),
this, SLOT(slotStateChanged()));
connect(Core::ICore::vcsManager(), SIGNAL(repositoryChanged(QString)),
connect(Core::VcsManager::instance(), SIGNAL(repositoryChanged(QString)),
this, SLOT(slotStateChanged()));
if (ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance())
......@@ -228,8 +228,6 @@ static inline QString displayNameOfEditor(const QString &fileName)
void StateListener::slotStateChanged()
{
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
// Get the current file. Are we on a temporary submit editor indicated by
// temporary path prefix or does the file contains a hash, indicating a project
// folder?
......@@ -280,7 +278,7 @@ void StateListener::slotStateChanged()
currentFileInfo->isDir() ? currentFileInfo->absoluteFilePath() :
currentFileInfo->absolutePath();
state.currentFileName = currentFileInfo->fileName();
fileControl = vcsManager->findVersionControlForDirectory(state.currentFileDirectory,
fileControl = Core::VcsManager::findVersionControlForDirectory(state.currentFileDirectory,
&state.currentFileTopLevel);
if (!fileControl)
state.clearFile();
......@@ -290,7 +288,7 @@ void StateListener::slotStateChanged()
if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
state.currentProjectPath = currentProject->projectDirectory();
state.currentProjectName = currentProject->displayName();
projectControl = vcsManager->findVersionControlForDirectory(state.currentProjectPath,
projectControl = Core::VcsManager::findVersionControlForDirectory(state.currentProjectPath,
&state.currentProjectTopLevel);
if (projectControl) {
// If we have both, let the file's one take preference
......@@ -561,7 +559,7 @@ void VcsBasePlugin::initializeVcs(Core::IVersionControl *vc)
SLOT(slotStateChanged(VcsBase::Internal::State,Core::IVersionControl*)));
// VCSes might have become (un-)available, so clear the VCS directory cache
connect(vc, SIGNAL(configurationChanged()),
Core::ICore::vcsManager(), SLOT(clearVersionControlCache()));
Core::VcsManager::instance(), SLOT(clearVersionControlCache()));
connect(vc, SIGNAL(configurationChanged()),
VcsBasePluginPrivate::m_listener, SLOT(slotStateChanged()));
}
......@@ -639,7 +637,7 @@ void VcsBasePlugin::promptToDeleteCurrentFile()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return);
const bool rc = Core::ICore::vcsManager()->promptToDelete(versionControl(), state.currentFile());
const bool rc = Core::VcsManager::promptToDelete(versionControl(), state.currentFile());
if (!rc)
QMessageBox::warning(0, tr("Version Control"),
tr("The file '%1' could not be deleted.").
......@@ -667,7 +665,7 @@ void VcsBasePlugin::createRepository()
directory = QFileDialog::getExistingDirectory(mw, tr("Choose Repository Directory"), directory);
if (directory.isEmpty())
return;
const Core::IVersionControl *managingControl = Core::ICore::vcsManager()->findVersionControlForDirectory(directory);
const Core::IVersionControl *managingControl = Core::VcsManager::findVersionControlForDirectory(directory);
if (managingControl == 0)
break;
const QString question = tr("The directory '%1' is already managed by a version control system (%2)."
......
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