/* Archive::removeEntry * Removes [entry] from the archive. If [delete_entry] is true, the * entry will also be deleted. Returns true if the removal succeeded *******************************************************************/ bool Archive::removeEntry(ArchiveEntry* entry, bool delete_entry) { // Abort if read only if (read_only) return false; // Check entry if (!checkEntry(entry)) return false; // Check if entry is locked if (entry->isLocked()) return false; // Get its directory ArchiveTreeNode* dir = entry->getParentDir(); // Error if entry has no parent directory if (!dir) return false; // Create undo step if (UndoRedo::currentlyRecording()) UndoRedo::currentManager()->recordUndoStep(new EntryCreateDeleteUS(false, entry)); // Get the entry index int index = dir->entryIndex(entry); // Announce (before actually removing in case entry is still needed) MemChunk mc; wxUIntPtr ptr = wxPtrToUInt(entry); mc.write(&index, sizeof(int)); mc.write(&ptr, sizeof(wxUIntPtr)); announce("entry_removing", mc); // Remove it from its directory bool ok = dir->removeEntry(index); // If it was removed ok if (ok) { // Announce removed announce("entry_removed", mc); // Delete if necessary if (delete_entry) delete entry; // Update variables etc setModified(true); } return ok; }
/* Archive::swapEntries * Swaps [entry1] and [entry2]. Returns false if either entry is * invalid or if both entries are not in the same directory, true * otherwise *******************************************************************/ bool Archive::swapEntries(ArchiveEntry* entry1, ArchiveEntry* entry2) { // Abort if read only if (read_only) return false; // Check both entries if (!checkEntry(entry1) || !checkEntry(entry2)) return false; // Check neither entry is locked if (entry1->isLocked() || entry2->isLocked()) return false; // Get their directory ArchiveTreeNode* dir = entry1->getParentDir(); // Error if no dir if (!dir) return false; // Check they are both in the same directory if (entry2->getParentDir() != dir) { wxLogMessage("Error: Can't swap two entries in different directories"); return false; } // Get entry indices int i1 = dir->entryIndex(entry1); int i2 = dir->entryIndex(entry2); // Check indices if (i1 < 0 || i2 < 0) return false; // Create undo step if (UndoRedo::currentlyRecording()) UndoRedo::currentManager()->recordUndoStep(new EntrySwapUS(dir, i1, i2)); // Swap entries dir->swapEntries(i1, i2); // Announce the swap announce("entries_swapped"); // Set modified setModified(true); // Return success return true; }