From 94ab229c1b823889cdd5d890764036a30851a692 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 28 Jan 2025 16:01:17 +0200 Subject: [PATCH] implement unsupported dialog as trait --- src/app/browser/window/tab/item.rs | 2 +- src/app/browser/window/tab/item/identity.rs | 5 +- .../window/tab/item/identity/unsupported.rs | 55 +++++++++++------- .../tab/item/identity/unsupported/widget.rs | 58 ------------------- 4 files changed, 37 insertions(+), 83 deletions(-) delete mode 100644 src/app/browser/window/tab/item/identity/unsupported/widget.rs diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index a2543417..7a848738 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -8,7 +8,7 @@ mod widget; use super::{Action as TabAction, BrowserAction, Position, WindowAction}; use crate::Profile; use action::Action; -use adw::TabView; +use adw::{prelude::AdwDialogExt, TabView}; use client::Client; use gtk::prelude::{ActionMapExt, Cast}; use page::Page; diff --git a/src/app/browser/window/tab/item/identity.rs b/src/app/browser/window/tab/item/identity.rs index ab179b1a..728032fa 100644 --- a/src/app/browser/window/tab/item/identity.rs +++ b/src/app/browser/window/tab/item/identity.rs @@ -1,6 +1,7 @@ mod default; mod unsupported; +use adw::AlertDialog; use default::Default; use unsupported::Unsupported; @@ -14,6 +15,6 @@ pub fn default(profile: &Rc, request: &Uri, on_apply: impl Fn() + 'stat } /// Create new identity widget for unknown request -pub fn unsupported() -> Unsupported { - Unsupported::new() +pub fn unsupported() -> AlertDialog { + AlertDialog::unsupported() } diff --git a/src/app/browser/window/tab/item/identity/unsupported.rs b/src/app/browser/window/tab/item/identity/unsupported.rs index c3ab3a4a..b664a12b 100644 --- a/src/app/browser/window/tab/item/identity/unsupported.rs +++ b/src/app/browser/window/tab/item/identity/unsupported.rs @@ -1,33 +1,44 @@ -mod widget; -use widget::Widget; +use adw::{ + prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, + AlertDialog, +}; -use gtk::prelude::IsA; -use std::rc::Rc; +const HEADING: &str = "Oops"; +const BODY: &str = "Identity not supported for this request"; +const RESPONSE_QUIT: (&str, &str) = ("close", "Close"); -pub struct Unsupported { - widget: Rc, +pub trait Unsupported { + fn unsupported() -> Self; } -impl Default for Unsupported { - fn default() -> Self { - Self::new() - } -} - -impl Unsupported { +impl Unsupported for AlertDialog { // Construct /// Create new `Self` - pub fn new() -> Self { - Self { - widget: Rc::new(Widget::new()), - } - } + fn unsupported() -> Self { + // Init gobject + let this = AlertDialog::builder() + .heading(HEADING) + .body(BODY) + .close_response(RESPONSE_QUIT.0) + .default_response(RESPONSE_QUIT.0) + .build(); + + // Set response variants + this.add_responses(&[RESPONSE_QUIT]); + + // Decorate default response preset + /* contrast issue with Ubuntu orange accents + this.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */ - // Actions + // Init events + this.connect_response(None, move |dialog, response| { + if response == RESPONSE_QUIT.0 { + dialog.close(); + } + }); - /// Show dialog for given parent - pub fn present(&self, parent: Option<&impl IsA>) { - self.widget.present(parent) + // Return new activated `Self` + this } } diff --git a/src/app/browser/window/tab/item/identity/unsupported/widget.rs b/src/app/browser/window/tab/item/identity/unsupported/widget.rs deleted file mode 100644 index a4df74b9..00000000 --- a/src/app/browser/window/tab/item/identity/unsupported/widget.rs +++ /dev/null @@ -1,58 +0,0 @@ -use adw::{ - prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, - AlertDialog, -}; -use gtk::prelude::IsA; - -const HEADING: &str = "Oops"; -const BODY: &str = "Identity not supported for this request"; -const RESPONSE_QUIT: (&str, &str) = ("close", "Close"); - -pub struct Widget { - gobject: AlertDialog, -} - -impl Default for Widget { - fn default() -> Self { - Self::new() - } -} - -impl Widget { - // Constructors - - /// Create new `Self` - pub fn new() -> Self { - // Init gobject - let gobject = AlertDialog::builder() - .heading(HEADING) - .body(BODY) - .close_response(RESPONSE_QUIT.0) - .default_response(RESPONSE_QUIT.0) - .build(); - - // Set response variants - gobject.add_responses(&[RESPONSE_QUIT]); - - // Decorate default response preset - /* contrast issue with Ubuntu orange accents - gobject.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */ - - // Init events - gobject.connect_response(None, move |dialog, response| { - if response == RESPONSE_QUIT.0 { - dialog.close(); - } - }); - - // Return new activated `Self` - Self { gobject } - } - - // Actions - - /// Show dialog for given parent - pub fn present(&self, parent: Option<&impl IsA>) { - self.gobject.present(parent) - } -}