gedit-plugins r392 - in trunk: . plugins/drawspaces



Author: pborelli
Date: Sat Nov 22 15:16:37 2008
New Revision: 392
URL: http://svn.gnome.org/viewvc/gedit-plugins?rev=392&view=rev

Log:
2008-11-22  Paolo Borelli  <pborelli katamail com>

	* plugins/drawspaces: new implementation of the drawspaces plugin
	using the appropriate gtksourceview api.
	* configure.ac: bump gtksourceview dep



Added:
   trunk/plugins/drawspaces/drawspaces.ui
   trunk/plugins/drawspaces/gedit-drawspaces-plugin.c
   trunk/plugins/drawspaces/gedit-drawspaces-plugin.h
Removed:
   trunk/plugins/drawspaces/drawspaces.py
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/plugins/drawspaces/Makefile.am
   trunk/plugins/drawspaces/drawspaces.gedit-plugin.desktop.in
   trunk/plugins/drawspaces/drawspaces.glade

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sat Nov 22 15:16:37 2008
@@ -58,7 +58,7 @@
 PKG_CHECK_MODULES(GEDIT, [
 	glib-2.0 >= 2.8.0
 	gtk+-2.0 >= 2.8.0
-	gtksourceview-2.0 >= 2.0.0
+	gtksourceview-2.0 >= 2.2.0
 	gedit-2.20 >= 2.20.0
 	libglade-2.0 >= 2.4.0
 	gnome-vfs-2.0 >= 2.13.4

Modified: trunk/plugins/drawspaces/Makefile.am
==============================================================================
--- trunk/plugins/drawspaces/Makefile.am	(original)
+++ trunk/plugins/drawspaces/Makefile.am	Sat Nov 22 15:16:37 2008
@@ -1,15 +1,35 @@
-# Draw Spaces Plugin
-
+# Drawspaces plugin
 plugindir = $(libdir)/gedit-2/plugins
 
+INCLUDES = \
+	-I$(top_srcdir) 				\
+	$(GEDIT_CFLAGS) 				\
+	$(WARN_CFLAGS)					\
+	$(DISABLE_DEPRECATED_CFLAGS)			\
+	-DGEDIT_UIDIR=\""$(datadir)/gedit-2/plugins/drawspaces"\" \
+	-DGEDIT_LOCALEDIR=\""$(datadir)/locale"\"
+
+plugin_LTLIBRARIES = libdrawspaces.la
+
+libdrawspaces_la_SOURCES = \
+	gedit-drawspaces-plugin.h				\
+	gedit-drawspaces-plugin.c				
+
+libdrawspaces_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
+libdrawspaces_la_LIBADD = $(GEDIT_LIBS)
+
+uidir = $(datadir)/gedit-2/plugins/drawspaces
+ui_DATA = drawspaces.ui
+
+# Plugin Info
+
 plugin_in_files = drawspaces.gedit-plugin.desktop.in
-plugin_file = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
 
 %.gedit-plugin: %.gedit-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
 
-plugin_PYTHON = drawspaces.py
-plugin_DATA = drawspaces.glade $(plugin_file)
+plugin_DATA = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
+
+EXTRA_DIST = $(plugin_in_files) $(ui_DATA)
 
-EXTRA_DIST = $(plugin_in_files) $(plugin_DATA)
-CLEANFILES = $(plugin_file)
-DISTCLEANFILES = $(plugin_file)
+CLEANFILES = $(plugin_DATA)
+DISTCLEANFILES = $(plugin_DATA)

Modified: trunk/plugins/drawspaces/drawspaces.gedit-plugin.desktop.in
==============================================================================
--- trunk/plugins/drawspaces/drawspaces.gedit-plugin.desktop.in	(original)
+++ trunk/plugins/drawspaces/drawspaces.gedit-plugin.desktop.in	Sat Nov 22 15:16:37 2008
@@ -1,9 +1,8 @@
 [Gedit Plugin]
-Loader=python
 Module=drawspaces
 IAge=2
 _Name=Draw Spaces
 _Description=Draw Spaces and Tabs
-Authors=Paolo Borelli <pborelli katamail com>\nSteve FrÃcinaux <code istique net>
-Copyright=Copyright  2006 Paolo Borelli\nCopyright  2007 Steve FrÃcinaux
+Authors=Paolo Borelli <pborelli katamail com>\nSteve FrÃcinaux <code istique net>\nIgnacio Casal Quinteiro <nacho resa gmail com>
+Copyright=Copyright  2006 Paolo Borelli\nCopyright  2007 Steve FrÃcinaux\nnCopyright  2008 Ignacio Casal Quinteiro
 Website=http://www.gedit.org

Modified: trunk/plugins/drawspaces/drawspaces.glade
==============================================================================
--- trunk/plugins/drawspaces/drawspaces.glade	(original)
+++ trunk/plugins/drawspaces/drawspaces.glade	Sat Nov 22 15:16:37 2008
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.2.0 on Thu Mar 15 18:25:11 2007 by sf mejai-->
+<!--Generated with glade3 3.4.5 on Sat Nov 15 16:38:11 2008 -->
 <glade-interface>
   <widget class="GtkDialog" id="config-dialog">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -20,71 +20,35 @@
             <property name="border_width">6</property>
             <property name="spacing">6</property>
             <child>
-              <widget class="GtkHBox" id="hbox1">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <child>
-                  <widget class="GtkLabel" id="label1">
-                    <property name="visible">True</property>
-                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes">Drawing color:</property>
-                  </widget>
-                </child>
-                <child>
-                  <widget class="GtkColorButton" id="color">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                    <property name="color">#000000000000</property>
-                    <signal name="color_set" handler="on_color_color_set"/>
-                  </widget>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-              </widget>
-            </child>
-            <child>
               <widget class="GtkCheckButton" id="draw-spaces">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="label" translatable="yes">Draw spaces</property>
                 <property name="draw_indicator">True</property>
-                <signal name="toggled" handler="on_draw_spaces_toggled"/>
               </widget>
-              <packing>
-                <property name="position">1</property>
-              </packing>
             </child>
             <child>
-              <widget class="GtkCheckButton" id="draw-nbsp">
+              <widget class="GtkCheckButton" id="draw-tabs">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Draw non-breaking spaces</property>
+                <property name="label" translatable="yes">Draw tabs</property>
                 <property name="draw_indicator">True</property>
-                <signal name="toggled" handler="on_draw_nbsp_toggled"/>
               </widget>
               <packing>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkCheckButton" id="draw-tabs">
+              <widget class="GtkCheckButton" id="draw-newlines">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Draw tabs</property>
+                <property name="label" translatable="yes">Draw new lines</property>
                 <property name="draw_indicator">True</property>
-                <signal name="toggled" handler="on_draw_tabs_toggled"/>
               </widget>
               <packing>
-                <property name="position">3</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </widget>
@@ -104,8 +68,9 @@
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="no">gtk-close</property>
+                <property name="label">gtk-close</property>
                 <property name="use_stock">True</property>
+                <property name="response_id">-7</property>
               </widget>
             </child>
           </widget>

Added: trunk/plugins/drawspaces/drawspaces.ui
==============================================================================
--- (empty file)
+++ trunk/plugins/drawspaces/drawspaces.ui	Sat Nov 22 15:16:37 2008
@@ -0,0 +1,86 @@
+<?xml version="1.0"?>
+<!--Generated with glade3 3.4.5 on Sat Nov 15 16:38:11 2008 -->
+<interface>
+  <object class="GtkDialog" id="config-dialog">
+    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+    <property name="border_width">5</property>
+    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="border_width">6</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkCheckButton" id="draw-spaces">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="label" translatable="yes">Draw spaces</property>
+                <property name="draw_indicator">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="draw-tabs">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="label" translatable="yes">Draw tabs</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="draw-newlines">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="label" translatable="yes">Draw new lines</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="label">gtk-close</property>
+                <property name="use_stock">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-7">button1</action-widget>
+    </action-widgets>
+  </object>
+</interface>

Added: trunk/plugins/drawspaces/gedit-drawspaces-plugin.c
==============================================================================
--- (empty file)
+++ trunk/plugins/drawspaces/gedit-drawspaces-plugin.c	Sat Nov 22 15:16:37 2008
@@ -0,0 +1,585 @@
+/* 
+ * Copyright (C) 2008 Ignacio Casal Quinteiro <nacho resa gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gedit-drawspaces-plugin.h"
+
+#include <glib/gi18n-lib.h>
+#include <gedit/gedit-app.h>
+#include <gedit/gedit-debug.h>
+#include <gedit/gedit-window.h>
+#include <gedit/gedit-view.h>
+#include <gedit/gedit-tab.h>
+
+#include <gconf/gconf-client.h>
+
+#define GCONF_KEY_BASE "/apps/gedit-2/plugins/drawspaces"
+#define GCONF_KEY_ENABLE       GCONF_KEY_BASE "/enable"
+#define GCONF_KEY_DRAW_TABS    GCONF_KEY_BASE "/draw_tabs"
+#define GCONF_KEY_DRAW_SPACES  GCONF_KEY_BASE "/draw_spaces"
+#define GCONF_KEY_DRAW_NEWLINE GCONF_KEY_BASE "/draw_newline"
+
+#define UI_FILE GEDIT_UIDIR "/drawspaces.ui"
+
+#define WINDOW_DATA_KEY "GeditDrawspacesPluginWindowData"
+
+#define GEDIT_DRAWSPACES_PLUGIN_GET_PRIVATE(object) \
+				(G_TYPE_INSTANCE_GET_PRIVATE ((object),	\
+				GEDIT_TYPE_DRAWSPACES_PLUGIN,		\
+				GeditDrawspacesPluginPrivate))
+
+
+GEDIT_PLUGIN_REGISTER_TYPE (GeditDrawspacesPlugin, gedit_drawspaces_plugin)
+
+struct _GeditDrawspacesPluginPrivate
+{
+	GConfClient *gconf_client;
+	
+	GtkSourceDrawSpacesFlags flags;
+};
+
+typedef struct
+{
+	GtkActionGroup *action_group;
+	guint           ui_id;
+	
+	gboolean enable;
+} WindowData;
+
+typedef struct
+{
+	GeditWindow *window;
+	GeditDrawspacesPlugin *plugin;
+} ActionData;
+
+typedef struct _DrawspacesConfigureDialog DrawspacesConfigureDialog;
+
+struct _DrawspacesConfigureDialog
+{
+	GtkWidget *dialog;
+	
+	GtkWidget *draw_tabs;
+	GtkWidget *draw_spaces;
+	GtkWidget *draw_newline;
+	
+	/* Needed to get and set info from gconf */
+	GeditDrawspacesPlugin *plugin;
+};
+
+static const gchar submenu [] = {
+"<ui>"
+"  <menubar name='MenuBar'>"
+"    <menu name='ViewMenu' action='View'>"
+"      <separator />"
+"      <menuitem name='DrawSpacesMenu' action='DrawSpaces'/>"
+"    </menu>"
+"  </menubar>"
+"</ui>"
+};
+
+static void draw_spaces_in_window (GeditWindow *window, GeditDrawspacesPlugin *plugin);
+
+static void
+free_window_data (WindowData *data)
+{
+	g_return_if_fail (data != NULL);
+
+	g_slice_free (WindowData, data);
+}
+
+static void
+free_action_data (gpointer data)
+{
+	g_slice_free (ActionData, data);
+}
+
+static void
+set_enable_draw (GeditDrawspacesPlugin *plugin,
+		 gboolean value)
+{
+	if (gconf_client_key_is_writable (plugin->priv->gconf_client,
+					   GCONF_KEY_ENABLE,
+					   NULL))
+	{
+		gconf_client_set_bool (plugin->priv->gconf_client,
+				       GCONF_KEY_ENABLE,
+				       value,
+				       NULL);
+	}
+}
+
+static void
+on_active_toggled (GtkToggleAction *action,
+		   ActionData *action_data)
+{
+	WindowData *data;
+	gboolean value;
+
+	data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+	
+	value = gtk_toggle_action_get_active (action);
+	data->enable = value;
+
+	set_enable_draw (action_data->plugin, value);
+
+	draw_spaces_in_window (action_data->window, action_data->plugin);
+}
+
+static const GtkToggleActionEntry action_entries[] =
+{
+	{ "DrawSpaces", NULL, N_("Show _White Space"), NULL,
+	 N_("Show spaces and tabs"),
+	 G_CALLBACK (on_active_toggled)}, 
+};
+
+static void on_gconf_notify (GConfClient *client,
+			     guint cnxn_id,
+			     GConfEntry *entry,
+			     gpointer user_data);
+
+static void
+gedit_drawspaces_plugin_init (GeditDrawspacesPlugin *plugin)
+{
+	gedit_debug_message (DEBUG_PLUGINS, "GeditDrawspacesPlugin initializing");
+	
+	plugin->priv = GEDIT_DRAWSPACES_PLUGIN_GET_PRIVATE (plugin);
+
+	plugin->priv->gconf_client = gconf_client_get_default ();
+
+	gconf_client_add_dir (plugin->priv->gconf_client,
+			      GCONF_KEY_BASE,
+			      GCONF_CLIENT_PRELOAD_ONELEVEL,
+			      NULL);
+			      
+	gconf_client_notify_add (plugin->priv->gconf_client,
+				 GCONF_KEY_BASE,
+				 on_gconf_notify,
+				 plugin, NULL, NULL);
+}
+
+static void
+gedit_drawspaces_plugin_finalize (GObject *object)
+{
+	GeditDrawspacesPlugin *plugin = GEDIT_DRAWSPACES_PLUGIN (object);
+
+	gedit_debug_message (DEBUG_PLUGINS, "GeditDrawspacesPlugin finalizing");
+
+	gconf_client_suggest_sync (plugin->priv->gconf_client, NULL);
+
+	g_object_unref (G_OBJECT (plugin->priv->gconf_client));
+
+	G_OBJECT_CLASS (gedit_drawspaces_plugin_parent_class)->finalize (object);
+}
+
+static void
+draw_spaces_in_window (GeditWindow *window,
+		       GeditDrawspacesPlugin *plugin)
+{
+	GList *views, *l;
+	WindowData *data;
+	
+	data = (WindowData *) g_object_get_data (G_OBJECT (window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+
+	views = gedit_window_get_views (window);
+	for (l = views; l != NULL; l = g_list_next (l))
+	{
+		gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (l->data),
+						 data->enable ? plugin->priv->flags : 0);
+	}
+}
+
+static void
+draw_spaces (GeditDrawspacesPlugin *plugin)
+{
+	const GList *windows, *l;
+
+	windows = gedit_app_get_windows (gedit_app_get_default ());
+	
+	for (l = windows; l != NULL; l = g_list_next (l))
+	{
+		draw_spaces_in_window (l->data, plugin);
+	}
+}
+
+static void
+tab_added_cb (GeditWindow *window,
+	      GeditTab *tab,
+	      GeditDrawspacesPlugin *plugin)
+{
+	GeditView *view;
+	WindowData *data;
+	
+	data = (WindowData *) g_object_get_data (G_OBJECT (window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+	
+	if (data->enable)
+	{
+		view = gedit_tab_get_view (tab);
+
+		gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (view),
+						 plugin->priv->flags);
+	}
+}
+
+static gboolean
+get_gconf_value_with_default (GeditDrawspacesPlugin *plugin,
+			      const gchar *key,
+			      gboolean def)
+{
+	GConfValue *value;
+
+	value = gconf_client_get (plugin->priv->gconf_client,
+				  key, NULL);
+				  
+	if (value == NULL || value->type != GCONF_VALUE_BOOL)
+		return def;
+	else
+		return gconf_value_get_bool (value);
+}
+
+static void
+get_config_options (WindowData *data,
+		    GeditDrawspacesPlugin *plugin)
+{
+	gboolean tabs, spaces, newline;
+
+	data->enable = get_gconf_value_with_default (plugin, GCONF_KEY_ENABLE,
+						     FALSE);
+
+	tabs = get_gconf_value_with_default (plugin, GCONF_KEY_DRAW_TABS,
+					     TRUE);
+					
+	spaces = get_gconf_value_with_default (plugin, GCONF_KEY_DRAW_SPACES,
+					       TRUE);
+
+	newline = get_gconf_value_with_default (plugin, GCONF_KEY_DRAW_NEWLINE,
+					        FALSE);			 
+
+	if (tabs)
+		plugin->priv->flags |= GTK_SOURCE_DRAW_SPACES_TAB;
+	if (spaces)
+		plugin->priv->flags |= GTK_SOURCE_DRAW_SPACES_SPACE;
+	if (newline)
+		plugin->priv->flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE;
+}
+
+static void
+impl_activate (GeditPlugin *plugin,
+	       GeditWindow *window)
+{
+	GList *views, *l;
+	GeditDrawspacesPlugin *ds_plugin = GEDIT_DRAWSPACES_PLUGIN (plugin);
+	GtkUIManager *manager;
+	GError *error = NULL;
+	GtkAction *action;
+	WindowData *data;
+	ActionData *action_data;
+
+	gedit_debug (DEBUG_PLUGINS);
+
+	data = g_slice_new (WindowData);
+	action_data = g_slice_new (ActionData);
+	
+	action_data->window = window;
+	action_data->plugin = ds_plugin;
+
+	get_config_options (data, ds_plugin);
+
+	manager = gedit_window_get_ui_manager (window);
+
+	data->action_group = gtk_action_group_new ("GeditDrawspacesPluginActions");
+	gtk_action_group_set_translation_domain (data->action_group, 
+						 GETTEXT_PACKAGE);
+	gtk_action_group_add_toggle_actions_full (data->action_group,
+						  action_entries,
+						  G_N_ELEMENTS (action_entries), 
+						  action_data,
+						  (GDestroyNotify) free_action_data);
+
+	/* Lets set the default value */
+	action = gtk_action_group_get_action (data->action_group,
+					      "DrawSpaces");
+	g_signal_handlers_block_by_func (action, on_active_toggled, action_data);
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+				      data->enable);
+	g_signal_handlers_unblock_by_func (action, on_active_toggled, action_data);
+
+	gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
+
+	data->ui_id = gtk_ui_manager_add_ui_from_string (manager,
+							 submenu,
+							 -1,
+							 &error);
+	if (error)
+	{
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+
+	g_object_set_data_full (G_OBJECT (window),
+				WINDOW_DATA_KEY,
+				data,
+				(GDestroyNotify) free_window_data);
+
+	if (data->enable)
+	{
+		draw_spaces_in_window (window, ds_plugin);
+	}
+
+	g_signal_connect (window, "tab-added",
+			  G_CALLBACK (tab_added_cb), ds_plugin);
+}
+
+static void
+impl_deactivate	(GeditPlugin *plugin,
+		 GeditWindow *window)
+{
+	GeditDrawspacesPlugin *ds_plugin = GEDIT_DRAWSPACES_PLUGIN (plugin);
+	GtkUIManager *manager;
+	WindowData *data;
+
+	gedit_debug (DEBUG_PLUGINS);
+	
+	data = (WindowData *) g_object_get_data (G_OBJECT (window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+	
+	manager = gedit_window_get_ui_manager (window);
+	
+	ds_plugin->priv->flags = 0;
+	draw_spaces (ds_plugin);
+	
+	g_signal_handlers_disconnect_by_func (window, tab_added_cb, NULL);
+	
+	gtk_ui_manager_remove_ui (manager, data->ui_id);
+	gtk_ui_manager_remove_action_group (manager, data->action_group);
+	
+	g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
+}
+
+static void
+set_draw_tab (GeditDrawspacesPlugin *plugin,
+	      gboolean value)
+{
+	if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
+					   GCONF_KEY_DRAW_TABS,
+					   NULL))
+		return;
+	gconf_client_set_bool (plugin->priv->gconf_client,
+			       GCONF_KEY_DRAW_TABS,
+			       value,
+			       NULL);
+}
+
+static void
+set_draw_spaces (GeditDrawspacesPlugin *plugin,
+		 gboolean value)
+{
+	if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
+					   GCONF_KEY_DRAW_SPACES,
+					   NULL))
+		return;
+	gconf_client_set_bool (plugin->priv->gconf_client,
+			       GCONF_KEY_DRAW_SPACES,
+			       value,
+			       NULL);
+}
+
+static void
+set_draw_newline (GeditDrawspacesPlugin *plugin,
+		  gboolean value)
+{
+	if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
+					   GCONF_KEY_DRAW_NEWLINE,
+					   NULL))
+		return;
+	gconf_client_set_bool (plugin->priv->gconf_client,
+			       GCONF_KEY_DRAW_NEWLINE,
+			       value,
+			       NULL);
+}
+
+static void
+on_draw_tabs_toggled (GtkToggleButton *button,
+		      GeditDrawspacesPlugin *plugin)
+{
+	set_draw_tab (plugin, gtk_toggle_button_get_active (button));
+}
+
+static void
+on_draw_spaces_toggled (GtkToggleButton *button,
+		        GeditDrawspacesPlugin *plugin)
+{
+	set_draw_spaces (plugin, gtk_toggle_button_get_active (button));
+}
+
+static void
+on_draw_newline_toggled (GtkToggleButton *button,
+		         GeditDrawspacesPlugin *plugin)
+{
+	set_draw_newline (plugin, gtk_toggle_button_get_active (button));
+}
+
+static void
+dialog_destroyed (GtkObject *obj, gpointer dialog_pointer)
+{
+	gedit_debug (DEBUG_PLUGINS);
+
+	g_slice_free (DrawspacesConfigureDialog, dialog_pointer);
+
+	gedit_debug_message (DEBUG_PLUGINS, "END");
+}
+
+static DrawspacesConfigureDialog *
+get_configuration_dialog (GeditDrawspacesPlugin *plugin)
+{
+	DrawspacesConfigureDialog *dialog = NULL;
+	gboolean ret;
+	GtkWidget *error_widget;
+	gchar *root_objects [] = {
+		"config-dialog",
+		NULL
+	};
+
+	dialog = g_slice_new (DrawspacesConfigureDialog);
+
+	dialog->plugin = plugin;
+
+	ret = gedit_utils_get_ui_objects (UI_FILE,
+					  root_objects,
+					  &error_widget,
+					  "config-dialog", &dialog->dialog,
+					  "draw-tabs", &dialog->draw_tabs,
+					  "draw-spaces", &dialog->draw_spaces,
+					  "draw-newlines", &dialog->draw_newline,
+					  NULL);
+
+	if(!ret)
+	{
+		GtkWidget *dialog_error;
+		GtkWidget *content;
+		
+		dialog_error = gtk_dialog_new_with_buttons (_("Error dialog"),
+							    NULL,
+							    GTK_DIALOG_DESTROY_WITH_PARENT,
+							    GTK_STOCK_CLOSE,
+							    GTK_RESPONSE_CLOSE,
+							    NULL);
+		content = gtk_dialog_get_content_area (GTK_DIALOG (dialog_error));
+		gtk_widget_show (error_widget);
+			
+		gtk_box_pack_start_defaults (GTK_BOX (content),
+					     error_widget);
+		gtk_widget_show (dialog_error);
+		gtk_dialog_run (GTK_DIALOG (dialog_error));
+		gtk_widget_destroy (dialog_error);
+	}
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->draw_tabs),
+				      plugin->priv->flags & GTK_SOURCE_DRAW_SPACES_TAB);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->draw_spaces),
+				      plugin->priv->flags & GTK_SOURCE_DRAW_SPACES_SPACE);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->draw_newline),
+				      plugin->priv->flags & GTK_SOURCE_DRAW_SPACES_NEWLINE);
+
+	g_signal_connect (dialog->draw_tabs, "toggled",
+			  G_CALLBACK (on_draw_tabs_toggled), plugin);
+	g_signal_connect (dialog->draw_spaces, "toggled",
+			  G_CALLBACK (on_draw_spaces_toggled), plugin);
+	g_signal_connect (dialog->draw_newline, "toggled",
+			  G_CALLBACK (on_draw_newline_toggled), plugin);
+	g_signal_connect (dialog->dialog, "destroy",
+			  G_CALLBACK (dialog_destroyed), dialog);
+
+	return dialog;
+}
+
+static GtkWidget *
+impl_create_configure_dialog (GeditPlugin *plugin)
+{
+	DrawspacesConfigureDialog *dialog;
+	
+	dialog = get_configuration_dialog (GEDIT_DRAWSPACES_PLUGIN (plugin));
+	
+	g_signal_connect (dialog->dialog,
+			  "response",
+			  G_CALLBACK (gtk_widget_destroy),
+			  dialog->dialog);
+	
+	return dialog->dialog;
+}
+
+static void
+on_gconf_notify (GConfClient *client,
+		 guint cnxn_id,
+		 GConfEntry *entry,
+		 gpointer user_data)
+{
+	GeditDrawspacesPlugin *plugin = GEDIT_DRAWSPACES_PLUGIN (user_data);
+	gboolean value;
+
+	if (strcmp (entry->key, GCONF_KEY_DRAW_TABS) == 0)
+	{
+		value = gconf_value_get_bool (entry->value);
+		if (value)
+			plugin->priv->flags |= GTK_SOURCE_DRAW_SPACES_TAB;
+		else
+			plugin->priv->flags &= ~GTK_SOURCE_DRAW_SPACES_TAB;
+	}
+	else if (strcmp (entry->key, GCONF_KEY_DRAW_SPACES) == 0)
+	{
+		value = gconf_value_get_bool (entry->value);
+		if (value)
+			plugin->priv->flags |= GTK_SOURCE_DRAW_SPACES_SPACE;
+		else
+			plugin->priv->flags &= ~GTK_SOURCE_DRAW_SPACES_SPACE;
+	}
+	else if (strcmp (entry->key, GCONF_KEY_DRAW_NEWLINE) == 0)
+	{
+		value = gconf_value_get_bool (entry->value);
+		if (value)
+			plugin->priv->flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE;
+		else
+			plugin->priv->flags &= ~GTK_SOURCE_DRAW_SPACES_NEWLINE;
+	}
+	
+	draw_spaces (plugin);
+}
+
+static void
+gedit_drawspaces_plugin_class_init (GeditDrawspacesPluginClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
+
+	g_type_class_add_private (object_class, sizeof (GeditDrawspacesPluginPrivate));
+
+	object_class->finalize = gedit_drawspaces_plugin_finalize;
+
+	plugin_class->activate = impl_activate;
+	plugin_class->deactivate = impl_deactivate;
+	plugin_class->create_configure_dialog = impl_create_configure_dialog;	
+}

Added: trunk/plugins/drawspaces/gedit-drawspaces-plugin.h
==============================================================================
--- (empty file)
+++ trunk/plugins/drawspaces/gedit-drawspaces-plugin.h	Sat Nov 22 15:16:37 2008
@@ -0,0 +1,76 @@
+/* 
+ * Copyright (C) 2008 Ignacio Casal Quinteiro <nacho resa gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id: gedit-drawspaces-plugin.h 137 2006-04-23 15:13:27Z sfre $
+ */
+
+#ifndef __GEDIT_DRAWSPACES_PLUGIN_H__
+#define __GEDIT_DRAWSPACES_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gedit/gedit-plugin.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_DRAWSPACES_PLUGIN		(gedit_drawspaces_plugin_get_type ())
+#define GEDIT_DRAWSPACES_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_DRAWSPACES_PLUGIN, GeditDrawspacesPlugin))
+#define GEDIT_DRAWSPACES_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_DRAWSPACES_PLUGIN, GeditDrawspacesPluginClass))
+#define GEDIT_IS_DRAWSPACES_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GEDIT_TYPE_DRAWSPACES_PLUGIN))
+#define GEDIT_IS_DRAWSPACES_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_DRAWSPACES_PLUGIN))
+#define GEDIT_DRAWSPACES_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_DRAWSPACES_PLUGIN, GeditDrawspacesPluginClass))
+
+/* Private structure type */
+typedef struct _GeditDrawspacesPluginPrivate	GeditDrawspacesPluginPrivate;
+
+/*
+ * Main object structure
+ */
+typedef struct _GeditDrawspacesPlugin		GeditDrawspacesPlugin;
+
+struct _GeditDrawspacesPlugin
+{
+	GeditPlugin parent_instance;
+	
+	/* private */
+	GeditDrawspacesPluginPrivate *priv;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _GeditDrawspacesPluginClass	GeditDrawspacesPluginClass;
+
+struct _GeditDrawspacesPluginClass
+{
+	GeditPluginClass parent_class;
+};
+
+/*
+ * Public methods
+ */
+GType	gedit_drawspaces_plugin_get_type	(void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GEDIT_DRAWSPACES_PLUGIN_H__ */



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