diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index 96d839fe3..6525f0d08 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -287,13 +287,21 @@ class DeckBrowser: self._renderPage(reuse=True) def _handle_drag_and_drop(self, source: int, target: int) -> None: - try: + def process() -> None: self.mw.col.decks.drag_drop_decks([source], target) - except Exception as e: - showWarning(str(e)) - return - gui_hooks.sidebar_should_refresh_decks() - self.show() + + def on_done(fut: Future) -> None: + try: + fut.result() + except Exception as e: + showWarning(str(e)) + return + + self.mw.update_undo_actions() + gui_hooks.sidebar_should_refresh_decks() + self.show() + + self.mw.taskman.with_progress(process, on_done) def ask_delete_deck(self, did: int) -> bool: deck = self.mw.col.decks.get(did) diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 4db53abaa..1d5544250 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -480,9 +480,9 @@ class SidebarTreeView(QTreeView): return self.refresh() self.mw.deckBrowser.refresh() + self.mw.update_undo_actions() def on_save() -> None: - self.mw.checkpoint(tr(TR.ACTIONS_RENAME_DECK)) self.browser.model.beginReset() self.mw.taskman.with_progress( lambda: self.col.decks.drag_drop_decks(source_ids, target.id), on_done diff --git a/rslib/src/decks/mod.rs b/rslib/src/decks/mod.rs index 9d8997dec..ea0d5d71b 100644 --- a/rslib/src/decks/mod.rs +++ b/rslib/src/decks/mod.rs @@ -617,9 +617,8 @@ impl Collection { source_decks: &[DeckID], target: Option, ) -> Result<()> { - self.state.deck_cache.clear(); let usn = self.usn()?; - self.transact(None, |col| { + self.transact(Some(UndoableOpKind::RenameDeck), |col| { let target_deck; let mut target_name = None; if let Some(target) = target { @@ -634,18 +633,25 @@ impl Collection { for source in source_decks { if let Some(mut source) = col.storage.get_deck(*source)? { - let orig = source.clone(); let new_name = drag_drop_deck_name(&source.name, target_name); if new_name == source.name { continue; } + let orig = source.clone(); + + // this is basically update_deck_inner(), except: + // - we skip the normalization in prepare_for_update() + // - we skip the match_or_create_parents() step + + source.set_modified(usn); source.name = new_name; col.ensure_deck_name_unique(&mut source, usn)?; col.rename_child_decks(&orig, &source.name, usn)?; - source.set_modified(usn); - col.storage.update_deck(&source)?; + col.update_single_deck_undoable(&mut source, orig)?; + // after updating, we need to ensure all grandparents exist, which may not be the case // in the parent->child case + // FIXME: maybe we only need to do this once at the end of the loop? col.create_missing_parents(&source.name, usn)?; } }