diff --git a/src/pages.rs b/src/pages.rs index 088e9a6..839e724 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -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: >k::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) -> Option { - if let Some(widget) = passed_widget.toplevel() { - return widget.downcast::().ok(); - } - None -} - -fn get_application_from_widget(passed_widget: &impl IsA) -> Option { - if let Some(window_widget) = get_window_from_widget(passed_widget) { - return window_widget.application(); - } - None -} diff --git a/src/utils.rs b/src/utils.rs index d398764..203c4b5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -76,6 +76,14 @@ pub fn create_combo_with_model(group_store: >k::ListStore) -> gtk::ComboBox { group_combo } +pub fn get_window_from_widget(passed_widget: &impl IsA) -> Option { + passed_widget.toplevel()?.downcast::().ok() +} + +pub fn get_application_from_widget(passed_widget: &impl IsA) -> Option { + get_window_from_widget(passed_widget)?.application() +} + pub fn get_translation_msgid(objname: &str) -> &'static str { match objname { "autostartlabel" => "launch-start-label",