mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
implement unsupported dialog as trait
This commit is contained in:
parent
6501738737
commit
94ab229c1b
4 changed files with 37 additions and 83 deletions
|
|
@ -8,7 +8,7 @@ mod widget;
|
||||||
use super::{Action as TabAction, BrowserAction, Position, WindowAction};
|
use super::{Action as TabAction, BrowserAction, Position, WindowAction};
|
||||||
use crate::Profile;
|
use crate::Profile;
|
||||||
use action::Action;
|
use action::Action;
|
||||||
use adw::TabView;
|
use adw::{prelude::AdwDialogExt, TabView};
|
||||||
use client::Client;
|
use client::Client;
|
||||||
use gtk::prelude::{ActionMapExt, Cast};
|
use gtk::prelude::{ActionMapExt, Cast};
|
||||||
use page::Page;
|
use page::Page;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
mod default;
|
mod default;
|
||||||
mod unsupported;
|
mod unsupported;
|
||||||
|
|
||||||
|
use adw::AlertDialog;
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use unsupported::Unsupported;
|
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
|
/// Create new identity widget for unknown request
|
||||||
pub fn unsupported() -> Unsupported {
|
pub fn unsupported() -> AlertDialog {
|
||||||
Unsupported::new()
|
AlertDialog::unsupported()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,44 @@
|
||||||
mod widget;
|
use adw::{
|
||||||
use widget::Widget;
|
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
|
||||||
|
AlertDialog,
|
||||||
|
};
|
||||||
|
|
||||||
use gtk::prelude::IsA;
|
const HEADING: &str = "Oops";
|
||||||
use std::rc::Rc;
|
const BODY: &str = "Identity not supported for this request";
|
||||||
|
const RESPONSE_QUIT: (&str, &str) = ("close", "Close");
|
||||||
|
|
||||||
pub struct Unsupported {
|
pub trait Unsupported {
|
||||||
widget: Rc<Widget>,
|
fn unsupported() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Unsupported {
|
impl Unsupported for AlertDialog {
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Unsupported {
|
|
||||||
// Construct
|
// Construct
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new() -> Self {
|
fn unsupported() -> Self {
|
||||||
Self {
|
// Init gobject
|
||||||
widget: Rc::new(Widget::new()),
|
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
|
// Decorate default response preset
|
||||||
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
|
/* contrast issue with Ubuntu orange accents
|
||||||
self.widget.present(parent)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue