/* Archive::removeDir * Deletes the directory matching [path], starting from [base]. If * [base] is NULL, the root directory is used. Returns false if * the directory does not exist, true otherwise *******************************************************************/ bool Archive::removeDir(string path, ArchiveTreeNode* base) { // Abort if read only if (read_only) return false; // Get the dir to remove ArchiveTreeNode* dir = getDir(path, base); // Check it exists (and that it isn't the root dir) if (!dir || dir == getRoot()) return false; // Record undo step if (UndoRedo::currentlyRecording()) UndoRedo::currentManager()->recordUndoStep(new DirCreateDeleteUS(false, dir)); // Remove the directory from its parent if (dir->getParent()) dir->getParent()->removeChild(dir); // Delete the directory delete dir; // Set the archive state to modified setModified(true); return true; }
/* ADatArchive::detectNamespace * Returns the namespace that [entry] is within *******************************************************************/ string ADatArchive::detectNamespace(ArchiveEntry* entry) { // Check entry if (!checkEntry(entry)) return "global"; // If the entry is in the root dir, it's in the global namespace if (entry->getParentDir() == getRoot()) return "global"; // Get the entry's *first* parent directory after root (ie <root>/namespace/) ArchiveTreeNode* dir = entry->getParentDir(); while (dir && dir->getParent() != getRoot()) dir = (ArchiveTreeNode*)dir->getParent(); // Namespace is the directory's name (in lowercase) if (dir) return dir->getName().Lower(); else return "global"; // Error, just return global }
/* ArchiveManager::deleteBookmarksInDir * Removes any bookmarked entries in [node] from the list *******************************************************************/ bool ArchiveManager::deleteBookmarksInDir(ArchiveTreeNode* node) { // Go through bookmarks Archive * archive = node->getArchive(); bool removed = deleteBookmark(node->getDirEntry()); for (unsigned a = 0; a < bookmarks.size(); ++a) { // Check bookmarked entry's parent archive if (bookmarks[a]->getParent() == archive) { // Now check if the bookmarked entry is within // the removed dir or one of its descendants ArchiveTreeNode* anode = bookmarks[a]->getParentDir(); bool remove = false; while (anode != archive->getRoot() && !remove) { if (anode == node) remove = true; else anode = (ArchiveTreeNode*)anode->getParent(); } if (remove) { bookmarks.erase(bookmarks.begin() + a); --a; removed = true; } } } if (removed) { // Announce announce("bookmarks_changed"); return true; } else return false; }