modified: bool,
is_saving: bool,
+ fixed_title: bool,
pub local_path: Option<PathBuf>,
pub local_lastmodified: Option<SystemTime>,
#[bind("note_type")]
pub note_type: UiInteger,
+ #[bind("note_title")]
+ pub title: UiString,
+
#[bind("note_text")]
pub text: UiText,
title_end: -1,
modified: false,
is_saving: false,
+ fixed_title: false,
local_path: None,
local_lastmodified: None,
note_type: Default::default(),
+ title: Default::default(),
text: Default::default(),
info: Default::default(),
}
_ => NoteTypeTabView::Empty
};
self.note_type.set(tab as i64);
+ self.title.set(model.title.as_str());
+ self.fixed_title = model.fixed_title;
}
pub fn init_new(&mut self) {
}
};
+ self.title.set(title);
+
if notify {
- let update = NoteTitleUpdate {
- collection_id: self.collection_id,
- note_id: self.id.clone(),
- title: title.to_string(),
- };
- _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NoteTitleUpdate(update));
+ self.notify_title_change(title);
}
}
+ pub fn notify_title_change(&mut self, title: &str) {
+ let update = NoteTitleUpdate {
+ collection_id: self.collection_id,
+ note_id: self.id.clone(),
+ title: title.to_string(),
+ };
+ _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NoteTitleUpdate(update));
+ }
+
#[action(Event)]
pub fn filesystem_notify(&mut self, _event: &ActionEvent, event: &Event) {
// for now we only care about modify events
}
}
- if !event.set && self.extract_title {
+ if !event.set && self.extract_title && !self.fixed_title {
self.update_title(self.text.get().as_str(), true);
}
self.extract_title = false;
}
+ #[action]
+ pub fn note_edit_title(&mut self, _event: &ActionEvent) {
+ let Some(doc) = self.doc.get_doc() else {
+ return;
+ };
+ doc.ctx.set_state(AppStates::NoteTitleInput as i32);
+ self.fixed_title = true;
+ }
+
+ #[action]
+ pub fn note_title_changed(&mut self, event: &ActionEvent) {
+ if event.set {
+ return;
+ }
+
+ let title = self.title.get();
+ self.notify_title_change(title.as_str());
+ self.modified = true;
+ }
+
#[action]
pub fn notebook_view_changed(&mut self, event: &mut ActionEvent) {
// This action is for the toolbar button, to change the notebook view
};
let content = self.text.get();
- let title = match generate_title(content.as_str()) {
- Some(title) => title.0.to_string(),
- None => "New Note".to_string() // TODO: see NoteItem::new()
+ let title = if self.fixed_title {
+ let title = self.title.get();
+ if title.is_empty() {
+ "New Note".to_string()
+ } else {
+ title
+ }
+ } else {
+ match generate_title(content.as_str()) {
+ Some(title) => title.0.to_string(),
+ None => "New Note".to_string() // TODO: see NoteItem::new()
+ }
};
let (note_id, created) = match &self.id {
title: Set(title),
lastmodified: Set(Utc::now().into()),
created: created,
+ fixed_title: Set(self.fixed_title),
version: Set(self.version)
};
button!(obj, label = "Reload", action = "note_reload");
button!(obj, label = "Close", action = "note_extmod_close");
});
+ hbox!(obj, visibility_states = &[AppStates::NoteTitleInput as i32], spacing = 4, margin = 4, |obj|{
+ label!(obj, label = "Title:");
+ textfield!(obj, fill = true, varname = "note_title", onchange_action = "note_title_changed");
+ });
let textarea = textarea!(obj, fill = true, varname = "note_text", onchange_action = "note_text_change", ontextchanged_action = "note_text_changed");
obj.ctx.add_action_untyped("textarea_focus", move|_event|{
textarea.focus();