gedit-plugins r350 - in trunk: . plugins/charmap



Author: chpe
Date: Fri Mar 21 12:03:04 2008
New Revision: 350
URL: http://svn.gnome.org/viewvc/gedit-plugins?rev=350&view=rev

Log:
	* configure.ac:
	* plugins/charmap/Makefile.am:
	* plugins/charmap/gedit-charmap-panel.c:
	(on_chapter_view_selection_changed), (gedit_charmap_panel_init),
	(gedit_charmap_panel_get_chartable):
	* plugins/charmap/gedit-charmap-panel.h:
	* plugins/charmap/gedit-charmap-plugin.c: (free_window_data),
	(on_table_status_message): Allow building with either gucharmap
	stable, or gucharmap trunk. Bug #523694.

Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/plugins/charmap/Makefile.am
   trunk/plugins/charmap/gedit-charmap-panel.c
   trunk/plugins/charmap/gedit-charmap-panel.h
   trunk/plugins/charmap/gedit-charmap-plugin.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Fri Mar 21 12:03:04 2008
@@ -328,12 +328,20 @@
 plugin_defined charmap
 if test "$?" = 1
 then
-	PKG_CHECK_MODULES([GUCHARMAP], [
-		gucharmap >= 1.6.0
-	], have_gucharmap=yes, have_gucharmap=no)
-	
-	if test "x$have_gucharmap" = "xno"
-	then
+        GUCHARMAP2_REQUIRED=2.23.0
+        GUCHARMAP_REQUIRED=1.6.0
+        PKG_CHECK_MODULES([GUCHARMAP],[gucharmap-2 >= $GUCHARMAP2_REQUIRED],
+                          [have_gucharmap=yes have_gucharmap_2=yes],[have_gucharmap_2=no])
+        if test "$have_gucharmap_2" = "no"; then
+              PKG_CHECK_MODULES([GUCHARMAP], [gucharmap >= $GUCHARMAP_REQUIRED],
+                                [have_gucharmap=yes],[have_gucharmap=no])
+        fi
+
+	if test "$have_gucharmap_2" = "yes"; then
+	       AC_DEFINE([HAVE_GUCHARMAP_2],[1],[Define if gucharmap API is version 2])
+	fi
+
+	if test "$have_gucharmap" = "no"; then
 		plugin_defined_explicit charmap
 		if test "$?" = 1
 		then

Modified: trunk/plugins/charmap/Makefile.am
==============================================================================
--- trunk/plugins/charmap/Makefile.am	(original)
+++ trunk/plugins/charmap/Makefile.am	Fri Mar 21 12:03:04 2008
@@ -7,7 +7,7 @@
 	$(GUCHARMAP_CFLAGS)				\
 	$(WARN_CFLAGS)					\
 	$(DISABLE_DEPRECATED_CFLAGS)			\
-	-DGEDIT_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+	-DGEDIT_LOCALEDIR=\""$(datadir)/locale"\"
 
 plugin_LTLIBRARIES = libcharmap.la
 

Modified: trunk/plugins/charmap/gedit-charmap-panel.c
==============================================================================
--- trunk/plugins/charmap/gedit-charmap-panel.c	(original)
+++ trunk/plugins/charmap/gedit-charmap-panel.c	Fri Mar 21 12:03:04 2008
@@ -24,7 +24,12 @@
 
 #include <gedit/gedit-plugin.h>
 #include "gedit-charmap-panel.h"
+
+#ifdef HAVE_GUCHARMAP_2
+#include <gucharmap/gucharmap.h>
+#else
 #include <gucharmap/gucharmap-script-chapters.h>
+#endif
 
 #define GEDIT_CHARMAP_PANEL_GET_PRIVATE(object)	(G_TYPE_INSTANCE_GET_PRIVATE ( \
 						 (object),		       \
@@ -33,12 +38,36 @@
 
 struct _GeditCharmapPanelPrivate
 {
+#ifdef HAVE_GUCHARMAP_2
+        GucharmapChaptersView *chapters_view;
+        GucharmapChartable *chartable;
+#else
 	GtkWidget	*table;
 	GtkWidget	*chapters;
+#endif
 };
 
 GEDIT_PLUGIN_DEFINE_TYPE(GeditCharmapPanel, gedit_charmap_panel, GTK_TYPE_VBOX)
 
+#ifdef HAVE_GUCHARMAP_2
+static void
+on_chapter_view_selection_changed (GtkTreeSelection *selection,
+                                   GeditCharmapPanel *panel)
+{
+        GeditCharmapPanelPrivate *priv = panel->priv;
+        GucharmapCodepointList *codepoint_list;
+        GtkTreeIter iter;
+
+        if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
+                return;
+
+        codepoint_list = gucharmap_chapters_view_get_codepoint_list (priv->chapters_view);
+        gucharmap_chartable_set_codepoint_list (priv->chartable, codepoint_list);
+        g_object_unref (codepoint_list);
+}
+
+#else
+
 static void
 on_chapter_changed (GucharmapChapters *chapters,
 		    GeditCharmapPanel *panel)
@@ -46,39 +75,90 @@
 	gucharmap_table_set_codepoint_list (GUCHARMAP_TABLE (panel->priv->table),
 					    gucharmap_chapters_get_codepoint_list (chapters));
 }
+#endif /* HAVE_GUCHARMAP_2 */
 
 static void
 gedit_charmap_panel_init (GeditCharmapPanel *panel)
 {
+        GeditCharmapPanelPrivate *priv;
 	GucharmapCodepointList *codepoint_list;
 	GtkPaned *paned;
+#ifdef HAVE_GUCHARMAP_2
+        GtkWidget *scrolled_window, *view, *chartable;
+        GtkTreeSelection *selection;
+        GucharmapChaptersModel *model;
+        GtkTreeIter iter;
+#endif
+
+	priv = panel->priv = GEDIT_CHARMAP_PANEL_GET_PRIVATE (panel);
+
+	paned = GTK_PANED (gtk_vpaned_new ());
+
+#ifdef HAVE_GUCHARMAP_2
+        scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+                                            GTK_SHADOW_ETCHED_IN);
+
+        view = gucharmap_chapters_view_new ();
+        priv->chapters_view = GUCHARMAP_CHAPTERS_VIEW (view);
+	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
+
+	model = gucharmap_script_chapters_model_new ();
+        gucharmap_chapters_view_set_model (priv->chapters_view, model);
+        g_object_unref (model);
+
+        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+        g_signal_connect (selection, "changed",
+                          G_CALLBACK (on_chapter_view_selection_changed), panel);
+
+        gtk_container_add (GTK_CONTAINER (scrolled_window), view);
+        gtk_widget_show (view);
+
+	gtk_paned_pack1 (paned, scrolled_window, FALSE, TRUE);
+        gtk_widget_show (scrolled_window);
+
+        scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+                                            GTK_SHADOW_ETCHED_IN);
+
+        chartable = gucharmap_chartable_new ();
+	priv->chartable = GUCHARMAP_CHARTABLE (chartable);
+        gtk_container_add (GTK_CONTAINER (scrolled_window), chartable);
+        gtk_widget_show (chartable);
+
+	gtk_paned_pack2 (paned, scrolled_window, TRUE, TRUE);
+        gtk_widget_show (scrolled_window);
+
+        gucharmap_chapters_view_select_locale (priv->chapters_view);
+#else
+	priv->chapters = gucharmap_script_chapters_new ();
+	g_signal_connect (priv->chapters,
+			  "changed",
+			  G_CALLBACK (on_chapter_changed),
+			  panel);
 	
-	panel->priv = GEDIT_CHARMAP_PANEL_GET_PRIVATE (panel);
-	
-	panel->priv->chapters = gucharmap_script_chapters_new ();
-	
-	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (GUCHARMAP_CHAPTERS (panel->priv->chapters)->tree_view),
+	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (GUCHARMAP_CHAPTERS (priv->chapters)->tree_view),
 					   FALSE);
 
 	codepoint_list = gucharmap_chapters_get_codepoint_list 
-				(GUCHARMAP_CHAPTERS (panel->priv->chapters));
+				(GUCHARMAP_CHAPTERS (priv->chapters));
 	
-	panel->priv->table = gucharmap_table_new ();
+	priv->table = gucharmap_table_new ();
 
-	gucharmap_table_set_codepoint_list (GUCHARMAP_TABLE (panel->priv->table),
+	gucharmap_table_set_codepoint_list (GUCHARMAP_TABLE (priv->table),
 					    codepoint_list);
-	
-	paned = GTK_PANED (gtk_vpaned_new ());
-	gtk_paned_pack1 (paned, panel->priv->chapters, FALSE, TRUE);
-	gtk_paned_pack2 (paned, panel->priv->table, TRUE, TRUE);
+
+	gtk_paned_pack1 (paned, priv->chapters, FALSE, TRUE);
+	gtk_paned_pack2 (paned, priv->table, TRUE, TRUE);
+#endif /* HAVE_GUCHARMAP_2 */
+
 	gtk_paned_set_position (paned, 150);
 	
 	gtk_box_pack_start (GTK_BOX (panel), GTK_WIDGET (paned), TRUE, TRUE, 0);
-
-	g_signal_connect (panel->priv->chapters,
-			  "changed",
-			  G_CALLBACK (on_chapter_changed),
-			  panel);
 }
 
 static void
@@ -103,9 +183,16 @@
 	return GTK_WIDGET (g_object_new (GEDIT_TYPE_CHARMAP_PANEL, NULL));
 }
 
+#ifdef HAVE_GUCHARMAP_2
+GucharmapChartable *
+gedit_charmap_panel_get_chartable (GeditCharmapPanel *panel)
+{
+	return panel->priv->chartable;
+}
+#else
 GucharmapTable *
 gedit_charmap_panel_get_table (GeditCharmapPanel *panel)
 {
 	return GUCHARMAP_TABLE (panel->priv->table);
 }
-
+#endif

Modified: trunk/plugins/charmap/gedit-charmap-panel.h
==============================================================================
--- trunk/plugins/charmap/gedit-charmap-panel.h	(original)
+++ trunk/plugins/charmap/gedit-charmap-panel.h	Fri Mar 21 12:03:04 2008
@@ -26,7 +26,12 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
+
+#ifdef HAVE_GUCHARMAP_2
+#include <gucharmap/gucharmap.h>
+#else
 #include <gucharmap/gucharmap-table.h>
+#endif
 
 G_BEGIN_DECLS
 
@@ -72,7 +77,12 @@
 GType		 gedit_charmap_panel_get_type	   (void) G_GNUC_CONST;
 GType		 gedit_charmap_panel_register_type (GTypeModule * module);
 GtkWidget	*gedit_charmap_panel_new	   (void);
-GucharmapTable  *gedit_charmap_panel_get_table	   (GeditCharmapPanel *panel);
+
+#ifdef HAVE_GUCHARMAP_2
+GucharmapChartable *gedit_charmap_panel_get_chartable (GeditCharmapPanel *panel);
+#else
+GucharmapTable *gedit_charmap_panel_get_table	   (GeditCharmapPanel *panel);
+#endif
 
 G_END_DECLS
 

Modified: trunk/plugins/charmap/gedit-charmap-plugin.c
==============================================================================
--- trunk/plugins/charmap/gedit-charmap-plugin.c	(original)
+++ trunk/plugins/charmap/gedit-charmap-plugin.c	Fri Mar 21 12:03:04 2008
@@ -31,8 +31,13 @@
 #include <gedit/gedit-panel.h>
 #include <gedit/gedit-document.h>
 #include <gedit/gedit-prefs-manager.h>
+
+#ifdef HAVE_GUCHARMAP_2
+#include <gucharmap/gucharmap.h>
+#else
 #include <gucharmap/gucharmap-table.h>
 #include <gucharmap/gucharmap-unicode-info.h>
+#endif
 
 #define WINDOW_DATA_KEY	"GeditCharmapPluginWindowData"
 
@@ -68,13 +73,15 @@
 static void
 free_window_data (WindowData *data)
 {
-	g_return_if_fail (data != NULL);
-	
-	g_free (data);
+	g_slice_free (WindowData, data);
 }
 
 static void
+#ifdef HAVE_GUCHARMAP_2
+on_table_status_message (GucharmapChartable *chartable,
+#else
 on_table_status_message (GucharmapTable *chartable,
+#endif
 			 const gchar    *message,
 			 GeditWindow    *window)
 {
@@ -92,14 +99,25 @@
 		gtk_statusbar_push (statusbar, data->context_id, message);
 }
 
+#ifdef HAVE_GUCHARMAP_2
+on_table_sync_active_char (GucharmapChartable *chartable,
+			   GParamSpec         *psepc,
+			   GeditWindow        *window)
+#else
 static void
 on_table_set_active_char (GucharmapTable *chartable,
 			  gunichar        wc,
 			  GeditWindow    *window)
+#endif
 {
 	GString *gs;
 	const gchar **temps;
 	gint i;
+#ifdef HAVE_GUCHARMAP_2
+        gunichar wc;
+
+        wc = gucharmap_chartable_get_active_character (chartable);
+#endif
 
 	gs = g_string_new (NULL);
 	g_string_append_printf (gs, "U+%4.4X %s", wc, 
@@ -132,30 +150,50 @@
 			  GdkEventFocus  *event,
 			  GeditWindow    *window)
 {
+#ifdef HAVE_GUCHARMAP_2
+	GucharmapChartable *chartable;
+#else
 	GucharmapTable *chartable;
+#endif
 	WindowData *data;
 	
 	data = (WindowData *) g_object_get_data (G_OBJECT (window),
 						 WINDOW_DATA_KEY);
 	g_return_val_if_fail (data != NULL, FALSE);
 
+#ifdef HAVE_GUCHARMAP_2
+	chartable = gedit_charmap_panel_get_chartable
+					(GEDIT_CHARMAP_PANEL (data->panel));
+#else
 	chartable = gedit_charmap_panel_get_table
 					(GEDIT_CHARMAP_PANEL (data->panel));
+#endif
 
 	on_table_status_message (chartable, NULL, window);
 	return FALSE;
 }
 
+#ifdef HAVE_GUCHARMAP_2
+static void
+on_table_activate (GucharmapChartable *chartable,
+		   GeditWindow *window)
+#else
 static void
 on_table_activate (GucharmapTable *chartable, 
 		   gunichar        wc, 
 		   GeditWindow    *window)
+#endif
 {
 	GtkTextView   *view;
 	GtkTextBuffer *document;
 	GtkTextIter start, end;
 	gchar buffer[6];
 	gchar length;
+#ifdef HAVE_GUCHARMAP_2
+        gunichar wc;
+
+        wc = gucharmap_chartable_get_active_character (chartable);
+#endif
 	
 	g_return_if_fail (gucharmap_unichar_validate (wc));
 	
@@ -185,37 +223,65 @@
 create_charmap_panel (GeditWindow *window)
 {
 	GtkWidget      *panel;
+#ifdef HAVE_GUCHARMAP_2
+        GucharmapChartable *chartable;
+#else
 	GucharmapTable *table;
+#endif
 	gchar          *font;
 
 	panel = gedit_charmap_panel_new ();
-	table = gedit_charmap_panel_get_table (GEDIT_CHARMAP_PANEL (panel));
 
 	/* Use the same font as the document */
 	font = gedit_prefs_manager_get_editor_font ();
+
+#ifdef HAVE_GUCHARMAP_2
+	chartable = gedit_charmap_panel_get_chartable (GEDIT_CHARMAP_PANEL (panel));
+	gucharmap_chartable_set_font (chartable, font);
+#else
+	table = gedit_charmap_panel_get_table (GEDIT_CHARMAP_PANEL (panel));
 	gucharmap_table_set_font (table, font);
+#endif
+
 	g_free (font);
 
-	g_signal_connect (table,
+#ifdef HAVE_GUCHARMAP_2
+	g_signal_connect (chartable,
+			  "notify::active-character",
+			  G_CALLBACK (on_table_sync_active_char),
+			  window);
+	g_signal_connect (chartable,
+			  "focus-out-event",
+			  G_CALLBACK (on_table_focus_out_event),
+			  window);
+	g_signal_connect (chartable,
 			  "status-message",
 			  G_CALLBACK (on_table_status_message),
 			  window);
+	g_signal_connect (chartable,
+			  "activate", 
+			  G_CALLBACK (on_table_activate),
+			  window);
 
+#else
 	g_signal_connect (table,
 			  "set-active-char",
 			  G_CALLBACK (on_table_set_active_char),
 			  window);
-
 	/* Note: GucharmapTable does not provide focus-out-event ... */
 	g_signal_connect (table->drawing_area,
 			  "focus-out-event",
 			  G_CALLBACK (on_table_focus_out_event),
 			  window);
-
+	g_signal_connect (table,
+			  "status-message",
+			  G_CALLBACK (on_table_status_message),
+			  window);
 	g_signal_connect (table,
 			  "activate", 
 			  G_CALLBACK (on_table_activate),
 			  window);
+#endif /* HAVE_GUCHARMAP_2 */
 
 	gtk_widget_show_all (panel);
 
@@ -236,7 +302,7 @@
 
 	panel = gedit_window_get_side_panel (window);
 
-	data = g_new (WindowData, 1);
+	data = g_slice_new (WindowData);
 
 	theme = gtk_icon_theme_get_default ();
 	
@@ -271,8 +337,12 @@
 		 GeditWindow *window)
 {
 	GeditPanel *panel;
-	GucharmapTable *chartable;
 	WindowData *data;
+#ifdef HAVE_GUCHARMAP_2
+	GucharmapChartable *chartable;
+#else
+	GucharmapTable *chartable;
+#endif
 
 	gedit_debug (DEBUG_PLUGINS);
 
@@ -280,8 +350,13 @@
 						 WINDOW_DATA_KEY);
 	g_return_if_fail (data != NULL);
 
+#ifdef HAVE_GUCHARMAP_2
+	chartable = gedit_charmap_panel_get_chartable
+					(GEDIT_CHARMAP_PANEL (data->panel));
+#else
 	chartable = gedit_charmap_panel_get_table
 					(GEDIT_CHARMAP_PANEL (data->panel));
+#endif
 	on_table_status_message (chartable, NULL, window);
 
 	panel = gedit_window_get_side_panel (window);



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