modified: bool,
- #[bind("note_maximized")]
- pub note_maximized: UiInteger,
-
#[bind("note_type")]
pub note_type: UiInteger,
title_end: -1,
modified: false,
- note_maximized: Default::default(),
note_type: Default::default(),
text: Default::default(),
info: Default::default(),
pub fn attachment_status_changed(&mut self, _event: &mut ActionEvent) -> Option<()>{
let doc = self.doc.get_doc()?;
- if let Some(mut obj) = doc.ctx.get_parent_object() {
+ if doc.ctx.is_attached_to_obj() {
// attached to an obj also means, this note is visible and the editor should
// require the lock for this note
// self.lock should always be none here
doc.ctx.unset_state(AppStates::NoteShowInfo as i32);
}
}
-
- let val = self.note_maximized.get();
- obj.splitview_set_visible(0, val == 0);
} else {
- // clean self.lock, however don't clean self.vhandle
self.lock = None;
self.text.set_readonly(false);
}
#[action]
pub fn notebook_view_changed(&mut self, event: &mut ActionEvent) {
+ // This action is for the toolbar button, to change the notebook view
+ // (dual view or maximized note), however, the view status variable is stored
+ // in the notebook.
let Some(obj) = &mut event.obj else {
return;
};
pub selected_note: Option<NoteSelection>,
- #[bind("notebook_dual_view")]
- pub view: UiInteger,
+ #[bind("note_maximized")]
+ pub note_maximized: UiInteger,
#[bind("notes")]
pub notes: UiList<NoteItem>
broadcast_rx: backend.btx.subscribe(),
collection_id: id,
selected_note: None,
- view: Default::default(),
+ note_maximized: Default::default(),
notes: Default::default()
}
}
+ pub fn into_doc(self) -> UiDoc<Notebook> {
+ UiDoc::new2(self, |notebook, doc| {
+ notebook.doc_ref = doc.doc_ref();
+ doc.ctx.on_attach_action("notebook_on_attach")
+ })
+ }
+
+ #[action]
+ pub fn notebook_on_attach(&mut self, event: &mut ActionEvent) {
+ let Some(obj) = &mut event.obj else {
+ return;
+ };
+
+ let val = self.note_maximized.get();
+ obj.splitview_set_visible(0, val == 0);
+ }
+
pub fn set_notes(&mut self, notes: Vec<Note>) {
let notes_list = self.notes.data_mut();
notes_list.clear();
if let EventType::ListSelection(s) = event.event_type {
let result = self.select_note_from(NoteSelectFrom::ListSelection(s));
//obj.splitview_set_visible(0, false);
- self.view.set(1);
// in case select_note_from didn't return a result, the note was already selected
// and no new navigation item was added
if result.is_none() {
pub fn load_notebook(&mut self, backend: &BackendHandle) -> UiDoc<Notebook> {
// Create Notebook UI model
let notebook = Notebook::new(self.data.collection_id, backend);
- let doc = UiDoc::new2(notebook, |notebook, doc| {
- notebook.doc_ref = doc.doc_ref();
- });
+ let doc = notebook.into_doc();
// Load notes
let proxy = doc.doc_proxy();
None
}
- pub fn list<T>(&self) -> UiList<T> {
- let mut ls = UiList::<T>::default();
- ls.init(self, None);
- ls
- }
-
pub unsafe fn add_action<T, F>(&self, name: &str, f: F)
where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
// if this is a document context, use the document pointer as target
self.add_action_for_target(target_ptr, name, f);
}
}
-
+
pub unsafe fn add_action_for_target<T, F>(&self, target_ptr: *mut T, name: &str, f: F)
where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
let wrapper = Box::new(ActionEventWrapper { callback: Box::new(f), target: target_ptr });