[gnome-builder/wip/gtk4-port: 1372/1774] libide/webkit: allow transforms of buffer content
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1372/1774] libide/webkit: allow transforms of buffer content
- Date: Mon, 11 Jul 2022 22:31:43 +0000 (UTC)
commit 903ae2dbd239558cca1d8d916ac45e08d807eb70
Author: Christian Hergert <chergert redhat com>
Date: Mon Jun 6 13:31:36 2022 -0700
libide/webkit: allow transforms of buffer content
This will be needed for things like reStructuredText and markdown preview.
src/libide/webkit/ide-webkit-page.c | 30 +++++++++++++++++++---
src/libide/webkit/ide-webkit-page.h | 28 ++++++++++++--------
.../gbp-html-preview-workspace-addin.c | 2 +-
3 files changed, 45 insertions(+), 15 deletions(-)
---
diff --git a/src/libide/webkit/ide-webkit-page.c b/src/libide/webkit/ide-webkit-page.c
index 3647effb4..ab8cb5ae9 100644
--- a/src/libide/webkit/ide-webkit-page.c
+++ b/src/libide/webkit/ide-webkit-page.c
@@ -40,8 +40,11 @@ typedef struct
GSimpleActionGroup *actions;
/* Used for pages linked to buffers */
- GtkTextBuffer *buffer;
- guint queued_update_source;
+ GtkTextBuffer *buffer;
+ IdeHtmlTransformFunc transform_func;
+ gpointer transform_data;
+ GDestroyNotify transform_data_destroy;
+ guint queued_update_source;
} IdeWebkitPagePrivate;
enum {
@@ -340,6 +343,14 @@ ide_webkit_page_dispose (GObject *object)
IdeWebkitPage *self = (IdeWebkitPage *)object;
IdeWebkitPagePrivate *priv = ide_webkit_page_get_instance_private (self);
+ if (priv->transform_data_destroy)
+ {
+ GDestroyNotify notify = g_steal_pointer (&priv->transform_data_destroy);
+ gpointer data = g_steal_pointer (&priv->transform_data);
+ priv->transform_func = NULL;
+ notify (data);
+ }
+
g_clear_object (&priv->actions);
g_clear_object (&priv->buffer);
g_clear_handle_id (&priv->queued_update_source, g_source_remove);
@@ -603,6 +614,12 @@ ide_webkit_page_do_update_cb (gpointer user_data)
if (IDE_IS_BUFFER (priv->buffer))
base_uri = g_file_get_uri (ide_buffer_get_file (IDE_BUFFER (priv->buffer)));
+ if (priv->transform_func != NULL)
+ {
+ g_autofree char *input = g_steal_pointer (&text);
+ text = priv->transform_func (input, priv->transform_data);
+ }
+
webkit_web_view_load_html (priv->web_view, text, base_uri);
return G_SOURCE_REMOVE;
@@ -625,7 +642,10 @@ ide_webkit_page_buffer_changed_cb (IdeWebkitPage *self,
}
IdeWebkitPage *
-ide_webkit_page_new_for_buffer (GtkTextBuffer *buffer)
+ide_webkit_page_new_for_buffer (GtkTextBuffer *buffer,
+ IdeHtmlTransformFunc transform_func,
+ gpointer transform_data,
+ GDestroyNotify transform_data_destroy)
{
IdeWebkitPage *self;
IdeWebkitPagePrivate *priv;
@@ -635,6 +655,10 @@ ide_webkit_page_new_for_buffer (GtkTextBuffer *buffer)
self = ide_webkit_page_new ();
priv = ide_webkit_page_get_instance_private (self);
+ priv->transform_func = transform_func;
+ priv->transform_data = transform_data;
+ priv->transform_data_destroy = transform_data_destroy;
+
priv->buffer = g_object_ref (buffer);
g_signal_connect_object (buffer,
"changed",
diff --git a/src/libide/webkit/ide-webkit-page.h b/src/libide/webkit/ide-webkit-page.h
index 5b704e46a..26e47335c 100644
--- a/src/libide/webkit/ide-webkit-page.h
+++ b/src/libide/webkit/ide-webkit-page.h
@@ -26,6 +26,9 @@ G_BEGIN_DECLS
#define IDE_TYPE_WEBKIT_PAGE (ide_webkit_page_get_type())
+typedef char *(*IdeHtmlTransformFunc) (const char *input,
+ gpointer user_data);
+
IDE_AVAILABLE_IN_ALL
G_DECLARE_DERIVABLE_TYPE (IdeWebkitPage, ide_webkit_page, IDE, WEBKIT_PAGE, IdePage)
@@ -37,24 +40,27 @@ struct _IdeWebkitPageClass
IDE_AVAILABLE_IN_ALL
IdeWebkitPage *ide_webkit_page_new (void);
IDE_AVAILABLE_IN_ALL
-IdeWebkitPage *ide_webkit_page_new_for_buffer (GtkTextBuffer *buffer);
+IdeWebkitPage *ide_webkit_page_new_for_buffer (GtkTextBuffer *buffer,
+ IdeHtmlTransformFunc transform_func,
+ gpointer transform_data,
+ GDestroyNotify transform_data_destroy);
IDE_AVAILABLE_IN_ALL
-void ide_webkit_page_load_uri (IdeWebkitPage *self,
- const char *uri);
+void ide_webkit_page_load_uri (IdeWebkitPage *self,
+ const char *uri);
IDE_AVAILABLE_IN_ALL
-gboolean ide_webkit_page_focus_address (IdeWebkitPage *self);
+gboolean ide_webkit_page_focus_address (IdeWebkitPage *self);
IDE_AVAILABLE_IN_ALL
-gboolean ide_webkit_page_get_show_toolbar (IdeWebkitPage *self);
+gboolean ide_webkit_page_get_show_toolbar (IdeWebkitPage *self);
IDE_AVAILABLE_IN_ALL
-void ide_webkit_page_set_show_toolbar (IdeWebkitPage *self,
- gboolean show_toolbar);
+void ide_webkit_page_set_show_toolbar (IdeWebkitPage *self,
+ gboolean show_toolbar);
IDE_AVAILABLE_IN_ALL
-void ide_webkit_page_go_back (IdeWebkitPage *self);
+void ide_webkit_page_go_back (IdeWebkitPage *self);
IDE_AVAILABLE_IN_ALL
-void ide_webkit_page_go_forward (IdeWebkitPage *self);
+void ide_webkit_page_go_forward (IdeWebkitPage *self);
IDE_AVAILABLE_IN_ALL
-void ide_webkit_page_reload (IdeWebkitPage *self);
+void ide_webkit_page_reload (IdeWebkitPage *self);
IDE_AVAILABLE_IN_ALL
-void ide_webkit_page_reload_ignoring_cache (IdeWebkitPage *self);
+void ide_webkit_page_reload_ignoring_cache (IdeWebkitPage *self);
G_END_DECLS
diff --git a/src/plugins/html-preview/gbp-html-preview-workspace-addin.c
b/src/plugins/html-preview/gbp-html-preview-workspace-addin.c
index aad1c796b..c31e4d614 100644
--- a/src/plugins/html-preview/gbp-html-preview-workspace-addin.c
+++ b/src/plugins/html-preview/gbp-html-preview-workspace-addin.c
@@ -226,7 +226,7 @@ live_preview_action (GbpHtmlPreviewWorkspaceAddin *self,
g_assert (IDE_IS_EDITOR_PAGE (self->editor_page));
buffer = g_signal_group_dup_target (self->buffer_signals);
- page = ide_webkit_page_new_for_buffer (GTK_TEXT_BUFFER (buffer));
+ page = ide_webkit_page_new_for_buffer (GTK_TEXT_BUFFER (buffer), NULL, NULL, NULL);
position = ide_page_get_position (IDE_PAGE (self->editor_page));
if (!ide_panel_position_get_column (position, &column))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]