Skip to content

Commit

Permalink
implement unsupported dialog as trait
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 28, 2025
1 parent 6501738 commit 94ab229
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/app/browser/window/tab/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/app/browser/window/tab/item/identity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod default;
mod unsupported;

use adw::AlertDialog;
use default::Default;
use unsupported::Unsupported;

Expand All @@ -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()
}
55 changes: 33 additions & 22 deletions src/app/browser/window/tab/item/identity/unsupported.rs
Original file line number Diff line number Diff line change
@@ -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();

// 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<gtk::Widget>>) {
self.widget.present(parent)
// Return new activated `Self`
this
}
}
58 changes: 0 additions & 58 deletions src/app/browser/window/tab/item/identity/unsupported/widget.rs

This file was deleted.

0 comments on commit 94ab229

Please sign in to comment.