diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index a34a01d88f3..0c5642f97f9 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 ee0a0baaca0..e916974ba8c 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 4f0ce9aaf37..ab6d384109d 100644 --- a/src/plugins/coreplugin/fileutils.cpp +++ b/src/plugins/coreplugin/fileutils.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -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 fdb62abe70e..33e6e010b4f 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 similarity index 97% rename from src/plugins/projectexplorer/removefiledialog.cpp rename to src/plugins/coreplugin/removefiledialog.cpp index 1c45f8ae983..eb2d4f473ee 100644 --- a/src/plugins/projectexplorer/removefiledialog.cpp +++ b/src/plugins/coreplugin/removefiledialog.cpp @@ -33,7 +33,7 @@ #include -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 similarity index 91% rename from src/plugins/projectexplorer/removefiledialog.h rename to src/plugins/coreplugin/removefiledialog.h index fec14486faf..0c8d7e390bc 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 -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 similarity index 91% rename from src/plugins/projectexplorer/removefiledialog.ui rename to src/plugins/coreplugin/removefiledialog.ui index 2e0c072d868..865a5ffd4bc 100644 --- a/src/plugins/projectexplorer/removefiledialog.ui +++ b/src/plugins/coreplugin/removefiledialog.ui @@ -1,7 +1,7 @@ - ProjectExplorer::Internal::RemoveFileDialog - + Core::RemoveFileDialog + 0 @@ -41,6 +41,9 @@ placeholder + + true + @@ -96,7 +99,7 @@ buttonBox accepted() - ProjectExplorer::Internal::RemoveFileDialog + Core::RemoveFileDialog accept() @@ -112,7 +115,7 @@ buttonBox rejected() - ProjectExplorer::Internal::RemoveFileDialog + Core::RemoveFileDialog reject() diff --git a/src/plugins/coreplugin/vcsmanager.cpp b/src/plugins/coreplugin/vcsmanager.cpp index b41e32701d8..b392cd1ab2b 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 e9aec641d85..4f25d36f523 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 9bb2f22ceda..6fcb31e4b62 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 #include #include +#include #include #include #include @@ -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(d->m_currentNode->projectNode()); ProjectNode *projectNode = qobject_cast(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(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 3fbbf4091e2..6856e6de312 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 f81ea1d2c2d..d8aa1f096e8 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 eb9d66eaac3..9ba65101fe5 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include @@ -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 7be80c5083b..bbd7cdfb934 100644 --- a/src/plugins/resourceeditor/qrceditor/resourceview.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourceview.cpp @@ -32,6 +32,10 @@ #include "undocommands_p.h" +#include +#include +#include + #include #include @@ -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; } }