Skip to content

Commit

Permalink
Add convenient theme menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Mar 26, 2023
1 parent 988a265 commit f75a597
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ impl ApplicationInner {
w.present();
}),
);
let set_theme =
gtk::gio::SimpleAction::new("settings.set_theme", Some(glib::VariantTy::STRING));
set_theme.connect_activate(glib::clone!(@weak obj => move |_, name| {
use glib::FromVariant;
if let Some(v) = name.map(String::from_variant).and_then(|s| Theme::kebab_str_deserialize(&s?)) {
obj.set_property(Application::THEME, v);
}
}));
let import_glyphs = gtk::gio::SimpleAction::new("project.import.glyphs", None);

import_glyphs.connect_activate(glib::clone!(@weak window => move |_, _| {
Expand Down Expand Up @@ -546,6 +554,7 @@ impl ApplicationInner {
application.add_action(&import_glyphs);
application.add_action(&import_ufo2);
application.add_action(&settings);
application.add_action(&set_theme);
application.add_action(&about);
application.add_action(&bug_report);
application.add_action(&open_path);
Expand Down Expand Up @@ -634,6 +643,21 @@ impl ApplicationInner {
let win_menu = gio::Menu::new();
win_menu.append(Some("_Next tab"), Some("win.next_tab"));
win_menu.append(Some("_Previous tab"), Some("win.prev_tab"));
let theme_menu = gio::Menu::new();
for (label, theme) in [
("System default", "system-default"),
("Paperwhite", "paperwhite"),
] {
// [ref:TODO] use SimpleAction with boolean state to make these menu entries into
// checkboxes
let themeitem = gio::MenuItem::new(Some(label), Some("app.settings.set_theme"));
themeitem.set_action_and_target_value(
Some("app.settings.set_theme"),
Some(&theme.to_variant()),
);
theme_menu.append_item(&themeitem);
}
win_menu.append_submenu(Some("_Theme"), &theme_menu);
menu_bar.append_submenu(Some("_Window"), &win_menu);
}

Expand Down

0 comments on commit f75a597

Please sign in to comment.