mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 22:13:58 -05:00
create deck if it doesn't exist
This commit is contained in:
parent
96a2c626b9
commit
db0b86e90f
2 changed files with 18 additions and 2 deletions
|
|
@ -147,7 +147,7 @@ impl Duplicate {
|
|||
}
|
||||
|
||||
impl DeckIdsByNameOrId {
|
||||
fn new(col: &mut Collection, default: &NameOrId) -> Result<Self> {
|
||||
fn new(col: &mut Collection, default: &NameOrId, usn: Usn) -> Result<Self> {
|
||||
let names: HashMap<UniCase<String>, DeckId> = col
|
||||
.get_all_normal_deck_names(false)?
|
||||
.into_iter()
|
||||
|
|
@ -160,6 +160,13 @@ impl DeckIdsByNameOrId {
|
|||
default: None,
|
||||
};
|
||||
new.default = new.get(default);
|
||||
if new.default.is_none() && *default != NameOrId::default() {
|
||||
let mut deck = Deck::new_normal();
|
||||
deck.name = NativeDeckName::from_human_name(default.to_string());
|
||||
col.add_deck_inner(&mut deck, usn)?;
|
||||
new.insert(deck.id, deck.human_name());
|
||||
new.default = Some(deck.id);
|
||||
}
|
||||
|
||||
Ok(new)
|
||||
}
|
||||
|
|
@ -193,7 +200,7 @@ impl<'a> Context<'a> {
|
|||
NameOrId::default(),
|
||||
col.notetype_by_name_or_id(&data.default_notetype)?,
|
||||
);
|
||||
let deck_ids = DeckIdsByNameOrId::new(col, &data.default_deck)?;
|
||||
let deck_ids = DeckIdsByNameOrId::new(col, &data.default_deck, usn)?;
|
||||
let existing_checksums = ExistingChecksums::new(col, data.match_scope)?;
|
||||
let existing_guids = col.storage.all_notes_by_guid()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,15 @@ impl From<String> for NameOrId {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for NameOrId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
NameOrId::Id(did) => write!(f, "{did}"),
|
||||
NameOrId::Name(name) => write!(f, "{name}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ForeignNote {
|
||||
pub(crate) fn into_log_note(self) -> LogNote {
|
||||
LogNote {
|
||||
|
|
|
|||
Loading…
Reference in a new issue