mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
give to gobject a name
This commit is contained in:
parent
d627fd1b72
commit
3ab3d53e75
@ -26,7 +26,7 @@ const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
|
|||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
// pub action: Rc<Action>,
|
// pub action: Rc<Action>,
|
||||||
pub form: Rc<Form>,
|
pub form: Rc<Form>,
|
||||||
pub gobject: AlertDialog,
|
pub alert_dialog: AlertDialog,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
@ -40,36 +40,36 @@ impl Widget {
|
|||||||
// Init child container
|
// Init child container
|
||||||
let form = Rc::new(Form::new(profile, action.clone()));
|
let form = Rc::new(Form::new(profile, action.clone()));
|
||||||
|
|
||||||
// Init main `GObject`
|
// Init main widget
|
||||||
let gobject = AlertDialog::builder()
|
let alert_dialog = AlertDialog::builder()
|
||||||
.heading(HEADING)
|
.heading(HEADING)
|
||||||
.body(BODY)
|
.body(BODY)
|
||||||
.close_response(RESPONSE_CANCEL.0)
|
.close_response(RESPONSE_CANCEL.0)
|
||||||
.default_response(RESPONSE_APPLY.0)
|
.default_response(RESPONSE_APPLY.0)
|
||||||
.extra_child(&form.gobject)
|
.extra_child(&form.g_box)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Set response variants
|
// Set response variants
|
||||||
gobject.add_responses(&[
|
alert_dialog.add_responses(&[
|
||||||
RESPONSE_CANCEL,
|
RESPONSE_CANCEL,
|
||||||
// RESPONSE_MANAGE,
|
// RESPONSE_MANAGE,
|
||||||
RESPONSE_APPLY,
|
RESPONSE_APPLY,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Deactivate not implemented feature @TODO
|
// Deactivate not implemented feature @TODO
|
||||||
// gobject.set_response_enabled(RESPONSE_MANAGE.0, false);
|
// alert_dialog.set_response_enabled(RESPONSE_MANAGE.0, false);
|
||||||
|
|
||||||
// Decorate default response preset
|
// Decorate default response preset
|
||||||
gobject.set_response_appearance(RESPONSE_APPLY.0, ResponseAppearance::Suggested);
|
alert_dialog.set_response_appearance(RESPONSE_APPLY.0, ResponseAppearance::Suggested);
|
||||||
gobject.set_response_appearance(RESPONSE_CANCEL.0, ResponseAppearance::Destructive);
|
alert_dialog.set_response_appearance(RESPONSE_CANCEL.0, ResponseAppearance::Destructive);
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
action.update.connect_activate({
|
action.update.connect_activate({
|
||||||
let form = form.clone();
|
let form = form.clone();
|
||||||
let gobject = gobject.clone();
|
let alert_dialog = alert_dialog.clone();
|
||||||
move || {
|
move || {
|
||||||
// Deactivate apply button if the form values could not be processed
|
// Deactivate apply button if the form values could not be processed
|
||||||
gobject.set_response_enabled(RESPONSE_APPLY.0, form.is_valid());
|
alert_dialog.set_response_enabled(RESPONSE_APPLY.0, form.is_valid());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ impl Widget {
|
|||||||
Self {
|
Self {
|
||||||
// action,
|
// action,
|
||||||
form,
|
form,
|
||||||
gobject,
|
alert_dialog,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ impl Widget {
|
|||||||
/// Callback wrapper for `apply` [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html)
|
/// Callback wrapper for `apply` [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html)
|
||||||
/// * return `Value` enum or new record request on `None`
|
/// * return `Value` enum or new record request on `None`
|
||||||
pub fn on_apply(&self, callback: impl Fn(Value) + 'static) {
|
pub fn on_apply(&self, callback: impl Fn(Value) + 'static) {
|
||||||
self.gobject.connect_response(Some(RESPONSE_APPLY.0), {
|
self.alert_dialog.connect_response(Some(RESPONSE_APPLY.0), {
|
||||||
let form = self.form.clone();
|
let form = self.form.clone();
|
||||||
move |this, response| {
|
move |this, response| {
|
||||||
// Prevent double-click action
|
// Prevent double-click action
|
||||||
@ -100,6 +100,6 @@ impl Widget {
|
|||||||
|
|
||||||
/// Show dialog with new preset
|
/// Show dialog with new preset
|
||||||
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
|
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
|
||||||
self.gobject.present(parent)
|
self.alert_dialog.present(parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ pub struct Form {
|
|||||||
pub list: Rc<List>,
|
pub list: Rc<List>,
|
||||||
pub name: Rc<Name>,
|
pub name: Rc<Name>,
|
||||||
// pub save: Rc<Save>,
|
// pub save: Rc<Save>,
|
||||||
pub gobject: Box,
|
pub g_box: Box,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Form {
|
impl Form {
|
||||||
@ -38,13 +38,13 @@ impl Form {
|
|||||||
let drop = Rc::new(Drop::new(profile.clone(), action.clone(), list.clone()));
|
let drop = Rc::new(Drop::new(profile.clone(), action.clone(), list.clone()));
|
||||||
|
|
||||||
// Init main container
|
// Init main container
|
||||||
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
let g_box = Box::builder().orientation(Orientation::Vertical).build();
|
||||||
|
|
||||||
gobject.append(&list.gobject);
|
g_box.append(&list.dropdown);
|
||||||
gobject.append(&name.gobject);
|
g_box.append(&name.entry);
|
||||||
gobject.append(&file.gobject);
|
g_box.append(&file.button);
|
||||||
gobject.append(&drop.gobject);
|
g_box.append(&drop.button);
|
||||||
gobject.append(&save.gobject);
|
g_box.append(&save.button);
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
list.on_select({
|
list.on_select({
|
||||||
@ -85,7 +85,7 @@ impl Form {
|
|||||||
list,
|
list,
|
||||||
name,
|
name,
|
||||||
// save,
|
// save,
|
||||||
gobject,
|
g_box,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ const RESPONSE_CONFIRM: (&str, &str) = ("confirm", "Confirm");
|
|||||||
|
|
||||||
pub struct Drop {
|
pub struct Drop {
|
||||||
profile_identity_gemini_id: Rc<RefCell<Option<i64>>>,
|
profile_identity_gemini_id: Rc<RefCell<Option<i64>>>,
|
||||||
pub gobject: Button,
|
pub button: Button,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop {
|
impl Drop {
|
||||||
@ -35,8 +35,8 @@ impl Drop {
|
|||||||
// Init selected option holder
|
// Init selected option holder
|
||||||
let profile_identity_gemini_id = Rc::new(RefCell::new(None::<i64>));
|
let profile_identity_gemini_id = Rc::new(RefCell::new(None::<i64>));
|
||||||
|
|
||||||
// Init `GObject`
|
// Init main widget
|
||||||
let gobject = Button::builder()
|
let button = Button::builder()
|
||||||
.label(LABEL)
|
.label(LABEL)
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
.tooltip_text(TOOLTIP_TEXT)
|
.tooltip_text(TOOLTIP_TEXT)
|
||||||
@ -44,16 +44,16 @@ impl Drop {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
gobject.connect_clicked({
|
button.connect_clicked({
|
||||||
let action = action.clone();
|
let action = action.clone();
|
||||||
let gobject = gobject.clone();
|
let button = button.clone();
|
||||||
let profile_identity_gemini_id = profile_identity_gemini_id.clone();
|
let profile_identity_gemini_id = profile_identity_gemini_id.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
// Get selected identity from holder
|
// Get selected identity from holder
|
||||||
match profile_identity_gemini_id.borrow().as_ref() {
|
match profile_identity_gemini_id.borrow().as_ref() {
|
||||||
Some(profile_identity_gemini_id) => {
|
Some(profile_identity_gemini_id) => {
|
||||||
// Init main `GObject`
|
// Init sub-widget
|
||||||
let dialog = AlertDialog::builder()
|
let alert_dialog = AlertDialog::builder()
|
||||||
.heading(HEADING)
|
.heading(HEADING)
|
||||||
.body(BODY)
|
.body(BODY)
|
||||||
.close_response(RESPONSE_CANCEL.0)
|
.close_response(RESPONSE_CANCEL.0)
|
||||||
@ -61,23 +61,23 @@ impl Drop {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Set response variants
|
// Set response variants
|
||||||
dialog.add_responses(&[RESPONSE_CANCEL, RESPONSE_CONFIRM]);
|
alert_dialog.add_responses(&[RESPONSE_CANCEL, RESPONSE_CONFIRM]);
|
||||||
|
|
||||||
// Decorate default response preset
|
// Decorate default response preset
|
||||||
dialog.set_response_appearance(
|
alert_dialog.set_response_appearance(
|
||||||
RESPONSE_CONFIRM.0,
|
RESPONSE_CONFIRM.0,
|
||||||
ResponseAppearance::Suggested,
|
ResponseAppearance::Suggested,
|
||||||
);
|
);
|
||||||
|
|
||||||
dialog.set_response_appearance(
|
alert_dialog.set_response_appearance(
|
||||||
RESPONSE_CANCEL.0,
|
RESPONSE_CANCEL.0,
|
||||||
ResponseAppearance::Destructive,
|
ResponseAppearance::Destructive,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Connect confirmation event
|
// Connect confirmation event
|
||||||
dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
|
alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
|
||||||
let action = action.clone();
|
let action = action.clone();
|
||||||
let gobject = gobject.clone();
|
let button = button.clone();
|
||||||
let list = list.clone();
|
let list = list.clone();
|
||||||
let profile = profile.clone();
|
let profile = profile.clone();
|
||||||
let profile_identity_gemini_id = *profile_identity_gemini_id;
|
let profile_identity_gemini_id = *profile_identity_gemini_id;
|
||||||
@ -85,17 +85,17 @@ impl Drop {
|
|||||||
match profile.identity.gemini.delete(profile_identity_gemini_id) {
|
match profile.identity.gemini.delete(profile_identity_gemini_id) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if list.remove(profile_identity_gemini_id).is_some() {
|
if list.remove(profile_identity_gemini_id).is_some() {
|
||||||
gobject.set_css_classes(&["success"]);
|
button.set_css_classes(&["success"]);
|
||||||
gobject.set_label("Identity successfully deleted")
|
button.set_label("Identity successfully deleted")
|
||||||
} else {
|
} else {
|
||||||
gobject.set_css_classes(&["error"]);
|
button.set_css_classes(&["error"]);
|
||||||
gobject.set_label("List item not found")
|
button.set_label("List item not found")
|
||||||
// @TODO unexpected
|
// @TODO unexpected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
gobject.set_css_classes(&["error"]);
|
button.set_css_classes(&["error"]);
|
||||||
gobject.set_label(&e.to_string())
|
button.set_label(&e.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.update.activate()
|
action.update.activate()
|
||||||
@ -103,7 +103,7 @@ impl Drop {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Show dialog
|
// Show dialog
|
||||||
dialog.present(Some(&gobject))
|
alert_dialog.present(Some(&button))
|
||||||
}
|
}
|
||||||
None => todo!(), // unexpected
|
None => todo!(), // unexpected
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ impl Drop {
|
|||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self {
|
Self {
|
||||||
profile_identity_gemini_id,
|
profile_identity_gemini_id,
|
||||||
gobject,
|
button,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ impl Drop {
|
|||||||
/// Update `profile_identity_gemini_id` holder,
|
/// Update `profile_identity_gemini_id` holder,
|
||||||
/// toggle visibility depending on given value
|
/// toggle visibility depending on given value
|
||||||
pub fn update(&self, profile_identity_gemini_id: Option<i64>) {
|
pub fn update(&self, profile_identity_gemini_id: Option<i64>) {
|
||||||
self.gobject.set_visible(match profile_identity_gemini_id {
|
self.button.set_visible(match profile_identity_gemini_id {
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
self.profile_identity_gemini_id.replace(Some(value));
|
self.profile_identity_gemini_id.replace(Some(value));
|
||||||
true
|
true
|
||||||
|
@ -14,7 +14,7 @@ const MARGIN: i32 = 8;
|
|||||||
|
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub pem: Rc<RefCell<Option<GString>>>,
|
pub pem: Rc<RefCell<Option<GString>>>,
|
||||||
pub gobject: Button,
|
pub button: Button,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
@ -25,8 +25,8 @@ impl File {
|
|||||||
// Init PEM
|
// Init PEM
|
||||||
let pem = Rc::new(RefCell::new(None));
|
let pem = Rc::new(RefCell::new(None));
|
||||||
|
|
||||||
// Init `GObject`
|
// Init main gobject
|
||||||
let gobject = Button::builder()
|
let button = Button::builder()
|
||||||
.label(LABEL)
|
.label(LABEL)
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
.tooltip_text(TOOLTIP_TEXT)
|
.tooltip_text(TOOLTIP_TEXT)
|
||||||
@ -34,13 +34,13 @@ impl File {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
gobject.connect_clicked({
|
button.connect_clicked({
|
||||||
let gobject = gobject.clone();
|
let button = button.clone();
|
||||||
let pem = pem.clone();
|
let pem = pem.clone();
|
||||||
let update = action.update.clone();
|
let update = action.update.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
// Lock open button (prevent double click)
|
// Lock open button (prevent double click)
|
||||||
gobject.set_sensitive(false);
|
button.set_sensitive(false);
|
||||||
|
|
||||||
// Init file filters related with PEM extension
|
// Init file filters related with PEM extension
|
||||||
let filters = ListStore::new::<FileFilter>();
|
let filters = ListStore::new::<FileFilter>();
|
||||||
@ -61,7 +61,7 @@ impl File {
|
|||||||
.default_filter(&filter_pem)
|
.default_filter(&filter_pem)
|
||||||
.build()
|
.build()
|
||||||
.open(None::<&Window>, None::<&Cancellable>, {
|
.open(None::<&Window>, None::<&Cancellable>, {
|
||||||
let gobject = gobject.clone();
|
let button = button.clone();
|
||||||
let pem = pem.clone();
|
let pem = pem.clone();
|
||||||
let update = update.clone();
|
let update = update.clone();
|
||||||
move |result| {
|
move |result| {
|
||||||
@ -72,23 +72,23 @@ impl File {
|
|||||||
match TlsCertificate::from_file(filename) {
|
match TlsCertificate::from_file(filename) {
|
||||||
Ok(certificate) => {
|
Ok(certificate) => {
|
||||||
pem.replace(to_pem(certificate));
|
pem.replace(to_pem(certificate));
|
||||||
gobject.set_css_classes(&["success"]);
|
button.set_css_classes(&["success"]);
|
||||||
gobject.set_label(filename)
|
button.set_label(filename)
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
gobject.set_css_classes(&["error"]);
|
button.set_css_classes(&["error"]);
|
||||||
gobject.set_label(reason.message())
|
button.set_label(reason.message())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
},
|
},
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
gobject.set_css_classes(&["warning"]);
|
button.set_css_classes(&["warning"]);
|
||||||
gobject.set_label(reason.message())
|
button.set_label(reason.message())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gobject.set_sensitive(true); // unlock
|
button.set_sensitive(true); // unlock
|
||||||
update.activate()
|
update.activate()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -96,7 +96,7 @@ impl File {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self { pem, gobject }
|
Self { pem, button }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -104,9 +104,9 @@ impl File {
|
|||||||
/// Change visibility status
|
/// Change visibility status
|
||||||
/// * grab focus on `is_visible`
|
/// * grab focus on `is_visible`
|
||||||
pub fn update(&self, is_visible: bool) {
|
pub fn update(&self, is_visible: bool) {
|
||||||
self.gobject.set_visible(is_visible);
|
self.button.set_visible(is_visible);
|
||||||
if is_visible {
|
if is_visible {
|
||||||
self.gobject.grab_focus();
|
self.button.grab_focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ use gtk::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct List {
|
pub struct List {
|
||||||
pub gobject: DropDown,
|
pub dropdown: DropDown,
|
||||||
model: ListStore,
|
list_store: ListStore,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl List {
|
impl List {
|
||||||
@ -20,14 +20,14 @@ impl List {
|
|||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// Init model with custom `GObject` properties
|
// Init `ListStore` with custom `DropDown` properties
|
||||||
let model = ListStore::new::<Item>();
|
let list_store = ListStore::new::<Item>();
|
||||||
|
|
||||||
// Setup item factory
|
// Setup item factory
|
||||||
// * wanted only to append items after `DropDown` init
|
// * wanted only to append items after `DropDown` init
|
||||||
let factory = SignalListItemFactory::new();
|
let factory = SignalListItemFactory::new();
|
||||||
|
|
||||||
factory.connect_setup(|_, gobject| {
|
factory.connect_setup(|_, dropdown| {
|
||||||
// Init widget for dropdown item
|
// Init widget for dropdown item
|
||||||
let widget = Box::builder()
|
let widget = Box::builder()
|
||||||
.orientation(gtk::Orientation::Vertical)
|
.orientation(gtk::Orientation::Vertical)
|
||||||
@ -45,15 +45,15 @@ impl List {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
gobject
|
dropdown
|
||||||
.downcast_ref::<ListItem>()
|
.downcast_ref::<ListItem>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_child(Some(&widget));
|
.set_child(Some(&widget));
|
||||||
});
|
});
|
||||||
|
|
||||||
factory.connect_bind(|_, gobject| {
|
factory.connect_bind(|_, dropdown| {
|
||||||
// Downcast requirements
|
// Downcast requirements
|
||||||
let list_item = gobject.downcast_ref::<ListItem>().unwrap();
|
let list_item = dropdown.downcast_ref::<ListItem>().unwrap();
|
||||||
let item = list_item.item().and_downcast::<Item>().unwrap();
|
let item = list_item.item().and_downcast::<Item>().unwrap();
|
||||||
let container = list_item.child().and_downcast::<Box>().unwrap();
|
let container = list_item.child().and_downcast::<Box>().unwrap();
|
||||||
|
|
||||||
@ -74,11 +74,17 @@ impl List {
|
|||||||
.set_label(&item.subtitle());
|
.set_label(&item.subtitle());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Init main `GObject`
|
// Init main `DropDown`
|
||||||
let gobject = DropDown::builder().model(&model).factory(&factory).build();
|
let dropdown = DropDown::builder()
|
||||||
|
.model(&list_store)
|
||||||
|
.factory(&factory)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self { model, gobject }
|
Self {
|
||||||
|
list_store,
|
||||||
|
dropdown,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -86,16 +92,17 @@ impl List {
|
|||||||
/// Append new item
|
/// Append new item
|
||||||
pub fn append(&self, value: Value, title: &str, subtitle: &str, is_selected: bool) {
|
pub fn append(&self, value: Value, title: &str, subtitle: &str, is_selected: bool) {
|
||||||
let item = Item::new(value, title, subtitle);
|
let item = Item::new(value, title, subtitle);
|
||||||
self.model.append(&item);
|
self.list_store.append(&item);
|
||||||
if is_selected {
|
if is_selected {
|
||||||
self.gobject.set_selected(self.model.find(&item).unwrap()); // @TODO panic or handle?
|
self.dropdown
|
||||||
|
.set_selected(self.list_store.find(&item).unwrap()); // @TODO panic or handle?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find list item by `Value`
|
/// Find list item by `Value`
|
||||||
/// * return `position` found
|
/// * return `position` found
|
||||||
pub fn find(&self, value: i64) -> Option<u32> {
|
pub fn find(&self, value: i64) -> Option<u32> {
|
||||||
self.model
|
self.list_store
|
||||||
.find_with_equal_func(|this| value == this.clone().downcast::<Item>().unwrap().value())
|
.find_with_equal_func(|this| value == this.clone().downcast::<Item>().unwrap().value())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +111,7 @@ impl List {
|
|||||||
pub fn remove(&self, value: i64) -> Option<u32> {
|
pub fn remove(&self, value: i64) -> Option<u32> {
|
||||||
match self.find(value) {
|
match self.find(value) {
|
||||||
Some(position) => {
|
Some(position) => {
|
||||||
self.model.remove(position);
|
self.list_store.remove(position);
|
||||||
Some(position)
|
Some(position)
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
@ -116,7 +123,7 @@ impl List {
|
|||||||
/// Run callback function on `connect_selected_notify` event
|
/// Run callback function on `connect_selected_notify` event
|
||||||
/// * return `Value` enum match selected item
|
/// * return `Value` enum match selected item
|
||||||
pub fn on_select(&self, callback: impl Fn(Value) + 'static) {
|
pub fn on_select(&self, callback: impl Fn(Value) + 'static) {
|
||||||
self.gobject.connect_selected_notify(move |list| {
|
self.dropdown.connect_selected_notify(move |list| {
|
||||||
callback(
|
callback(
|
||||||
list.selected_item()
|
list.selected_item()
|
||||||
.and_downcast::<Item>()
|
.and_downcast::<Item>()
|
||||||
@ -130,7 +137,7 @@ impl List {
|
|||||||
|
|
||||||
/// Get formatted `value` match selected item
|
/// Get formatted `value` match selected item
|
||||||
pub fn selected(&self) -> Value {
|
pub fn selected(&self) -> Value {
|
||||||
self.gobject
|
self.dropdown
|
||||||
.selected_item()
|
.selected_item()
|
||||||
.and_downcast::<Item>()
|
.and_downcast::<Item>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -12,7 +12,7 @@ const MIN_LENGTH: u16 = 1;
|
|||||||
const MAX_LENGTH: u16 = 36;
|
const MAX_LENGTH: u16 = 36;
|
||||||
|
|
||||||
pub struct Name {
|
pub struct Name {
|
||||||
pub gobject: Entry,
|
pub entry: Entry,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Name {
|
impl Name {
|
||||||
@ -20,8 +20,8 @@ impl Name {
|
|||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(action: Rc<Action>) -> Self {
|
pub fn new(action: Rc<Action>) -> Self {
|
||||||
// Init `GObject`
|
// Init main gobject
|
||||||
let gobject = Entry::builder()
|
let entry = Entry::builder()
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
.max_length(MAX_LENGTH as i32)
|
.max_length(MAX_LENGTH as i32)
|
||||||
.placeholder_text(PLACEHOLDER_TEXT)
|
.placeholder_text(PLACEHOLDER_TEXT)
|
||||||
@ -29,10 +29,10 @@ impl Name {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
gobject.connect_changed(move |_| action.update.activate());
|
entry.connect_changed(move |_| action.update.activate());
|
||||||
|
|
||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self { gobject }
|
Self { entry }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -40,20 +40,20 @@ impl Name {
|
|||||||
/// Change visibility status
|
/// Change visibility status
|
||||||
/// * grab focus on `is_visible`
|
/// * grab focus on `is_visible`
|
||||||
pub fn update(&self, is_visible: bool) {
|
pub fn update(&self, is_visible: bool) {
|
||||||
self.gobject.set_visible(is_visible);
|
self.entry.set_visible(is_visible);
|
||||||
if is_visible {
|
if is_visible {
|
||||||
self.gobject.grab_focus();
|
self.entry.grab_focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
self.gobject.text_length() >= MIN_LENGTH && self.gobject.text_length() <= MAX_LENGTH
|
self.entry.text_length() >= MIN_LENGTH && self.entry.text_length() <= MAX_LENGTH
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value(&self) -> Option<GString> {
|
pub fn value(&self) -> Option<GString> {
|
||||||
let text = self.gobject.text();
|
let text = self.entry.text();
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,7 +15,7 @@ const MARGIN: i32 = 8;
|
|||||||
|
|
||||||
pub struct Save {
|
pub struct Save {
|
||||||
profile_identity_gemini_id: Rc<RefCell<Option<i64>>>,
|
profile_identity_gemini_id: Rc<RefCell<Option<i64>>>,
|
||||||
pub gobject: Button,
|
pub button: Button,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save {
|
impl Save {
|
||||||
@ -26,8 +26,8 @@ impl Save {
|
|||||||
// Init selected option holder
|
// Init selected option holder
|
||||||
let profile_identity_gemini_id = Rc::new(RefCell::new(None));
|
let profile_identity_gemini_id = Rc::new(RefCell::new(None));
|
||||||
|
|
||||||
// Init `GObject`
|
// Init main widget
|
||||||
let gobject = Button::builder()
|
let button = Button::builder()
|
||||||
.label(LABEL)
|
.label(LABEL)
|
||||||
.margin_top(MARGIN)
|
.margin_top(MARGIN)
|
||||||
.tooltip_text(TOOLTIP_TEXT)
|
.tooltip_text(TOOLTIP_TEXT)
|
||||||
@ -35,15 +35,15 @@ impl Save {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
gobject.connect_clicked({
|
button.connect_clicked({
|
||||||
let profile_identity_gemini_id = profile_identity_gemini_id.clone();
|
let profile_identity_gemini_id = profile_identity_gemini_id.clone();
|
||||||
let gobject = gobject.clone();
|
let button = button.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
// Get selected identity from holder
|
// Get selected identity from holder
|
||||||
match profile_identity_gemini_id.borrow().as_ref() {
|
match profile_identity_gemini_id.borrow().as_ref() {
|
||||||
Some(profile_identity_gemini_id) => {
|
Some(profile_identity_gemini_id) => {
|
||||||
// Lock open button (prevent double click)
|
// Lock open button (prevent double click)
|
||||||
gobject.set_sensitive(false);
|
button.set_sensitive(false);
|
||||||
|
|
||||||
// Create PEM file based on option ID selected
|
// Create PEM file based on option ID selected
|
||||||
match Certificate::new(profile.clone(), *profile_identity_gemini_id) {
|
match Certificate::new(profile.clone(), *profile_identity_gemini_id) {
|
||||||
@ -68,7 +68,7 @@ impl Save {
|
|||||||
.initial_name(format!("{}.pem", certificate.name))
|
.initial_name(format!("{}.pem", certificate.name))
|
||||||
.build()
|
.build()
|
||||||
.save(None::<&Window>, None::<&Cancellable>, {
|
.save(None::<&Window>, None::<&Cancellable>, {
|
||||||
let gobject = gobject.clone();
|
let button = button.clone();
|
||||||
move |result| {
|
move |result| {
|
||||||
match result {
|
match result {
|
||||||
Ok(file) => match file.path() {
|
Ok(file) => match file.path() {
|
||||||
@ -78,47 +78,46 @@ impl Save {
|
|||||||
certificate.data.as_bytes(),
|
certificate.data.as_bytes(),
|
||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
gobject.set_css_classes(&[
|
button.set_css_classes(&[
|
||||||
"success",
|
"success",
|
||||||
]);
|
]);
|
||||||
gobject.set_label(&format!(
|
button.set_label(&format!(
|
||||||
"Saved to {}",
|
"Saved to {}",
|
||||||
path.to_string_lossy()
|
path.to_string_lossy()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
gobject.set_css_classes(&[
|
button.set_css_classes(&[
|
||||||
"error",
|
"error",
|
||||||
]);
|
]);
|
||||||
gobject
|
button.set_label(&e.to_string())
|
||||||
.set_label(&e.to_string())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
gobject.set_css_classes(&["error"]);
|
button.set_css_classes(&["error"]);
|
||||||
gobject.set_label(&e.to_string())
|
button.set_label(&e.to_string())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
gobject.set_css_classes(&["warning"]);
|
button.set_css_classes(&["warning"]);
|
||||||
gobject.set_label(
|
button.set_label(
|
||||||
"Could not init destination path",
|
"Could not init destination path",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
gobject.set_css_classes(&["warning"]);
|
button.set_css_classes(&["warning"]);
|
||||||
gobject.set_label(e.message())
|
button.set_label(e.message())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gobject.set_sensitive(true); // unlock
|
button.set_sensitive(true); // unlock
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
gobject.set_css_classes(&["error"]);
|
button.set_css_classes(&["error"]);
|
||||||
gobject.set_label(&e.to_string())
|
button.set_label(&e.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ impl Save {
|
|||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self {
|
Self {
|
||||||
profile_identity_gemini_id,
|
profile_identity_gemini_id,
|
||||||
gobject,
|
button,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +138,7 @@ impl Save {
|
|||||||
/// Update `profile_identity_gemini_id` holder,
|
/// Update `profile_identity_gemini_id` holder,
|
||||||
/// toggle visibility depending on given value
|
/// toggle visibility depending on given value
|
||||||
pub fn update(&self, profile_identity_gemini_id: Option<i64>) {
|
pub fn update(&self, profile_identity_gemini_id: Option<i64>) {
|
||||||
self.gobject.set_visible(match profile_identity_gemini_id {
|
self.button.set_visible(match profile_identity_gemini_id {
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
self.profile_identity_gemini_id.replace(Some(value));
|
self.profile_identity_gemini_id.replace(Some(value));
|
||||||
true
|
true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user