implement unsupported dialog as trait

This commit is contained in:
yggverse 2025-01-28 16:01:17 +02:00
parent 6501738737
commit 94ab229c1b
4 changed files with 37 additions and 83 deletions

View file

@ -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;

View file

@ -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<Profile>, 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()
}

View file

@ -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<Widget>,
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();
// Actions
// Set response variants
this.add_responses(&[RESPONSE_QUIT]);
/// Show dialog for given parent
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
self.widget.present(parent)
// Decorate default response preset
/* contrast issue with Ubuntu orange accents
this.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */
// Init events
this.connect_response(None, move |dialog, response| {
if response == RESPONSE_QUIT.0 {
dialog.close();
}
});
// Return new activated `Self`
this
}
}

View file

@ -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<gtk::Widget>>) {
self.gobject.present(parent)
}
}