Implemented file rename in ResourceEditor.

Renaming supports version control.

To prevent code duplication part of ProjectExplorerPlugin::renameFile
implementation was separated into FileUtils::renameFile.

Change-Id: I28481bea89d0824339e5db025ceb7216713bd5a0
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Konstantin Tokarev
2012-05-24 23:04:29 +04:00
committed by Eike Ziller
parent bb66e54626
commit eef043e055
10 changed files with 162 additions and 40 deletions

View File

@@ -32,6 +32,9 @@
#include "fileutils.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
#include <utils/environment.h>
#include <QDir>
@@ -41,6 +44,10 @@
#include <QMessageBox>
#include <QWidget>
#if QT_VERSION < 0x050000
#include <QAbstractFileEngine>
#endif
#ifndef Q_OS_WIN
#include <coreplugin/icore.h>
#include <utils/consoleprocess.h>
@@ -165,3 +172,35 @@ QString FileUtils::msgTerminalAction()
return QApplication::translate("Core::Internal", "Open Terminal Here");
#endif
}
static inline bool fileSystemRenameFile(const QString &orgFilePath,
const QString &newFilePath)
{
#if QT_VERSION < 0x050000 // ### fixme: QTBUG-3570 might be fixed in Qt 5?
QFile f(orgFilePath); // Due to QTBUG-3570
QAbstractFileEngine *fileEngine = f.fileEngine();
if (!fileEngine->caseSensitive() && orgFilePath.compare(newFilePath, Qt::CaseInsensitive) == 0)
return fileEngine->rename(newFilePath);
#endif
return QFile::rename(orgFilePath, newFilePath);
}
bool FileUtils::renameFile(const QString &orgFilePath, const QString &newFilePath)
{
if (orgFilePath == newFilePath)
return false;
QString dir = QFileInfo(orgFilePath).absolutePath();
Core::IVersionControl *vc = Core::ICore::vcsManager()->findVersionControlForDirectory(dir);
bool result = false;
if (vc && vc->supportsOperation(Core::IVersionControl::MoveOperation))
result = vc->vcsMove(orgFilePath, newFilePath);
if (!result) // The moving via vcs failed or the vcs does not support moving, fall back
result = fileSystemRenameFile(orgFilePath, newFilePath);
if (result) {
// yeah we moved, tell the filemanager about it
Core::DocumentManager::renamedFile(orgFilePath, newFilePath);
}
return result;
}