Make adding notetype with id undoable

This commit is contained in:
RumovZ 2022-04-09 12:31:23 +02:00
parent 2a15ba5404
commit 1ba5444d7d
2 changed files with 16 additions and 3 deletions

View file

@ -204,10 +204,12 @@ impl<'a> Context<'a> {
}
fn add_notetype(&mut self, notetype: &mut Notetype) -> Result<()> {
notetype.usn = self.usn;
// TODO: make undoable
notetype.prepare_for_update(None, true)?;
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<()> {

View file

@ -42,6 +42,17 @@ impl Collection {
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(
&mut self,
notetype: &Notetype,