pidgin: fe97c224: Tab-completion for commands in finch.

sadrul at pidgin.im sadrul at pidgin.im
Wed Jul 2 20:00:42 EDT 2008


-----------------------------------------------------------------
Revision: fe97c224d861e94e493dd8d4e1fac8bcd91b0161
Ancestor: 2f8748670d99df0274b367a89aa1bdffbd814226
Author: sadrul at pidgin.im
Date: 2008-07-02T23:58:53
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/fe97c224d861e94e493dd8d4e1fac8bcd91b0161

Modified files:
        ChangeLog finch/gntconv.c

ChangeLog: 

Tab-completion for commands in finch.

-------------- next part --------------
============================================================
--- ChangeLog	5e65a99f7afacb25ec32c70bf49fe37e90a8d697
+++ ChangeLog	9f48dd31842c7136dbcfbc5f95dd5c1a8525fa84
@@ -16,7 +16,7 @@ version 2.5.0 (??/??/2008):
 	* Resize large incoming custom smileys to a maximum of 96px on either
 	  side.
 	* Offer to add new buddies into the same contact as existing buddies
-          in the same group if the alias given is the same.
+	  in the same group if the alias given is the same.
 
 	General:
 	* Group and Chat buddy list entries can now be given custom buddy
@@ -28,6 +28,7 @@ version 2.5.0 (??/??/2008):
 	  logs.
 	* Added '/msgcolor' command to change colors of different classes of
 	  messages in a conversation. See '/help msgcolor' for details.
+	* Added tab-completion for commands in conversation windows.
 
 version 2.4.3 (07/01/2008):
 	libpurple:
============================================================
--- finch/gntconv.c	326b123f8f33457266968a55c9857fba6ccff8ee
+++ finch/gntconv.c	0f03247f6d08305fd7bae0331f8d40039abbe95e
@@ -692,11 +692,48 @@ completion_cb(GntEntry *entry, const cha
 static void
 completion_cb(GntEntry *entry, const char *start, const char *end)
 {
-	if (start == entry->start)
+	if (start == entry->start && *start != '/')
 		gnt_widget_key_pressed(GNT_WIDGET(entry), ": ");
 }
 
 static void
+gg_setup_commands(FinchConv *fconv, gboolean remove_first)
+{
+	GList *commands;
+	char command[256] = "/";
+
+	if (remove_first) {
+		commands = purple_cmd_list(NULL);
+		for (; commands; commands = g_list_delete_link(commands, commands)) {
+			g_strlcpy(command + 1, commands->data, sizeof(command) - 1);
+			gnt_entry_remove_suggest(GNT_ENTRY(fconv->entry), command);
+		}
+	}
+
+	commands = purple_cmd_list(fconv->active_conv);
+	for (; commands; commands = g_list_delete_link(commands, commands)) {
+		g_strlcpy(command + 1, commands->data, sizeof(command) - 1);
+		gnt_entry_add_suggest(GNT_ENTRY(fconv->entry), command);
+	}
+}
+
+static void
+cmd_added_cb(const char *cmd, PurpleCmdPriority prior, PurpleCmdFlag flags,
+		FinchConv *fconv)
+{
+	gg_setup_commands(fconv, TRUE);
+}
+
+static void
+cmd_removed_cb(const char *cmd, FinchConv *fconv)
+{
+	char command[256] = "/";
+	g_strlcpy(command + 1, cmd, sizeof(command) - 1);
+	gnt_entry_remove_suggest(GNT_ENTRY(fconv->entry), command);
+	gg_setup_commands(fconv, TRUE);
+}
+
+static void
 finch_create_conversation(PurpleConversation *conv)
 {
 	FinchConv *ggc = FINCH_GET_DATA(conv);
@@ -819,7 +856,13 @@ finch_create_conversation(PurpleConversa
 		ggc->flags |= FINCH_CONV_NO_SOUND;
 
 	gg_create_menu(ggc);
+	gg_setup_commands(ggc, FALSE);
 
+	purple_signal_connect(purple_cmds_get_handle(), "cmd-added", ggc,
+			G_CALLBACK(cmd_added_cb), ggc);
+	purple_signal_connect(purple_cmds_get_handle(), "cmd-removed", ggc,
+			G_CALLBACK(cmd_removed_cb), ggc);
+
 	g_free(title);
 	gnt_box_give_focus_to_child(GNT_BOX(ggc->window), ggc->entry);
 	g_signal_connect(G_OBJECT(ggc->window), "gained-focus", G_CALLBACK(gained_focus_cb), ggc);
@@ -831,11 +874,14 @@ finch_destroy_conversation(PurpleConvers
 	/* do stuff here */
 	FinchConv *ggc = FINCH_GET_DATA(conv);
 	ggc->list = g_list_remove(ggc->list, conv);
-	if (ggc->list && conv == ggc->active_conv)
+	if (ggc->list && conv == ggc->active_conv) {
 		ggc->active_conv = ggc->list->data;
-	
+		gg_setup_commands(ggc, TRUE);
+	}
+
 	if (ggc->list == NULL) {
 		g_free(ggc->u.chat);
+		purple_signals_disconnect_by_handle(ggc);
 		if (ggc->window)
 			gnt_widget_destroy(ggc->window);
 		g_free(ggc);
@@ -1404,8 +1450,11 @@ void finch_conversation_set_active(Purpl
 
 	g_return_if_fail(ggconv);
 	g_return_if_fail(g_list_find(ggconv->list, conv));
+	if (ggconv->active_conv == conv)
+		return;
 
 	ggconv->active_conv = conv;
+	gg_setup_commands(ggconv, TRUE);
 	account = purple_conversation_get_account(conv);
 	title = get_conversation_title(conv, account);
 	gnt_screen_rename_widget(ggconv->window, title);


More information about the Commits mailing list