summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2012-07-18 13:41:13 +0400
committerTobias Hunger <tobias.hunger@nokia.com>2012-07-19 22:26:47 +0200
commit728579ef52aee2bfa1e08f1badd91c7787576b09 (patch)
treefb90afcc3ef587148540d596c056b28be739ccdb
parentbd7499b896359ff70f26dbf183ea99f6990bfa11 (diff)
downloadqt-creator-728579ef52aee2bfa1e08f1badd91c7787576b09.tar.gz
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 <orgads@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
-rw-r--r--src/plugins/coreplugin/coreplugin.pro9
-rw-r--r--src/plugins/coreplugin/coreplugin.qbs3
-rw-r--r--src/plugins/coreplugin/fileutils.cpp20
-rw-r--r--src/plugins/coreplugin/fileutils.h3
-rw-r--r--src/plugins/coreplugin/removefiledialog.cpp (renamed from src/plugins/projectexplorer/removefiledialog.cpp)2
-rw-r--r--src/plugins/coreplugin/removefiledialog.h (renamed from src/plugins/projectexplorer/removefiledialog.h)10
-rw-r--r--src/plugins/coreplugin/removefiledialog.ui (renamed from src/plugins/projectexplorer/removefiledialog.ui)11
-rw-r--r--src/plugins/coreplugin/vcsmanager.cpp27
-rw-r--r--src/plugins/coreplugin/vcsmanager.h6
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp44
-rw-r--r--src/plugins/projectexplorer/projectexplorer.pro3
-rw-r--r--src/plugins/projectexplorer/projectexplorer.qbs3
-rw-r--r--src/plugins/resourceeditor/qrceditor/resourcefile.cpp5
-rw-r--r--src/plugins/resourceeditor/qrceditor/resourceview.cpp17
14 files changed, 101 insertions, 62 deletions
diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro
index a34a01d88f..0c5642f97f 100644
--- a/src/plugins/coreplugin/coreplugin.pro
+++ b/src/plugins/coreplugin/coreplugin.pro
@@ -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
diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs
index ee0a0baaca..e916974ba8 100644
--- a/src/plugins/coreplugin/coreplugin.qbs
+++ b/src/plugins/coreplugin/coreplugin.qbs
@@ -122,6 +122,9 @@ QtcPlugin {
"outputwindow.h",
"plugindialog.cpp",
"plugindialog.h",
+ "removefiledialog.cpp",
+ "removefiledialog.h",
+ "removefiledialog.ui",
"rightpane.cpp",
"rightpane.h",
"settingsdatabase.cpp",
diff --git a/src/plugins/coreplugin/fileutils.cpp b/src/plugins/coreplugin/fileutils.cpp
index 4f0ce9aaf3..ab6d384109 100644
--- a/src/plugins/coreplugin/fileutils.cpp
+++ b/src/plugins/coreplugin/fileutils.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)
{
diff --git a/src/plugins/coreplugin/fileutils.h b/src/plugins/coreplugin/fileutils.h
index fdb62abe70..33e6e010b4 100644
--- a/src/plugins/coreplugin/fileutils.h
+++ b/src/plugins/coreplugin/fileutils.h
@@ -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);
};
diff --git a/src/plugins/projectexplorer/removefiledialog.cpp b/src/plugins/coreplugin/removefiledialog.cpp
index 1c45f8ae98..eb2d4f473e 100644
--- a/src/plugins/projectexplorer/removefiledialog.cpp
+++ b/src/plugins/coreplugin/removefiledialog.cpp
@@ -33,7 +33,7 @@
#include <QDir>
-using namespace ProjectExplorer::Internal;
+using namespace Core;
RemoveFileDialog::RemoveFileDialog(const QString &filePath, QWidget *parent) :
QDialog(parent),
diff --git a/src/plugins/projectexplorer/removefiledialog.h b/src/plugins/coreplugin/removefiledialog.h
index fec14486fa..0c8d7e390b 100644
--- a/src/plugins/projectexplorer/removefiledialog.h
+++ b/src/plugins/coreplugin/removefiledialog.h
@@ -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
diff --git a/src/plugins/projectexplorer/removefiledialog.ui b/src/plugins/coreplugin/removefiledialog.ui
index 2e0c072d86..865a5ffd4b 100644
--- a/src/plugins/projectexplorer/removefiledialog.ui
+++ b/src/plugins/coreplugin/removefiledialog.ui
@@ -1,7 +1,7 @@
<?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">
diff --git a/src/plugins/coreplugin/vcsmanager.cpp b/src/plugins/coreplugin/vcsmanager.cpp
index b41e32701d..b392cd1ab2 100644
--- a/src/plugins/coreplugin/vcsmanager.cpp
+++ b/src/plugins/coreplugin/vcsmanager.cpp
@@ -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
diff --git a/src/plugins/coreplugin/vcsmanager.h b/src/plugins/coreplugin/vcsmanager.h
index e9aec641d8..4f25d36f52 100644
--- a/src/plugins/coreplugin/vcsmanager.h
+++ b/src/plugins/coreplugin/vcsmanager.h
@@ -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);
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 9bb2f22ced..6fcb31e4b6 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -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);
}
}
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index 3fbbf4091e..6856e6de31 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -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 \
diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs
index f81ea1d2c2..d8aa1f096e 100644
--- a/src/plugins/projectexplorer/projectexplorer.qbs
+++ b/src/plugins/projectexplorer/projectexplorer.qbs
@@ -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",
diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp
index eb9d66eaac..9ba65101fe 100644
--- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp
+++ b/src/plugins/resourceeditor/qrceditor/resourcefile.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);
}
diff --git a/src/plugins/resourceeditor/qrceditor/resourceview.cpp b/src/plugins/resourceeditor/qrceditor/resourceview.cpp
index 7be80c5083..bbd7cdfb93 100644
--- a/src/plugins/resourceeditor/qrceditor/resourceview.cpp
+++ b/src/plugins/resourceeditor/qrceditor/resourceview.cpp
@@ -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;
}
}