mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-11 02:44:15 +00:00
make update action by item id
This commit is contained in:
parent
c92a5406f5
commit
6c4137f2b6
@ -9,7 +9,10 @@ use database::Database;
|
|||||||
use adw::Application;
|
use adw::Application;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib::ExitCode,
|
glib::ExitCode,
|
||||||
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
prelude::{
|
||||||
|
ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt,
|
||||||
|
StaticVariantType, ToVariant,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::{Connection, Transaction};
|
||||||
|
|
||||||
@ -41,7 +44,7 @@ impl App {
|
|||||||
let action_tool_debug = Action::new("win", true, None);
|
let action_tool_debug = Action::new("win", true, None);
|
||||||
let action_tool_profile = Action::new("win", true, None);
|
let action_tool_profile = Action::new("win", true, None);
|
||||||
let action_quit = Action::new("win", true, None);
|
let action_quit = Action::new("win", true, None);
|
||||||
let action_update = Action::new("win", true, None);
|
let action_update = Action::new("win", true, Some(&String::static_variant_type()));
|
||||||
let action_tab_append = Action::new("win", true, None);
|
let action_tab_append = Action::new("win", true, None);
|
||||||
let action_tab_close = Action::new("win", true, None);
|
let action_tab_close = Action::new("win", true, None);
|
||||||
let action_tab_close_all = Action::new("win", true, None);
|
let action_tab_close_all = Action::new("win", true, None);
|
||||||
@ -102,7 +105,7 @@ impl App {
|
|||||||
let action_update = action_update.simple();
|
let action_update = action_update.simple();
|
||||||
move |_| {
|
move |_| {
|
||||||
// Make initial update
|
// Make initial update
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&"".to_variant())); // @TODO
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -107,8 +107,13 @@ impl Browser {
|
|||||||
|
|
||||||
action_update.connect_activate({
|
action_update.connect_activate({
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |_, _| {
|
move |_, id| {
|
||||||
window.update();
|
window.update(
|
||||||
|
id.expect("Page ID required for update action")
|
||||||
|
.get::<String>()
|
||||||
|
.expect("Parameter does not match `String`")
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ impl Window {
|
|||||||
self.tab.pin();
|
self.tab.pin();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&self) {
|
pub fn update(&self, id: &str) {
|
||||||
self.tab.update();
|
self.tab.update(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
|
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
|
||||||
|
@ -26,7 +26,7 @@ pub struct Tab {
|
|||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
// Dynamically allocated reference index
|
// Dynamically allocated reference index
|
||||||
index: Arc<RefCell<HashMap<Arc<GString>, Arc<Item>>>>,
|
index: Arc<RefCell<HashMap<GString, Arc<Item>>>>,
|
||||||
// GTK
|
// GTK
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
@ -208,18 +208,16 @@ impl Tab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&self) {
|
pub fn update(&self, id: &str) {
|
||||||
if let Some(id) = self.widget.current_page_keyword() {
|
if let Some(item) = self.index.borrow().get(id) {
|
||||||
if let Some(item) = self.index.borrow().get(&id) {
|
// Update item components
|
||||||
// Update item components
|
item.update();
|
||||||
item.update();
|
|
||||||
|
|
||||||
// Update tab title on loading indicator inactive
|
// Update tab title on loading indicator inactive
|
||||||
if !item.page_is_loading() {
|
if !item.page_is_loading() {
|
||||||
if let Some(title) = item.page_meta_title() {
|
if let Some(title) = item.page_meta_title() {
|
||||||
item.gobject().set_title(title.as_str())
|
item.gobject().set_title(title.as_str())
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ use std::sync::Arc;
|
|||||||
pub struct Item {
|
pub struct Item {
|
||||||
// Auto-generated unique item ID
|
// Auto-generated unique item ID
|
||||||
// useful as widget name in GTK actions callback
|
// useful as widget name in GTK actions callback
|
||||||
id: Arc<GString>,
|
id: GString,
|
||||||
// Components
|
// Components
|
||||||
page: Arc<Page>,
|
page: Arc<Page>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
@ -39,7 +39,7 @@ impl Item {
|
|||||||
is_selected: bool,
|
is_selected: bool,
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
// Generate unique ID for new page components
|
// Generate unique ID for new page components
|
||||||
let id = Arc::new(uuid_string_random());
|
let id = uuid_string_random();
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let page = Page::new_arc(
|
let page = Page::new_arc(
|
||||||
@ -201,7 +201,7 @@ impl Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn id(&self) -> Arc<GString> {
|
pub fn id(&self) -> GString {
|
||||||
self.id.clone()
|
self.id.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ use sqlite::Transaction;
|
|||||||
use std::{cell::RefCell, path::Path, sync::Arc};
|
use std::{cell::RefCell, path::Path, sync::Arc};
|
||||||
|
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
id: Arc<GString>,
|
id: GString,
|
||||||
// Actions
|
// Actions
|
||||||
action_page_open: Arc<SimpleAction>,
|
action_page_open: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
@ -44,7 +44,7 @@ pub struct Page {
|
|||||||
impl Page {
|
impl Page {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc(
|
pub fn new_arc(
|
||||||
id: Arc<GString>,
|
id: GString,
|
||||||
action_tab_open: Arc<SimpleAction>,
|
action_tab_open: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
@ -155,6 +155,7 @@ impl Page {
|
|||||||
let request_text = self.navigation.request_text();
|
let request_text = self.navigation.request_text();
|
||||||
|
|
||||||
// Init shared objects for async access
|
// Init shared objects for async access
|
||||||
|
let id = self.id.to_variant();
|
||||||
let navigation = self.navigation.clone();
|
let navigation = self.navigation.clone();
|
||||||
let content = self.content.clone();
|
let content = self.content.clone();
|
||||||
let meta = self.meta.clone();
|
let meta = self.meta.clone();
|
||||||
@ -166,7 +167,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Loading.."));
|
meta.borrow_mut().title = Some(gformat!("Loading.."));
|
||||||
meta.borrow_mut().description = None;
|
meta.borrow_mut().description = None;
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
/*let _uri = */
|
/*let _uri = */
|
||||||
match Uri::parse(&request_text, UriFlags::NONE) {
|
match Uri::parse(&request_text, UriFlags::NONE) {
|
||||||
@ -187,7 +188,7 @@ impl Page {
|
|||||||
meta.borrow_mut().status = Some(Status::Prepare);
|
meta.borrow_mut().status = Some(Status::Prepare);
|
||||||
meta.borrow_mut().description = Some(gformat!("Connect {host}.."));
|
meta.borrow_mut().description = Some(gformat!("Connect {host}.."));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Create new connection
|
// Create new connection
|
||||||
let cancellable = Cancellable::new();
|
let cancellable = Cancellable::new();
|
||||||
@ -208,7 +209,7 @@ impl Page {
|
|||||||
meta.borrow_mut().status = Some(Status::Connect);
|
meta.borrow_mut().status = Some(Status::Connect);
|
||||||
meta.borrow_mut().description = Some(gformat!("Connected to {host}.."));
|
meta.borrow_mut().description = Some(gformat!("Connected to {host}.."));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
connection.output_stream().write_all_async(
|
connection.output_stream().write_all_async(
|
||||||
@ -221,7 +222,7 @@ impl Page {
|
|||||||
meta.borrow_mut().status = Some(Status::Request);
|
meta.borrow_mut().status = Some(Status::Request);
|
||||||
meta.borrow_mut().description = Some(gformat!("Request data from {host}.."));
|
meta.borrow_mut().description = Some(gformat!("Request data from {host}.."));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Read response
|
// Read response
|
||||||
connection.input_stream().read_all_async(
|
connection.input_stream().read_all_async(
|
||||||
@ -239,7 +240,7 @@ impl Page {
|
|||||||
meta.borrow_mut().description = Some(host);
|
meta.borrow_mut().description = Some(host);
|
||||||
meta.borrow_mut().title = Some(uri.path());
|
meta.borrow_mut().title = Some(uri.path());
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Try create short base for title
|
// Try create short base for title
|
||||||
let path = uri.path();
|
let path = uri.path();
|
||||||
@ -290,7 +291,7 @@ impl Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update window components
|
// Update window components
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
},
|
},
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
}
|
}
|
||||||
@ -299,7 +300,7 @@ impl Page {
|
|||||||
meta.borrow_mut().status = Some(Status::Success);
|
meta.borrow_mut().status = Some(Status::Success);
|
||||||
meta.borrow_mut().mime = Some(Mime::TextPlain);
|
meta.borrow_mut().mime = Some(Mime::TextPlain);
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
todo!()
|
todo!()
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
@ -307,7 +308,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Content {mime} not supported"));
|
meta.borrow_mut().description = Some(gformat!("Content {mime} not supported"));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
@ -320,7 +321,7 @@ impl Page {
|
|||||||
meta.borrow_mut().mime = Some(Mime::TextGemini);
|
meta.borrow_mut().mime = Some(Mime::TextGemini);
|
||||||
meta.borrow_mut().title = Some(gformat!("Redirect"));
|
meta.borrow_mut().title = Some(gformat!("Redirect"));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Select widget
|
// Select widget
|
||||||
match parts.get(3) {
|
match parts.get(3) {
|
||||||
@ -342,7 +343,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Status {code} not supported"));
|
meta.borrow_mut().description = Some(gformat!("Status {code} not supported"));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
@ -353,7 +354,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}"));
|
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}"));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +369,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Failed to read response: {:?}", e));
|
meta.borrow_mut().description = Some(gformat!("Failed to read response: {:?}", e));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
if let Err(e) = connection.close(Some(&cancellable)) {
|
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||||
@ -384,7 +385,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Failed to read request: {:?}", e));
|
meta.borrow_mut().description = Some(gformat!("Failed to read request: {:?}", e));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
if let Err(e) = connection.close(Some(&cancellable)) {
|
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||||
@ -400,7 +401,7 @@ impl Page {
|
|||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Failed to connect: {:?}", e));
|
meta.borrow_mut().description = Some(gformat!("Failed to connect: {:?}", e));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&id));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -415,7 +416,7 @@ impl Page {
|
|||||||
meta.borrow_mut().description =
|
meta.borrow_mut().description =
|
||||||
Some(gformat!("Protocol {scheme} not supported"));
|
Some(gformat!("Protocol {scheme} not supported"));
|
||||||
|
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&self.id.to_variant()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use database::Database;
|
|||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{timeout_add_local, ControlFlow, GString, SourceId},
|
glib::{timeout_add_local, ControlFlow, GString, SourceId},
|
||||||
prelude::{ActionExt, EditableExt, EntryExt},
|
prelude::{ActionExt, EditableExt, EntryExt, ToVariant},
|
||||||
Entry,
|
Entry,
|
||||||
};
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
@ -47,7 +47,7 @@ impl Widget {
|
|||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
gobject.connect_changed(move |_| {
|
gobject.connect_changed(move |_| {
|
||||||
action_update.activate(None);
|
action_update.activate(Some(&"".to_variant())); // @TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
gobject.connect_activate(move |_| {
|
gobject.connect_activate(move |_| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user