widget/policycheck: introduce key_event
* handle Escape in menu Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -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::<PolicycheckState>(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::<PolicycheckState>(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),
|
||||
|
||||
Reference in New Issue
Block a user