2021-02-08 18:37:25 +11:00
|
|
|
//! The main Todos window toolbar. Contains a button to enable adding a new task.
|
|
|
|
|
2022-07-16 00:14:02 +10:00
|
|
|
use cacao::appkit::toolbar::{ItemIdentifier, Toolbar, ToolbarDelegate, ToolbarDisplayMode, ToolbarItem};
|
2021-02-08 18:37:25 +11:00
|
|
|
use cacao::button::Button;
|
|
|
|
|
|
|
|
use crate::storage::{dispatch_ui, Message};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TodosToolbar(ToolbarItem);
|
|
|
|
|
|
|
|
impl Default for TodosToolbar {
|
|
|
|
fn default() -> Self {
|
|
|
|
TodosToolbar({
|
|
|
|
let mut item = ToolbarItem::new("AddTodoButton");
|
|
|
|
item.set_title("Add Todo");
|
|
|
|
item.set_button(Button::new("+ New"));
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2021-02-08 18:37:25 +11:00
|
|
|
item.set_action(|| {
|
|
|
|
dispatch_ui(Message::OpenNewTodoSheet);
|
|
|
|
});
|
|
|
|
|
|
|
|
item
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToolbarDelegate for TodosToolbar {
|
|
|
|
const NAME: &'static str = "TodosToolbar";
|
|
|
|
|
|
|
|
fn did_load(&mut self, toolbar: Toolbar) {
|
|
|
|
toolbar.set_display_mode(ToolbarDisplayMode::IconOnly);
|
|
|
|
}
|
|
|
|
|
2021-03-05 12:24:39 +11:00
|
|
|
fn allowed_item_identifiers(&self) -> Vec<ItemIdentifier> {
|
|
|
|
vec![ItemIdentifier::Custom("AddTodoButton")]
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
|
2021-03-05 12:24:39 +11:00
|
|
|
fn default_item_identifiers(&self) -> Vec<ItemIdentifier> {
|
|
|
|
vec![ItemIdentifier::Custom("AddTodoButton")]
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// We only have one item, so we don't care about the identifier.
|
|
|
|
fn item_for(&self, _identifier: &str) -> &ToolbarItem {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|