mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
optimize identity dialog mod
This commit is contained in:
parent
fc8c967891
commit
a8008ad92c
4 changed files with 36 additions and 56 deletions
|
|
@ -2,7 +2,7 @@ mod database;
|
|||
mod identity;
|
||||
mod primary_icon;
|
||||
|
||||
use adw::prelude::AdwDialogExt;
|
||||
use adw::{prelude::AdwDialogExt, AlertDialog};
|
||||
use primary_icon::PrimaryIcon;
|
||||
|
||||
use super::{ItemAction, Profile};
|
||||
|
|
@ -244,10 +244,13 @@ impl Request for Entry {
|
|||
}
|
||||
}
|
||||
|
||||
/// Present identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self`
|
||||
fn identity(&self, profile: &Rc<Profile>) {
|
||||
// connect identity traits
|
||||
use identity::{Common, Unsupported};
|
||||
if let Some(uri) = self.uri() {
|
||||
if ["gemini", "titan"].contains(&uri.scheme().as_str()) {
|
||||
return identity::common(
|
||||
return AlertDialog::common(
|
||||
profile,
|
||||
&uri,
|
||||
&Rc::new({
|
||||
|
|
@ -264,7 +267,7 @@ impl Request for Entry {
|
|||
.present(Some(self));
|
||||
}
|
||||
}
|
||||
identity::unsupported().present(Some(self));
|
||||
AlertDialog::unsupported().present(Some(self));
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
|
|
|||
|
|
@ -1,24 +1,5 @@
|
|||
mod common;
|
||||
mod unsupported;
|
||||
|
||||
use adw::AlertDialog;
|
||||
use common::Common;
|
||||
use unsupported::Unsupported;
|
||||
|
||||
use super::Profile;
|
||||
use gtk::glib::Uri;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Create new identity widget for Gemini protocol match given URI
|
||||
pub fn common(
|
||||
profile: &Rc<Profile>,
|
||||
request: &Uri,
|
||||
callback: &Rc<impl Fn(bool) + 'static>,
|
||||
) -> AlertDialog {
|
||||
AlertDialog::common(profile, request, callback)
|
||||
}
|
||||
|
||||
/// Create new identity widget for unknown request
|
||||
pub fn unsupported() -> AlertDialog {
|
||||
AlertDialog::unsupported()
|
||||
}
|
||||
pub use common::Common;
|
||||
pub use unsupported::Unsupported;
|
||||
|
|
|
|||
|
|
@ -1,26 +1,12 @@
|
|||
mod action;
|
||||
pub mod form;
|
||||
|
||||
use action::Action as WidgetAction;
|
||||
use form::{list::item::value::Value, Form};
|
||||
mod form;
|
||||
|
||||
use crate::Profile;
|
||||
use adw::{
|
||||
prelude::{AlertDialogExt, AlertDialogExtManual},
|
||||
AlertDialog, ResponseAppearance,
|
||||
};
|
||||
use action::Action as WidgetAction;
|
||||
use adw::AlertDialog;
|
||||
use gtk::glib::Uri;
|
||||
use std::rc::Rc;
|
||||
|
||||
// Defaults
|
||||
const HEADING: &str = "Identity";
|
||||
const BODY: &str = "Select identity certificate";
|
||||
|
||||
// Response variants
|
||||
const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply");
|
||||
const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
|
||||
// const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage");
|
||||
|
||||
// Select options
|
||||
|
||||
pub trait Common {
|
||||
|
|
@ -37,6 +23,17 @@ impl Common for AlertDialog {
|
|||
request: &Uri,
|
||||
callback: &Rc<impl Fn(bool) + 'static>,
|
||||
) -> Self {
|
||||
use adw::{
|
||||
prelude::{AlertDialogExt, AlertDialogExtManual},
|
||||
ResponseAppearance,
|
||||
};
|
||||
use form::{list::item::value::Value, Form};
|
||||
|
||||
// Response variants
|
||||
const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply");
|
||||
const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
|
||||
// const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage");
|
||||
|
||||
// Init actions
|
||||
let action = Rc::new(WidgetAction::new());
|
||||
|
||||
|
|
@ -45,8 +42,8 @@ impl Common for AlertDialog {
|
|||
|
||||
// Init main widget
|
||||
let alert_dialog = AlertDialog::builder()
|
||||
.heading(HEADING)
|
||||
.body(BODY)
|
||||
.heading("Identity")
|
||||
.body("Select identity certificate")
|
||||
.close_response(RESPONSE_CANCEL.0)
|
||||
.default_response(RESPONSE_APPLY.0)
|
||||
.extra_child(&form.g_box)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,4 @@
|
|||
use adw::{
|
||||
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
|
||||
AlertDialog,
|
||||
};
|
||||
|
||||
const HEADING: &str = "Oops";
|
||||
const BODY: &str = "Identity not supported for this request";
|
||||
const RESPONSE_QUIT: (&str, &str) = ("close", "Close");
|
||||
use adw::AlertDialog;
|
||||
|
||||
pub trait Unsupported {
|
||||
fn unsupported() -> Self;
|
||||
|
|
@ -16,8 +9,14 @@ impl Unsupported for AlertDialog {
|
|||
|
||||
/// Create new `Self`
|
||||
fn unsupported() -> Self {
|
||||
use adw::prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual};
|
||||
|
||||
const HEADING: &str = "Oops";
|
||||
const BODY: &str = "Identity not supported for this request";
|
||||
const RESPONSE_QUIT: (&str, &str) = ("close", "Close");
|
||||
|
||||
// Init gobject
|
||||
let this = AlertDialog::builder()
|
||||
let alert_dialog = AlertDialog::builder()
|
||||
.heading(HEADING)
|
||||
.body(BODY)
|
||||
.close_response(RESPONSE_QUIT.0)
|
||||
|
|
@ -25,20 +24,20 @@ impl Unsupported for AlertDialog {
|
|||
.build();
|
||||
|
||||
// Set response variants
|
||||
this.add_responses(&[RESPONSE_QUIT]);
|
||||
alert_dialog.add_responses(&[RESPONSE_QUIT]);
|
||||
|
||||
// Decorate default response preset
|
||||
/* contrast issue with Ubuntu orange accents
|
||||
this.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */
|
||||
alert_dialog.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); */
|
||||
|
||||
// Init events
|
||||
this.connect_response(None, move |dialog, response| {
|
||||
alert_dialog.connect_response(None, move |dialog, response| {
|
||||
if response == RESPONSE_QUIT.0 {
|
||||
dialog.close();
|
||||
}
|
||||
});
|
||||
|
||||
// Return new activated `Self`
|
||||
this
|
||||
alert_dialog
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue