mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
optimize clone semantics, enshort namespaces
This commit is contained in:
parent
fd9f69a9f0
commit
eabd16aaf7
20 changed files with 134 additions and 114 deletions
|
|
@ -4,17 +4,15 @@ mod unsupported;
|
|||
use gemini::Gemini;
|
||||
use unsupported::Unsupported;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use crate::profile::Profile;
|
||||
use super::{BrowserAction, Profile, WindowAction};
|
||||
use gtk::glib::Uri;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Create new identity widget for Gemini protocol match given URI
|
||||
pub fn new_gemini(
|
||||
action: (Rc<BrowserAction>, Rc<WindowAction>),
|
||||
profile: Rc<Profile>,
|
||||
auth_uri: Uri,
|
||||
action: (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
auth_uri: &Uri,
|
||||
) -> Gemini {
|
||||
Gemini::new(action, profile, auth_uri)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
mod widget;
|
||||
use widget::{form::list::item::value::Value, Widget};
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use crate::profile::Profile;
|
||||
use super::{BrowserAction, Profile, WindowAction};
|
||||
use gtk::{glib::Uri, prelude::IsA};
|
||||
use std::rc::Rc;
|
||||
|
||||
|
|
@ -17,25 +15,30 @@ impl Gemini {
|
|||
|
||||
/// Create new `Self` for given `Profile`
|
||||
pub fn new(
|
||||
action: (Rc<BrowserAction>, Rc<WindowAction>),
|
||||
profile: Rc<Profile>,
|
||||
auth_uri: Uri,
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
auth_uri: &Uri,
|
||||
) -> Self {
|
||||
// Init shared URL string from URI
|
||||
let auth_url = auth_uri.to_string();
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(
|
||||
(action.0.clone(), action.1.clone()),
|
||||
profile.clone(),
|
||||
auth_uri.clone(),
|
||||
(browser_action, window_action),
|
||||
profile,
|
||||
auth_uri,
|
||||
));
|
||||
|
||||
// Init events
|
||||
widget.on_cancel(move || action.0.update.activate(None));
|
||||
widget.on_cancel({
|
||||
let browser_action = browser_action.clone();
|
||||
move || browser_action.update.activate(None)
|
||||
});
|
||||
|
||||
widget.on_apply({
|
||||
let profile = profile.clone();
|
||||
let widget = widget.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |response| {
|
||||
// Get option match user choice
|
||||
let option = match response {
|
||||
|
|
@ -85,7 +88,7 @@ impl Gemini {
|
|||
}
|
||||
|
||||
// Reload page to apply changes
|
||||
action.1.reload.activate();
|
||||
window_action.reload.activate();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@ impl Widget {
|
|||
|
||||
/// Create new `Self`
|
||||
pub fn new(
|
||||
action: (Rc<BrowserAction>, Rc<WindowAction>),
|
||||
profile: Rc<Profile>,
|
||||
auth_uri: Uri,
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
auth_uri: &Uri,
|
||||
) -> Self {
|
||||
// Init actions
|
||||
let widget_action = Rc::new(WidgetAction::new());
|
||||
|
||||
// Init child container
|
||||
let form = Rc::new(Form::new(
|
||||
(action.0.clone(), action.1.clone(), widget_action.clone()),
|
||||
(browser_action, window_action, &widget_action),
|
||||
profile,
|
||||
auth_uri,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -38,25 +38,25 @@ impl Form {
|
|||
|
||||
/// Create new `Self`
|
||||
pub fn new(
|
||||
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<WidgetAction>),
|
||||
profile: Rc<Profile>,
|
||||
auth_uri: Uri,
|
||||
(browser_action, _window_action, widget_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
&Rc<WidgetAction>,
|
||||
),
|
||||
profile: &Rc<Profile>,
|
||||
auth_uri: &Uri,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let list = Rc::new(List::new(
|
||||
action.2.clone(),
|
||||
profile.clone(),
|
||||
auth_uri.clone(),
|
||||
));
|
||||
let file = Rc::new(File::new(action.2.clone()));
|
||||
let name = Rc::new(Name::new(action.2.clone()));
|
||||
let save = Rc::new(Save::new(profile.clone(), list.clone()));
|
||||
let drop = Rc::new(Drop::new(profile.clone(), list.clone()));
|
||||
let list = Rc::new(List::new(widget_action, profile, auth_uri));
|
||||
let file = Rc::new(File::new(widget_action));
|
||||
let name = Rc::new(Name::new(widget_action));
|
||||
let save = Rc::new(Save::new(profile, &list));
|
||||
let drop = Rc::new(Drop::new(profile, &list));
|
||||
let exit = Rc::new(Exit::new(
|
||||
(action.0.clone(), action.2.clone()),
|
||||
profile.clone(),
|
||||
list.clone(),
|
||||
auth_uri.clone(),
|
||||
(browser_action, widget_action),
|
||||
profile,
|
||||
&list,
|
||||
auth_uri,
|
||||
));
|
||||
|
||||
// Init main container
|
||||
|
|
@ -79,8 +79,8 @@ impl Form {
|
|||
name,
|
||||
save,
|
||||
g_box,
|
||||
auth_uri,
|
||||
profile,
|
||||
auth_uri: auth_uri.clone(),
|
||||
profile: profile.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ impl Drop {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(profile: Rc<Profile>, list: Rc<List>) -> Self {
|
||||
pub fn new(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
.label(LABEL)
|
||||
|
|
@ -42,6 +42,7 @@ impl Drop {
|
|||
button.connect_clicked({
|
||||
let button = button.clone();
|
||||
let list = list.clone();
|
||||
let profile = profile.clone();
|
||||
move |_| {
|
||||
match list.selected().value_enum() {
|
||||
Value::ProfileIdentityGeminiId(profile_identity_gemini_id) => {
|
||||
|
|
|
|||
|
|
@ -34,10 +34,10 @@ impl Exit {
|
|||
|
||||
/// Create new `Self`
|
||||
pub fn new(
|
||||
action: (Rc<BrowserAction>, Rc<WidgetAction>),
|
||||
profile: Rc<Profile>,
|
||||
list: Rc<List>,
|
||||
auth_uri: Uri,
|
||||
(browser_action, widget_action): (&Rc<BrowserAction>, &Rc<WidgetAction>),
|
||||
profile: &Rc<Profile>,
|
||||
list: &Rc<List>,
|
||||
auth_uri: &Uri,
|
||||
) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
|
|
@ -50,7 +50,11 @@ impl Exit {
|
|||
// Init events
|
||||
button.connect_clicked({
|
||||
let auth_uri = auth_uri.clone();
|
||||
let browser_action = browser_action.clone();
|
||||
let button = button.clone();
|
||||
let list = list.clone();
|
||||
let profile = profile.clone();
|
||||
let widget_action = widget_action.clone();
|
||||
move |_| {
|
||||
// Get selected identity from holder
|
||||
match list.selected().value_enum() {
|
||||
|
|
@ -84,8 +88,8 @@ impl Exit {
|
|||
let button = button.clone();
|
||||
let list = list.clone();
|
||||
let profile = profile.clone();
|
||||
let browser_action = action.0.clone();
|
||||
let widget_action = action.1.clone();
|
||||
let browser_action = browser_action.clone();
|
||||
let widget_action = widget_action.clone();
|
||||
move |_, _| {
|
||||
match profile
|
||||
.identity
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl File {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(widget_action: Rc<WidgetAction>) -> Self {
|
||||
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
|
||||
// Init PEM
|
||||
let pem = Rc::new(RefCell::new(None));
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl List {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(widget_action: Rc<WidgetAction>, profile: Rc<Profile>, auth_uri: Uri) -> Self {
|
||||
pub fn new(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, auth_uri: &Uri) -> Self {
|
||||
// Init dropdown items
|
||||
let guest_session = Item::new_guest_session();
|
||||
let generate_pem = Item::new_generate_pem();
|
||||
|
|
@ -43,7 +43,7 @@ impl List {
|
|||
let mut is_guest_session = true;
|
||||
for identity in identities {
|
||||
match Item::new_profile_identity_gemini_id(
|
||||
&profile,
|
||||
profile,
|
||||
identity.id,
|
||||
&auth_uri.to_string(),
|
||||
) {
|
||||
|
|
@ -164,7 +164,10 @@ impl List {
|
|||
.build();
|
||||
|
||||
// Connect events
|
||||
dropdown.connect_selected_notify(move |_| widget_action.update.activate());
|
||||
dropdown.connect_selected_notify({
|
||||
let widget_action = widget_action.clone();
|
||||
move |_| widget_action.update.activate()
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl Name {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(widget_action: Rc<WidgetAction>) -> Self {
|
||||
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
|
||||
// Init main gobject
|
||||
let entry = Entry::builder()
|
||||
.margin_top(MARGIN)
|
||||
|
|
@ -29,7 +29,10 @@ impl Name {
|
|||
.build();
|
||||
|
||||
// Init events
|
||||
entry.connect_changed(move |_| widget_action.update.activate());
|
||||
entry.connect_changed({
|
||||
let widget_action = widget_action.clone();
|
||||
move |_| widget_action.update.activate()
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { entry }
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl Save {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(profile: Rc<Profile>, list: Rc<List>) -> Self {
|
||||
pub fn new(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
.label(LABEL)
|
||||
|
|
@ -35,6 +35,8 @@ impl Save {
|
|||
// Init events
|
||||
button.connect_clicked({
|
||||
let button = button.clone();
|
||||
let list = list.clone();
|
||||
let profile = profile.clone();
|
||||
move |_| {
|
||||
// Get selected identity from holder
|
||||
match list.selected().value_enum() {
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ impl Page {
|
|||
// Constructors
|
||||
|
||||
pub fn new(
|
||||
id: Rc<GString>,
|
||||
profile: Rc<Profile>,
|
||||
id: &Rc<GString>,
|
||||
profile: &Rc<Profile>,
|
||||
(browser_action, window_action, tab_action): (
|
||||
Rc<BrowserAction>,
|
||||
Rc<WindowAction>,
|
||||
Rc<TabAction>,
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
),
|
||||
) -> Self {
|
||||
// Init components
|
||||
|
|
@ -80,7 +80,7 @@ impl Page {
|
|||
let input = Rc::new(Input::new());
|
||||
|
||||
let widget = Rc::new(Widget::new(
|
||||
&id,
|
||||
id,
|
||||
&navigation.widget.g_box,
|
||||
&content.g_box,
|
||||
&search.g_box,
|
||||
|
|
@ -91,12 +91,12 @@ impl Page {
|
|||
|
||||
// Done
|
||||
Self {
|
||||
id,
|
||||
profile,
|
||||
id: id.clone(),
|
||||
profile: profile.clone(),
|
||||
// Actions
|
||||
browser_action,
|
||||
tab_action,
|
||||
window_action,
|
||||
browser_action: browser_action.clone(),
|
||||
tab_action: tab_action.clone(),
|
||||
window_action: window_action.clone(),
|
||||
// Components
|
||||
client: Rc::new(Client::new()),
|
||||
content,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue