Fixes: Enable switching of VCS according to currentProject

Task: 205821
RevBy: con
Details:  Add a IVersionControl to git. Extend IF to able to return a name and add enabling options. Connect project explorer to enable the right VCS.
This commit is contained in:
Friedemann Kleint
2008-12-03 15:04:51 +01:00
parent 876c775805
commit 0b99d82d4e
21 changed files with 283 additions and 138 deletions

View File

@@ -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