mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
modify add_note
to return count
This commit is contained in:
parent
95d7445ff6
commit
c4cfcee4a5
4 changed files with 8 additions and 7 deletions
|
@ -59,7 +59,7 @@ message AddNoteRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message AddNoteResponse {
|
message AddNoteResponse {
|
||||||
collection.OpChanges changes = 1;
|
collection.OpChangesWithCount changes = 1;
|
||||||
int64 note_id = 2;
|
int64 note_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -528,7 +528,7 @@ class Collection(DeprecatedNamesMixin):
|
||||||
def new_note(self, notetype: NotetypeDict) -> Note:
|
def new_note(self, notetype: NotetypeDict) -> Note:
|
||||||
return Note(self, notetype)
|
return Note(self, notetype)
|
||||||
|
|
||||||
def add_note(self, note: Note, deck_id: DeckId) -> OpChanges:
|
def add_note(self, note: Note, deck_id: DeckId) -> OpChangesWithCount:
|
||||||
hooks.note_will_be_added(self, note, deck_id)
|
hooks.note_will_be_added(self, note, deck_id)
|
||||||
out = self._backend.add_note(note=note._to_backend_note(), deck_id=deck_id)
|
out = self._backend.add_note(note=note._to_backend_note(), deck_id=deck_id)
|
||||||
note.id = NoteId(out.note_id)
|
note.id = NoteId(out.note_id)
|
||||||
|
|
|
@ -18,7 +18,7 @@ def add_note(
|
||||||
parent: QWidget,
|
parent: QWidget,
|
||||||
note: Note,
|
note: Note,
|
||||||
target_deck_id: DeckId,
|
target_deck_id: DeckId,
|
||||||
) -> CollectionOp[OpChanges]:
|
) -> CollectionOp[OpChangesWithCount]:
|
||||||
return CollectionOp(parent, lambda col: col.add_note(note, target_deck_id))
|
return CollectionOp(parent, lambda col: col.add_note(note, target_deck_id))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl TryFrom<anki_proto::notes::AddNoteRequest> for AddNoteRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn add_note(&mut self, note: &mut Note, did: DeckId) -> Result<OpOutput<()>> {
|
pub fn add_note(&mut self, note: &mut Note, did: DeckId) -> Result<OpOutput<usize>> {
|
||||||
self.transact(Op::AddNote, |col| col.add_note_inner(note, did))
|
self.transact(Op::AddNote, |col| col.add_note_inner(note, did))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ impl Collection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_note_inner(&mut self, note: &mut Note, did: DeckId) -> Result<()> {
|
pub(crate) fn add_note_inner(&mut self, note: &mut Note, did: DeckId) -> Result<usize> {
|
||||||
let nt = self
|
let nt = self
|
||||||
.get_notetype(note.notetype_id)?
|
.get_notetype(note.notetype_id)?
|
||||||
.or_invalid("missing note type")?;
|
.or_invalid("missing note type")?;
|
||||||
|
@ -383,10 +383,11 @@ impl Collection {
|
||||||
note.prepare_for_update(ctx.notetype, normalize_text)?;
|
note.prepare_for_update(ctx.notetype, normalize_text)?;
|
||||||
note.set_modified(ctx.usn);
|
note.set_modified(ctx.usn);
|
||||||
self.add_note_only_undoable(note)?;
|
self.add_note_only_undoable(note)?;
|
||||||
self.generate_cards_for_new_note(&ctx, note, did)?;
|
let count = self.generate_cards_for_new_note(&ctx, note, did)?;
|
||||||
self.set_last_deck_for_notetype(note.notetype_id, did)?;
|
self.set_last_deck_for_notetype(note.notetype_id, did)?;
|
||||||
self.set_last_notetype_for_deck(did, note.notetype_id)?;
|
self.set_last_notetype_for_deck(did, note.notetype_id)?;
|
||||||
self.set_current_notetype_id(note.notetype_id)
|
self.set_current_notetype_id(note.notetype_id)?;
|
||||||
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_note(&mut self, note: &mut Note) -> Result<OpOutput<()>> {
|
pub fn update_note(&mut self, note: &mut Note) -> Result<OpOutput<()>> {
|
||||||
|
|
Loading…
Reference in a new issue