[gnome-builder/wip/gtk4-port] plugins/web-browser: add focus-address action



commit b1db9ee154eb88b1e5685541d6ae2f9b86652f42
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 3 14:32:25 2022 -0700

    plugins/web-browser: add focus-address action
    
    This will focus the url bar of the most recently focused page if it is
    an IdeWebkitPage.

 .../web-browser/gbp-web-browser-workspace-addin.c  | 31 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/web-browser/gbp-web-browser-workspace-addin.c 
b/src/plugins/web-browser/gbp-web-browser-workspace-addin.c
index d9ad08906..2f907d15c 100644
--- a/src/plugins/web-browser/gbp-web-browser-workspace-addin.c
+++ b/src/plugins/web-browser/gbp-web-browser-workspace-addin.c
@@ -33,12 +33,15 @@ struct _GbpWebBrowserWorkspaceAddin
   IdeWorkspace *workspace;
 };
 
-static void workspace_addin_iface_init  (IdeWorkspaceAddinInterface  *iface);
-static void web_browser_new_page_action (GbpWebBrowserWorkspaceAddin *self,
-                                         GVariant                    *param);
+static void workspace_addin_iface_init       (IdeWorkspaceAddinInterface  *iface);
+static void web_browser_new_page_action      (GbpWebBrowserWorkspaceAddin *self,
+                                              GVariant                    *param);
+static void web_browser_focus_address_action (GbpWebBrowserWorkspaceAddin *self,
+                                              GVariant                    *param);
 
 IDE_DEFINE_ACTION_GROUP (GbpWebBrowserWorkspaceAddin, gbp_web_browser_workspace_addin, {
   { "new-page", web_browser_new_page_action },
+  { "focus-address", web_browser_focus_address_action },
 })
 
 G_DEFINE_FINAL_TYPE_WITH_CODE (GbpWebBrowserWorkspaceAddin, gbp_web_browser_workspace_addin, G_TYPE_OBJECT,
@@ -122,3 +125,25 @@ web_browser_new_page_action (GbpWebBrowserWorkspaceAddin *self,
 
   IDE_EXIT;
 }
+
+static void
+web_browser_focus_address_action (GbpWebBrowserWorkspaceAddin *self,
+                                  GVariant                    *param)
+{
+  IdePage *page;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_WEB_BROWSER_WORKSPACE_ADDIN (self));
+  g_assert (IDE_IS_WORKSPACE (self->workspace));
+
+  if (!(page = ide_workspace_get_most_recent_page (self->workspace)))
+    IDE_EXIT;
+
+  if (!IDE_IS_WEBKIT_PAGE (page))
+    IDE_EXIT;
+
+  ide_webkit_page_focus_address (IDE_WEBKIT_PAGE (page));
+
+  IDE_EXIT;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]