pidgin: 1a1746f0: history-search action for text-entries.

sadrul at pidgin.im sadrul at pidgin.im
Fri Apr 2 17:00:54 EDT 2010


-----------------------------------------------------------------
Revision: 1a1746f06141d503935b2b6b46108d5119b96915
Ancestor: 41bf911ac5453f6aa1050d8a72b4ea476ba688cc
Author: sadrul at pidgin.im
Date: 2010-04-02T21:01:42
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/1a1746f06141d503935b2b6b46108d5119b96915

Modified files:
        ChangeLog doc/finch.1.in finch/libgnt/gntentry.c
        finch/libgnt/gntentry.h

ChangeLog: 

history-search action for text-entries.

-------------- next part --------------
============================================================
--- ChangeLog	350172c2dfed85478072298a6847b7996c2ff50a
+++ ChangeLog	0a853882a9f0ff250e5c434abc0bd0d2780216d8
@@ -81,6 +81,10 @@ version 2.7.0 (??/??/????):
 	* Retrieve the pager server address from Yahoo!'s servers directly.
 	* Removed the "Pager server" account option, as it is no longer needed.
 
+	Finch:
+	* New action 'history-search', with default binding ctrl+r, to search
+	  the entered string in the input history.
+
 version 2.6.6 (02/18/2010):
 	libpurple:
 	* Fix 'make check' on OS X. (David Fang)
============================================================
--- doc/finch.1.in	d782b05ee1a44e5e415a10e75d94921f2d9a2d34
+++ doc/finch.1.in	916937ed475157200611774d4a04afcd84d666af
@@ -348,6 +348,16 @@ c-v = clipboard-paste
 a-d = delete-next-word
 .br
 c-v = clipboard-paste
+.br
+c-p = history-prev
+.br
+c-n = history-next
+.br
+c-r = history-search
+.br
+c-up = history-prev
+.br
+c-down = history-next
 
 .br
 [GntTree::binding]
============================================================
--- finch/libgnt/gntentry.c	aab15984d2897e625531f155b67623568e1446bc
+++ finch/libgnt/gntentry.c	957093af6c1454c2bf4e1eb4d292c1ccdbf5e22c
@@ -55,6 +55,11 @@ struct _GntEntryKillRing
 	GntEntryAction last;
 };
 
+struct _GntEntrySearch
+{
+	char *needle;
+};
+
 static guint signals[SIGS] = { 0 };
 
 static GntWidgetClass *parent_class = NULL;
@@ -471,6 +476,55 @@ static gboolean
 }
 
 static gboolean
+history_search(GntBindable *bind, GList *null)
+{
+	GntEntry *entry = GNT_ENTRY(bind);
+	GList *iter;
+	const char *current , *pos;
+	int len;
+	
+	if (entry->history->prev && entry->search->needle)
+		current = entry->search->needle;
+	else
+		current = gnt_entry_get_text(entry);
+
+	if (!entry->histlength || !entry->history->next || !*current)
+		return FALSE;
+
+	len = g_utf8_strlen(current, -1);
+
+	for (iter = entry->history->next; iter; iter = iter->next) {
+		const char *str = iter->data;
+		/* A more utf8-friendly version of strstr would have been better, but
+		 * for now, this will have to do. */
+		if ((pos = strstr(str, current)))
+			break;
+	}
+
+	if (!iter)
+		return TRUE;
+
+	if (entry->history->prev == NULL) {
+		/* We are doing it for the first time. Save the current contents */
+		char *text = g_strdup(gnt_entry_get_text(entry));
+
+		g_free(entry->search->needle);
+		entry->search->needle = g_strdup(current);
+
+		g_free(entry->history->data);
+		entry->history->data = text;
+	}
+
+	entry->history = iter;
+	gnt_entry_set_text_internal(entry, entry->history->data);
+	destroy_suggest(entry);
+	entry_text_changed(entry);
+
+	update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
+	return TRUE;
+}
+
+static gboolean
 clipboard_paste(GntBindable *bind, GList *n)
 {
 	GntEntry *entry = GNT_ENTRY(bind);
@@ -833,6 +887,9 @@ gnt_entry_destroy(GntWidget *widget)
 		gnt_widget_destroy(entry->ddown->parent);
 	}
 
+	g_free(entry->search->needle);
+	g_free(entry->search);
+
 	jail_killring(entry->killring);
 }
 
@@ -935,6 +992,8 @@ gnt_entry_class_init(GntEntryClass *klas
 				GNT_KEY_CTRL_UP, NULL);
 	gnt_bindable_register_binding(bindable, "history-prev", GNT_KEY_CTRL_P, NULL);
 	gnt_bindable_register_binding(bindable, "history-next", GNT_KEY_CTRL_N, NULL);
+	gnt_bindable_class_register_action(bindable, "history-search", history_search,
+				GNT_KEY_CTRL_R, NULL);
 	gnt_bindable_class_register_action(bindable, "clipboard-paste", clipboard_paste,
 				GNT_KEY_CTRL_V, NULL);
 
@@ -966,6 +1025,7 @@ gnt_entry_init(GTypeInstance *instance, 
 	entry->always = FALSE;
 	entry->suggests = NULL;
 	entry->killring = new_killring();
+	entry->search = g_new0(GntEntrySearch, 1);
 
 	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(entry),
 			GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW | GNT_WIDGET_CAN_TAKE_FOCUS);
============================================================
--- finch/libgnt/gntentry.h	4be38f89219eec94a088a7993c20eafaf2ae46ae
+++ finch/libgnt/gntentry.h	6be322aa877c064c4eab659b26306587046ddfcc
@@ -49,6 +49,7 @@ typedef struct _GntEntryKillRing    GntE
 typedef struct _GntEntryPriv		GntEntryPriv;
 typedef struct _GntEntryClass	GntEntryClass;
 typedef struct _GntEntryKillRing    GntEntryKillRing;
+typedef struct _GntEntrySearch		GntEntrySearch;
 
 typedef enum
 {
@@ -86,6 +87,7 @@ struct _GntEntry
 	gboolean always;    /* Should the list of suggestions show at all times, or only on tab-press? */
 	GntWidget *ddown;   /* The dropdown with the suggested list */
 	GntEntryKillRing *killring; /**< @since 2.3.0 */
+	GntEntrySearch *search;		/**< @since 2.7.0 */
 };
 
 struct _GntEntryClass


More information about the Commits mailing list