Core: Allow "Remove Folder" in File System View pane

As a CMake user from time to time I have the need to simply remove a
build directory.

This is now possible from the File System pane. Previously one had to
open a Terminal an do there a "rm -rf" or "rmdir /q /s" operation.

The user will be asked before, and there is no possibility of a misclick
and remove something the user didn't consent to.

Fixes: QTCREATORBUG-27331
Change-Id: I61aa42ce6587e46d635d9743b154f2bc9d163b1e
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2022-10-20 12:37:05 +02:00
parent fb40998549
commit d42214e556
2 changed files with 13 additions and 10 deletions

View File

@@ -16,7 +16,8 @@ namespace Utils {
RemoveFileDialog::RemoveFileDialog(const FilePath &filePath, QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("Remove File"));
const bool isFile = filePath.isFile();
setWindowTitle(isFile ? tr("Remove File") : tr("Remove Folder"));
resize(514, 159);
QFont font;
@@ -36,7 +37,7 @@ RemoveFileDialog::RemoveFileDialog(const FilePath &filePath, QWidget *parent)
using namespace Layouting;
Column {
tr("File to remove:"),
isFile ? tr("File to remove:") : tr("Folder to remove:"),
fileNameLabel,
Space(10),
m_deleteFileCheckBox,

View File

@@ -708,14 +708,9 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
if (m_fileSystemModel->flags(current) & Qt::ItemIsEditable)
menu.addAction(Core::ActionManager::command(RENAMEFILE)->action());
newFolder = menu.addAction(tr("New Folder"));
if (isDir) {
QDirIterator it(filePath.toString(),
QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
// only allow removing folders that are empty
if (!it.hasNext())
if (isDir)
removeFolder = menu.addAction(tr("Remove Folder"));
}
}
menu.addSeparator();
QAction *const collapseAllAction = menu.addAction(tr("Collapse All"));
@@ -733,7 +728,14 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
else
createNewFolder(current.parent());
} else if (action == removeFolder) {
QDir().rmdir(filePath.toString());
RemoveFileDialog dialog(filePath, Core::ICore::dialogParent());
dialog.setDeleteFileVisible(false);
if (dialog.exec() == QDialog::Accepted) {
QString errorMessage;
filePath.removeRecursively(&errorMessage);
if (!errorMessage.isEmpty())
QMessageBox::critical(ICore::dialogParent(), tr("Error"), errorMessage);
}
} else if (action == collapseAllAction) {
m_listView->collapseAll();
}