mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
update current note type in backend
This commit is contained in:
parent
3cb870ec9c
commit
803aeff16e
3 changed files with 10 additions and 8 deletions
|
@ -205,15 +205,10 @@ class ModelManager:
|
|||
self.col.backend.remove_notetype(nt.id)
|
||||
|
||||
def remove(self, id: int) -> None:
|
||||
self.col.modSchema(check=True)
|
||||
"Modifies schema."
|
||||
self._remove_from_cache(id)
|
||||
was_current = self.current()["id"] == id
|
||||
self.col.backend.remove_notetype(id)
|
||||
|
||||
# fixme: handle in backend
|
||||
if was_current:
|
||||
self.col.conf["curModel"] = self.all_names_and_ids()[0].id
|
||||
|
||||
def add(self, m: NoteType) -> None:
|
||||
self.save(m)
|
||||
|
||||
|
|
|
@ -173,7 +173,6 @@ impl Collection {
|
|||
self.get_config_optional(ConfigKey::CurrentNoteTypeID)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_current_notetype_id(&self, id: NoteTypeID) -> Result<()> {
|
||||
self.set_config(ConfigKey::CurrentNoteTypeID, &id)
|
||||
}
|
||||
|
|
|
@ -446,7 +446,15 @@ impl Collection {
|
|||
self.transact(None, |col| {
|
||||
col.storage.set_schema_modified()?;
|
||||
col.state.notetype_cache.remove(&ntid);
|
||||
col.storage.remove_notetype(ntid)
|
||||
col.storage.remove_notetype(ntid)?;
|
||||
let all = col.storage.get_all_notetype_names()?;
|
||||
if all.is_empty() {
|
||||
let mut nt = all_stock_notetypes(&col.i18n).remove(0);
|
||||
col.add_notetype_inner(&mut nt, col.usn()?)?;
|
||||
col.set_current_notetype_id(nt.id)
|
||||
} else {
|
||||
col.set_current_notetype_id(all[0].0)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue