SF.net SVN: geany:[3605] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Fri Feb 27 14:05:50 UTC 2009


Revision: 3605
          http://geany.svn.sourceforge.net/geany/?rev=3605&view=rev
Author:   eht16
Date:     2009-02-27 14:05:50 +0000 (Fri, 27 Feb 2009)

Log Message:
-----------
Move ui_set_search_entry_background() into ui_utils.c.
Change the background colour of the search entries in the Find and Replace dialogs according to the search results like in the toolbar search field.
Add images to the 'Replace' and 'Replace and Find' buttons in the Replace dialog.
Minor cleanups in search.c.

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-02-26 23:11:06 UTC (rev 3604)
+++ trunk/ChangeLog	2009-02-27 14:05:50 UTC (rev 3605)
@@ -1,3 +1,15 @@
+2009-02-27  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
+
+ * src/callbacks.c, src/search.c, src/ui_utils.c, src/ui_utils.c:
+   Move ui_set_search_entry_background() into ui_utils.c.
+   Change the background colour of the search entries in the Find
+   and Replace dialogs according to the search results like in the
+   toolbar search field.
+   Add images to the 'Replace' and 'Replace and Find' buttons in the
+   Replace dialog.
+   Minor cleanups in search.c.
+
+
 2009-02-26  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>
 
  * plugins/vcdiff.c, plugins/Makefile.am, po/POTFILES.in:

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2009-02-26 23:11:06 UTC (rev 3604)
+++ trunk/src/callbacks.c	2009-02-27 14:05:50 UTC (rev 3605)
@@ -535,26 +535,6 @@
 }
 
 
-static void set_search_bar_background(GtkWidget *widget, gboolean success)
-{
-	const GdkColor red   = {0, 0xffff, 0x6666, 0x6666};
-	const GdkColor white = {0, 0xffff, 0xffff, 0xffff};
-	static gboolean old_value = TRUE;
-
-	if (widget == NULL)
-		widget = toolbar_get_widget_child_by_name("SearchEntry");
-
-	/* only update if really needed */
-	if (search_data.search_bar && old_value != success)
-	{
-		gtk_widget_modify_base(widget, GTK_STATE_NORMAL, success ? NULL : &red);
-		gtk_widget_modify_text(widget, GTK_STATE_NORMAL, success ? NULL : &white);
-
-		old_value = success;
-	}
-}
-
-
 /* store text, clear search flags so we can use Search->Find Next/Previous */
 static void setup_find_next(const gchar *text)
 {
@@ -574,7 +554,8 @@
 
 	setup_find_next(text);
 	result = document_search_bar_find(doc, search_data.text, 0, TRUE);
-	set_search_bar_background(NULL, result);
+	if (search_data.search_bar)
+		ui_set_search_entry_background(toolbar_get_widget_child_by_name("SearchEntry"), result);
 }
 
 
@@ -593,7 +574,8 @@
 
 		setup_find_next(text);
 		result = document_search_bar_find(doc, search_data.text, 0, FALSE);
-		set_search_bar_background(entry, result);
+		if (search_data.search_bar)
+			ui_set_search_entry_background(entry, result);
 	}
 }
 
@@ -1146,7 +1128,9 @@
 		if (result > -1)
 			editor_display_current_line(doc->editor, 0.3F);
 
-		set_search_bar_background(NULL, (result > -1) ? TRUE : FALSE);
+		if (search_data.search_bar)
+			ui_set_search_entry_background(
+				toolbar_get_widget_child_by_name("SearchEntry"), (result > -1));
 	}
 }
 

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2009-02-26 23:11:06 UTC (rev 3604)
+++ trunk/src/search.c	2009-02-27 14:05:50 UTC (rev 3605)
@@ -101,9 +101,10 @@
 {
 	GtkWidget	*dialog;
 	GtkWidget	*find_entry;
+	GtkWidget	*replace_entry;
 	gboolean	all_expanded;
 }
-replace_dlg = {NULL, NULL, FALSE};
+replace_dlg = {NULL, NULL, NULL, FALSE};
 
 static struct
 {
@@ -469,10 +470,11 @@
 	{
 		/* only set selection if the dialog is not already visible */
 		if (! GTK_WIDGET_VISIBLE(find_dlg.dialog) && sel)
-			gtk_entry_set_text(GTK_ENTRY(GTK_BIN(
-							ui_lookup_widget(find_dlg.dialog, "entry"))->child), sel);
-		gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(ui_lookup_widget(find_dlg.dialog, "entry"))->child));
+			gtk_entry_set_text(GTK_ENTRY(find_dlg.entry), sel);
+		gtk_widget_grab_focus(find_dlg.entry);
 		gtk_widget_show(find_dlg.dialog);
+		if (sel != NULL) /* when we have a selection, reset the entry widget's background colour */
+			ui_set_search_entry_background(find_dlg.entry, TRUE);
 		/* bring the dialog back in the foreground in case it is already open but the focus is away */
 		gtk_window_present(GTK_WINDOW(find_dlg.dialog));
 	}
@@ -505,9 +507,13 @@
 	gtk_dialog_add_action_widget(GTK_DIALOG(replace_dlg.dialog), button,
 		GEANY_RESPONSE_FIND);
 	button = gtk_button_new_with_mnemonic(_("_Replace"));
+	gtk_button_set_image(GTK_BUTTON(button),
+		gtk_image_new_from_stock(GTK_STOCK_FIND_AND_REPLACE, GTK_ICON_SIZE_BUTTON));
 	gtk_dialog_add_action_widget(GTK_DIALOG(replace_dlg.dialog), button,
 		GEANY_RESPONSE_REPLACE);
 	button = gtk_button_new_with_mnemonic(_("Replace & Fi_nd"));
+	gtk_button_set_image(GTK_BUTTON(button),
+		gtk_image_new_from_stock(GTK_STOCK_FIND_AND_REPLACE, GTK_ICON_SIZE_BUTTON));
 	gtk_dialog_add_action_widget(GTK_DIALOG(replace_dlg.dialog), button,
 		GEANY_RESPONSE_REPLACE_AND_FIND);
 
@@ -533,6 +539,7 @@
 	gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace))), 50);
 	g_object_set_data_full(G_OBJECT(replace_dlg.dialog), "entry_replace",
 		g_object_ref(entry_replace), (GDestroyNotify)g_object_unref);
+	replace_dlg.replace_entry = GTK_BIN(entry_replace)->child;
 
 	g_signal_connect(gtk_bin_get_child(GTK_BIN(entry_find)),
 			"key-press-event", G_CALLBACK(on_widget_key_pressed_set_focus),
@@ -629,6 +636,8 @@
 		/* only set selection if the dialog is not already visible */
 		if (! GTK_WIDGET_VISIBLE(replace_dlg.dialog) && sel)
 			gtk_entry_set_text(GTK_ENTRY(replace_dlg.find_entry), sel);
+		if (sel != NULL) /* when we have a selection, reset the entry widget's background colour */
+			ui_set_search_entry_background(replace_dlg.find_entry, TRUE);
 		gtk_widget_grab_focus(replace_dlg.find_entry);
 		gtk_widget_show(replace_dlg.dialog);
 		/* bring the dialog back in the foreground in case it is already open but the focus is away */
@@ -1019,7 +1028,7 @@
 			(search_replace_escape && ! utils_str_replace_escape(search_data.text)))
 		{
 			utils_beep();
-			gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(ui_lookup_widget(find_dlg.dialog, "entry"))->child));
+			gtk_widget_grab_focus(find_dlg.entry);
 			return;
 		}
 
@@ -1031,13 +1040,15 @@
 		{
 			case GEANY_RESPONSE_FIND:
 			case GEANY_RESPONSE_FIND_PREVIOUS:
-				document_find_text(doc, search_data.text, search_data.flags,
+			{
+				gint result = document_find_text(doc, search_data.text, search_data.flags,
 					(response == GEANY_RESPONSE_FIND_PREVIOUS), TRUE, GTK_WIDGET(find_dlg.dialog));
+				ui_set_search_entry_background(find_dlg.entry, (result > -1));
 				check_close = FALSE;
 				if (search_prefs.suppress_dialogs)
 					check_close = TRUE;
 				break;
-
+			}
 			case GEANY_RESPONSE_FIND_IN_FILE:
 				search_find_usage(search_data.text, search_data.flags, FALSE);
 				break;
@@ -1077,8 +1088,6 @@
 on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
 {
 	GeanyDocument *doc = document_get_current();
-	GtkWidget *entry_find = ui_lookup_widget(GTK_WIDGET(replace_dlg.dialog), "entry_find");
-	GtkWidget *entry_replace = ui_lookup_widget(GTK_WIDGET(replace_dlg.dialog), "entry_replace");
 	gint search_flags_re;
 	gboolean search_backwards_re, search_replace_escape_re;
 	gboolean close_window;
@@ -1096,8 +1105,8 @@
 				ui_lookup_widget(GTK_WIDGET(replace_dlg.dialog), "check_back")));
 	search_replace_escape_re = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
 				ui_lookup_widget(GTK_WIDGET(replace_dlg.dialog), "check_escape")));
-	find = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_find)))));
-	replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry_replace)))));
+	find = g_strdup(gtk_entry_get_text(GTK_ENTRY(replace_dlg.find_entry)));
+	replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(replace_dlg.replace_entry)));
 
 	search_flags_re = get_search_flags(replace_dlg.dialog);
 
@@ -1105,18 +1114,20 @@
 		&& (strcmp(find, replace) == 0))
 	{
 		utils_beep();
-		gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(ui_lookup_widget(replace_dlg.dialog, "entry_find"))->child));
+		gtk_widget_grab_focus(replace_dlg.find_entry);
 		return;
 	}
 
-	ui_combo_box_add_to_history(GTK_COMBO_BOX(entry_find), find);
-	ui_combo_box_add_to_history(GTK_COMBO_BOX(entry_replace), replace);
+	ui_combo_box_add_to_history(GTK_COMBO_BOX(
+		gtk_widget_get_parent(replace_dlg.find_entry)), find);
+	ui_combo_box_add_to_history(GTK_COMBO_BOX(
+		gtk_widget_get_parent(replace_dlg.replace_entry)), replace);
 
 	if (search_replace_escape_re &&
 		(! utils_str_replace_escape(find) || ! utils_str_replace_escape(replace)))
 	{
 		utils_beep();
-		gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(ui_lookup_widget(replace_dlg.dialog, "entry_find"))->child));
+		gtk_widget_grab_focus(replace_dlg.find_entry);
 		return;
 	}
 
@@ -1139,8 +1150,9 @@
 		}
 		case GEANY_RESPONSE_FIND:
 		{
-			document_find_text(doc, find, search_flags_re, search_backwards_re, TRUE,
-							   GTK_WIDGET(dialog));
+			gint result = document_find_text(doc, find, search_flags_re,
+								search_backwards_re, TRUE, GTK_WIDGET(dialog));
+			ui_set_search_entry_background(replace_dlg.find_entry, (result > -1));
 			break;
 		}
 		case GEANY_RESPONSE_REPLACE_IN_FILE:

Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c	2009-02-26 23:11:06 UTC (rev 3604)
+++ trunk/src/ui_utils.c	2009-02-27 14:05:50 UTC (rev 3605)
@@ -811,6 +811,25 @@
 }
 
 
+void ui_set_search_entry_background(GtkWidget *widget, gboolean success)
+{
+	static const GdkColor red   = {0, 0xffff, 0x6666, 0x6666};
+	static const GdkColor white = {0, 0xffff, 0xffff, 0xffff};
+	static gboolean old_value = TRUE;
+
+	g_return_if_fail(widget != NULL);
+
+	/* update only if really needed */
+	if (old_value != success)
+	{
+		gtk_widget_modify_base(widget, GTK_STATE_NORMAL, success ? NULL : &red);
+		gtk_widget_modify_text(widget, GTK_STATE_NORMAL, success ? NULL : &white);
+
+		old_value = success;
+	}
+}
+
+
 /* Note: remember to unref the pixbuf once an image or window has added a reference. */
 GdkPixbuf *ui_new_pixbuf_from_inline(gint img)
 {

Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h	2009-02-26 23:11:06 UTC (rev 3604)
+++ trunk/src/ui_utils.h	2009-02-27 14:05:50 UTC (rev 3605)
@@ -244,6 +244,7 @@
 
 void ui_document_show_hide(GeanyDocument *doc);
 
+void ui_set_search_entry_background(GtkWidget *widget, gboolean success);
 
 
 GdkPixbuf *ui_new_pixbuf_from_inline(gint img);


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