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 locales::t;
|
||||||
use orbtk::prelude::*;
|
use orbtk::prelude::*;
|
||||||
|
use orbtk::shell::event::Key;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::process;
|
use std::process;
|
||||||
@@ -502,8 +503,8 @@ impl State for PolicycheckState {
|
|||||||
0 => ctx.switch_theme(theme_default_dark()),
|
0 => ctx.switch_theme(theme_default_dark()),
|
||||||
1 => ctx.switch_theme(theme_default_light()),
|
1 => ctx.switch_theme(theme_default_light()),
|
||||||
2 => ctx.switch_theme(theme_redox()),
|
2 => ctx.switch_theme(theme_redox()),
|
||||||
3 => ctx.switch_theme(theme_fluent_dark()),
|
//3 => ctx.switch_theme(theme_fluent_dark()),
|
||||||
4 => ctx.switch_theme(theme_fluent_light()),
|
//4 => ctx.switch_theme(theme_fluent_light()),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -592,7 +593,7 @@ impl State for PolicycheckState {
|
|||||||
}
|
}
|
||||||
PolicycheckAction::SetToggleTheme(_entity) => {
|
PolicycheckAction::SetToggleTheme(_entity) => {
|
||||||
self.set_menu_toggle_theme(ctx);
|
self.set_menu_toggle_theme(ctx);
|
||||||
self.remove_popup(_entity, ctx);
|
//self.remove_popup(_entity, ctx);
|
||||||
}
|
}
|
||||||
PolicycheckAction::SetVisibility(_entity) => {
|
PolicycheckAction::SetVisibility(_entity) => {
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
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)
|
.open(true)
|
||||||
.width(280)
|
.width(280)
|
||||||
.height(140)
|
.height(140)
|
||||||
.on_mouse_down(move |ctx, _| {
|
.on_key_down(move | ctx, key_event | {
|
||||||
println!("create_menu: on_click -> remove_popup(menu)");
|
match key_event.key {
|
||||||
ctx.get_mut::<PolicycheckState>(menu)
|
Key::Q(..) => {
|
||||||
.action(PolicycheckAction::RemoveMenu(menu));
|
//if is_ctrl_home_down(ctx) {
|
||||||
// ToDo: print the entity id!
|
println!("got: Ctrl+Q");
|
||||||
//.action(PolicycheckAction::RemovePopup(menu));
|
process::exit(0);
|
||||||
|
//}
|
||||||
|
},
|
||||||
|
Key::Escape => {
|
||||||
|
ctx.get_mut::<PolicycheckState>(menu)
|
||||||
|
.action(PolicycheckAction::RemoveMenu(menu));
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -739,7 +748,6 @@ fn create_menu_toggle_theme(menu_toggle_theme: Entity, ctx: &mut BuildContext<'_
|
|||||||
.on_changed("selected_index", move |ctx, _| {
|
.on_changed("selected_index", move |ctx, _| {
|
||||||
ctx.send_message(PolicycheckAction::ChangeTheme, menu_toggle_theme);
|
ctx.send_message(PolicycheckAction::ChangeTheme, menu_toggle_theme);
|
||||||
println!("changed theme.");
|
println!("changed theme.");
|
||||||
|
|
||||||
})
|
})
|
||||||
.selected_index(menu_toggle_theme)
|
.selected_index(menu_toggle_theme)
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
|
|||||||
Reference in New Issue
Block a user