🧹 we just need to provide window object

This commit is contained in:
Vladislav Nepogodin 2023-04-01 22:36:39 +04:00
parent 5711e106aa
commit 231a29c9a9
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
3 changed files with 2 additions and 22 deletions

View File

@ -44,11 +44,7 @@ static mut G_HELLO_WINDOW: Option<Arc<HelloWindow>> = None;
fn quick_message(message: &'static str) {
// Create the widgets
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
let application_window =
window_ref.application().expect("Unable to retrieve application instance!");
let dialog = gtk::Dialog::builder()
.application(&application_window)
.attached_to(window_ref)
.transient_for(window_ref)
.title(message)
.modal(true)
@ -87,12 +83,7 @@ fn quick_message(message: &'static str) {
if !status && result == gtk::ResponseType::Yes {
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
let application_window =
window_ref.application().expect("Unable to retrieve application instance!");
let errordialog = gtk::MessageDialog::builder()
.application(&application_window)
.attached_to(window_ref)
.transient_for(window_ref)
.message_type(gtk::MessageType::Error)
.text(fl!("offline-error"))

View File

@ -219,13 +219,10 @@ fn create_fixes_section() -> gtk::Box {
Action::RemoveLock => &removelock_btn_clone,
Action::RemoveOrphans => &remove_orphans_btn_clone,
};
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 widget_window =
utils::get_window_from_widget(widget_obj).expect("Failed to retrieve window");
let dialog = gtk::MessageDialog::builder()
.application(&window_application)
.attached_to(&widget_window)
.transient_for(&widget_window)
.message_type(msg.msg_type)
.text(msg.msg)
@ -558,8 +555,6 @@ fn on_servbtn_clicked(button: &gtk::CheckButton) {
if !msg {
let widget_window =
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 =
unsafe { glib::signal::SignalHandlerId::from_glib(signal_handler) };
@ -568,8 +563,6 @@ fn on_servbtn_clicked(button: &gtk::CheckButton) {
button_sh.unblock_signal(&sighandle_id_obj);
let dialog = gtk::MessageDialog::builder()
.application(&window_application)
.attached_to(&widget_window)
.transient_for(&widget_window)
.message_type(gtk::MessageType::Error)
.text(fl!("package-not-installed", package_name = alpm_package_name))

View File

@ -80,10 +80,6 @@ pub fn get_window_from_widget(passed_widget: &impl IsA<gtk::Widget>) -> Option<g
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",