Browse Source

draft new tab open on middle click

master
yggverse 2 months ago
parent
commit
8f1e94dd68
  1. 1
      src/app/browser/window.rs
  2. 5
      src/app/browser/window/tab.rs
  3. 4
      src/app/browser/window/tab/item.rs
  4. 6
      src/app/browser/window/tab/item/page.rs
  5. 11
      src/app/browser/window/tab/item/page/content.rs
  6. 9
      src/app/browser/window/tab/item/page/content/text.rs
  7. 9
      src/app/browser/window/tab/item/page/content/text/gemini.rs
  8. 35
      src/app/browser/window/tab/item/page/content/text/gemini/reader.rs

1
src/app/browser/window.rs

@ -38,6 +38,7 @@ impl Window { @@ -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(),

5
src/app/browser/window/tab.rs

@ -17,6 +17,7 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc}; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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(),

4
src/app/browser/window/tab/item.rs

@ -28,6 +28,7 @@ impl Item { @@ -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 { @@ -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 { @@ -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 { @@ -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(),

6
src/app/browser/window/tab/item/page.rs

@ -41,6 +41,7 @@ impl Page { @@ -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 { @@ -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(),

11
src/app/browser/window/tab/item/page/content.rs

@ -25,14 +25,16 @@ pub struct Content { @@ -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 { @@ -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());

9
src/app/browser/window/tab/item/page/content/text.rs

@ -21,9 +21,14 @@ pub struct Text { @@ -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 {

9
src/app/browser/window/tab/item/page/content/text/gemini.rs

@ -20,9 +20,14 @@ pub struct Gemini { @@ -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());

35
src/app/browser/window/tab/item/page/content/text/gemini/reader.rs

@ -23,7 +23,12 @@ pub struct Reader { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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…
Cancel
Save