2021-02-08 18:37:25 +11:00
|
|
|
//! Implements an example toolbar for a Preferences app. Could be cleaner, probably worth cleaning
|
|
|
|
//! up at some point.
|
|
|
|
|
2022-07-16 00:14:02 +10:00
|
|
|
use cacao::appkit::toolbar::{ItemIdentifier, Toolbar, ToolbarDelegate, ToolbarItem};
|
2021-02-08 18:37:25 +11:00
|
|
|
use cacao::image::{Image, MacSystemIcon};
|
|
|
|
|
|
|
|
use crate::storage::{dispatch_ui, Message};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct PreferencesToolbar((ToolbarItem, ToolbarItem));
|
|
|
|
|
|
|
|
impl Default for PreferencesToolbar {
|
|
|
|
fn default() -> Self {
|
2022-07-16 00:14:02 +10:00
|
|
|
PreferencesToolbar((
|
|
|
|
{
|
|
|
|
let mut item = ToolbarItem::new("general");
|
|
|
|
item.set_title("General");
|
|
|
|
|
|
|
|
let icon = Image::toolbar_icon(MacSystemIcon::PreferencesGeneral, "General");
|
|
|
|
item.set_image(icon);
|
|
|
|
|
2023-08-01 16:51:53 +10:00
|
|
|
item.set_action(|_| {
|
2022-07-16 00:14:02 +10:00
|
|
|
dispatch_ui(Message::SwitchPreferencesToGeneralPane);
|
|
|
|
});
|
|
|
|
|
|
|
|
item
|
|
|
|
},
|
|
|
|
{
|
|
|
|
let mut item = ToolbarItem::new("advanced");
|
|
|
|
item.set_title("Advanced");
|
|
|
|
|
|
|
|
let icon = Image::toolbar_icon(MacSystemIcon::PreferencesAdvanced, "Advanced");
|
|
|
|
item.set_image(icon);
|
|
|
|
|
2023-08-01 16:51:53 +10:00
|
|
|
item.set_action(|_| {
|
2022-07-16 00:14:02 +10:00
|
|
|
dispatch_ui(Message::SwitchPreferencesToAdvancedPane);
|
|
|
|
});
|
|
|
|
|
|
|
|
item
|
|
|
|
}
|
|
|
|
))
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToolbarDelegate for PreferencesToolbar {
|
|
|
|
const NAME: &'static str = "PreferencesToolbar";
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2021-02-08 18:37:25 +11:00
|
|
|
fn did_load(&mut self, toolbar: Toolbar) {
|
|
|
|
toolbar.set_selected("general");
|
|
|
|
}
|
|
|
|
|
2021-03-05 12:24:39 +11:00
|
|
|
fn allowed_item_identifiers(&self) -> Vec<ItemIdentifier> {
|
|
|
|
vec![ItemIdentifier::Custom("general"), ItemIdentifier::Custom("advanced")]
|
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("general"), ItemIdentifier::Custom("advanced")]
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
|
2021-03-05 12:24:39 +11:00
|
|
|
fn selectable_item_identifiers(&self) -> Vec<ItemIdentifier> {
|
|
|
|
vec![ItemIdentifier::Custom("general"), ItemIdentifier::Custom("advanced")]
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
fn item_for(&self, identifier: &str) -> &ToolbarItem {
|
|
|
|
match identifier {
|
2022-07-16 00:14:02 +10:00
|
|
|
"general" => &self.0 .0,
|
|
|
|
"advanced" => &self.0 .1,
|
|
|
|
_ => {
|
|
|
|
unreachable!();
|
|
|
|
}
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|