log when the window popped up. Change the window title too

main
_ 2022-03-31 03:03:25 +00:00
parent f07ce8a5dd
commit 833692d7ed
1 changed files with 12 additions and 6 deletions

View File

@ -3,6 +3,7 @@ use std::{
};
use chrono::{
DateTime,
Local,
SecondsFormat,
};
@ -123,11 +124,12 @@ enum Error {
#[derive (serde::Serialize)]
struct JournalLine {
text: String,
time_popped_up: Option <String>,
time_submitted: String,
}
struct Gui {
armed: bool,
time_popped_up: Option <DateTime <Local>>,
editor: text::TextEditor,
wind: Window,
}
@ -150,23 +152,25 @@ impl Gui {
let mut but = button::ReturnButton::new (640 - 100, 480 - 50, 100, 50, "Submit");
but.emit (fltk_tx, Message::Submit);
wind.set_label ("ANNOYING JOURNAL");
wind.end ();
wind.show ();
Self {
armed: true,
time_popped_up: Some (Local::now ()),
editor,
wind,
}
}
fn pop_up (&mut self) -> Result <(), Error> {
if ! self.armed {
eprintln! ("O4U6E36V Ignoring pop-up, not armed");
if self.time_popped_up.is_some () {
eprintln! ("O4U6E36V Ignoring pop-up, already popped up");
return Ok (());
}
self.armed = false;
self.time_popped_up = Some (Local::now ());
self.wind.set_label ("ANNOYING JOURNAL");
self.wind.show ();
self.editor.take_focus ()?;
@ -181,6 +185,7 @@ impl Gui {
let jl = JournalLine {
text: buffer.text (),
time_popped_up: self.time_popped_up.map (|x| x.to_rfc3339_opts (SecondsFormat::Secs, true)),
time_submitted: Local::now ().to_rfc3339_opts (SecondsFormat::Secs, true),
};
@ -198,7 +203,8 @@ impl Gui {
println! ("{}", s);
self.editor.set_buffer (text::TextBuffer::default ());
self.wind.iconize ();
self.armed = true;
self.time_popped_up = None;
self.wind.set_label ("annoying journal");
Ok (())
}