mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
Simplify reparenting solution
This commit is contained in:
parent
3fa01c50df
commit
858250f26f
2 changed files with 11 additions and 22 deletions
|
@ -32,13 +32,13 @@ def remove_decks(
|
|||
def reparent_decks(
|
||||
*, parent: QWidget, deck_ids: Sequence[DeckId], new_parent: DeckId
|
||||
) -> CollectionOp[OpChangesWithCount]:
|
||||
def on_success(out):
|
||||
if out.count > 0:
|
||||
tooltip(tr.browsing_reparented_decks(count=out.count), parent=parent)
|
||||
|
||||
return CollectionOp(
|
||||
parent, lambda col: col.decks.reparent(deck_ids=deck_ids, new_parent=new_parent)
|
||||
).success(on_success)
|
||||
).success(
|
||||
lambda out: tooltip(
|
||||
tr.browsing_reparented_decks(count=out.count), parent=parent
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def rename_deck(
|
||||
|
|
|
@ -20,36 +20,25 @@ impl Collection {
|
|||
new_parent: Option<DeckId>,
|
||||
) -> Result<usize> {
|
||||
let usn = self.usn()?;
|
||||
let mut target_deck = None;
|
||||
let target_deck;
|
||||
let mut target_name = None;
|
||||
if let Some(target) = new_parent {
|
||||
if let Some(target) = self.storage.get_deck(target)? {
|
||||
if target.is_filtered() {
|
||||
return Err(FilteredDeckError::MustBeLeafNode.into());
|
||||
}
|
||||
target_deck = Some(target);
|
||||
target_name = Some(target_deck.as_ref().unwrap().name.clone());
|
||||
target_deck = target;
|
||||
target_name = Some(&target_deck.name);
|
||||
}
|
||||
}
|
||||
|
||||
let mut count = 0;
|
||||
for deck in deck_ids {
|
||||
if let Some(mut deck) = self.storage.get_deck(*deck)? {
|
||||
if let Some(new_name) = deck.name.reparented_name(target_name.as_ref()) {
|
||||
let parent_decks = self.storage.parent_decks(&deck).unwrap();
|
||||
match target_deck {
|
||||
Some(ref target) => {
|
||||
if parent_decks.contains(target) {
|
||||
if let Some(new_name) = deck.name.reparented_name(target_name) {
|
||||
if new_name == deck.name {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if parent_decks.is_empty() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
count += 1;
|
||||
let orig = deck.clone();
|
||||
|
||||
|
|
Loading…
Reference in a new issue