From 2799ce37fe851d41c98f42949f0cedc4f79caff8 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 5 Dec 2024 21:17:32 +0200 Subject: [PATCH] remove extra getters, give name to gobjects --- src/app/browser/window/tab/item/page/input.rs | 2 +- .../window/tab/item/page/input/response.rs | 22 +++++------- .../tab/item/page/input/response/control.rs | 15 +++----- .../page/input/response/control/counter.rs | 8 +---- .../input/response/control/counter/widget.rs | 17 ++++------ .../item/page/input/response/control/send.rs | 9 ++--- .../input/response/control/send/widget.rs | 17 ++++------ .../page/input/response/control/widget.rs | 17 ++++------ .../tab/item/page/input/response/form.rs | 18 ++-------- .../item/page/input/response/form/widget.rs | 24 +++++-------- .../tab/item/page/input/response/title.rs | 8 +---- .../item/page/input/response/title/widget.rs | 19 ++++------- .../tab/item/page/input/response/widget.rs | 17 ++++------ .../window/tab/item/page/input/sensitive.rs | 10 +++--- .../tab/item/page/input/sensitive/form.rs | 19 ++--------- .../item/page/input/sensitive/form/widget.rs | 34 +++++-------------- 16 files changed, 76 insertions(+), 180 deletions(-) diff --git a/src/app/browser/window/tab/item/page/input.rs b/src/app/browser/window/tab/item/page/input.rs index 853efdc5..be68e120 100644 --- a/src/app/browser/window/tab/item/page/input.rs +++ b/src/app/browser/window/tab/item/page/input.rs @@ -38,7 +38,7 @@ impl Input { size_limit: Option, ) { self.widget.update(Some( - Response::new(action, base, title, size_limit).gobject(), + &Response::new(action, base, title, size_limit).widget.g_box, )); } diff --git a/src/app/browser/window/tab/item/page/input/response.rs b/src/app/browser/window/tab/item/page/input/response.rs index 035a8c28..a8142ad3 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -13,13 +13,12 @@ use gtk::{ gio::SimpleAction, glib::{uuid_string_random, Uri, UriHideFlags}, prelude::WidgetExt, - Box, }; use std::rc::Rc; pub struct Response { // Components - widget: Rc, + pub widget: Rc, } impl Response { @@ -41,9 +40,9 @@ impl Response { // Init widget let widget = Rc::new(Widget::new( - title.gobject(), - form.gobject(), - control.gobject(), + &title.widget.label, + &form.widget.text_view, + &control.widget.g_box, )); // Init events @@ -55,7 +54,7 @@ impl Response { control.update(size_limit.map(|limit| { limit as i32 - (base.to_string_partial(UriHideFlags::QUERY).len() as i32 - + Uri::escape_string(form.text().as_str(), None, false).len() as i32) + + Uri::escape_string(&form.widget.text(), None, false).len() as i32) })); } }); @@ -67,21 +66,18 @@ impl Response { Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), - Uri::escape_string(form.text().as_str(), None, false), + Uri::escape_string(&form.widget.text(), None, false), )), true, ); } }); - widget.gobject().connect_realize(move |_| form.focus()); + widget.g_box.connect_realize(move |_| { + form.widget.text_view.grab_focus(); + }); // Return activated struct Self { widget } } - - // Getters - pub fn gobject(&self) -> &Box { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/response/control.rs b/src/app/browser/window/tab/item/page/input/response/control.rs index 9b9ea7ab..6919c183 100644 --- a/src/app/browser/window/tab/item/page/input/response/control.rs +++ b/src/app/browser/window/tab/item/page/input/response/control.rs @@ -6,13 +6,13 @@ use counter::Counter; use send::Send; use widget::Widget; -use gtk::{gio::SimpleAction, Box}; +use gtk::gio::SimpleAction; use std::rc::Rc; pub struct Control { - counter: Rc, - send: Rc, - widget: Rc, + pub counter: Rc, + pub send: Rc, + pub widget: Rc, } impl Control { @@ -23,7 +23,7 @@ impl Control { let send = Rc::new(Send::new(action_send)); // Init widget - let widget = Rc::new(Widget::new(counter.gobject(), send.gobject())); + let widget = Rc::new(Widget::new(&counter.widget.label, &send.widget.button)); // Return activated struct Self { @@ -42,9 +42,4 @@ impl Control { None => false, }); } - - // Getters - pub fn gobject(&self) -> &Box { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/counter.rs b/src/app/browser/window/tab/item/page/input/response/control/counter.rs index ae62ff24..5e417bd1 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/counter.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/counter.rs @@ -2,11 +2,10 @@ mod widget; use widget::Widget; -use gtk::Label; use std::rc::Rc; pub struct Counter { - widget: Rc, + pub widget: Rc, } impl Counter { @@ -21,9 +20,4 @@ impl Counter { pub fn update(&self, chars_left: Option) { self.widget.update(chars_left); } - - // Getters - pub fn gobject(&self) -> &Label { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs b/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs index ab58a5dd..6b0cec68 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/counter/widget.rs @@ -1,14 +1,14 @@ use gtk::{prelude::WidgetExt, Label}; pub struct Widget { - gobject: Label, + pub label: Label, } impl Widget { // Construct pub fn new() -> Self { Self { - gobject: Label::builder().build(), + label: Label::builder().build(), } } @@ -17,21 +17,16 @@ impl Widget { match chars_left { Some(value) => { // Update color on chars left reached - self.gobject + self.label .set_css_classes(&[if value > 0 { "success" } else { "error" }]); // @TODO add warning step? // Update text - self.gobject.set_label(&value.to_string()); + self.label.set_label(&value.to_string()); // Toggle visibility on chars left provided - self.gobject.set_visible(true); + self.label.set_visible(true); } - None => self.gobject.set_visible(false), + None => self.label.set_visible(false), } } - - // Getters - pub fn gobject(&self) -> &Label { - &self.gobject - } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/send.rs b/src/app/browser/window/tab/item/page/input/response/control/send.rs index 21d4514a..95c99577 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/send.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/send.rs @@ -1,11 +1,11 @@ mod widget; use widget::Widget; -use gtk::{gio::SimpleAction, Button}; +use gtk::gio::SimpleAction; use std::rc::Rc; pub struct Send { - widget: Rc, + pub widget: Rc, } impl Send { @@ -22,9 +22,4 @@ impl Send { pub fn update(&self, is_sensitive: bool) { self.widget.update(is_sensitive); } - - // Getters - pub fn gobject(&self) -> &Button { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs b/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs index d3706868..d8b376c4 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/send/widget.rs @@ -5,36 +5,31 @@ use gtk::{ }; pub struct Widget { - gobject: Button, + pub button: Button, } impl Widget { // Construct pub fn new(action_send: SimpleAction) -> Self { - // Init gobject - let gobject = Button::builder() + // Init main widget + let button = Button::builder() //.css_classes(["accent"]) .label("Send") .build(); // Init events - gobject.connect_clicked({ + button.connect_clicked({ move |_| { action_send.activate(None); } }); // Return activated `Self` - Self { gobject } + Self { button } } // Actions pub fn update(&self, is_sensitive: bool) { - self.gobject.set_sensitive(is_sensitive); - } - - // Getters - pub fn gobject(&self) -> &Button { - &self.gobject + self.button.set_sensitive(is_sensitive); } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/widget.rs b/src/app/browser/window/tab/item/page/input/response/control/widget.rs index 1fec9bb4..427205c2 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/widget.rs @@ -3,28 +3,23 @@ use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation}; const SPACING: i32 = 8; pub struct Widget { - gobject: Box, + pub g_box: Box, } impl Widget { // Construct pub fn new(limit: &Label, send: &Button) -> Self { - // Init gobject - let gobject = Box::builder() + // Init main widget + let g_box = Box::builder() .halign(Align::End) .orientation(Orientation::Horizontal) .spacing(SPACING) .build(); - gobject.append(limit); - gobject.append(send); + g_box.append(limit); + g_box.append(send); // Return new `Self` - Self { gobject } - } - - // Getters - pub fn gobject(&self) -> &Box { - &self.gobject + Self { g_box } } } diff --git a/src/app/browser/window/tab/item/page/input/response/form.rs b/src/app/browser/window/tab/item/page/input/response/form.rs index ee67e718..f75a2ad7 100644 --- a/src/app/browser/window/tab/item/page/input/response/form.rs +++ b/src/app/browser/window/tab/item/page/input/response/form.rs @@ -2,11 +2,11 @@ mod widget; use widget::Widget; -use gtk::{gio::SimpleAction, glib::GString, TextView}; +use gtk::gio::SimpleAction; use std::rc::Rc; pub struct Form { - widget: Rc, + pub widget: Rc, } impl Form { @@ -16,18 +16,4 @@ impl Form { widget: Rc::new(Widget::new(action_update)), } } - - // Actions - pub fn focus(&self) { - self.widget.focus(); - } - - // Getters - pub fn text(&self) -> GString { - self.widget.text() - } - - pub fn gobject(&self) -> &TextView { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/response/form/widget.rs b/src/app/browser/window/tab/item/page/input/response/form/widget.rs index fa3d7d97..072d77f3 100644 --- a/src/app/browser/window/tab/item/page/input/response/form/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/form/widget.rs @@ -1,21 +1,21 @@ use gtk::{ gio::SimpleAction, glib::GString, - prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt}, + prelude::{ActionExt, TextBufferExt, TextViewExt}, TextView, WrapMode, }; const MARGIN: i32 = 8; pub struct Widget { - gobject: TextView, + pub text_view: TextView, } impl Widget { // Construct pub fn new(action_update: SimpleAction) -> Self { - // Init gobject - let gobject = TextView::builder() + // Init main widget + let text_view = TextView::builder() .bottom_margin(MARGIN) .left_margin(MARGIN) .right_margin(MARGIN) @@ -24,26 +24,18 @@ impl Widget { .build(); // Init events - gobject.buffer().connect_changed(move |_| { + text_view.buffer().connect_changed(move |_| { action_update.activate(None); }); // Return activated `Self` - Self { gobject } - } - - // Actions - pub fn focus(&self) { - self.gobject.grab_focus(); + Self { text_view } } // Getters + pub fn text(&self) -> GString { - let buffer = self.gobject.buffer(); + let buffer = self.text_view.buffer(); buffer.text(&buffer.start_iter(), &buffer.end_iter(), true) } - - pub fn gobject(&self) -> &TextView { - &self.gobject - } } diff --git a/src/app/browser/window/tab/item/page/input/response/title.rs b/src/app/browser/window/tab/item/page/input/response/title.rs index 73e713ab..de5d2ff1 100644 --- a/src/app/browser/window/tab/item/page/input/response/title.rs +++ b/src/app/browser/window/tab/item/page/input/response/title.rs @@ -2,11 +2,10 @@ mod widget; use widget::Widget; -use gtk::Label; use std::rc::Rc; pub struct Title { - widget: Rc, + pub widget: Rc, } impl Title { @@ -16,9 +15,4 @@ impl Title { widget: Rc::new(Widget::new(title)), } } - - // Getters - pub fn gobject(&self) -> &Label { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/response/title/widget.rs b/src/app/browser/window/tab/item/page/input/response/title/widget.rs index 54881031..4cb208b1 100644 --- a/src/app/browser/window/tab/item/page/input/response/title/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/title/widget.rs @@ -1,13 +1,13 @@ use gtk::{prelude::WidgetExt, Align, Label}; pub struct Widget { - gobject: Label, + pub label: Label, } impl Widget { // Construct pub fn new(title: Option<&str>) -> Self { - let gobject = Label::builder() + let label = Label::builder() .css_classes(["heading"]) .halign(Align::Start) .margin_end(8) @@ -15,18 +15,13 @@ impl Widget { .visible(false) .build(); - if let Some(label) = title { - if !label.is_empty() { - gobject.set_label(label); - gobject.set_visible(true) + if let Some(value) = title { + if !value.is_empty() { + label.set_label(value); + label.set_visible(true) } } - Self { gobject } - } - - // Getters - pub fn gobject(&self) -> &Label { - &self.gobject + Self { label } } } diff --git a/src/app/browser/window/tab/item/page/input/response/widget.rs b/src/app/browser/window/tab/item/page/input/response/widget.rs index ad3587ba..54d4739c 100644 --- a/src/app/browser/window/tab/item/page/input/response/widget.rs +++ b/src/app/browser/window/tab/item/page/input/response/widget.rs @@ -4,13 +4,13 @@ const MARGIN: i32 = 6; const SPACING: i32 = 8; pub struct Widget { - gobject: Box, + pub g_box: Box, } impl Widget { // Construct pub fn new(title: &Label, response: &TextView, control: &Box) -> Self { - let gobject = Box::builder() + let g_box = Box::builder() .margin_bottom(MARGIN) .margin_end(MARGIN) .margin_start(MARGIN) @@ -19,15 +19,10 @@ impl Widget { .orientation(Orientation::Vertical) .build(); - gobject.append(title); - gobject.append(response); - gobject.append(control); + g_box.append(title); + g_box.append(response); + g_box.append(control); - Self { gobject } - } - - // Getters - pub fn gobject(&self) -> &Box { - &self.gobject + Self { g_box } } } diff --git a/src/app/browser/window/tab/item/page/input/sensitive.rs b/src/app/browser/window/tab/item/page/input/sensitive.rs index 64c67784..cf90d95a 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive.rs @@ -8,7 +8,7 @@ use crate::app::browser::window::tab::item::action::Action as TabAction; use gtk::{ gio::SimpleAction, glib::{uuid_string_random, Uri, UriHideFlags}, - prelude::WidgetExt, + prelude::{EditableExt, WidgetExt}, Box, }; use std::rc::Rc; @@ -38,7 +38,7 @@ impl Sensitive { )); // Init widget - let widget = Rc::new(Widget::new(form.gobject())); + let widget = Rc::new(Widget::new(&form.widget.password_entry_row)); // Init events action_send.connect_activate({ @@ -48,14 +48,16 @@ impl Sensitive { Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), - Uri::escape_string(form.text().as_str(), None, false), + Uri::escape_string(&form.widget.password_entry_row.text(), None, false), )), true, ); } }); - widget.gobject().connect_realize(move |_| form.focus()); + widget.gobject().connect_realize(move |_| { + form.widget.password_entry_row.grab_focus(); + }); // Return activated struct Self { widget } diff --git a/src/app/browser/window/tab/item/page/input/sensitive/form.rs b/src/app/browser/window/tab/item/page/input/sensitive/form.rs index 4978a271..a9532c36 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive/form.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive/form.rs @@ -2,12 +2,11 @@ mod widget; use widget::Widget; -use adw::PasswordEntryRow; -use gtk::{gio::SimpleAction, glib::GString}; +use gtk::gio::SimpleAction; use std::rc::Rc; pub struct Form { - widget: Rc, + pub widget: Rc, } impl Form { @@ -19,18 +18,4 @@ impl Form { // Result Self { widget } } - - // Actions - pub fn focus(&self) { - self.widget.focus(); - } - - // Getters - pub fn text(&self) -> GString { - self.widget.text() - } - - pub fn gobject(&self) -> &PasswordEntryRow { - self.widget.gobject() - } } diff --git a/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs b/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs index d8a3d758..2e023d79 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs @@ -2,51 +2,33 @@ use adw::{ prelude::{EntryRowExt, PreferencesRowExt}, PasswordEntryRow, }; -use gtk::{ - gio::SimpleAction, - glib::GString, - prelude::{ActionExt, EditableExt, WidgetExt}, -}; +use gtk::{gio::SimpleAction, prelude::ActionExt}; pub struct Widget { - gobject: PasswordEntryRow, + pub password_entry_row: PasswordEntryRow, } impl Widget { // Construct pub fn new(action_send: SimpleAction, title: Option<&str>, _max_length: Option) -> Self { - // Init gobject - let gobject = PasswordEntryRow::builder().show_apply_button(true).build(); + // Init main widget + let password_entry_row = PasswordEntryRow::builder().show_apply_button(true).build(); if let Some(value) = title { - gobject.set_title(value); + password_entry_row.set_title(value); } /* @TODO adw 1.6 / ubuntu 24.10+ if let Some(value) = max_length { - gobject.set_max_length(value); + password_entry_row.set_max_length(value); } */ // Init events - gobject.connect_apply(move |_| { + password_entry_row.connect_apply(move |_| { action_send.activate(None); }); // Return activated struct - Self { gobject } - } - - // Actions - pub fn focus(&self) { - self.gobject.grab_focus(); - } - - // Getters - pub fn text(&self) -> GString { - self.gobject.text() - } - - pub fn gobject(&self) -> &PasswordEntryRow { - &self.gobject + Self { password_entry_row } } }