mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
reorganize home action, add middle click handler
This commit is contained in:
parent
418b04c86c
commit
3ee6a03c30
5 changed files with 93 additions and 30 deletions
|
|
@ -56,9 +56,10 @@ impl Item {
|
|||
let id = Rc::new(uuid_string_random());
|
||||
|
||||
// Init components
|
||||
|
||||
let action = Rc::new(Action::new());
|
||||
|
||||
tab_action.simple_action_group.add_action(&action.home);
|
||||
|
||||
tab_action
|
||||
.simple_action_group
|
||||
.add_action(&action.history.back);
|
||||
|
|
@ -85,16 +86,20 @@ impl Item {
|
|||
// Update tab loading indicator
|
||||
let client = Rc::new(Client::init(&page, &widget.tab_page));
|
||||
|
||||
// Init events
|
||||
|
||||
if let Some(text) = request {
|
||||
page.navigation.request.widget.entry.set_text(text);
|
||||
if is_load {
|
||||
client.handle(text, true);
|
||||
// Connect events
|
||||
action.home.connect_activate({
|
||||
let client = client.clone();
|
||||
let page = page.clone();
|
||||
move |this, _| {
|
||||
this.set_enabled(false);
|
||||
if let Some(uri) = page.navigation.request.home() {
|
||||
let request = uri.to_string();
|
||||
page.navigation.request.widget.entry.set_text(&request);
|
||||
client.handle(&request, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Show identity selection for item
|
||||
action.ident.connect_activate({
|
||||
let browser_action = browser_action.clone();
|
||||
let page = page.clone();
|
||||
|
|
@ -102,9 +107,7 @@ impl Item {
|
|||
let profile = profile.clone();
|
||||
let window_action = window_action.clone();
|
||||
move || {
|
||||
// Request should match valid URI for all drivers supported
|
||||
if let Some(uri) = page.navigation.request.uri() {
|
||||
// Route by scheme
|
||||
let scheme = uri.scheme();
|
||||
if scheme == "gemini" || scheme == "titan" {
|
||||
return identity::default(
|
||||
|
|
@ -115,12 +118,10 @@ impl Item {
|
|||
.present(Some(&parent));
|
||||
}
|
||||
}
|
||||
// Show dialog with unsupported request message
|
||||
identity::unsupported().present(Some(&parent));
|
||||
}
|
||||
});
|
||||
|
||||
// Load new request for item
|
||||
action.load.connect_activate({
|
||||
let page = page.clone();
|
||||
let client = client.clone();
|
||||
|
|
@ -132,6 +133,13 @@ impl Item {
|
|||
}
|
||||
});
|
||||
|
||||
// Handle immediately on request
|
||||
if let Some(text) = request {
|
||||
page.navigation.request.widget.entry.set_text(text);
|
||||
if is_load {
|
||||
client.handle(text, true);
|
||||
}
|
||||
}
|
||||
// Done
|
||||
Self {
|
||||
id,
|
||||
|
|
@ -144,6 +152,13 @@ impl Item {
|
|||
|
||||
// Actions
|
||||
pub fn update(&self) {
|
||||
// Update self actions
|
||||
self.action
|
||||
.home
|
||||
.set_enabled(self.page.navigation.request.home().is_some_and(|home| {
|
||||
home.to_string() != self.page.navigation.request.widget.entry.text()
|
||||
}));
|
||||
|
||||
// Update child components
|
||||
self.page.update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
mod history;
|
||||
mod home;
|
||||
mod ident;
|
||||
mod load;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use history::History;
|
||||
use home::Home;
|
||||
use ident::Ident;
|
||||
use load::Load;
|
||||
|
||||
|
|
@ -11,6 +14,7 @@ use std::rc::Rc;
|
|||
/// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions
|
||||
pub struct Action {
|
||||
pub history: Rc<History>,
|
||||
pub home: SimpleAction,
|
||||
pub ident: Rc<Ident>,
|
||||
pub load: Rc<Load>,
|
||||
}
|
||||
|
|
@ -28,6 +32,7 @@ impl Action {
|
|||
pub fn new() -> Self {
|
||||
let ident = Rc::new(Ident::new());
|
||||
let load = Rc::new(Load::new());
|
||||
let home = SimpleAction::home();
|
||||
|
||||
let history = Rc::new(History::build({
|
||||
let load = load.clone();
|
||||
|
|
@ -36,6 +41,7 @@ impl Action {
|
|||
|
||||
Self {
|
||||
history,
|
||||
home,
|
||||
ident,
|
||||
load,
|
||||
}
|
||||
|
|
|
|||
13
src/app/browser/window/tab/item/action/home.rs
Normal file
13
src/app/browser/window/tab/item/action/home.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use gtk::{gio::SimpleAction, glib::uuid_string_random};
|
||||
|
||||
pub trait Home {
|
||||
fn home() -> Self;
|
||||
}
|
||||
|
||||
impl Home for SimpleAction {
|
||||
fn home() -> Self {
|
||||
let home = SimpleAction::new(&uuid_string_random(), None);
|
||||
home.set_enabled(false);
|
||||
home
|
||||
}
|
||||
}
|
||||
|
|
@ -38,10 +38,10 @@ impl Navigation {
|
|||
) -> Self {
|
||||
// init children components
|
||||
|
||||
let home = Button::home(window_action);
|
||||
let history = Box::history((window_action, tab_action, item_action));
|
||||
let reload = Button::reload(window_action);
|
||||
let request = Rc::new(Request::build((browser_action, item_action)));
|
||||
let home = Button::home((window_action, tab_action, item_action), &request);
|
||||
let bookmark = Button::bookmark(window_action);
|
||||
|
||||
// init main widget
|
||||
|
|
@ -80,11 +80,6 @@ impl Navigation {
|
|||
.get(&self.request.strip_prefix())
|
||||
.is_some(),
|
||||
);
|
||||
self.home.set_sensitive(
|
||||
self.request
|
||||
.home()
|
||||
.is_some_and(|home| home.to_string() != request),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
|
|
|
|||
|
|
@ -1,21 +1,55 @@
|
|||
use super::WindowAction;
|
||||
use gtk::{prelude::ActionExt, Button};
|
||||
use super::{ItemAction, Request, TabAction, WindowAction};
|
||||
use crate::app::browser::window::action::Position;
|
||||
use gtk::{
|
||||
gdk::BUTTON_MIDDLE,
|
||||
prelude::{ActionExt, WidgetExt},
|
||||
Button, GestureClick,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub trait Home {
|
||||
fn home(action: &Rc<WindowAction>) -> Self;
|
||||
fn home(
|
||||
action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>),
|
||||
request: &Rc<Request>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl Home for Button {
|
||||
fn home(action: &Rc<WindowAction>) -> Self {
|
||||
Button::builder()
|
||||
.action_name(format!(
|
||||
"{}.{}",
|
||||
action.id,
|
||||
action.home.simple_action.name()
|
||||
)) // @TODO
|
||||
fn home(
|
||||
(window_action, tab_action, item_action): (
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
&Rc<ItemAction>,
|
||||
),
|
||||
request: &Rc<Request>,
|
||||
) -> Self {
|
||||
let button = Button::builder()
|
||||
.action_name(format!("{}.{}", tab_action.id, item_action.home.name()))
|
||||
.icon_name("go-home-symbolic")
|
||||
.tooltip_text("Home")
|
||||
.build()
|
||||
.build();
|
||||
|
||||
// Navigate home in the new tab (feature)
|
||||
let button_middle_controller = GestureClick::builder().button(BUTTON_MIDDLE).build();
|
||||
|
||||
button_middle_controller.connect_pressed({
|
||||
let request = request.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_, _, _, _| {
|
||||
if let Some(uri) = request.home() {
|
||||
window_action.append.activate_stateful_once(
|
||||
Position::After,
|
||||
Some(uri.to_string()),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
button.add_controller(button_middle_controller);
|
||||
button
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue