implement exit button as trait, set disconnect button status update by total

This commit is contained in:
yggverse 2025-01-29 20:37:56 +02:00
parent e1345a4922
commit 91cd9cbae9
4 changed files with 41 additions and 26 deletions

View file

@ -14,19 +14,22 @@ use save::Save;
use super::WidgetAction;
use crate::Profile;
use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation};
use gtk::{
glib::Uri,
prelude::{BoxExt, WidgetExt},
Box, Button, Orientation,
};
use std::rc::Rc;
pub struct Form {
// pub action_widget: Rc<Action>,
pub drop: Rc<Drop>,
pub exit: Rc<Exit>,
pub exit: Button,
pub file: Rc<File>,
pub list: Rc<List>,
pub name: Rc<Name>,
pub save: Rc<Save>,
pub g_box: Box,
request: Uri,
profile: Rc<Profile>,
}
@ -41,7 +44,7 @@ impl Form {
let name = Rc::new(Name::build(widget_action));
let save = Rc::new(Save::build(profile, &list));
let drop = Rc::new(Drop::build(profile, &list));
let exit = Rc::new(Exit::build(widget_action, profile, &list, request));
let exit = Button::exit(widget_action, profile, &list, request);
// Init main container
let g_box = Box::builder().orientation(Orientation::Vertical).build();
@ -49,7 +52,7 @@ impl Form {
g_box.append(&list.dropdown);
g_box.append(&name.entry);
g_box.append(&file.button);
g_box.append(&exit.button);
g_box.append(&exit);
g_box.append(&drop.button);
g_box.append(&save.button);
@ -63,7 +66,6 @@ impl Form {
name,
save,
g_box,
request: request.clone(),
profile: profile.clone(),
}
}
@ -90,18 +92,15 @@ impl Form {
match value {
Value::ProfileIdentityId(profile_identity_id) => {
self.drop.update(true);
self.exit.update(
true,
self.profile
.identity
.auth
.is_matches(&self.request.to_string(), profile_identity_id),
);
self.exit.set_visible(true);
self.exit
.set_sensitive(self.profile.identity.auth.total(profile_identity_id) > 0);
self.save.update(true);
}
_ => {
self.drop.update(false);
self.exit.update(false, false);
self.exit.set_visible(false);
self.exit.set_sensitive(false);
self.save.update(false);
}
}

View file

@ -25,15 +25,20 @@ const BODY: &str = "Stop use selected identity for all scopes?";
const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
const RESPONSE_CONFIRM: (&str, &str) = ("confirm", "Confirm");
pub struct Exit {
pub button: Button,
pub trait Exit {
fn exit(
widget_action: &Rc<WidgetAction>,
profile: &Rc<Profile>,
list: &Rc<List>,
request: &Uri,
) -> Self;
}
impl Exit {
impl Exit for Button {
// Constructors
/// Create new `Self`
pub fn build(
fn exit(
widget_action: &Rc<WidgetAction>,
profile: &Rc<Profile>,
list: &Rc<List>,
@ -122,13 +127,6 @@ impl Exit {
});
// Return activated `Self`
Self { button }
}
// Actions
pub fn update(&self, is_visible: bool, is_sensitive: bool) {
self.button.set_visible(is_visible);
self.button.set_sensitive(is_sensitive);
button
}
}