🧹 simplify and move functions to utils

This commit is contained in:
Vladislav Nepogodin 2023-04-01 22:26:15 +04:00
parent 43e6e58500
commit 5711e106aa
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
2 changed files with 12 additions and 18 deletions

View File

@ -219,8 +219,8 @@ fn create_fixes_section() -> gtk::Box {
Action::RemoveLock => &removelock_btn_clone,
Action::RemoveOrphans => &remove_orphans_btn_clone,
};
let widget_window = get_window_from_widget(widget_obj).expect("Failed to retrieve window");
let window_application = get_application_from_widget(widget_obj)
let widget_window = utils::get_window_from_widget(widget_obj).expect("Failed to retrieve window");
let window_application = utils::get_application_from_widget(widget_obj)
.expect("Failed to retrieve application instance");
let dialog = gtk::MessageDialog::builder()
@ -557,8 +557,8 @@ fn on_servbtn_clicked(button: &gtk::CheckButton) {
rx.attach(None, move |msg| {
if !msg {
let widget_window =
get_window_from_widget(&button_sh).expect("Failed to retrieve window");
let window_application = get_application_from_widget(&button_sh)
utils::get_window_from_widget(&button_sh).expect("Failed to retrieve window");
let window_application = utils::get_application_from_widget(&button_sh)
.expect("Failed to retrieve application instance");
let sighandle_id_obj =
@ -700,17 +700,3 @@ where
passed_btn.set_data("signalHandle", sighandle_id.as_raw());
}
}
fn get_window_from_widget(passed_widget: &impl IsA<gtk::Widget>) -> Option<gtk::Window> {
if let Some(widget) = passed_widget.toplevel() {
return widget.downcast::<gtk::Window>().ok();
}
None
}
fn get_application_from_widget(passed_widget: &impl IsA<gtk::Widget>) -> Option<gtk::Application> {
if let Some(window_widget) = get_window_from_widget(passed_widget) {
return window_widget.application();
}
None
}

View File

@ -76,6 +76,14 @@ pub fn create_combo_with_model(group_store: &gtk::ListStore) -> gtk::ComboBox {
group_combo
}
pub fn get_window_from_widget(passed_widget: &impl IsA<gtk::Widget>) -> Option<gtk::Window> {
passed_widget.toplevel()?.downcast::<gtk::Window>().ok()
}
pub fn get_application_from_widget(passed_widget: &impl IsA<gtk::Widget>) -> Option<gtk::Application> {
get_window_from_widget(passed_widget)?.application()
}
pub fn get_translation_msgid(objname: &str) -> &'static str {
match objname {
"autostartlabel" => "launch-start-label",