mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
Make adding notetype with id undoable
This commit is contained in:
parent
2a15ba5404
commit
1ba5444d7d
2 changed files with 16 additions and 3 deletions
|
@ -204,10 +204,12 @@ impl<'a> Context<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_notetype(&mut self, notetype: &mut Notetype) -> Result<()> {
|
fn add_notetype(&mut self, notetype: &mut Notetype) -> Result<()> {
|
||||||
notetype.usn = self.usn;
|
notetype.prepare_for_update(None, true)?;
|
||||||
// TODO: make undoable
|
|
||||||
self.target_col
|
self.target_col
|
||||||
.add_or_update_notetype_with_existing_id_inner(notetype, None, self.usn, true)
|
.ensure_notetype_name_unique(notetype, self.usn)?;
|
||||||
|
notetype.usn = self.usn;
|
||||||
|
self.target_col
|
||||||
|
.add_notetype_with_unique_id_undoable(notetype)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_notetype(&mut self, notetype: &mut Notetype, original: Notetype) -> Result<()> {
|
fn update_notetype(&mut self, notetype: &mut Notetype, original: Notetype) -> Result<()> {
|
||||||
|
|
|
@ -42,6 +42,17 @@ impl Collection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Caller must ensure [NotetypeId] is unique.
|
||||||
|
pub(crate) fn add_notetype_with_unique_id_undoable(
|
||||||
|
&mut self,
|
||||||
|
notetype: &Notetype,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.storage
|
||||||
|
.add_or_update_notetype_with_existing_id(notetype)?;
|
||||||
|
self.save_undo(UndoableNotetypeChange::Added(Box::new(notetype.clone())));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn update_notetype_undoable(
|
pub(super) fn update_notetype_undoable(
|
||||||
&mut self,
|
&mut self,
|
||||||
notetype: &Notetype,
|
notetype: &Notetype,
|
||||||
|
|
Loading…
Reference in a new issue