#[derive(Clone)]
pub enum BroadcastMessage {
NotebookStructureUpdate(Vec<Node>),
- NotesUpdate(NotesUpdate),
+ NoteTitleUpdate(NoteTitleUpdate),
}
#[derive(Clone, PartialEq, Eq)]
}
#[derive(Clone, Default)]
-pub struct NoteUpdate {
- pub note_id: NoteId,
- pub title: Option<String>,
- pub content: bool,
-}
-
-#[derive(Clone, Default)]
-pub struct NotesUpdate {
+pub struct NoteTitleUpdate {
pub collection_id: i32,
- pub note_updates: Vec<NoteUpdate>,
-}
-
-impl NotesUpdate {
- pub fn new(collection_id: i32, note_updates: Vec<NoteUpdate>) -> Self {
- NotesUpdate {
- collection_id: collection_id,
- note_updates: note_updates,
- }
- }
+ pub note_id: NoteId,
+ pub title: String,
}
use entity::note::NoteType;
use ui_rs::{action, ui_actions, UiModel};
use ui_rs::ui::*;
-use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteUpdate, NotesUpdate};
+use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate};
use crate::window::NoteTypeTabView;
static TMP_ID: AtomicU64 = AtomicU64::new(1);
self.title_end = result.1 as i32 + title.len() as i32;
if notify {
- let update = NoteUpdate {
+ let update = NoteTitleUpdate {
+ collection_id: self.collection_id,
note_id: self.id.clone(),
- title: Some(title.to_string()),
- ..Default::default()
+ title: title.to_string(),
};
- let msg = NotesUpdate::new(self.collection_id, vec![update]);
- _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NotesUpdate(msg));
+ _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NoteTitleUpdate(update));
}
},
None => {
let content = self.text.get();
let title = match generate_title(content.as_str()) {
Some(title) => title.0.to_string(),
- None => "New Note".to_string()
+ None => "New Note".to_string() // TODO: see NoteItem::new()
};
let (note_id, created) = match &self.id {
use ui_rs::ui::*;
use entity::note::{Model as Note};
-use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteUpdate};
+use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate};
use crate::note::new_note_id;
use crate::window::NavigationItem;
if let Some(mut nb) = self.doc_ref.get_doc() {
nb.ctx.attach(&doc);
- //nb.ctx.call_action("textarea_focus");
- nb.doc_proxy().call_mainthread(move |doc, note|{
- doc.ctx.call_action("textarea_focus");
- });
+ nb.ctx.call_action("textarea_focus");
self.selected_note = Some(doc);
if add_to_nav {
self.select_note_from(NoteSelectFrom::NavigationItem(nav.clone()));
}
- pub fn update_note(&mut self, update: &NoteUpdate) {
+ pub fn update_note_title(&mut self, update: &NoteTitleUpdate) {
// Find the note in the list (or add it if it doesn't exist yet)
// Start with the currently selected note
let mut update_row: Option<usize> = None;
if let Some(index) = self.selected_index {
if let Some(item) = self.notes.data_mut().get_mut(index) {
if item.id == update.note_id {
- item.update(&update);
+ item.data.title = update.title.clone();
update_row = Some(index);
}
}
if update_row.is_none() {
for (index, item) in self.notes.data_mut().iter_mut().enumerate() {
if item.id == update.note_id {
- item.update(&update);
+ item.data.title = update.title.clone();
update_row = Some(index);
break;
}
pub fn message(&mut self, _event: &ActionEvent) {
while let Ok(msg) = self.broadcast_rx.try_recv() {
match msg {
- BroadcastMessage::NotesUpdate(update) => {
- if update.note_updates.len() == 1 {
- self.update_note(&update.note_updates[0]);
- } else if update.note_updates.len() > 1 {
- let mut update_rows: Vec<usize> = Vec::new();
- for u in &update.note_updates {
- if let NoteId::Id(id) = u.note_id {
- let note_data = self.notes.data_mut();
- for (i, note) in note_data.iter_mut().enumerate() {
- if note.data.note_id == id {
- note.update(u);
- update_rows.push(i);
- }
- }
- }
- }
-
- for i in update_rows {
- self.notes.update_row(i);
- }
+ BroadcastMessage::NoteTitleUpdate(update) => {
+ if update.collection_id == self.collection_id {
+ self.update_note_title(&update);
}
},
_ => {
pub fn is_new(&self) -> bool {
return matches!(self.id, NoteId::TmpId(_))
}
-
- pub fn update(&mut self, update: &NoteUpdate) {
- // update note
- if let Some(title) = &update.title {
- self.data.title = title.clone();
- }
- }
}
\ No newline at end of file