update actions

This commit is contained in:
yggverse 2024-11-11 05:11:48 +02:00
parent a5fc2a7475
commit a6ef61486d
24 changed files with 190 additions and 294 deletions

View file

@ -6,10 +6,9 @@ use image::Image;
use status::Status;
use text::Text;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
use gtk::{
gdk_pixbuf::Pixbuf,
gio::SimpleAction,
glib::Uri,
prelude::{BoxExt, WidgetExt},
Box, Orientation,
@ -17,22 +16,20 @@ use gtk::{
use std::{rc::Rc, time::Duration};
pub struct Content {
// GTK
gobject: Box,
// Actions
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
gobject: Box,
}
impl Content {
// Construct
/// Create new container for different components
pub fn new(tab_action: Rc<TabAction>, action_page_open: SimpleAction) -> Self {
pub fn new(window_action: Rc<WindowAction>, tab_action: Rc<TabAction>) -> Self {
Self {
gobject: Box::builder().orientation(Orientation::Vertical).build(),
window_action,
tab_action,
action_page_open,
}
}
@ -88,8 +85,8 @@ impl Content {
let text = Text::gemini(
data,
base,
self.window_action.clone(),
self.tab_action.clone(),
self.action_page_open.clone(),
);
self.gobject.append(text.gobject());
text

View file

@ -2,9 +2,8 @@ mod gemini;
use gemini::Gemini;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
ScrolledWindow,
};
@ -24,11 +23,11 @@ impl Text {
pub fn gemini(
gemtext: &str,
base: &Uri,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Self {
// Init components
let gemini = Gemini::new(gemtext, base, tab_action, action_page_open);
let gemini = Gemini::new(gemtext, base, window_action, tab_action);
// Init meta
let meta = Meta {

View file

@ -4,12 +4,9 @@ mod widget;
use reader::Reader;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
use adw::ClampScrollable;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
};
use gtk::glib::{GString, Uri};
use std::rc::Rc;
pub struct Gemini {
@ -22,11 +19,11 @@ impl Gemini {
pub fn new(
gemtext: &str,
base: &Uri,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Self {
// Init components
let reader = Rc::new(Reader::new(gemtext, base, tab_action, action_page_open));
let reader = Rc::new(Reader::new(gemtext, base, window_action, tab_action));
let widget = Rc::new(Widget::new(reader.gobject()));
// Result

View file

@ -4,7 +4,7 @@ mod widget;
use tag::Tag;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
use adw::StyleManager;
use gemtext::line::{
code::Code,
@ -15,9 +15,9 @@ use gemtext::line::{
};
use gtk::{
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY},
gio::{Cancellable, SimpleAction},
gio::Cancellable,
glib::{GString, TimeZone, Uri},
prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt},
prelude::{TextBufferExt, TextBufferExtManual, TextViewExt, WidgetExt},
EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType,
UriLauncher, Window, WrapMode,
};
@ -33,8 +33,8 @@ impl Reader {
pub fn new(
gemtext: &str,
base: &Uri,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Self {
// Init default values
let mut title = None;
@ -232,7 +232,7 @@ impl Reader {
// Init events
primary_button_controller.connect_released({
let action_page_open = action_page_open.clone();
let tab_action = tab_action.clone();
let gobject = widget.gobject().clone();
let _links_ = links.clone(); // is copy
move |_, _, window_x, window_y| {
@ -251,7 +251,7 @@ impl Reader {
return match uri.scheme().as_str() {
"gemini" => {
// Open new page in browser
action_page_open.activate(Some(&uri.to_str().to_variant()));
tab_action.load().activate(Some(&uri.to_str()));
}
// Scheme not supported, delegate
_ => UriLauncher::new(&uri.to_str()).launch(
@ -259,8 +259,7 @@ impl Reader {
None::<&Cancellable>,
|result| {
if let Err(error) = result {
// @TODO
println!("Could not delegate launch action: {error}")
println!("{error}")
}
},
),
@ -289,7 +288,7 @@ impl Reader {
return match uri.scheme().as_str() {
"gemini" => {
// Open new page in browser
tab_action.open().activate(Some(&uri.to_string()));
window_action.append().activate();
}
// Scheme not supported, delegate
_ => UriLauncher::new(&uri.to_str()).launch(
@ -297,8 +296,7 @@ impl Reader {
None::<&Cancellable>,
|result| {
if let Err(error) = result {
// @TODO
println!("Could not delegate launch action: {error}")
println!("{error}")
}
},
),

View file

@ -6,7 +6,7 @@ use response::Response;
use sensitive::Sensitive;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::tab::item::Action as TabAction;
use adw::Clamp;
use gtk::glib::Uri;
use std::rc::Rc;

View file

@ -8,7 +8,7 @@ use form::Form;
use title::Title;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::tab::item::action::Action as TabAction;
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags},
@ -63,7 +63,7 @@ impl Response {
action_send.connect_activate({
let form = form.clone();
move |_, _| {
tab_action.open().activate(Some(&format!(
tab_action.load().activate(Some(&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),

View file

@ -4,7 +4,7 @@ mod widget;
use form::Form;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use crate::app::browser::window::tab::item::action::Action as TabAction;
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags},
@ -44,7 +44,7 @@ impl Sensitive {
action_send.connect_activate({
let form = form.clone();
move |_, _| {
tab_action.open().activate(Some(&format!(
tab_action.load().activate(Some(&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),

View file

@ -14,9 +14,10 @@ use reload::Reload;
use request::Request;
use widget::Widget;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{gio::SimpleAction, prelude::EditableExt};
use crate::app::browser::window::tab::item::Action as TabAction;
use crate::app::browser::window::Action as WindowAction;
use crate::app::browser::Action as BrowserAction;
use gtk::prelude::EditableExt;
use sqlite::Transaction;
use std::rc::Rc;
@ -33,22 +34,22 @@ impl Navigation {
pub fn new(
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
action_page_open: SimpleAction,
tab_action: Rc<TabAction>,
) -> Self {
// Init components
let home = Rc::new(Home::new(window_action.clone()));
let history = Rc::new(History::new(window_action.clone()));
let reload = Rc::new(Reload::new(window_action));
let request = Rc::new(Request::new(browser_action, action_page_open.clone()));
let request = Rc::new(Request::new(browser_action, tab_action));
let bookmark = Rc::new(Bookmark::new());
// Init widget
let widget = Rc::new(Widget::new(
home.gobject(),
history.gobject(),
reload.gobject(),
home.widget().gobject(),
history.widget().gobject(),
reload.widget().gobject(),
request.widget().gobject(),
bookmark.gobject(),
bookmark.widget().gobject(),
));
// Done

View file

@ -2,7 +2,6 @@ mod widget;
use widget::Widget;
use gtk::Button;
use std::rc::Rc;
pub struct Bookmark {
@ -23,7 +22,8 @@ impl Bookmark {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -7,7 +7,7 @@ use forward::Forward;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{glib::GString, Box};
use gtk::glib::GString;
use std::{cell::RefCell, rc::Rc};
struct Memory {
@ -34,7 +34,10 @@ impl History {
let forward = Rc::new(Forward::new(window_action));
// Init widget
let widget = Rc::new(Widget::new(back.gobject(), forward.gobject()));
let widget = Rc::new(Widget::new(
back.widget().gobject(),
forward.widget().gobject(),
));
// Init memory
let memory = RefCell::new(Vec::new());
@ -122,7 +125,8 @@ impl History {
}
// Getters
pub fn gobject(&self) -> &Box {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -3,7 +3,6 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Back {
@ -12,7 +11,8 @@ pub struct Back {
}
impl Back {
// Construct
// Constructors
pub fn new(window_action: Rc<WindowAction>) -> Self {
Self {
window_action: window_action.clone(),
@ -21,6 +21,7 @@ impl Back {
}
// Actions
pub fn update(&self, status: bool) {
// Update actions
self.window_action
@ -33,7 +34,8 @@ impl Back {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -3,7 +3,6 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Forward {
@ -33,7 +32,8 @@ impl Forward {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -3,10 +3,7 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{
glib::{gformat, GString, Uri},
Button,
};
use gtk::glib::{gformat, GString, Uri};
use std::{cell::RefCell, rc::Rc};
pub struct Home {
@ -44,8 +41,8 @@ impl Home {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
pub fn url(&self) -> Option<GString> {

View file

@ -3,7 +3,6 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Reload {
@ -21,6 +20,7 @@ impl Reload {
}
// Actions
pub fn update(&self, is_enabled: bool) {
// Update actions
self.window_action
@ -33,7 +33,8 @@ impl Reload {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -4,9 +4,8 @@ mod widget;
use database::Database;
use widget::Widget;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
use gtk::{
gio::SimpleAction,
glib::{Uri, UriFlags},
prelude::EditableExt,
};
@ -23,10 +22,10 @@ impl Request {
pub fn new(
// Actions
browser_action: Rc<BrowserAction>,
action_page_reload: SimpleAction, // @TODO local `action_page_open`?
tab_action: Rc<TabAction>,
) -> Self {
Self {
widget: Rc::new(Widget::new(browser_action, action_page_reload)),
widget: Rc::new(Widget::new(browser_action, tab_action)),
}
}

View file

@ -2,11 +2,10 @@ mod database;
use database::Database;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
use gtk::{
gio::SimpleAction,
glib::{timeout_add_local, ControlFlow, SourceId},
prelude::{ActionExt, EditableExt, EntryExt, ToVariant, WidgetExt},
prelude::{EditableExt, EntryExt, WidgetExt},
Entry, StateFlags,
};
use sqlite::Transaction;
@ -30,7 +29,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new(browser_action: Rc<BrowserAction>, action_page_open: SimpleAction) -> Self {
pub fn new(browser_action: Rc<BrowserAction>, tab_action: Rc<TabAction>) -> Self {
// Init animated progress bar state
let progress = Rc::new(Progress {
fraction: RefCell::new(0.0),
@ -49,7 +48,7 @@ impl Widget {
});
gobject.connect_activate(move |this| {
action_page_open.activate(Some(&this.text().to_variant()));
tab_action.load().activate(Some(&this.text()));
});
gobject.connect_state_flags_changed({

View file

@ -1,7 +1,5 @@
use gtk::{
gio::{SimpleAction, SimpleActionGroup},
glib::uuid_string_random,
prelude::{ActionMapExt, BoxExt, IsA, WidgetExt},
prelude::{BoxExt, IsA},
Box, Orientation,
};
@ -13,17 +11,11 @@ impl Widget {
// Construct
pub fn new(
name: &str,
// Actions
action_page_open: SimpleAction,
// Components
navigation: &impl IsA<gtk::Widget>,
content: &impl IsA<gtk::Widget>,
input: &impl IsA<gtk::Widget>,
) -> Self {
// Init additional action group
let action_group = SimpleActionGroup::new();
action_group.add_action(&action_page_open);
// Init self
let gobject = Box::builder()
.orientation(Orientation::Vertical)
@ -34,8 +26,6 @@ impl Widget {
gobject.append(content);
gobject.append(input);
gobject.insert_action_group(&uuid_string_random(), Some(&action_group));
Self { gobject }
}