SF.net SVN: geany: [1031] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Sat Nov 25 12:32:23 UTC 2006


Revision: 1031
          http://svn.sourceforge.net/geany/?rev=1031&view=rev
Author:   ntrel
Date:     2006-11-25 04:32:22 -0800 (Sat, 25 Nov 2006)

Log Message:
-----------
When replacing in session, use notebook page order and show a count
of the files changed.
Show the filename when replacing text over a range.
Add DOC_FILENAME() null-safe macro to get the filename at doc_idx.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/document.c
    trunk/src/document.h
    trunk/src/search.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-11-25 12:23:49 UTC (rev 1030)
+++ trunk/ChangeLog	2006-11-25 12:32:22 UTC (rev 1031)
@@ -6,6 +6,11 @@
  * src/vte.c:
    Remove vte_char_size_changed() workaround, not needed since r988;
    this also fixes an issue where the VTE is limited to 30x5 chars.
+ * src/search.c, src/document.c, src/document.h:
+   When replacing in session, use notebook page order and show a count
+   of the files changed.
+   Show the filename when replacing text over a range.
+   Add DOC_FILENAME() null-safe macro to get the filename at doc_idx.
 
 
 2006-11-24  Nick Treleaven  <nick.treleaven at btinternet.com>

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-11-25 12:23:49 UTC (rev 1030)
+++ trunk/src/document.c	2006-11-25 12:32:22 UTC (rev 1031)
@@ -305,7 +305,6 @@
 	g_free(fname);
 
 	title = (filename) ? g_path_get_basename(filename) : g_strdup(GEANY_STRING_UNTITLED);
-
 	tabnum = notebook_new_tab(new_idx, title, GTK_WIDGET(sci));
 	gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), tabnum);
 
@@ -365,8 +364,7 @@
 			//g_object_unref(doc_list[idx].tag_tree); // no need to unref when destroying?
 			gtk_widget_destroy(doc_list[idx].tag_tree);
 		}
-		msgwin_status_add(_("File %s closed."),
-				(doc_list[idx].file_name) ? doc_list[idx].file_name : GEANY_STRING_UNTITLED);
+		msgwin_status_add(_("File %s closed."), DOC_FILENAME(idx));
 		g_free(doc_list[idx].encoding);
 		g_free(doc_list[idx].saved_encoding.encoding);
 		g_free(doc_list[idx].file_name);
@@ -1130,7 +1128,7 @@
 	gint count = 0;
 	gint find_len = 0, replace_len = 0;
 	gboolean match_found = FALSE;
-	gchar *escaped_find_text, *escaped_replace_text;
+	gchar *escaped_find_text, *escaped_replace_text, *filename;
 	struct TextToFind ttf;
 
 	g_return_val_if_fail(find_text != NULL && replace_text != NULL, FALSE);
@@ -1164,22 +1162,24 @@
 	}
 	sci_end_undo_action(doc_list[idx].sci);
 
+	filename = g_path_get_basename(DOC_FILENAME(idx));
+
 	if (escaped_chars)
 	{	// escape special characters for showing
 		escaped_find_text = g_strescape(find_text, NULL);
 		escaped_replace_text = g_strescape(replace_text, NULL);
-		msgwin_status_add(_("Replaced %d occurrences of \"%s\" with \"%s\"."),
-							count, escaped_find_text, escaped_replace_text);
+		msgwin_status_add(_("%s: replaced %d occurrences of \"%s\" with \"%s\"."),
+						filename, count, escaped_find_text, escaped_replace_text);
 		g_free(escaped_find_text);
 		g_free(escaped_replace_text);
 	}
 	else
 	{
-		msgwin_status_add(_("Replaced %d occurrences of \"%s\" with \"%s\"."),
-							count, find_text, replace_text);
+		msgwin_status_add(_("%s: replaced %d occurrences of \"%s\" with \"%s\"."),
+						filename, count, find_text, replace_text);
 	}
+	g_free(filename);
 
-
 	if (match_found)
 	{
 		// scroll last match in view.
@@ -1220,16 +1220,21 @@
 }
 
 
-void document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
-						  gint flags, gboolean escaped_chars)
+// returns TRUE if at least one replacement was made.
+gboolean document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
+		gint flags, gboolean escaped_chars)
 {
 	gint len;
-	g_return_if_fail(find_text != NULL && replace_text != NULL);
-	if (idx == -1 || ! *find_text) return;
+	g_return_val_if_fail(find_text != NULL && replace_text != NULL, FALSE);
+	if (idx == -1 || ! *find_text) return FALSE;
 
 	len = sci_get_length(doc_list[idx].sci);
 	if (document_replace_range(idx, find_text, replace_text, flags, 0, len, escaped_chars) == -1)
+	{
 		utils_beep();
+		return FALSE;
+	}
+	return TRUE;
 }
 
 

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2006-11-25 12:23:49 UTC (rev 1030)
+++ trunk/src/document.h	2006-11-25 12:32:22 UTC (rev 1031)
@@ -82,7 +82,11 @@
 #define DOC_IDX_VALID(idx) \
 	((idx) >= 0 && (guint)(idx) < doc_array->len && doc_list[idx].is_valid)
 
+#define DOC_FILENAME(doc_idx) \
+	((doc_list[doc_idx].file_name != NULL) ? \
+	(doc_list[doc_idx].file_name) : GEANY_STRING_UNTITLED)
 
+
 /* returns the index of the notebook page which has the given filename */
 gint document_find_by_filename(const gchar*, gboolean is_tm_filename);
 
@@ -155,7 +159,8 @@
 gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
 	gint flags, gboolean search_backwards);
 
-void document_replace_all(gint, const gchar*, const gchar*, gint, gboolean);
+gboolean document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
+		gint flags, gboolean escaped_chars);
 
 void document_replace_sel(gint, const gchar*, const gchar*, gint, gboolean);
 

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2006-11-25 12:23:49 UTC (rev 1030)
+++ trunk/src/search.c	2006-11-25 12:32:22 UTC (rev 1031)
@@ -887,13 +887,22 @@
 		}
 		case GEANY_RESPONSE_REPLACE_IN_SESSION:
 		{
-			guint i;
-			for (i = 0; i < doc_array->len; i++)
+			guint n, count = 0;
+			gchar *msg;
+			// replace in all documents following notebook tab order
+			for (n = 0; (gint) n < gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); n++)
 			{
-				if (! doc_list[i].is_valid) continue;
+				gint idx = document_get_n_idx(n);
 
-				document_replace_all(i, find, replace, search_flags_re, search_replace_escape_re);
+				if (! doc_list[idx].is_valid) continue;
+
+				if (document_replace_all(idx, find, replace, search_flags_re,
+					search_replace_escape_re)) count++;
 			}
+			msg = g_strdup_printf(_("Replaced text in %u files."), count);
+			ui_set_statusbar(msg, FALSE);
+			g_free(msg);
+
 			ui_save_buttons_toggle(doc_list[idx].changed);	// update save all
 			if (close_window) gtk_widget_hide(widgets.replace_dialog);
 			break;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list