2021-02-08 18:37:25 +11:00
|
|
|
//! Implements a window for adding a new Todo.
|
|
|
|
|
2021-08-08 15:31:48 +10:00
|
|
|
use cacao::appkit::window::{Window, WindowDelegate};
|
2021-02-08 18:37:25 +11:00
|
|
|
use cacao::view::ViewController;
|
|
|
|
|
|
|
|
use crate::storage::{dispatch_ui, Message};
|
|
|
|
|
|
|
|
mod view;
|
|
|
|
use view::AddNewTodoContentView;
|
|
|
|
|
|
|
|
pub struct AddNewTodoWindow {
|
|
|
|
pub content: ViewController<AddNewTodoContentView>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddNewTodoWindow {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
let content = ViewController::new(AddNewTodoContentView::default());
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2021-02-08 18:37:25 +11:00
|
|
|
AddNewTodoWindow {
|
|
|
|
content: content
|
|
|
|
}
|
|
|
|
}
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2021-02-08 18:37:25 +11:00
|
|
|
pub fn on_message(&self, message: Message) {
|
|
|
|
if let Some(delegate) = &self.content.view.delegate {
|
|
|
|
delegate.on_message(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WindowDelegate for AddNewTodoWindow {
|
|
|
|
const NAME: &'static str = "AddNewTodoWindow";
|
2022-07-11 01:15:29 +10:00
|
|
|
|
|
|
|
fn did_load(&mut self, window: Window) {
|
2021-02-08 18:37:25 +11:00
|
|
|
window.set_autosave_name("AddNewTodoWindow");
|
|
|
|
window.set_minimum_content_size(300, 100);
|
|
|
|
window.set_title("Add a New Task");
|
|
|
|
window.set_content_view_controller(&self.content);
|
|
|
|
}
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2021-02-08 18:37:25 +11:00
|
|
|
fn cancel(&self) {
|
|
|
|
dispatch_ui(Message::CloseSheet);
|
|
|
|
}
|
|
|
|
}
|