mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-11 14:32:00 +00:00
draft new tab open on middle click
This commit is contained in:
parent
0d55d492f3
commit
8f1e94dd68
@ -38,6 +38,7 @@ impl Window {
|
||||
) -> Self {
|
||||
// Init components
|
||||
let tab = Tab::new_arc(
|
||||
action_tab_append.clone(),
|
||||
action_tab_page_navigation_base.clone(),
|
||||
action_tab_page_navigation_history_back.clone(),
|
||||
action_tab_page_navigation_history_forward.clone(),
|
||||
|
@ -17,6 +17,7 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc};
|
||||
// Main
|
||||
pub struct Tab {
|
||||
// Actions
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
@ -32,6 +33,7 @@ impl Tab {
|
||||
// Construct
|
||||
pub fn new_arc(
|
||||
// Actions
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
@ -67,6 +69,7 @@ impl Tab {
|
||||
// Return activated struct
|
||||
Arc::new(Self {
|
||||
// Define action links
|
||||
action_tab_append,
|
||||
action_tab_page_navigation_base,
|
||||
action_tab_page_navigation_history_back,
|
||||
action_tab_page_navigation_history_forward,
|
||||
@ -85,6 +88,7 @@ impl Tab {
|
||||
let item = Item::new_arc(
|
||||
self.gobject(),
|
||||
// Actions
|
||||
self.action_tab_append.clone(),
|
||||
self.action_tab_page_navigation_base.clone(),
|
||||
self.action_tab_page_navigation_history_back.clone(),
|
||||
self.action_tab_page_navigation_history_forward.clone(),
|
||||
@ -206,6 +210,7 @@ impl Tab {
|
||||
self.gobject(),
|
||||
transaction,
|
||||
&record.id,
|
||||
self.action_tab_append.clone(),
|
||||
self.action_tab_page_navigation_base.clone(),
|
||||
self.action_tab_page_navigation_history_back.clone(),
|
||||
self.action_tab_page_navigation_history_forward.clone(),
|
||||
|
@ -28,6 +28,7 @@ impl Item {
|
||||
pub fn new_arc(
|
||||
tab_view: &TabView,
|
||||
// Actions
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
@ -43,6 +44,7 @@ impl Item {
|
||||
// Init components
|
||||
let page = Page::new_arc(
|
||||
id.clone(),
|
||||
action_tab_append.clone(),
|
||||
action_tab_page_navigation_base.clone(),
|
||||
action_tab_page_navigation_history_back.clone(),
|
||||
action_tab_page_navigation_history_forward.clone(),
|
||||
@ -123,6 +125,7 @@ impl Item {
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_id: &i64,
|
||||
// Actions
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
@ -138,6 +141,7 @@ impl Item {
|
||||
let item = Item::new_arc(
|
||||
tab_view,
|
||||
// Actions
|
||||
action_tab_append.clone(),
|
||||
action_tab_page_navigation_base.clone(),
|
||||
action_tab_page_navigation_history_back.clone(),
|
||||
action_tab_page_navigation_history_forward.clone(),
|
||||
|
@ -41,6 +41,7 @@ impl Page {
|
||||
// Construct
|
||||
pub fn new_arc(
|
||||
name: GString,
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
@ -54,7 +55,10 @@ impl Page {
|
||||
));
|
||||
|
||||
// Init components
|
||||
let content = Arc::new(Content::new(action_page_open.clone()));
|
||||
let content = Arc::new(Content::new(
|
||||
action_tab_append.clone(),
|
||||
action_page_open.clone(),
|
||||
));
|
||||
let navigation = Navigation::new_arc(
|
||||
action_tab_page_navigation_base.clone(),
|
||||
action_tab_page_navigation_history_back.clone(),
|
||||
|
@ -25,14 +25,16 @@ pub struct Content {
|
||||
// GTK
|
||||
widget: Box,
|
||||
// Actions
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_page_open: Arc<SimpleAction>,
|
||||
}
|
||||
|
||||
impl Content {
|
||||
// Construct
|
||||
pub fn new(action_page_open: Arc<SimpleAction>) -> Self {
|
||||
pub fn new(action_tab_append: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>) -> Self {
|
||||
Self {
|
||||
widget: Box::builder().orientation(Orientation::Vertical).build(),
|
||||
action_tab_append,
|
||||
action_page_open,
|
||||
}
|
||||
}
|
||||
@ -47,7 +49,12 @@ impl Content {
|
||||
// Re-compose
|
||||
match mime {
|
||||
Mime::TextGemini => {
|
||||
let child = Text::gemini(data, base, self.action_page_open.clone());
|
||||
let child = Text::gemini(
|
||||
data,
|
||||
base,
|
||||
self.action_tab_append.clone(),
|
||||
self.action_page_open.clone(),
|
||||
);
|
||||
|
||||
self.widget.append(child.widget());
|
||||
|
||||
|
@ -21,9 +21,14 @@ pub struct Text {
|
||||
|
||||
impl Text {
|
||||
// Construct
|
||||
pub fn gemini(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Self {
|
||||
pub fn gemini(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_page_open: Arc<SimpleAction>,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let gemini = Gemini::new(gemtext, base, action_page_open);
|
||||
let gemini = Gemini::new(gemtext, base, action_tab_append, action_page_open);
|
||||
|
||||
// Init meta
|
||||
let meta = Meta {
|
||||
|
@ -20,9 +20,14 @@ pub struct Gemini {
|
||||
|
||||
impl Gemini {
|
||||
// Construct
|
||||
pub fn new(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Self {
|
||||
pub fn new(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_page_open: Arc<SimpleAction>,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let reader = Reader::new_arc(gemtext, base, action_page_open);
|
||||
let reader = Reader::new_arc(gemtext, base, action_tab_append, action_page_open);
|
||||
|
||||
let widget = Widget::new_arc(&reader.gobject());
|
||||
|
||||
|
@ -23,7 +23,12 @@ pub struct Reader {
|
||||
|
||||
impl Reader {
|
||||
// Construct
|
||||
pub fn new_arc(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Arc<Self> {
|
||||
pub fn new_arc(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_page_open: Arc<SimpleAction>,
|
||||
) -> Arc<Self> {
|
||||
// Init default values
|
||||
let mut title = None;
|
||||
|
||||
@ -162,7 +167,7 @@ impl Reader {
|
||||
|
||||
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
||||
for tag in iter.tags() {
|
||||
// Detect links on tag contain URI
|
||||
// Tag is link
|
||||
if let Some(uri) = _links_.get(&tag) {
|
||||
// Select handler by scheme
|
||||
match uri.scheme().as_str() {
|
||||
@ -178,6 +183,27 @@ impl Reader {
|
||||
}
|
||||
});
|
||||
|
||||
middle_button_controller.connect_pressed({
|
||||
let gobject = widget.gobject().clone();
|
||||
let _links_ = links.clone(); // is copy
|
||||
move |_, _, window_x, window_y| {
|
||||
// Detect tag match current coords hovered
|
||||
let (buffer_x, buffer_y) = gobject.window_to_buffer_coords(
|
||||
TextWindowType::Widget,
|
||||
window_x as i32,
|
||||
window_y as i32,
|
||||
);
|
||||
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
||||
for tag in iter.tags() {
|
||||
// Tag is link
|
||||
if let Some(_) = _links_.get(&tag) {
|
||||
action_tab_append.activate(None); // @TODO implement URI option
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
motion_controller.connect_motion({
|
||||
let gobject = widget.gobject().clone();
|
||||
let _links_ = links.clone(); // is copy
|
||||
@ -191,7 +217,7 @@ impl Reader {
|
||||
|
||||
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
||||
for tag in iter.tags() {
|
||||
// Tag contain URI (is link)
|
||||
// Tag is link
|
||||
if let Some(uri) = _links_.get(&tag) {
|
||||
// Toggle cursor
|
||||
gobject.set_cursor_from_name(Some("pointer"));
|
||||
@ -214,9 +240,6 @@ impl Reader {
|
||||
}
|
||||
}); // @TODO may be expensive for CPU, add timeout?
|
||||
|
||||
// @TODO
|
||||
// middle_button_controller(|_, _, _, _| {});
|
||||
|
||||
// Result
|
||||
Arc::new(Self { title, widget })
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user