added proper remove for files/dirs

This commit is contained in:
csoler 2024-03-19 23:22:46 +01:00
parent a36f7221e7
commit 2ebd7617fc
3 changed files with 40 additions and 0 deletions

View File

@ -670,4 +670,16 @@ void RsCollection::saveColl(std::vector<ColFileInfo> colFileInfos, const QString
}
#endif
bool RsCollection::removeFile(RsFileTree::FileIndex index_to_remove,RsFileTree::DirIndex parent_index)
{
mFileTree->removeFile(index_to_remove,parent_index);
}
bool RsCollection::removeDirectory(RsFileTree::DirIndex index_to_remove,RsFileTree::DirIndex parent_index)
{
mFileTree->removeDirectory(index_to_remove,parent_index);
}
void RsCollection::cleanup()
{
mFileTree = RsFileTree::fromTreeCleaned(*mFileTree);
}

View File

@ -80,6 +80,11 @@ public:
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash,RsFileTree::DirIndex parent_index=0) ;
void merge_in(const RsFileTree& tree,RsFileTree::DirIndex parent_index=0) ;
bool removeFile(RsFileTree::FileIndex index_to_remove,RsFileTree::DirIndex parent_index);
bool removeDirectory(RsFileTree::DirIndex index_to_remove,RsFileTree::DirIndex parent_index);
void cleanup(); // cleans up the collection, which may contain unreferenced files/dirs after lazy editing.
static const QString ExtensionString ;
#ifdef TO_REMOVE

View File

@ -954,6 +954,27 @@ bool RsCollectionDialog::addAllChild(QFileInfo &fileInfoParent
*/
void RsCollectionDialog::remove()
{
QMap<QString, QString > dirToRemove;
int count=0;//to not scan all items on list .count()
QModelIndexList milSelectionList = ui._fileEntriesTW->selectionModel()->selectedIndexes();
mCollectionModel->preMods();
foreach (QModelIndex index, milSelectionList)
if(index.column()==0) //Get only FileName
{
auto indx = mCollectionModel->getIndex(index);
auto parent_indx = mCollectionModel->getIndex(index.parent());
if(indx.is_file)
mCollection->removeFile(indx.index,parent_indx.index);
else
mCollection->removeDirectory(indx.index,parent_indx.index);
}
mCollectionModel->postMods();
#ifdef TODO_COLLECTION
bool removeOnlyFile=false;
QString listDir;
@ -1538,6 +1559,8 @@ void RsCollectionDialog::download()
*/
void RsCollectionDialog::save()
{
mCollectionModel->preMods();
mCollection->cleanup();
mCollection->save(_fileName);
close();
#ifdef TO_REMOVE