diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index a3b6eda3..4462f6ca 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -24,7 +24,35 @@ Page::Page( // Init shared actions action__update = ACTION__UPDATE; + // Init additional local action group (for clickable content) + const auto ACTION_GROUP__PAGE = Gio::SimpleActionGroup::create(); + + const auto ACTION__OPEN_LINK_VARIANT = ACTION_GROUP__PAGE->add_action_with_parameter( + "open_link_variant", + Glib::VARIANT_TYPE_STRING, + [this](const Glib::VariantBase & PARAMETER) + { + if (PARAMETER.is_of_type(Glib::VARIANT_TYPE_STRING)) + { + pageNavigation->set_request_text( + Glib::VariantBase::cast_dynamic>( + PARAMETER + ).get() + ); + + navigation_reload( + true + ); + } + } + ); + // Init widget + insert_action_group( + "page", + ACTION_GROUP__PAGE + ); + set_orientation( Gtk::Orientation::VERTICAL ); @@ -42,41 +70,14 @@ Page::Page( * pageNavigation ); - pageContent = Gtk::make_managed(); + pageContent = Gtk::make_managed( + ACTION__OPEN_LINK_VARIANT + ); append( * pageContent ); - // Init widget action group @TODO - auto GioSimpleActionGroup = Gio::SimpleActionGroup::create(); - - // Define group actions - GioSimpleActionGroup->add_action_with_parameter( - "open", - Glib::VARIANT_TYPE_STRING, - [this](const Glib::VariantBase & PARAMETER) - { - if (PARAMETER.is_of_type(Glib::VARIANT_TYPE_STRING)) - { - pageNavigation->set_request_text( - Glib::VariantBase::cast_dynamic>( - PARAMETER - ).get() - ); - - navigation_reload( - true - ); - } - } - ); - - insert_action_group( - "page", - GioSimpleActionGroup - ); - // Connect events /* activated twice on tab change @TODO signal_realize().connect( diff --git a/src/app/browser/main/tab/page/content.cpp b/src/app/browser/main/tab/page/content.cpp index 78b9b237..b2d9a59a 100644 --- a/src/app/browser/main/tab/page/content.cpp +++ b/src/app/browser/main/tab/page/content.cpp @@ -3,8 +3,12 @@ using namespace app::browser::main::tab::page; -Content::Content() -{ +Content::Content( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT +) { + // Init actions + action__open_link_variant = ACTION__OPEN_LINK_VARIANT; + // Init widget set_orientation( Gtk::Orientation::VERTICAL @@ -63,6 +67,7 @@ void Content::update( case MIME::TEXT_GEMINI: contentText = new content::Text( + action__open_link_variant, content::Text::Type::GEMINI, SOURCE, uri diff --git a/src/app/browser/main/tab/page/content.hpp b/src/app/browser/main/tab/page/content.hpp index 8acdcad6..0edba5b5 100644 --- a/src/app/browser/main/tab/page/content.hpp +++ b/src/app/browser/main/tab/page/content.hpp @@ -1,6 +1,7 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP +#include #include #include #include @@ -19,6 +20,9 @@ namespace app::browser::main::tab::page */ private: + // Actions + Glib::RefPtr action__open_link_variant; + // Components content::Text * contentText; @@ -36,7 +40,10 @@ namespace app::browser::main::tab::page TEXT_PLAIN }; - Content(); + Content( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT + ); + ~Content(); // Actions diff --git a/src/app/browser/main/tab/page/content/text.cpp b/src/app/browser/main/tab/page/content/text.cpp index 2ded775b..5444c996 100644 --- a/src/app/browser/main/tab/page/content/text.cpp +++ b/src/app/browser/main/tab/page/content/text.cpp @@ -5,6 +5,7 @@ using namespace app::browser::main::tab::page::content; Text::Text( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT, const Type & TYPE, const Glib::ustring & SOURCE, GUri * uri @@ -15,6 +16,7 @@ Text::Text( set_child( * Gtk::make_managed( + ACTION__OPEN_LINK_VARIANT, SOURCE, title, uri diff --git a/src/app/browser/main/tab/page/content/text.hpp b/src/app/browser/main/tab/page/content/text.hpp index a0cf2c82..6de7ae8a 100644 --- a/src/app/browser/main/tab/page/content/text.hpp +++ b/src/app/browser/main/tab/page/content/text.hpp @@ -1,6 +1,7 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP +#include #include #include #include @@ -29,6 +30,7 @@ namespace app::browser::main::tab::page::content * Text class API */ Text( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT, const Type & TYPE, const Glib::ustring & SOURCE, GUri * uri diff --git a/src/app/browser/main/tab/page/content/text/gemini.cpp b/src/app/browser/main/tab/page/content/text/gemini.cpp index ce0397ac..cf32c8d3 100644 --- a/src/app/browser/main/tab/page/content/text/gemini.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini.cpp @@ -4,6 +4,7 @@ using namespace app::browser::main::tab::page::content::text; Gemini::Gemini( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT, const Glib::ustring & GEMTEXT, Glib::ustring & title, GUri * uri @@ -18,6 +19,7 @@ Gemini::Gemini( set_child( * Gtk::make_managed( + ACTION__OPEN_LINK_VARIANT, GEMTEXT, title, uri diff --git a/src/app/browser/main/tab/page/content/text/gemini.hpp b/src/app/browser/main/tab/page/content/text/gemini.hpp index d3226478..0d7cb990 100644 --- a/src/app/browser/main/tab/page/content/text/gemini.hpp +++ b/src/app/browser/main/tab/page/content/text/gemini.hpp @@ -1,6 +1,7 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP +#include #include #include @@ -14,6 +15,7 @@ namespace app::browser::main::tab::page::content::text public: Gemini( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT, const Glib::ustring & GEMTEXT, Glib::ustring & title, GUri * uri diff --git a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp index ab0ceef4..5b9b3d4a 100644 --- a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp @@ -3,10 +3,14 @@ using namespace app::browser::main::tab::page::content::text::gemini; Reader::Reader( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT, const Glib::ustring & GEMTEXT, Glib::ustring & title, GUri * base ) { + // Init shared actions + action__open_link_variant = ACTION__OPEN_LINK_VARIANT; + // Build markup Glib::ustring markup; @@ -125,12 +129,13 @@ Reader::Reader( if (SCHEME == NULL || SCHEME == Glib::ustring("gemini")) { - return activate_action( - "page.open", // @TODO use action argument + action__open_link_variant->activate_variant( Glib::Variant::create( URI ) ); + + return true; } return false; // delegate unsupported URI to external application diff --git a/src/app/browser/main/tab/page/content/text/gemini/reader.hpp b/src/app/browser/main/tab/page/content/text/gemini/reader.hpp index ad221997..5aea57dc 100644 --- a/src/app/browser/main/tab/page/content/text/gemini/reader.hpp +++ b/src/app/browser/main/tab/page/content/text/gemini/reader.hpp @@ -1,6 +1,7 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_READER_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_READER_HPP +#include #include #include #include @@ -63,12 +64,18 @@ namespace app::browser::main::tab::page::content::text::gemini ); }; + /* + * Internal members + */ + Glib::RefPtr action__open_link_variant; + /* * Reader class API */ public: Reader( + const Glib::RefPtr & ACTION__OPEN_LINK_VARIANT, const Glib::ustring & GEMTEXT, Glib::ustring & title, GUri * uri