Added ability to create/delete directories

This commit is contained in:
Aruki
2017-07-20 20:48:12 -06:00
parent 16e310fb2f
commit 905173a0a0
13 changed files with 270 additions and 46 deletions

View File

@@ -1,4 +1,6 @@
#include "CResourceTableView.h"
#include "CResourceBrowser.h"
#include "CResourceProxyModel.h"
#include <QAction>
#include <QDragEnterEvent>
@@ -11,6 +13,17 @@ CResourceTableView::CResourceTableView(QWidget *pParent /*= 0*/)
mpRenameAction->setShortcut( QKeySequence(Qt::Key_F2) );
connect(mpRenameAction, SIGNAL(triggered(bool)), this, SLOT(RenameSelected()));
addAction(mpRenameAction);
mpDeleteAction = new QAction(this);
mpDeleteAction->setShortcut(QKeySequence::Delete);
connect(mpDeleteAction, SIGNAL(triggered(bool)), this, SLOT(DeleteSelected()));
addAction(mpDeleteAction);
}
void CResourceTableView::setModel(QAbstractItemModel *pModel)
{
if (qobject_cast<CResourceProxyModel*>(pModel) != nullptr)
QTableView::setModel(pModel);
}
void CResourceTableView::dragEnterEvent(QDragEnterEvent *pEvent)
@@ -47,3 +60,42 @@ void CResourceTableView::RenameSelected()
edit(List.front());
}
}
void CResourceTableView::DeleteSelected()
{
QModelIndexList List = selectionModel()->selectedIndexes();
// Figure out which indices can actually be deleted
CResourceProxyModel *pProxy = static_cast<CResourceProxyModel*>(model());
CResourceTableModel *pModel = static_cast<CResourceTableModel*>(pProxy->sourceModel());
QList<CVirtualDirectory*> DirsToDelete;
bool HasNonEmptyDirSelected = false;
foreach (QModelIndex Index, List)
{
QModelIndex SourceIndex = pProxy->mapToSource(Index);
if (pModel->IsIndexDirectory(SourceIndex))
{
CVirtualDirectory *pDir = pModel->IndexDirectory(SourceIndex);
if (pDir)
{
if (pDir->IsEmpty(true))
DirsToDelete << pDir;
else
HasNonEmptyDirSelected = true;
}
}
}
// Let the user know if all selected directories are non empty
if (HasNonEmptyDirSelected && DirsToDelete.isEmpty())
{
UICommon::ErrorMsg(parentWidget(), "Unable to delete; one or more of the selected directories is non-empty.");
return;
}
// Delete
gpEdApp->ResourceBrowser()->DeleteDirectories(DirsToDelete);
}