From c03acf832bfb141ef63f96776cc83d0a01cbb2b4 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 16 Apr 2021 08:30:16 +0200 Subject: [PATCH] Split Col impls in decks in pub and private blocks --- rslib/src/decks/add.rs | 2 ++ rslib/src/decks/remove.rs | 2 ++ rslib/src/decks/stats.rs | 2 ++ rslib/src/decks/undo.rs | 26 ++++++++++++++------------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/rslib/src/decks/add.rs b/rslib/src/decks/add.rs index 7559c1675..bf30c9c35 100644 --- a/rslib/src/decks/add.rs +++ b/rslib/src/decks/add.rs @@ -93,7 +93,9 @@ impl Collection { deck.set_modified(usn); self.add_or_update_single_deck_with_existing_id(&mut deck, usn) } +} +impl Collection { /// Add a single, normal deck with the provided name for a child deck. /// Caller must have done necessarily validation on name. fn add_parent_deck(&mut self, machine_name: &str, usn: Usn) -> Result<()> { diff --git a/rslib/src/decks/remove.rs b/rslib/src/decks/remove.rs index b28ea7c3f..997100dfa 100644 --- a/rslib/src/decks/remove.rs +++ b/rslib/src/decks/remove.rs @@ -46,7 +46,9 @@ impl Collection { } Ok(card_count) } +} +impl Collection { fn delete_all_cards_in_normal_deck(&mut self, did: DeckId) -> Result { let cids = self.storage.all_cards_in_single_deck(did)?; self.remove_cards_and_orphaned_notes(&cids)?; diff --git a/rslib/src/decks/stats.rs b/rslib/src/decks/stats.rs index 5eda8b0c9..b69bccca6 100644 --- a/rslib/src/decks/stats.rs +++ b/rslib/src/decks/stats.rs @@ -67,7 +67,9 @@ impl Collection { Ok(()) } +} +impl Collection { fn update_deck_stats_single( &mut self, today: u32, diff --git a/rslib/src/decks/undo.rs b/rslib/src/decks/undo.rs index 39cdfaf14..5bbdb81f7 100644 --- a/rslib/src/decks/undo.rs +++ b/rslib/src/decks/undo.rs @@ -30,6 +30,20 @@ impl Collection { } } + pub(crate) fn remove_deck_and_add_grave_undoable( + &mut self, + deck: Deck, + usn: Usn, + ) -> Result<()> { + self.state.deck_cache.clear(); + self.add_deck_grave_undoable(deck.id, usn)?; + self.storage.remove_deck(deck.id)?; + self.save_undo(UndoableDeckChange::Removed(Box::new(deck))); + Ok(()) + } +} + +impl Collection { pub(super) fn add_deck_undoable(&mut self, deck: &mut Deck) -> Result<(), AnkiError> { self.storage.add_deck(deck)?; self.save_undo(UndoableDeckChange::Added(Box::new(deck.clone()))); @@ -59,18 +73,6 @@ impl Collection { self.storage.update_deck(deck) } - pub(crate) fn remove_deck_and_add_grave_undoable( - &mut self, - deck: Deck, - usn: Usn, - ) -> Result<()> { - self.state.deck_cache.clear(); - self.add_deck_grave_undoable(deck.id, usn)?; - self.storage.remove_deck(deck.id)?; - self.save_undo(UndoableDeckChange::Removed(Box::new(deck))); - Ok(()) - } - fn restore_deleted_deck(&mut self, deck: Deck) -> Result<()> { self.storage.add_or_update_deck_with_existing_id(&deck)?; self.save_undo(UndoableDeckChange::Added(Box::new(deck)));