[gnome-builder] libide/webkit: add print support for web pages



commit e6c94d8b15ad3e36c21d667aa76e2389d7d97d5f
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 5 20:12:02 2022 -0700

    libide/webkit: add print support for web pages
    
    Fixes #51

 src/libide/webkit/ide-webkit-page.c  | 26 ++++++++++++++++++++++++++
 src/libide/webkit/ide-webkit-page.h  |  2 ++
 src/libide/webkit/ide-webkit-page.ui |  6 ++++++
 3 files changed, 34 insertions(+)
---
diff --git a/src/libide/webkit/ide-webkit-page.c b/src/libide/webkit/ide-webkit-page.c
index 9709104b6..b76313872 100644
--- a/src/libide/webkit/ide-webkit-page.c
+++ b/src/libide/webkit/ide-webkit-page.c
@@ -353,6 +353,14 @@ add_property_action (gpointer    object,
     g_action_map_add_action (action_map, G_ACTION (action));
 }
 
+static void
+ide_webkit_page_print_action (GtkWidget  *widget,
+                              const char *action_name,
+                              GVariant   *param)
+{
+  ide_webkit_page_print (IDE_WEBKIT_PAGE (widget));
+}
+
 static void
 ide_webkit_page_constructed (GObject *object)
 {
@@ -425,6 +433,7 @@ ide_webkit_page_class_init (IdeWebkitPageClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  PanelWidgetClass *p_widget_class = PANEL_WIDGET_CLASS (klass);
 
   object_class->constructed = ide_webkit_page_constructed;
   object_class->dispose = ide_webkit_page_dispose;
@@ -453,6 +462,8 @@ ide_webkit_page_class_init (IdeWebkitPageClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, ide_webkit_page_update_reload);
   gtk_widget_class_bind_template_callback (widget_class, on_web_view_decide_policy_cb);
 
+  panel_widget_class_install_action (p_widget_class, "web.print", NULL, ide_webkit_page_print_action);
+
   g_type_ensure (WEBKIT_TYPE_SETTINGS);
   g_type_ensure (WEBKIT_TYPE_WEB_VIEW);
   g_type_ensure (IDE_TYPE_URL_BAR);
@@ -734,3 +745,18 @@ ide_webkit_page_get_view (IdeWebkitPage *self)
 
   return GTK_WIDGET (priv->web_view);
 }
+
+void
+ide_webkit_page_print (IdeWebkitPage *self)
+{
+  IdeWebkitPagePrivate *priv = ide_webkit_page_get_instance_private (self);
+  g_autoptr(WebKitPrintOperation) operation = NULL;
+  GtkRoot *root;
+
+  g_return_if_fail (IDE_IS_WEBKIT_PAGE (self));
+
+  operation = webkit_print_operation_new (priv->web_view);
+  root = gtk_widget_get_root (GTK_WIDGET (self));
+
+  webkit_print_operation_run_dialog (operation, GTK_WINDOW (root));
+}
diff --git a/src/libide/webkit/ide-webkit-page.h b/src/libide/webkit/ide-webkit-page.h
index b74071ad3..60347627d 100644
--- a/src/libide/webkit/ide-webkit-page.h
+++ b/src/libide/webkit/ide-webkit-page.h
@@ -66,5 +66,7 @@ IDE_AVAILABLE_IN_ALL
 void           ide_webkit_page_reload_ignoring_cache (IdeWebkitPage        *self);
 IDE_AVAILABLE_IN_ALL
 gboolean       ide_webkit_page_has_generator         (IdeWebkitPage        *self);
+IDE_AVAILABLE_IN_44
+void           ide_webkit_page_print                 (IdeWebkitPage        *self);
 
 G_END_DECLS
diff --git a/src/libide/webkit/ide-webkit-page.ui b/src/libide/webkit/ide-webkit-page.ui
index c809725d2..f33a53493 100644
--- a/src/libide/webkit/ide-webkit-page.ui
+++ b/src/libide/webkit/ide-webkit-page.ui
@@ -99,5 +99,11 @@
         <attribute name="action">web.enable-javascript</attribute>
       </item>
     </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Print</attribute>
+        <attribute name="action">page.web.print</attribute>
+      </item>
+    </section>
   </menu>
 </interface>


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