SF.net SVN: geany: [1687] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Mon Jul 9 17:33:31 UTC 2007


Revision: 1687
          http://svn.sourceforge.net/geany/?rev=1687&view=rev
Author:   eht16
Date:     2007-07-09 10:33:31 -0700 (Mon, 09 Jul 2007)

Log Message:
-----------
Change the background colour of the search bar in the toolbar according to the search result.

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-07-09 16:01:23 UTC (rev 1686)
+++ trunk/ChangeLog	2007-07-09 17:33:31 UTC (rev 1687)
@@ -13,6 +13,9 @@
    Use only supported symbol types in the symbol view for PHP.
  * src/treeviews.c: Focus the editor widget after switching between
                     files with the open files list.
+ * src/callbacks.c, src/document.c, src/document.h:
+   Change the background colour of the search bar in the toolbar
+   according to the search result.
 
 
 2007-07-08  Enrico Tröger  <enrico.troeger at uvena.de>

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2007-07-09 16:01:23 UTC (rev 1686)
+++ trunk/src/callbacks.c	2007-07-09 17:33:31 UTC (rev 1687)
@@ -566,6 +566,23 @@
 }
 
 
+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;
+
+	// only update 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;
+	}
+}
+
+
 // store text, clear search flags so we can use Search->Find Next/Previous
 static void setup_find_next(GtkEditable *editable)
 {
@@ -582,9 +599,11 @@
                                         gpointer         user_data)
 {
 	gint idx = document_get_cur_idx();
+	gboolean result;
 
 	setup_find_next(GTK_EDITABLE(entry));
-	document_search_bar_find(idx, search_data.text, 0, FALSE);
+	result = document_search_bar_find(idx, search_data.text, 0, FALSE);
+	set_search_bar_background(GTK_WIDGET(entry), result);
 }
 
 
@@ -594,9 +613,11 @@
                                         gpointer         user_data)
 {
 	gint idx = document_get_cur_idx();
+	gboolean result;
 
 	setup_find_next(editable);
-	document_search_bar_find(idx, search_data.text, 0, TRUE);
+	result = document_search_bar_find(idx, search_data.text, 0, TRUE);
+	set_search_bar_background(GTK_WIDGET(editable), result);
 }
 
 
@@ -607,10 +628,12 @@
 {
 	//on_entry1_changed(NULL, NULL);
 	gint idx = document_get_cur_idx();
+	gboolean result;
 	GtkWidget *entry = lookup_widget(GTK_WIDGET(app->window), "entry1");
 
 	setup_find_next(GTK_EDITABLE(entry));
-	document_search_bar_find(idx, search_data.text, 0, FALSE);
+	result = document_search_bar_find(idx, search_data.text, 0, FALSE);
+	set_search_bar_background(entry, result);
 }
 
 

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2007-07-09 16:01:23 UTC (rev 1686)
+++ trunk/src/document.c	2007-07-09 17:33:31 UTC (rev 1687)
@@ -1113,14 +1113,19 @@
 }
 
 
-/* special search function, used from the find entry in the toolbar */
-void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc)
+/* special search function, used from the find entry in the toolbar
+ * return TRUE if text was found otherwise FALSE
+ * return also TRUE if text is empty  */
+gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc)
 {
 	gint start_pos, search_pos;
 	struct TextToFind ttf;
 
-	g_return_if_fail(text != NULL);
-	if (! DOC_IDX_VALID(idx) || ! *text) return;
+	g_return_val_if_fail(text != NULL, FALSE);
+	if (! DOC_IDX_VALID(idx))
+		return FALSE;
+	if (! *text)
+		return TRUE;
 
 	start_pos = (inc) ? sci_get_selection_start(doc_list[idx].sci) :
 		sci_get_selection_end(doc_list[idx].sci);	// equal if no selection
@@ -1144,6 +1149,7 @@
 		sci_set_selection_start(doc_list[idx].sci, ttf.chrgText.cpMin);
 		sci_set_selection_end(doc_list[idx].sci, ttf.chrgText.cpMax);
 		doc_list[idx].scroll_percent = 0.3F;
+		return TRUE;
 	}
 	else
 	{
@@ -1153,6 +1159,7 @@
 		}
 		utils_beep();
 		sci_goto_pos(doc_list[idx].sci, start_pos, FALSE);	// clear selection
+		return FALSE;
 	}
 }
 

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2007-07-09 16:01:23 UTC (rev 1686)
+++ trunk/src/document.h	2007-07-09 17:33:31 UTC (rev 1687)
@@ -160,8 +160,7 @@
  * It returns whether the file could be saved or not. */
 gboolean document_save_file(gint idx, gboolean force);
 
-/* special search function, used from the find entry in the toolbar */
-void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
+gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
 
 /* General search function, used from the find dialog.
  * Returns -1 on failure or the start position of the matching text. */


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