Commit 728579ef authored by Konstantin Tokarev's avatar Konstantin Tokarev Committed by Tobias Hunger

Added VCS integration to ResourceEditor.

Made add and remove operations of ResourceEditor VCS-aware. Also, remove
operation now can remove files from filesystem.

FileUtils::removeFile() and VcsManager::promptToAdd functions were
extracted from ProjectExplorer to prevent code duplication.
RemoveFileDialog was also moved to coreplugin.

Change-Id: Ia51127288030e52ce9475b369e56ea034dfa5d1e
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent bd7499b8
......@@ -97,7 +97,8 @@ SOURCES += mainwindow.cpp \
featureprovider.cpp \
idocument.cpp \
textdocument.cpp \
documentmanager.cpp
documentmanager.cpp \
removefiledialog.cpp
HEADERS += mainwindow.h \
editmode.h \
......@@ -194,7 +195,8 @@ HEADERS += mainwindow.h \
idocument.h \
idocumentfactory.h \
textdocument.h \
documentmanager.h
documentmanager.h \
removefiledialog.h
FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \
......@@ -205,7 +207,8 @@ FORMS += dialogs/newdialog.ui \
dialogs/externaltoolconfig.ui \
variablechooser.ui \
mimetypesettingspage.ui \
mimetypemagicdialog.ui
mimetypemagicdialog.ui \
removefiledialog.ui
RESOURCES += core.qrc \
fancyactionbar.qrc
......
......@@ -122,6 +122,9 @@ QtcPlugin {
"outputwindow.h",
"plugindialog.cpp",
"plugindialog.h",
"removefiledialog.cpp",
"removefiledialog.h",
"removefiledialog.ui",
"rightpane.cpp",
"rightpane.h",
"settingsdatabase.cpp",
......
......@@ -33,6 +33,7 @@
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/removefiledialog.h>
#include <coreplugin/vcsmanager.h>
#include <utils/environment.h>
......@@ -171,6 +172,25 @@ QString FileUtils::msgTerminalAction()
#endif
}
void FileUtils::removeFile(const QString &filePath, bool deleteFromFS)
{
// remove from version control
ICore::vcsManager()->promptToDelete(filePath);
// remove from file system
if (deleteFromFS) {
QFile file(filePath);
if (file.exists()) {
// could have been deleted by vc
if (!file.remove())
QMessageBox::warning(ICore::mainWindow(),
QApplication::translate("Core::Internal", "Deleting File Failed"),
QApplication::translate("Core::Internal", "Could not delete file %1.").arg(filePath));
}
}
}
static inline bool fileSystemRenameFile(const QString &orgFilePath,
const QString &newFilePath)
{
......
......@@ -47,7 +47,8 @@ struct CORE_EXPORT FileUtils
// Platform-dependent action descriptions
static QString msgGraphicalShellAction();
static QString msgTerminalAction();
// File rename aware of version control and file system case-insensitiveness
// File operations aware of version control and file system case-insensitiveness
static void removeFile(const QString &filePath, bool deleteFromFS);
static bool renameFile(const QString &from, const QString &to);
};
......
......@@ -33,7 +33,7 @@
#include <QDir>
using namespace ProjectExplorer::Internal;
using namespace Core;
RemoveFileDialog::RemoveFileDialog(const QString &filePath, QWidget *parent) :
QDialog(parent),
......
......@@ -31,16 +31,17 @@
#ifndef REMOVEFILEDIALOG_H
#define REMOVEFILEDIALOG_H
#include "core_global.h"
#include <QDialog>
namespace ProjectExplorer {
namespace Internal {
namespace Core {
namespace Ui {
class RemoveFileDialog;
}
class RemoveFileDialog : public QDialog
class CORE_EXPORT RemoveFileDialog : public QDialog
{
Q_OBJECT
......@@ -58,7 +59,6 @@ private:
Ui::RemoveFileDialog *m_ui;
};
} // namespace Internal
} // namespace ProjectExplorer
} // namespace Core
#endif // REMOVEFILEDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectExplorer::Internal::RemoveFileDialog</class>
<widget class="QDialog" name="ProjectExplorer::Internal::RemoveFileDialog">
<class>Core::RemoveFileDialog</class>
<widget class="QDialog" name="Core::RemoveFileDialog">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -41,6 +41,9 @@
<property name="text">
<string notr="true">placeholder</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
......@@ -96,7 +99,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ProjectExplorer::Internal::RemoveFileDialog</receiver>
<receiver>Core::RemoveFileDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
......@@ -112,7 +115,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ProjectExplorer::Internal::RemoveFileDialog</receiver>
<receiver>Core::RemoveFileDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
......
......@@ -326,4 +326,31 @@ bool VcsManager::promptToDelete(IVersionControl *vc, const QString &fileName)
return vc->vcsDelete(fileName);
}
void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNames)
{
IVersionControl *vc = findVersionControlForDirectory(directory);
if (!vc || !vc->supportsOperation(Core::IVersionControl::AddOperation))
return;
const QString files = fileNames.join(QString(QLatin1Char('\n')));
QMessageBox::StandardButton button =
QMessageBox::question(Core::ICore::mainWindow(), tr("Add to Version Control"),
tr("Add files\n%1\nto version control (%2)?").arg(files, vc->displayName()),
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) {
QStringList notAddedToVc;
foreach (const QString &file, fileNames) {
if (!vc->vcsAdd(file))
notAddedToVc << file;
}
if (!notAddedToVc.isEmpty()) {
const QString message = tr("Could not add following files to version control (%1)\n").arg(vc->displayName());
const QString filesNotAdded = notAddedToVc.join(QString(QLatin1Char('\n')));
QMessageBox::warning(Core::ICore::mainWindow(), tr("Adding to Version Control Failed"),
message + filesNotAdded);
}
}
}
} // namespace Core
......@@ -78,11 +78,15 @@ public:
QString repositoryUrl(const QString &directory);
// Shows a confirmation dialog, whether the file should also be deleted
// from revision control Calls sccDelete on the file. Returns false
// 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);
// 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);
signals:
void repositoryChanged(const QString &repository);
......
......@@ -67,7 +67,6 @@
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "removefiledialog.h"
#include "runsettingspropertiespage.h"
#include "session.h"
#include "projectnodes.h"
......@@ -111,6 +110,7 @@
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/variablemanager.h>
#include <coreplugin/fileutils.h>
#include <coreplugin/removefiledialog.h>
#include <extensionsystem/pluginmanager.h>
#include <find/searchresultwindow.h>
#include <utils/consoleprocess.h>
......@@ -2668,28 +2668,7 @@ void ProjectExplorerPlugin::addExistingFiles(ProjectNode *projectNode, const QSt
fileNames.removeOne(file);
}
if (Core::IVersionControl *vcManager = Core::ICore::vcsManager()->findVersionControlForDirectory(dir))
if (vcManager->supportsOperation(Core::IVersionControl::AddOperation)) {
const QString files = fileNames.join(QString(QLatin1Char('\n')));
QMessageBox::StandardButton button =
QMessageBox::question(Core::ICore::mainWindow(), tr("Add to Version Control"),
tr("Add files\n%1\nto version control (%2)?").arg(files, vcManager->displayName()),
QMessageBox::Yes | QMessageBox::No);
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 (%1)\n").arg(vcManager->displayName());
const QString filesNotAdded = notAddedToVc.join(QString(QLatin1Char('\n')));
QMessageBox::warning(Core::ICore::mainWindow(), tr("Adding to Version Control Failed"),
message + filesNotAdded);
}
}
}
Core::ICore::vcsManager()->promptToAdd(dir, fileNames);
}
void ProjectExplorerPlugin::removeProject()
......@@ -2697,7 +2676,7 @@ void ProjectExplorerPlugin::removeProject()
ProjectNode *subProjectNode = qobject_cast<ProjectNode*>(d->m_currentNode->projectNode());
ProjectNode *projectNode = qobject_cast<ProjectNode *>(subProjectNode->parentFolderNode());
if (projectNode) {
RemoveFileDialog removeFileDialog(subProjectNode->path(), Core::ICore::mainWindow());
Core::RemoveFileDialog removeFileDialog(subProjectNode->path(), Core::ICore::mainWindow());
removeFileDialog.setDeleteFileVisible(false);
if (removeFileDialog.exec() == QDialog::Accepted)
projectNode->removeSubProjects(QStringList() << subProjectNode->path());
......@@ -2736,7 +2715,7 @@ void ProjectExplorerPlugin::removeFile()
FileNode *fileNode = qobject_cast<FileNode*>(d->m_currentNode);
QString filePath = d->m_currentNode->path();
RemoveFileDialog removeFileDialog(filePath, Core::ICore::mainWindow());
Core::RemoveFileDialog removeFileDialog(filePath, Core::ICore::mainWindow());
if (removeFileDialog.exec() == QDialog::Accepted) {
const bool deleteFile = removeFileDialog.isDeleteFileChecked();
......@@ -2751,20 +2730,7 @@ void ProjectExplorerPlugin::removeFile()
return;
}
// remove from version control
Core::ICore::vcsManager()->promptToDelete(filePath);
// remove from file system
if (deleteFile) {
QFile file(filePath);
if (file.exists()) {
// could have been deleted by vc
if (!file.remove())
QMessageBox::warning(Core::ICore::mainWindow(), tr("Deleting File Failed"),
tr("Could not delete file %1.").arg(filePath));
}
}
Core::FileUtils::removeFile(filePath, deleteFile);
}
}
......
......@@ -79,7 +79,6 @@ HEADERS += projectexplorer.h \
sessiondialog.h \
projectwizardpage.h \
buildstepspage.h \
removefiledialog.h \
nodesvisitor.h \
projectmodels.h \
currentprojectfind.h \
......@@ -184,7 +183,6 @@ SOURCES += projectexplorer.cpp \
sessiondialog.cpp \
projectwizardpage.cpp \
buildstepspage.cpp \
removefiledialog.cpp \
nodesvisitor.cpp \
projectmodels.cpp \
currentprojectfind.cpp \
......@@ -229,7 +227,6 @@ FORMS += processstep.ui \
editorsettingspropertiespage.ui \
sessiondialog.ui \
projectwizardpage.ui \
removefiledialog.ui \
projectexplorersettingspage.ui \
targetsettingswidget.ui \
doubletabwidget.ui \
......
......@@ -27,7 +27,6 @@ QtcPlugin {
"doubletabwidget.ui",
"processstep.ui",
"projectexplorer.qrc",
"removefiledialog.ui",
"sessiondialog.ui",
"targetsettingswidget.ui",
"projectwizardpage.ui",
......@@ -142,8 +141,6 @@ QtcPlugin {
"projectwindow.cpp",
"projectwindow.h",
"projectwizardpage.h",
"removefiledialog.cpp",
"removefiledialog.h",
"runconfigurationmodel.cpp",
"runconfigurationmodel.h",
"runsettingspropertiespage.cpp",
......
......@@ -32,6 +32,8 @@
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/fileutils.h>
#include <coreplugin/icore.h>
#include <coreplugin/vcsmanager.h>
#include <utils/fileutils.h>
#include <QCoreApplication>
......@@ -981,6 +983,9 @@ 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);
}
......
......@@ -32,6 +32,10 @@
#include "undocommands_p.h"
#include <coreplugin/fileutils.h>
#include <coreplugin/icore.h>
#include <coreplugin/removefiledialog.h>
#include <QDebug>
#include <QAction>
......@@ -165,8 +169,17 @@ EntryBackup * RelativeResourceModel::removeEntry(const QModelIndex &index)
} else {
const QString fileNameBackup = file(index);
const QString aliasBackup = alias(index);
deleteItem(index);
return new FileEntryBackup(*this, prefixIndex.row(), index.row(), fileNameBackup, aliasBackup);
if (!QFile::exists(fileNameBackup)) {
deleteItem(index);
return new FileEntryBackup(*this, prefixIndex.row(), index.row(), fileNameBackup, aliasBackup);
}
Core::RemoveFileDialog removeFileDialog(fileNameBackup, Core::ICore::mainWindow());
if (removeFileDialog.exec() == QDialog::Accepted) {
deleteItem(index);
Core::FileUtils::removeFile(fileNameBackup, removeFileDialog.isDeleteFileChecked());
return new FileEntryBackup(*this, prefixIndex.row(), index.row(), fileNameBackup, aliasBackup);
}
return 0;
}
}
......
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