connect bookmark action

This commit is contained in:
yggverse 2024-11-14 08:51:14 +02:00
parent 7b9bd95c09
commit d0a7c3079d
12 changed files with 76 additions and 64 deletions

View File

@ -7,11 +7,11 @@ mod window;
use about::About; use about::About;
use action::Action; use action::Action;
use welcome::Welcome; //use welcome::Welcome;
use widget::Widget; use widget::Widget;
use window::Window; use window::Window;
use crate::profile::Profile; use crate::Profile;
use gtk::{ use gtk::{
gio::{Cancellable, File}, gio::{Cancellable, File},
prelude::{GtkWindowExt, IsA}, prelude::{GtkWindowExt, IsA},
@ -32,7 +32,7 @@ impl Browser {
pub fn new(profile: Rc<Profile>) -> Browser { pub fn new(profile: Rc<Profile>) -> Browser {
// Init components // Init components
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
let window = Rc::new(Window::new(action.clone())); let window = Rc::new(Window::new(profile.clone(), action.clone()));
// Init widget // Init widget
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(

View File

@ -11,6 +11,7 @@ use tab::Tab;
use widget::Widget; use widget::Widget;
use crate::app::browser::action::Action as BrowserAction; use crate::app::browser::action::Action as BrowserAction;
use crate::Profile;
use gtk::glib::GString; use gtk::glib::GString;
use std::rc::Rc; use std::rc::Rc;
@ -22,15 +23,12 @@ pub struct Window {
impl Window { impl Window {
// Construct // Construct
pub fn new( pub fn new(profile: Rc<Profile>, browser_action: Rc<BrowserAction>) -> Self {
// Actions
browser_action: Rc<BrowserAction>,
) -> Self {
// Init local actions // Init local actions
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
// Init components // Init components
let tab = Rc::new(Tab::new(browser_action.clone(), action.clone())); let tab = Rc::new(Tab::new(profile, (browser_action.clone(), action.clone())));
let header = Header::new(browser_action, action.clone(), tab.widget().gobject()); let header = Header::new(browser_action, action.clone(), tab.widget().gobject());
let widget = Rc::new(Widget::new(header.gobject(), tab.widget().gobject())); let widget = Rc::new(Widget::new(header.gobject(), tab.widget().gobject()));
@ -52,7 +50,7 @@ impl Window {
action.bookmark().connect_activate({ action.bookmark().connect_activate({
let tab = tab.clone(); let tab = tab.clone();
move |position| tab.bookmark(position) move |position| tab.bookmark(position)
}); }); // @TODO
action.pin().connect_activate({ action.pin().connect_activate({
let tab = tab.clone(); let tab = tab.clone();

View File

@ -11,6 +11,7 @@ use crate::app::browser::{
window::action::{Action as WindowAction, Position}, window::action::{Action as WindowAction, Position},
Action as BrowserAction, Action as BrowserAction,
}; };
use crate::Profile;
use gtk::{ use gtk::{
glib::{GString, Propagation}, glib::{GString, Propagation},
prelude::WidgetExt, prelude::WidgetExt,
@ -20,6 +21,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};
// Main // Main
pub struct Tab { pub struct Tab {
profile: Rc<Profile>,
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
index: Rc<RefCell<HashMap<GString, Rc<Item>>>>, index: Rc<RefCell<HashMap<GString, Rc<Item>>>>,
@ -28,12 +30,12 @@ pub struct Tab {
impl Tab { impl Tab {
// Construct // Construct
pub fn new(browser_action: Rc<BrowserAction>, window_action: Rc<WindowAction>) -> Self { pub fn new(profile: Rc<Profile>, action: (Rc<BrowserAction>, Rc<WindowAction>)) -> Self {
// Init empty HashMap index // Init empty HashMap index
let index: Rc<RefCell<HashMap<GString, Rc<Item>>>> = Rc::new(RefCell::new(HashMap::new())); let index: Rc<RefCell<HashMap<GString, Rc<Item>>>> = Rc::new(RefCell::new(HashMap::new()));
// Init context menu // Init context menu
let menu = Menu::new(window_action.clone()); let menu = Menu::new(action.1.clone());
// Init widget // Init widget
let widget = Rc::new(Widget::new(menu.gobject())); let widget = Rc::new(Widget::new(menu.gobject()));
@ -41,20 +43,20 @@ impl Tab {
// Init events // Init events
widget.gobject().connect_setup_menu({ widget.gobject().connect_setup_menu({
let window_action = window_action.clone(); let action = action.1.clone();
move |tab_view, tab_page| { move |tab_view, tab_page| {
// Set new state for page selected on menu open // Set new state for page selected on menu open
// * this action return default state (`None`) on menu close // * this action return default state (`None`) on menu close
let state = tab_page.map(|this| tab_view.page_position(this)); let state = tab_page.map(|this| tab_view.page_position(this));
// Update actions with new state value // Update actions with new state value
window_action.close_all().change_state(state); action.close_all().change_state(state);
window_action.close().change_state(state); action.close().change_state(state);
window_action.history_back().change_state(state); action.history_back().change_state(state);
window_action.history_forward().change_state(state); action.history_forward().change_state(state);
window_action.home().change_state(state); action.home().change_state(state);
window_action.pin().change_state(state); action.pin().change_state(state);
window_action.reload().change_state(state); action.reload().change_state(state);
} }
}); });
@ -94,8 +96,9 @@ impl Tab {
// Return activated `Self` // Return activated `Self`
Self { Self {
browser_action, profile,
window_action, browser_action: action.0,
window_action: action.1,
index, index,
widget, widget,
} }
@ -114,6 +117,7 @@ impl Tab {
// Init new tab item // Init new tab item
let item = Rc::new(Item::new( let item = Rc::new(Item::new(
self.widget.gobject(), self.widget.gobject(),
self.profile.clone(),
self.browser_action.clone(), self.browser_action.clone(),
self.window_action.clone(), self.window_action.clone(),
// Options tuple // Options tuple
@ -280,8 +284,8 @@ impl Tab {
self.widget.gobject(), self.widget.gobject(),
transaction, transaction,
&record.id, &record.id,
self.browser_action.clone(), self.profile.clone(),
self.window_action.clone(), (self.browser_action.clone(), self.window_action.clone()),
) { ) {
Ok(items) => { Ok(items) => {
for item in items { for item in items {

View File

@ -11,6 +11,7 @@ use crate::app::browser::{
window::action::{Action as WindowAction, Position}, window::action::{Action as WindowAction, Position},
Action as BrowserAction, Action as BrowserAction,
}; };
use crate::Profile;
use adw::TabView; use adw::TabView;
use gtk::{ use gtk::{
glib::{uuid_string_random, GString}, glib::{uuid_string_random, GString},
@ -32,6 +33,7 @@ impl Item {
// Construct // Construct
pub fn new( pub fn new(
tab_view: &TabView, tab_view: &TabView,
profile: Rc<Profile>,
// Actions // Actions
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
@ -50,6 +52,7 @@ impl Item {
let page = Rc::new(Page::new( let page = Rc::new(Page::new(
id.clone(), id.clone(),
profile,
(browser_action, window_action, action.clone()), (browser_action, window_action, action.clone()),
)); ));
@ -133,9 +136,9 @@ impl Item {
tab_view: &TabView, tab_view: &TabView,
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_id: &i64, app_browser_window_tab_id: &i64,
profile: Rc<Profile>,
// Actions // Actions
browser_action: Rc<BrowserAction>, action: (Rc<BrowserAction>, Rc<WindowAction>),
window_action: Rc<WindowAction>,
) -> Result<Vec<Rc<Item>>, String> { ) -> Result<Vec<Rc<Item>>, String> {
let mut items = Vec::new(); let mut items = Vec::new();
@ -145,9 +148,10 @@ impl Item {
// Construct new item object // Construct new item object
let item = Rc::new(Item::new( let item = Rc::new(Item::new(
tab_view, tab_view,
profile.clone(),
// Actions // Actions
browser_action.clone(), action.0.clone(),
window_action.clone(), action.1.clone(),
// Options tuple // Options tuple
( (
Position::End, Position::End,

View File

@ -15,6 +15,7 @@ use crate::app::browser::{
window::{tab::item::Action as TabAction, Action as WindowAction}, window::{tab::item::Action as TabAction, Action as WindowAction},
Action as BrowserAction, Action as BrowserAction,
}; };
use crate::Profile;
use gtk::{ use gtk::{
gdk_pixbuf::Pixbuf, gdk_pixbuf::Pixbuf,
gio::{Cancellable, SocketClient, SocketClientEvent, SocketProtocol, TlsCertificateFlags}, gio::{Cancellable, SocketClient, SocketClientEvent, SocketProtocol, TlsCertificateFlags},
@ -44,15 +45,18 @@ pub struct Page {
impl Page { impl Page {
// Constructors // Constructors
pub fn new(id: GString, action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>)) -> Self { pub fn new(
id: GString,
profile: Rc<Profile>,
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>),
) -> Self {
// Init components // Init components
let content = Rc::new(Content::new((action.1.clone(), action.2.clone()))); let content = Rc::new(Content::new((action.1.clone(), action.2.clone())));
let navigation = Rc::new(Navigation::new(( let navigation = Rc::new(Navigation::new(
action.0.clone(), profile,
action.1.clone(), (action.0.clone(), action.1.clone(), action.2.clone()),
action.2.clone(), ));
)));
let input = Rc::new(Input::new()); let input = Rc::new(Input::new());

View File

@ -16,11 +16,13 @@ use widget::Widget;
use crate::app::browser::window::tab::item::Action as TabAction; use crate::app::browser::window::tab::item::Action as TabAction;
use crate::app::browser::window::Action as WindowAction; use crate::app::browser::window::Action as WindowAction;
use crate::app::browser::Action as BrowserAction; use crate::app::browser::Action as BrowserAction;
use crate::Profile;
use gtk::prelude::EditableExt; use gtk::prelude::EditableExt;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::rc::Rc;
pub struct Navigation { pub struct Navigation {
profile: Rc<Profile>,
bookmark: Rc<Bookmark>, bookmark: Rc<Bookmark>,
history: Rc<History>, history: Rc<History>,
home: Rc<Home>, home: Rc<Home>,
@ -30,7 +32,10 @@ pub struct Navigation {
} }
impl Navigation { impl Navigation {
pub fn new(action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>)) -> Self { pub fn new(
profile: Rc<Profile>,
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>),
) -> Self {
// Init components // Init components
let home = Rc::new(Home::new(action.1.clone())); let home = Rc::new(Home::new(action.1.clone()));
let history = Rc::new(History::new(action.1.clone())); let history = Rc::new(History::new(action.1.clone()));
@ -49,6 +54,7 @@ impl Navigation {
// Done // Done
Self { Self {
profile,
bookmark, bookmark,
history, history,
home, home,
@ -61,11 +67,13 @@ impl Navigation {
// Actions // Actions
pub fn update(&self, progress_fraction: Option<f64>) { pub fn update(&self, progress_fraction: Option<f64>) {
self.bookmark.update(false); // @TODO DB from request let request = self.request.widget().gobject().text();
self.bookmark
.update(!self.profile.bookmark.has_request(&request, true));
self.history.update(); self.history.update();
self.home.update(self.request.uri()); self.home.update(self.request.uri());
self.reload self.reload.update(!request.is_empty());
.update(!self.request.widget().gobject().text().is_empty());
self.request.update(progress_fraction); self.request.update(progress_fraction);
} }

View File

@ -6,26 +6,23 @@ use crate::app::browser::window::action::Action as WindowAction;
use std::rc::Rc; use std::rc::Rc;
pub struct Bookmark { pub struct Bookmark {
window_action: Rc<WindowAction>, action: Rc<WindowAction>,
widget: Rc<Widget>, widget: Rc<Widget>,
} }
impl Bookmark { impl Bookmark {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
Self { Self {
widget: Rc::new(Widget::new(window_action.clone())), widget: Rc::new(Widget::new(action.clone())),
window_action, action,
} }
} }
// Actions // Actions
pub fn update(&self, is_enabled: bool) { pub fn update(&self, is_enabled: bool) {
// Update actions // Update actions
self.window_action self.action.bookmark().gobject().set_enabled(is_enabled);
.bookmark()
.gobject()
.set_enabled(is_enabled);
// Update child components // Update child components
self.widget.update(is_enabled); self.widget.update(is_enabled);

View File

@ -13,7 +13,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Constructors // Constructors
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("starred-symbolic") .icon_name("starred-symbolic")
@ -22,7 +22,7 @@ impl Widget {
.build(); .build();
// Init events // Init events
gobject.connect_clicked(move |_| window_action.home().activate()); gobject.connect_clicked(move |_| action.home().activate());
// Return activated `Self` // Return activated `Self`
Self { gobject } Self { gobject }

View File

@ -7,18 +7,18 @@ use gtk::glib::{gformat, GString, Uri};
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
pub struct Home { pub struct Home {
window_action: Rc<WindowAction>, action: Rc<WindowAction>,
uri: RefCell<Option<Uri>>, uri: RefCell<Option<Uri>>,
widget: Rc<Widget>, widget: Rc<Widget>,
} }
impl Home { impl Home {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
Self { Self {
window_action: window_action.clone(), action: action.clone(),
uri: RefCell::new(None), uri: RefCell::new(None),
widget: Rc::new(Widget::new(window_action)), widget: Rc::new(Widget::new(action)),
} }
} }
@ -34,7 +34,7 @@ impl Home {
self.uri.replace(uri); self.uri.replace(uri);
// Update action status // Update action status
self.window_action.home().gobject().set_enabled(status); self.action.home().gobject().set_enabled(status);
// Update child components // Update child components
self.widget.update(status); self.widget.update(status);

View File

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("go-home-symbolic") .icon_name("go-home-symbolic")
@ -20,7 +20,7 @@ impl Widget {
.build(); .build();
// Init events // Init events
gobject.connect_clicked(move |_| window_action.home().activate()); gobject.connect_clicked(move |_| action.home().activate());
// Return activated `Self` // Return activated `Self`
Self { gobject } Self { gobject }

View File

@ -6,16 +6,16 @@ use crate::app::browser::window::action::Action as WindowAction;
use std::rc::Rc; use std::rc::Rc;
pub struct Reload { pub struct Reload {
window_action: Rc<WindowAction>, action: Rc<WindowAction>,
widget: Rc<Widget>, widget: Rc<Widget>,
} }
impl Reload { impl Reload {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
Self { Self {
window_action: window_action.clone(), action: action.clone(),
widget: Rc::new(Widget::new(window_action)), widget: Rc::new(Widget::new(action)),
} }
} }
@ -23,10 +23,7 @@ impl Reload {
pub fn update(&self, is_enabled: bool) { pub fn update(&self, is_enabled: bool) {
// Update actions // Update actions
self.window_action self.action.reload().gobject().set_enabled(is_enabled);
.reload()
.gobject()
.set_enabled(is_enabled);
// Update child components // Update child components
self.widget.update(is_enabled); self.widget.update(is_enabled);

View File

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("view-refresh-symbolic") .icon_name("view-refresh-symbolic")
@ -20,7 +20,7 @@ impl Widget {
.build(); .build();
// Init events // Init events
gobject.connect_clicked(move |_| window_action.reload().activate()); gobject.connect_clicked(move |_| action.reload().activate());
// Return activated `Self` // Return activated `Self`
Self { gobject } Self { gobject }