Remove deck remove prompt but show card count

This commit is contained in:
RumovZ 2021-03-11 09:52:11 +01:00
parent 3219bb2539
commit f1dd010489
7 changed files with 40 additions and 34 deletions

View File

@ -14,6 +14,11 @@ browsing-card = Card
browsing-card-list = Card List
browsing-card-state = Card State
browsing-cards-cant-be-manually-moved-into = Cards can't be manually moved into a filtered deck.
browsing-cards-deleted =
{ $count ->
[one] { $count } card deleted.
*[other] { $count } cards deleted.
}
browsing-change-deck = Change Deck
browsing-change-deck2 = Change Deck...
browsing-change-note-type = Change Note Type

View File

@ -2,7 +2,6 @@ decks-add-new-deck-ctrlandn = Add New Deck (Ctrl+N)
decks-are-you-sure-you-wish-to = Are you sure you wish to delete { $val }?
decks-build = Build
decks-cards-selected-by = cards selected by
decks-confirm-deletion = Are you sure you want to delete all selected decks including { $count } cards?
decks-create-deck = Create Deck
decks-custom-steps-in-minutes = Custom steps (in minutes)
decks-deck = Deck

View File

@ -137,8 +137,8 @@ class DeckManager:
assert cardsToo and childrenToo
self.remove([did])
def remove(self, dids: List[int]) -> None:
self.col._backend.remove_decks(dids)
def remove(self, dids: List[int]) -> int:
return self.col._backend.remove_decks(dids)
def all_names_and_ids(
self, skip_empty_default: bool = False, include_filtered: bool = True

View File

@ -1199,22 +1199,20 @@ class SidebarTreeView(QTreeView):
self.browser.editor.saveNow(self._delete_decks)
def _delete_decks(self) -> None:
def do_delete() -> None:
return self.mw.col.decks.remove(dids)
def on_done(fut: Future) -> None:
self.mw.requireReset(reason=ResetReason.BrowserDeleteDeck, context=self)
self.browser.search()
self.browser.model.endReset()
tooltip(tr(TR.BROWSING_CARDS_DELETED, count=fut.result()), parent=self)
self.refresh()
dids = self._selected_decks()
if self.mw.deckBrowser.ask_delete_decks(dids):
def do_delete() -> None:
return self.mw.col.decks.remove(dids)
def on_done(fut: Future) -> None:
self.mw.requireReset(reason=ResetReason.BrowserDeleteDeck, context=self)
self.browser.search()
self.browser.model.endReset()
self.refresh()
res = fut.result() # Required to check for errors
self.mw.checkpoint(tr(TR.DECKS_DELETE_DECK))
self.browser.model.beginReset()
self.mw.taskman.run_in_background(do_delete, on_done)
self.mw.checkpoint(tr(TR.DECKS_DELETE_DECK))
self.browser.model.beginReset()
self.mw.taskman.run_in_background(do_delete, on_done)
def rename_node(self, item: SidebarItem, text: str) -> bool:
new_name = text.replace('"', "")

View File

@ -151,7 +151,7 @@ service BackendService {
rpc GetDeckLegacy(DeckID) returns (Json);
rpc GetDeckNames(GetDeckNamesIn) returns (DeckNames);
rpc NewDeckLegacy(Bool) returns (Json);
rpc RemoveDecks(DeckIDs) returns (Empty);
rpc RemoveDecks(DeckIDs) returns (UInt32);
rpc DragDropDecks(DragDropDecksIn) returns (Empty);
// deck config

View File

@ -662,7 +662,7 @@ impl BackendService for Backend {
.map(Into::into)
}
fn remove_decks(&self, input: pb::DeckIDs) -> BackendResult<Empty> {
fn remove_decks(&self, input: pb::DeckIDs) -> BackendResult<pb::UInt32> {
self.with_col(|col| col.remove_decks_and_child_decks(&Into::<Vec<DeckID>>::into(input)))
.map(Into::into)
}
@ -1218,9 +1218,7 @@ impl BackendService for Backend {
}
fn expunge_tags(&self, tags: pb::String) -> BackendResult<pb::UInt32> {
self.with_col(|col| {
col.expunge_tags(tags.val.as_str()).map(Into::into)
})
self.with_col(|col| col.expunge_tags(tags.val.as_str()).map(Into::into))
}
fn set_tag_expanded(&self, input: pb::SetTagExpandedIn) -> BackendResult<pb::Empty> {

View File

@ -440,9 +440,10 @@ impl Collection {
self.storage.get_deck_id(&machine_name)
}
pub fn remove_decks_and_child_decks(&mut self, dids: &[DeckID]) -> Result<()> {
pub fn remove_decks_and_child_decks(&mut self, dids: &[DeckID]) -> Result<usize> {
// fixme: vet cache clearing
self.state.deck_cache.clear();
let mut card_count = 0;
self.transact(None, |col| {
let usn = col.usn()?;
@ -451,24 +452,28 @@ impl Collection {
let child_decks = col.storage.child_decks(&deck)?;
// top level
col.remove_single_deck(&deck, usn)?;
card_count += col.remove_single_deck(&deck, usn)?;
// remove children
for deck in child_decks {
col.remove_single_deck(&deck, usn)?;
card_count += col.remove_single_deck(&deck, usn)?;
}
}
}
Ok(())
})
})?;
Ok(card_count)
}
pub(crate) fn remove_single_deck(&mut self, deck: &Deck, usn: Usn) -> Result<()> {
pub(crate) fn remove_single_deck(&mut self, deck: &Deck, usn: Usn) -> Result<usize> {
// fixme: undo
match deck.kind {
let card_count = match deck.kind {
DeckKind::Normal(_) => self.delete_all_cards_in_normal_deck(deck.id)?,
DeckKind::Filtered(_) => self.return_all_cards_in_filtered_deck(deck.id)?,
}
DeckKind::Filtered(_) => {
self.return_all_cards_in_filtered_deck(deck.id)?;
0
}
};
self.clear_aux_config_for_deck(deck.id)?;
if deck.id.0 == 1 {
let mut deck = deck.to_owned();
@ -480,12 +485,13 @@ impl Collection {
self.storage.remove_deck(deck.id)?;
self.storage.add_deck_grave(deck.id, usn)?;
}
Ok(())
Ok(card_count)
}
fn delete_all_cards_in_normal_deck(&mut self, did: DeckID) -> Result<()> {
fn delete_all_cards_in_normal_deck(&mut self, did: DeckID) -> Result<usize> {
let cids = self.storage.all_cards_in_single_deck(did)?;
self.remove_cards_and_orphaned_notes(&cids)
self.remove_cards_and_orphaned_notes(&cids)?;
Ok(cids.len())
}
pub fn get_all_deck_names(&self, skip_empty_default: bool) -> Result<Vec<(DeckID, String)>> {