SF.net SVN: geany: [597] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Thu Jul 20 21:19:29 UTC 2006


Revision: 597
Author:   ntrel
Date:     2006-07-20 14:19:18 -0700 (Thu, 20 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=597&view=rev

Log Message:
-----------
Added Find button to Replace dialog to skip a match; Change Replace button to find first & use current selection; Ask whether to wraparound when replacing and no next match is found

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/dialogs.c
    trunk/src/dialogs.h
    trunk/src/document.c
    trunk/src/document.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-07-20 21:17:17 UTC (rev 596)
+++ trunk/ChangeLog	2006-07-20 21:19:18 UTC (rev 597)
@@ -8,6 +8,13 @@
  * TODO: Added 3 more items discussed on the ML.
  * doc/scikeybinding.docbook: Commented out some keys not working.
  * src/dialogs.c: Share find/replace common checkbox setup code.
+ * src/build.c, src/build.h, src/sciwrappers.h, src/dialogs.c,
+   src/dialogs.h: Don't include geany.h.
+ * src/geany.h, src/callbacks.h: Moved GEANY_RESPONSE_* to callbacks.h.
+ * src/callbacks.c, src/document.c, src/document.h, src/dialogs.c:
+   Added Find button to Replace dialog to skip a match.
+   Change Replace button to find first & use current selection.
+   Ask whether to wraparound when replacing and no next match is found.
 
 
 2006-07-19  Enrico Tröger  <enrico.troeger at uvena.de>

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2006-07-20 21:17:17 UTC (rev 596)
+++ trunk/src/callbacks.c	2006-07-20 21:19:18 UTC (rev 597)
@@ -1984,6 +1984,11 @@
 					search_backwards_re);
 				break;
 			}
+			case GEANY_RESPONSE_FIND:
+			{
+				document_find_text(idx, find, search_flags_re, search_backwards_re);
+				break;
+			}
 			case GEANY_RESPONSE_REPLACE_ALL:
 			{
 				document_replace_all(idx, find, replace, search_flags_re);

Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c	2006-07-20 21:17:17 UTC (rev 596)
+++ trunk/src/dialogs.c	2006-07-20 21:19:18 UTC (rev 597)
@@ -948,6 +948,10 @@
 		gtk_widget_show(button);
 		gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button,
 			GEANY_RESPONSE_REPLACE_ALL);
+		button = gtk_button_new_from_stock("gtk-find");
+		gtk_widget_show(button);
+		gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button,
+			GEANY_RESPONSE_FIND);
 		button = gtk_button_new_with_mnemonic(_("_Replace"));
 		gtk_widget_show(button);
 		gtk_dialog_add_action_widget(GTK_DIALOG(app->replace_dialog), button,
@@ -993,7 +997,7 @@
 		g_signal_connect(G_OBJECT(check_regexp), "toggled",
 			G_CALLBACK(on_replace_checkbutton_toggled), NULL);
 
-		checkbox6 = gtk_check_button_new_with_mnemonic(_("Replace in all open files"));
+		checkbox6 = gtk_check_button_new_with_mnemonic(_("Replace in all _open files"));
 		g_object_set_data_full(G_OBJECT(app->replace_dialog), "check_all_buffers",
 						gtk_widget_ref(checkbox6), (GDestroyNotify)gtk_widget_unref);
 		gtk_tooltips_set_tip(tooltips, checkbox6,

Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h	2006-07-20 21:17:17 UTC (rev 596)
+++ trunk/src/dialogs.h	2006-07-20 21:19:18 UTC (rev 597)
@@ -21,13 +21,9 @@
  */
 
 
-#include "geany.h"
-
 #ifndef GEANY_DIALOGS_H
 #define GEANY_DIALOGS_H 1
 
-
-
 /* This shows the file selection dialog to open a file. */
 void dialogs_show_open_file(void);
 

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-07-20 21:17:17 UTC (rev 596)
+++ trunk/src/document.c	2006-07-20 21:19:18 UTC (rev 597)
@@ -50,7 +50,6 @@
 #include "sci_cb.h"
 #include "dialogs.h"
 #include "msgwindow.h"
-#include "callbacks.h"
 #include "templates.h"
 #include "treeviews.h"
 #include "utils.h"
@@ -730,18 +729,20 @@
 }
 
 
-/* general search function, used from the find dialog */
-void document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards)
+/* General search function, used from the find dialog.
+ * Returns -1 on failure or the start position of the matching text.
+ * Will skip past any selection, ignoring it. */
+gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards)
 {
 	gint selection_end, selection_start, search_pos;
 
-	g_return_if_fail(text != NULL);
-	if (idx == -1 || ! *text) return;
+	g_return_val_if_fail(text != NULL, -1);
+	if (idx == -1 || ! *text) return -1;
 	// Sci doesn't support searching backwards with a regex
 	if (flags & SCFIND_REGEXP) search_backwards = FALSE;
 
-	selection_start =  sci_get_selection_start(doc_list[idx].sci);
-	selection_end =  sci_get_selection_end(doc_list[idx].sci);
+	selection_start = sci_get_selection_start(doc_list[idx].sci);
+	selection_end = sci_get_selection_end(doc_list[idx].sci);
 	if ((selection_end - selection_start) > 0)
 	{ // there's a selection so go to the end
 		if (search_backwards)
@@ -765,12 +766,14 @@
 		if (dialogs_show_not_found(text))
 		{
 			sci_goto_pos(doc_list[idx].sci, (search_backwards) ? sci_get_length(doc_list[idx].sci) : 0, TRUE);
-			document_find_text(idx, text, flags, search_backwards);
+			return document_find_text(idx, text, flags, search_backwards);
 		}
 	}
+	return search_pos;
 }
 
 
+/* Replaces the selection if it matches, otherwise just finds the next match */
 void document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
 	gint flags, gboolean search_backwards)
 {
@@ -783,33 +786,37 @@
 
 	selection_start =  sci_get_selection_start(doc_list[idx].sci);
 	selection_end =  sci_get_selection_end(doc_list[idx].sci);
-	if ((selection_end - selection_start) > 0)
-	{ // there's a selection so go to the end
-		if (search_backwards)
-			sci_goto_pos(doc_list[idx].sci, selection_start, TRUE);
-		else
-			sci_goto_pos(doc_list[idx].sci, selection_end, TRUE);
+	if (selection_end == selection_start)
+	{
+		// no selection so just find the next match
+		document_find_text(idx, find_text, flags, search_backwards);
+		return;
 	}
-
-	sci_set_search_anchor(doc_list[idx].sci);
+	// there's a selection so go to the start before finding to search through it
+	// this ensures there is a match
 	if (search_backwards)
-		search_pos = sci_search_prev(doc_list[idx].sci, flags, find_text);
+		sci_goto_pos(doc_list[idx].sci, selection_end, TRUE);
 	else
-		search_pos = sci_search_next(doc_list[idx].sci, flags, find_text);
+		sci_goto_pos(doc_list[idx].sci, selection_start, TRUE);
 
+	search_pos = document_find_text(idx, find_text, flags, search_backwards);	
+	// return if the original selected text did not match (at the start of the selection)
+	if (search_pos != selection_start) return;
+
 	if (search_pos != -1)
 	{
 		gint replace_len;
 		// search next/prev will select matching text, which we use to set the replace target
 		sci_target_from_selection(doc_list[idx].sci);
 		replace_len = sci_target_replace(doc_list[idx].sci, replace_text, flags & SCFIND_REGEXP);
-		// select the replacement and scroll in view
+		// select the replacement - find text will skip past the selected text
 		sci_set_selection_start(doc_list[idx].sci, search_pos);
 		sci_set_selection_end(doc_list[idx].sci, search_pos + replace_len);
-		sci_scroll_caret(doc_list[idx].sci);
+		document_find_text(idx, find_text, flags, search_backwards);
 	}
 	else
 	{
+		// no match in the selection
 		utils_beep();
 	}
 }

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2006-07-20 21:17:17 UTC (rev 596)
+++ trunk/src/document.h	2006-07-20 21:19:18 UTC (rev 597)
@@ -88,16 +88,19 @@
    be UTF-8). */
 void document_save_file (gint);
 
-void document_find_text(gint, const gchar*, gint, gboolean);
+/* special search function, used from the find entry in the toolbar */
+void document_find_next(gint, const gchar*, gint, gboolean, gboolean);
 
+/* General search function, used from the find dialog.
+ * Returns -1 on failure or the start position of the matching text. */
+gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards);
+
 void document_replace_text(gint, const gchar*, const gchar*, gint, gboolean);
 
 void document_replace_all(gint, const gchar*, const gchar*, gint);
 
 void document_replace_sel(gint, const gchar*, const gchar*, gint);
 
-void document_find_next(gint, const gchar*, gint, gboolean, gboolean);
-
 void document_set_font(gint, const gchar*, gint);
 
 void document_update_tag_list(gint, gboolean);


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