[gnome-builder/wip/gtk4-port] libide/webkit: allow toggling javascript
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/webkit: allow toggling javascript
- Date: Fri, 3 Jun 2022 23:35:21 +0000 (UTC)
commit 79543cb34ae9bbbf9b5b5ce2635252b4737bc71b
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 3 16:35:15 2022 -0700
libide/webkit: allow toggling javascript
src/libide/webkit/ide-webkit-page.c | 24 ++++++++++++++++++++++++
src/libide/webkit/ide-webkit-page.ui | 17 +++++++++++++++++
2 files changed, 41 insertions(+)
---
diff --git a/src/libide/webkit/ide-webkit-page.c b/src/libide/webkit/ide-webkit-page.c
index 2e2fd2f40..fda26931e 100644
--- a/src/libide/webkit/ide-webkit-page.c
+++ b/src/libide/webkit/ide-webkit-page.c
@@ -32,6 +32,7 @@ typedef struct
GtkStack *reload_stack;
GtkCenterBox *toolbar;
IdeUrlBar *url_bar;
+ WebKitSettings *web_settings;
WebKitWebView *web_view;
GSimpleActionGroup *actions;
@@ -295,6 +296,23 @@ ide_webkit_page_update_reload (IdeWebkitPage *self)
IDE_EXIT;
}
+static void
+add_property_action (gpointer object,
+ const char *property_name,
+ GActionMap *action_map)
+{
+ g_autoptr(GPropertyAction) action = NULL;
+
+ g_assert (G_IS_OBJECT (object));
+ g_assert (property_name != NULL);
+ g_assert (G_IS_ACTION_MAP (action_map));
+
+ action = g_property_action_new (property_name, object, property_name);
+
+ if (action != NULL)
+ g_action_map_add_action (action_map, G_ACTION (action));
+}
+
static void
ide_webkit_page_constructed (GObject *object)
{
@@ -386,10 +404,12 @@ ide_webkit_page_class_init (IdeWebkitPageClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, IdeWebkitPage, reload_stack);
gtk_widget_class_bind_template_child_private (widget_class, IdeWebkitPage, toolbar);
gtk_widget_class_bind_template_child_private (widget_class, IdeWebkitPage, url_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, IdeWebkitPage, web_settings);
gtk_widget_class_bind_template_child_private (widget_class, IdeWebkitPage, web_view);
gtk_widget_class_bind_template_callback (widget_class, on_toolbar_notify_visible_cb);
gtk_widget_class_bind_template_callback (widget_class, ide_webkit_page_update_reload);
+ g_type_ensure (WEBKIT_TYPE_SETTINGS);
g_type_ensure (WEBKIT_TYPE_WEB_VIEW);
g_type_ensure (IDE_TYPE_URL_BAR);
}
@@ -418,6 +438,10 @@ ide_webkit_page_init (IdeWebkitPage *self)
"web",
G_ACTION_GROUP (priv->actions));
+ add_property_action (priv->web_settings,
+ "enable-javascript",
+ G_ACTION_MAP (priv->actions));
+
list = webkit_web_view_get_back_forward_list (priv->web_view);
g_signal_connect_object (list,
"changed",
diff --git a/src/libide/webkit/ide-webkit-page.ui b/src/libide/webkit/ide-webkit-page.ui
index 84d88e880..4d4f28ed5 100644
--- a/src/libide/webkit/ide-webkit-page.ui
+++ b/src/libide/webkit/ide-webkit-page.ui
@@ -8,6 +8,7 @@
<property name="orientation">vertical</property>
<child>
<object class="WebKitWebView" id="web_view">
+ <property name="settings">web_settings</property>
<property name="hexpand">true</property>
<property name="vexpand">true</property>
<signal name="notify::is-loading" handler="ide_webkit_page_update_reload" swapped="true"
object="IdeWebkitPage"/>
@@ -76,9 +77,25 @@
<property name="web_view">web_view</property>
</object>
</child>
+ <child type="end">
+ <object class="GtkMenuButton">
+ <property name="icon-name">open-menu-symbolic</property>
+ <property name="menu-model">primary_menu</property>
+ </object>
+ </child>
</object>
</child>
</object>
</child>
</template>
+ <object class="WebKitSettings" id="web_settings"/>
+ <menu id="primary_menu">
+ <section>
+ <attribute name="label" translatable="yes">Settings</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Allow JavaScript</attribute>
+ <attribute name="action">web.enable-javascript</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]