app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

menus.rs (1630B)


      1 use gpui::{App, KeyBinding, Menu, MenuItem, SystemMenuType, actions};
      2 use radroots_app_i18n::{AppTextKey, app_text};
      3 
      4 use crate::{
      5     runtime::DesktopAppRuntime,
      6     window::{SettingsPanelViewKey, open_settings_window, settings_window_options},
      7 };
      8 
      9 actions!(radroots_app, [OpenAboutWindow, QuitApp]);
     10 
     11 const fn about_menu_settings_view() -> SettingsPanelViewKey {
     12     SettingsPanelViewKey::Account
     13 }
     14 
     15 pub fn install_native_app_menu(runtime: DesktopAppRuntime, cx: &mut App) {
     16     cx.on_action(move |_: &OpenAboutWindow, cx| {
     17         let options = settings_window_options(cx);
     18         cx.open_window(options, |window, cx| {
     19             open_settings_window(window, cx, runtime.clone(), about_menu_settings_view())
     20         })
     21         .expect("settings window should open");
     22     });
     23     cx.on_action(|_: &QuitApp, cx| cx.quit());
     24     cx.bind_keys([KeyBinding::new("cmd-q", QuitApp, None)]);
     25 
     26     let app_name = app_text(AppTextKey::AppName);
     27     cx.set_menus(vec![Menu {
     28         name: app_name.into(),
     29         items: vec![
     30             MenuItem::action(app_text(AppTextKey::MenuAbout), OpenAboutWindow),
     31             MenuItem::separator(),
     32             MenuItem::os_submenu(app_text(AppTextKey::MenuServices), SystemMenuType::Services),
     33             MenuItem::separator(),
     34             MenuItem::action(app_text(AppTextKey::MenuQuit), QuitApp),
     35         ],
     36     }]);
     37 }
     38 
     39 #[cfg(test)]
     40 mod tests {
     41     use super::about_menu_settings_view;
     42     use crate::window::SettingsPanelViewKey;
     43 
     44     #[test]
     45     fn about_menu_targets_the_account_settings_panel() {
     46         assert_eq!(about_menu_settings_view(), SettingsPanelViewKey::Account);
     47     }
     48 }