mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +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 identity;
|
||||||
mod primary_icon;
|
mod primary_icon;
|
||||||
|
|
||||||
use adw::prelude::AdwDialogExt;
|
use adw::{prelude::AdwDialogExt, AlertDialog};
|
||||||
use primary_icon::PrimaryIcon;
|
use primary_icon::PrimaryIcon;
|
||||||
|
|
||||||
use super::{ItemAction, Profile};
|
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>) {
|
fn identity(&self, profile: &Rc<Profile>) {
|
||||||
|
// connect identity traits
|
||||||
|
use identity::{Common, Unsupported};
|
||||||
if let Some(uri) = self.uri() {
|
if let Some(uri) = self.uri() {
|
||||||
if ["gemini", "titan"].contains(&uri.scheme().as_str()) {
|
if ["gemini", "titan"].contains(&uri.scheme().as_str()) {
|
||||||
return identity::common(
|
return AlertDialog::common(
|
||||||
profile,
|
profile,
|
||||||
&uri,
|
&uri,
|
||||||
&Rc::new({
|
&Rc::new({
|
||||||
|
|
@ -264,7 +267,7 @@ impl Request for Entry {
|
||||||
.present(Some(self));
|
.present(Some(self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
identity::unsupported().present(Some(self));
|
AlertDialog::unsupported().present(Some(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,5 @@
|
||||||
mod common;
|
mod common;
|
||||||
mod unsupported;
|
mod unsupported;
|
||||||
|
|
||||||
use adw::AlertDialog;
|
pub use common::Common;
|
||||||
use common::Common;
|
pub use unsupported::Unsupported;
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,12 @@
|
||||||
mod action;
|
mod action;
|
||||||
pub mod form;
|
mod form;
|
||||||
|
|
||||||
use action::Action as WidgetAction;
|
|
||||||
use form::{list::item::value::Value, Form};
|
|
||||||
|
|
||||||
use crate::Profile;
|
use crate::Profile;
|
||||||
use adw::{
|
use action::Action as WidgetAction;
|
||||||
prelude::{AlertDialogExt, AlertDialogExtManual},
|
use adw::AlertDialog;
|
||||||
AlertDialog, ResponseAppearance,
|
|
||||||
};
|
|
||||||
use gtk::glib::Uri;
|
use gtk::glib::Uri;
|
||||||
use std::rc::Rc;
|
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
|
// Select options
|
||||||
|
|
||||||
pub trait Common {
|
pub trait Common {
|
||||||
|
|
@ -37,6 +23,17 @@ impl Common for AlertDialog {
|
||||||
request: &Uri,
|
request: &Uri,
|
||||||
callback: &Rc<impl Fn(bool) + 'static>,
|
callback: &Rc<impl Fn(bool) + 'static>,
|
||||||
) -> Self {
|
) -> 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
|
// Init actions
|
||||||
let action = Rc::new(WidgetAction::new());
|
let action = Rc::new(WidgetAction::new());
|
||||||
|
|
||||||
|
|
@ -45,8 +42,8 @@ impl Common for AlertDialog {
|
||||||
|
|
||||||
// Init main widget
|
// Init main widget
|
||||||
let alert_dialog = AlertDialog::builder()
|
let alert_dialog = AlertDialog::builder()
|
||||||
.heading(HEADING)
|
.heading("Identity")
|
||||||
.body(BODY)
|
.body("Select identity certificate")
|
||||||
.close_response(RESPONSE_CANCEL.0)
|
.close_response(RESPONSE_CANCEL.0)
|
||||||
.default_response(RESPONSE_APPLY.0)
|
.default_response(RESPONSE_APPLY.0)
|
||||||
.extra_child(&form.g_box)
|
.extra_child(&form.g_box)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
use adw::{
|
use adw::AlertDialog;
|
||||||
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");
|
|
||||||
|
|
||||||
pub trait Unsupported {
|
pub trait Unsupported {
|
||||||
fn unsupported() -> Self;
|
fn unsupported() -> Self;
|
||||||
|
|
@ -16,8 +9,14 @@ impl Unsupported for AlertDialog {
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
fn unsupported() -> 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
|
// Init gobject
|
||||||
let this = AlertDialog::builder()
|
let alert_dialog = AlertDialog::builder()
|
||||||
.heading(HEADING)
|
.heading(HEADING)
|
||||||
.body(BODY)
|
.body(BODY)
|
||||||
.close_response(RESPONSE_QUIT.0)
|
.close_response(RESPONSE_QUIT.0)
|
||||||
|
|
@ -25,20 +24,20 @@ impl Unsupported for AlertDialog {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Set response variants
|
// Set response variants
|
||||||
this.add_responses(&[RESPONSE_QUIT]);
|
alert_dialog.add_responses(&[RESPONSE_QUIT]);
|
||||||
|
|
||||||
// Decorate default response preset
|
// Decorate default response preset
|
||||||
/* contrast issue with Ubuntu orange accents
|
/* 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
|
// Init events
|
||||||
this.connect_response(None, move |dialog, response| {
|
alert_dialog.connect_response(None, move |dialog, response| {
|
||||||
if response == RESPONSE_QUIT.0 {
|
if response == RESPONSE_QUIT.0 {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return new activated `Self`
|
// Return new activated `Self`
|
||||||
this
|
alert_dialog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue