forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Tobias Hunger
parent
bd7499b896
commit
728579ef52
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
74
src/plugins/coreplugin/removefiledialog.cpp
Normal file
74
src/plugins/coreplugin/removefiledialog.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "removefiledialog.h"
|
||||
#include "ui_removefiledialog.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
RemoveFileDialog::RemoveFileDialog(const QString &filePath, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
m_ui(new Ui::RemoveFileDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->fileNameLabel->setText(QDir::toNativeSeparators(filePath));
|
||||
|
||||
// TODO
|
||||
m_ui->removeVCCheckBox->setVisible(false);
|
||||
}
|
||||
|
||||
RemoveFileDialog::~RemoveFileDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void RemoveFileDialog::setDeleteFileVisible(bool visible)
|
||||
{
|
||||
m_ui->deleteFileCheckBox->setVisible(visible);
|
||||
}
|
||||
|
||||
bool RemoveFileDialog::isDeleteFileChecked() const
|
||||
{
|
||||
return m_ui->deleteFileCheckBox->isChecked();
|
||||
}
|
||||
|
||||
void RemoveFileDialog::changeEvent(QEvent *e)
|
||||
{
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
m_ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
64
src/plugins/coreplugin/removefiledialog.h
Normal file
64
src/plugins/coreplugin/removefiledialog.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||
** Please review the following information to ensure the GNU Lesser General
|
||||
** Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef REMOVEFILEDIALOG_H
|
||||
#define REMOVEFILEDIALOG_H
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Core {
|
||||
|
||||
namespace Ui {
|
||||
class RemoveFileDialog;
|
||||
}
|
||||
|
||||
class CORE_EXPORT RemoveFileDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RemoveFileDialog(const QString &filePath, QWidget *parent = 0);
|
||||
virtual ~RemoveFileDialog();
|
||||
|
||||
void setDeleteFileVisible(bool visible);
|
||||
bool isDeleteFileChecked() const;
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent *e);
|
||||
|
||||
private:
|
||||
Ui::RemoveFileDialog *m_ui;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // REMOVEFILEDIALOG_H
|
||||
132
src/plugins/coreplugin/removefiledialog.ui
Normal file
132
src/plugins/coreplugin/removefiledialog.ui
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Core::RemoveFileDialog</class>
|
||||
<widget class="QDialog" name="Core::RemoveFileDialog">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Remove File</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="fileToDeleteLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>File to remove:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="fileNameLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">placeholder</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="deleteFileCheckBox">
|
||||
<property name="text">
|
||||
<string>&Delete file permanently</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="removeVCCheckBox">
|
||||
<property name="text">
|
||||
<string>&Remove from Version Control</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Core::RemoveFileDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Core::RemoveFileDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user