[geany/geany-plugins] 1c97b5: Reenable gtk2 for markdown

Chow Loong Jin git-noreply at xxxxx
Wed May 30 05:21:17 UTC 2018


Branch:      refs/heads/master
Author:      Chow Loong Jin <hyperair at debian.org>
Committer:   Chow Loong Jin <hyperair at debian.org>
Date:        Mon, 14 May 2018 19:50:46 UTC
Commit:      1c97b5d2b4c0b75e7137724b448fd4fe659106e0
             https://github.com/geany/geany-plugins/commit/1c97b5d2b4c0b75e7137724b448fd4fe659106e0

Log Message:
-----------
Reenable gtk2 for markdown

Use #ifdef's around the relevant portions that have been changed for
webkit2gtk-4.0.


Modified Paths:
--------------
    build/markdown.m4
    markdown/src/Makefile.am
    markdown/src/viewer.c
    markdown/src/viewer.h

Modified: build/markdown.m4
6 lines changed, 4 insertions(+), 2 deletions(-)
===================================================================
@@ -49,11 +49,13 @@ AC_DEFUN([GP_CHECK_MARKDOWN],
     GTK_VERSION=2.16
     WEBKIT_VERSION=1.1.13
 
-    GP_CHECK_PLUGIN_GTK3_ONLY([markdown])
+    GP_CHECK_GTK3([webkit_package=webkit2gtk-4.0],
+                  [webkit_package=webkit-1.0])
     GP_CHECK_PLUGIN_DEPS([markdown], [MARKDOWN],
                          [$GP_GTK_PACKAGE >= ${GTK_VERSION}
-                          webkit2gtk-4.0 >= ${WEBKIT_VERSION}
+                          $webkit_package >= ${WEBKIT_VERSION}
                           gthread-2.0])
+    AM_CONDITIONAL([MARKDOWN_WEBKIT2], [test "$webkit_package" = webkit2gtk-4.0])
 
     GP_COMMIT_PLUGIN_STATUS([Markdown])
 


Modified: markdown/src/Makefile.am
3 lines changed, 3 insertions(+), 0 deletions(-)
===================================================================
@@ -35,4 +35,7 @@ markdown_la_CFLAGS += $(LIBMARKDOWN_CFLAGS)
 markdown_la_LIBADD += $(LIBMARKDOWN_LIBS)
 endif
 
+if WEBKIT2
+markdown_la_CFLAGS += -DWEBKIT2
+
 include $(top_srcdir)/build/cppcheck.mk


Modified: markdown/src/viewer.c
33 lines changed, 32 insertions(+), 1 deletions(-)
===================================================================
@@ -22,7 +22,11 @@
 #include "config.h"
 #include <string.h>
 #include <gtk/gtk.h>
-#include <webkit2/webkit2.h>
+#ifdef WEBKIT2
+# include <webkit2/webkit2.h>
+#else
+# include <webkit/webkitwebview.h>
+#endif
 #include <geanyplugin.h>
 #ifndef FULL_PRICE
 # include <mkdio.h>
@@ -296,6 +300,7 @@ pop_scroll_pos(MarkdownViewer *self)
   return popped;
 }
 
+#ifdef WEBKIT2
 static void
 on_webview_load_changed(MarkdownViewer  *self,
                         WebKitLoadEvent  load_event,
@@ -306,6 +311,21 @@ on_webview_load_changed(MarkdownViewer  *self,
     pop_scroll_pos(self);
   }
 }
+#else
+static void
+on_webview_load_status_notify(WebKitWebView *view, GParamSpec *pspec,
+  MarkdownViewer *self)
+{
+  WebKitLoadStatus load_status;
+
+  g_object_get(view, "load-status", &load_status, NULL);
+
+  /* When the webkit is done loading, reset the scroll position. */
+  if (load_status == WEBKIT_LOAD_FINISHED) {
+    pop_scroll_pos(self);
+  }
+}
+#endif
 
 gchar *
 markdown_viewer_get_html(MarkdownViewer *self)
@@ -385,12 +405,23 @@ markdown_viewer_update_view(MarkdownViewer *self)
     /* Connect a signal handler (only needed once) to restore the scroll
      * position once the webview is reloaded. */
     if (self->priv->load_handle == 0) {
+#ifdef WEBKIT2
       self->priv->load_handle =
         g_signal_connect_swapped(WEBKIT_WEB_VIEW(self), "load-changed",
           G_CALLBACK(on_webview_load_changed), self);
+#else
+      self->priv->load_handle =
+        g_signal_connect_swapped(WEBKIT_WEB_VIEW(self), "notify::load-status",
+          G_CALLBACK(on_webview_load_status_notify), self);
+#endif
     }
 
+#ifdef WEBKIT2
     webkit_web_view_load_html(WEBKIT_WEB_VIEW(self), html, base_uri);
+#else
+    webkit_web_view_load_string(WEBKIT_WEB_VIEW(self), html, "text/html",
+      self->priv->enc, base_uri);
+#endif
 
     g_free(base_uri);
     g_free(html);


Modified: markdown/src/viewer.h
6 lines changed, 5 insertions(+), 1 deletions(-)
===================================================================
@@ -23,7 +23,11 @@
 #define MARKDOWN_VIEWER_H 1
 
 #include <gtk/gtk.h>
-#include <webkit2/webkit2.h>
+#ifdef WEBKIT2
+# include <webkit2/webkit2.h>
+#else
+# include <webkit/webkitwebview.h>
+#endif
 
 G_BEGIN_DECLS
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list