[gedit-list] part of replace in all open documents



Hi..
I submit a patch for gedit-window.[c,h] and gedit-app.[c,h] for
replacement in all opened files..
I know it's only a part of work (todo is dialog, etc.), but it's a
good start I hope ;)

I'm using ubuntu Dapper, so (I'm sorry!) I didn't check this.. I just
hope it will be usefull..

Regards,
Krzysiek Szczuka
Index: gedit/gedit-app.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-app.c,v
retrieving revision 1.9
diff -U3 -r1.9 gedit-app.c
--- gedit/gedit-app.c	16 Aug 2006 17:45:04 -0000	1.9
+++ gedit/gedit-app.c	14 Sep 2006 16:09:03 -0000
@@ -516,6 +516,46 @@
 	return res;
 }
 
+
+/**
+ * gedit_app_replace_all:
+ * @app: the #GeditApp
+ * @find: text to find 
+ * @replace: text to replace
+ *
+ * Replaces text in all documents currently open in #GeditApp.
+ *
+ * Return value: count of replacements
+ */
+gint
+gedit_app_replace_all	(GeditApp 	*app,
+			 const gchar    *find, 
+			 const gchar    *replace, 
+			 guint          flags)
+{
+	GList *windows;
+	gint   cont = 0;
+
+	g_return_val_if_fail (GEDIT_IS_APP (app), 0); //fixme: -1?
+	g_return_val_if_fail (find != NULL, 0);
+
+	windows = app->priv->windows;
+
+	while (windows != NULL)
+	{
+		res = g_list_concat (res,
+				     gedit_window_get_documents (GEDIT_WINDOW (windows->data)));
+		cont += gedit_window_replace_all (GEDIT_WINDOW (windows->data),
+						  find,
+						  replace,
+						  flags);						  
+
+		windows = g_list_next (windows);
+	}
+
+	return res;
+}
+
 /**
  * gedit_app_get_lockdown:
  * @app: a #GeditApp
Index: gedit/gedit-app.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-app.h,v
retrieving revision 1.5
diff -U3 -r1.5 gedit-app.h
--- gedit/gedit-app.h	16 Aug 2006 17:45:04 -0000	1.5
+++ gedit/gedit-app.h	14 Sep 2006 16:09:03 -0000
@@ -105,6 +105,11 @@
 /* Returns a newly allocated list with all the views */
 GList		*gedit_app_get_views			(GeditApp *app);
 
+/* Replaces text in all documents currently open in app */
+gint gedit_app_replace_all				(GeditApp 	*app,
+							 const gchar    *find, 
+							 const gchar    *replace, 
+							 guint          flags);
 /* Lockdown state */
 GeditLockdownMask gedit_app_get_lockdown		(GeditApp *app);
 
Index: gedit/gedit-window.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-window.c,v
retrieving revision 1.38
diff -U3 -r1.38 gedit-window.c
--- gedit/gedit-window.c	26 Aug 2006 15:06:00 -0000	1.38
+++ gedit/gedit-window.c	14 Sep 2006 16:09:09 -0000
@@ -3281,6 +3281,34 @@
 	return res;
 }
 
+/* Replace all in all window's documents */
+gint
+gedit_window_replace_all 	(GeditWindow    *window,
+				 const gchar    *find, 
+				 const gchar    *replace, 
+				 guint          flags)
+{
+	GList *docs = NULL;
+	gint   cont = 0;
+	
+	g_return_val_if_fail (GEDIT_IS_WINDOW (window), 0); //fixme: -1 as error?
+	g_return_val_if_fail (find != NULL, 0);
+	
+	docs = gedit_window_get_documents (window);
+	docs = g_list_first (docs);
+	
+	while (docs != NULL) {
+		cont += gedit_document_replace_all (GEDIT_DOCUMENT (docs->data),
+						    find,
+						    replace,
+						    flags);
+		docs = g_list_next (docs);
+	}
+	
+	g_list_free (docs);
+	return cont;
+}
+
 static void
 add_view (GeditTab *tab, GList **res)
 {
Index: gedit/gedit-window.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-window.h,v
retrieving revision 1.7
diff -U3 -r1.7 gedit-window.h
--- gedit/gedit-window.h	7 Aug 2006 16:42:41 -0000	1.7
+++ gedit/gedit-window.h	14 Sep 2006 16:09:10 -0000
@@ -152,6 +152,12 @@
 	
 GeditTab        *gedit_window_get_tab_from_uri		(GeditWindow         *window,
 							 const gchar         *uri);
+
+/* Replace in all window's documents */
+gint		 gedit_window_replace_all 		(GeditWindow       *window,
+							 const gchar         *find, 
+							 const gchar         *replace, 
+							 guint                flags);
 /*
  * Non exported functions
  */


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