forked from qt-creator/qt-creator
File System: Allow removing empty folders
As the reverse operation of New Folder. Fixes: QTCREATORBUG-26886 Change-Id: I9c65a152850ec8260e9c260ea49cdad048a92aa2 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -694,6 +694,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
const bool hasCurrentItem = current.isValid();
|
const bool hasCurrentItem = current.isValid();
|
||||||
QAction *actionOpenFile = nullptr;
|
QAction *actionOpenFile = nullptr;
|
||||||
QAction *newFolder = nullptr;
|
QAction *newFolder = nullptr;
|
||||||
|
QAction *removeFolder = nullptr;
|
||||||
const bool isDir = m_fileSystemModel->isDir(current);
|
const bool isDir = m_fileSystemModel->isDir(current);
|
||||||
const Utils::FilePath filePath = hasCurrentItem ? Utils::FilePath::fromString(
|
const Utils::FilePath filePath = hasCurrentItem ? Utils::FilePath::fromString(
|
||||||
m_fileSystemModel->filePath(current))
|
m_fileSystemModel->filePath(current))
|
||||||
@@ -719,6 +720,13 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
if (m_fileSystemModel->flags(current) & Qt::ItemIsEditable)
|
if (m_fileSystemModel->flags(current) & Qt::ItemIsEditable)
|
||||||
menu.addAction(Core::ActionManager::command(RENAMEFILE)->action());
|
menu.addAction(Core::ActionManager::command(RENAMEFILE)->action());
|
||||||
newFolder = menu.addAction(tr("New Folder"));
|
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())
|
||||||
|
removeFolder = menu.addAction(tr("Remove Folder"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
@@ -736,6 +744,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
createNewFolder(current);
|
createNewFolder(current);
|
||||||
else
|
else
|
||||||
createNewFolder(current.parent());
|
createNewFolder(current.parent());
|
||||||
|
} else if (action == removeFolder) {
|
||||||
|
QDir().rmdir(filePath.toString());
|
||||||
} else if (action == collapseAllAction) {
|
} else if (action == collapseAllAction) {
|
||||||
m_listView->collapseAll();
|
m_listView->collapseAll();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user