From b352f2a581da3d8f4f0ce9ecc142180ad36eacfd Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Tue, 3 Nov 2020 10:27:07 +0100 Subject: [PATCH] widget/policycheck: introduce key_event * handle Escape in menu Signed-off-by: Ralf Zerres --- .../widgets/policycheck/policycheck_state.rs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/advotracker/src/widgets/policycheck/policycheck_state.rs b/advotracker/src/widgets/policycheck/policycheck_state.rs index b14a912..d9d4946 100644 --- a/advotracker/src/widgets/policycheck/policycheck_state.rs +++ b/advotracker/src/widgets/policycheck/policycheck_state.rs @@ -1,5 +1,6 @@ use locales::t; use orbtk::prelude::*; +use orbtk::shell::event::Key; use serde::Deserialize; use std::process; @@ -502,8 +503,8 @@ impl State for PolicycheckState { 0 => ctx.switch_theme(theme_default_dark()), 1 => ctx.switch_theme(theme_default_light()), 2 => ctx.switch_theme(theme_redox()), - 3 => ctx.switch_theme(theme_fluent_dark()), - 4 => ctx.switch_theme(theme_fluent_light()), + //3 => ctx.switch_theme(theme_fluent_dark()), + //4 => ctx.switch_theme(theme_fluent_light()), _ => {} } }, @@ -592,7 +593,7 @@ impl State for PolicycheckState { } PolicycheckAction::SetToggleTheme(_entity) => { self.set_menu_toggle_theme(ctx); - self.remove_popup(_entity, ctx); + //self.remove_popup(_entity, ctx); } PolicycheckAction::SetVisibility(_entity) => { TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); @@ -621,12 +622,20 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity { .open(true) .width(280) .height(140) - .on_mouse_down(move |ctx, _| { - println!("create_menu: on_click -> remove_popup(menu)"); - ctx.get_mut::(menu) - .action(PolicycheckAction::RemoveMenu(menu)); - // ToDo: print the entity id! - //.action(PolicycheckAction::RemovePopup(menu)); + .on_key_down(move | ctx, key_event | { + match key_event.key { + Key::Q(..) => { + //if is_ctrl_home_down(ctx) { + println!("got: Ctrl+Q"); + process::exit(0); + //} + }, + Key::Escape => { + ctx.get_mut::(menu) + .action(PolicycheckAction::RemoveMenu(menu)); + }, + _ => (), + }; true }) .child( @@ -739,7 +748,6 @@ fn create_menu_toggle_theme(menu_toggle_theme: Entity, ctx: &mut BuildContext<'_ .on_changed("selected_index", move |ctx, _| { ctx.send_message(PolicycheckAction::ChangeTheme, menu_toggle_theme); println!("changed theme."); - }) .selected_index(menu_toggle_theme) .build(ctx),