|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Input History PatchHi all,
Here's a small patch that adds support for input history to gmud. The keys are bound to Up and Down for the moment. It works something like a shell in as much as you hit the up key to go back through the input history and down to go forward through it. Les [gmud_input_history.diff] Index: src/mud-connection-view.c =================================================================== --- src/mud-connection-view.c (revision 662) +++ src/mud-connection-view.c (working copy) @@ -24,6 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> #include <gtk/gtkmenu.h> +#include <glib/gqueue.h> #include <vte/vte.h> #include "gnome-mud.h" @@ -60,6 +61,9 @@ gchar *connect_string; MudParseBase *parse; + + GQueue *history; + guint current_history_index; }; static void mud_connection_view_init (MudConnectionView *connection_view); @@ -300,10 +304,13 @@ mud_connection_view_init (MudConnectionView *connection_view) { GtkWidget *box; - + connection_view->priv = g_new0(MudConnectionViewPrivate, 1); //FIXME connection_view->priv->prefs = mud_preferences_new(NULL); + connection_view->priv->history = g_queue_new(); + connection_view->priv->current_history_index = 0; + connection_view->priv->parse = mud_parse_base_new(connection_view); connection_view->priv->connect_hook = FALSE; @@ -354,13 +361,21 @@ { MudConnectionView *connection_view; GObjectClass *parent_class; + gchar *history_item; connection_view = MUD_CONNECTION_VIEW(object); + while((history_item = (gchar *)g_queue_pop_head(connection_view->priv->history)) != NULL) + if(history_item != NULL) + g_free(history_item); + + if(connection_view->priv->history) + g_queue_free(connection_view->priv->history); + gnetwork_connection_close(GNETWORK_CONNECTION(connection_view->connection)); g_object_unref(connection_view->connection); g_free(connection_view->priv); - + parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object)); parent_class->finalize(object); } @@ -486,6 +501,9 @@ GList *commands, *command; gchar *text; + g_queue_push_head(view->priv->history, (gpointer)g_strdup(data)); + view->priv->current_history_index = 0; + commands = mud_profile_process_commands(view->priv->profile, data); for (command = g_list_first(commands); command != NULL; command = command->next) @@ -796,3 +814,24 @@ { return view->priv->parse; } + +gchar * +mud_connection_view_get_history_item(MudConnectionView *view, enum +MudConnectionHistoryDirection direction) +{ + gchar *history_item; + + if(direction == HISTORY_DOWN) + if(view->priv->current_history_index != 0) + view->priv->current_history_index--; + + history_item = (gchar *)g_queue_peek_nth(view->priv->history, + view->priv->current_history_index); + + if(direction == HISTORY_UP) + if(view->priv->current_history_index < + g_queue_get_length(view->priv->history) - 1) + view->priv->current_history_index++; + + return history_item; +} Index: src/mud-connection-view.h =================================================================== --- src/mud-connection-view.h (revision 662) +++ src/mud-connection-view.h (working copy) @@ -40,6 +40,12 @@ System }; +enum MudConnectionHistoryDirection +{ + HISTORY_UP, + HISTORY_DOWN +}; + GType mud_connection_view_get_type (void) G_GNUC_CONST; MudConnectionView* mud_connection_view_new (const gchar *profile, const gchar *hostname, const gint port, GtkWidget *window, GtkWidget *tray, gchar *name); @@ -51,6 +57,8 @@ void mud_connection_view_set_connect_string(MudConnectionView *view, gchar *connect_string); void mud_connection_view_set_id(MudConnectionView *view, gint id); void mud_connection_view_add_text(MudConnectionView *view, gchar *message, enum MudConnectionColorType type); +gchar *mud_connection_view_get_history_item(MudConnectionView *view, enum +MudConnectionHistoryDirection direction); #include "mud-profile.h" void mud_connection_view_set_profile(MudConnectionView *view, MudProfile *profile); Index: src/mud-window.c =================================================================== --- src/mud-window.c (revision 662) +++ src/mud-window.c (working copy) @@ -275,10 +275,34 @@ else gtk_text_buffer_select_range(buffer, &start, &end); - free(text); + g_free(text); return TRUE; } + + if(event->keyval == GDK_Up) + { + text = mud_connection_view_get_history_item( + MUD_CONNECTION_VIEW(window->priv->current_view), HISTORY_UP); + + gtk_text_buffer_set_text(buffer, text, strlen(text)); + gtk_text_buffer_get_bounds(buffer, &start, &end); + gtk_text_buffer_select_range(buffer, &start, &end); + + return TRUE; + } + + if(event->keyval == GDK_Down) + { + text = mud_connection_view_get_history_item( + MUD_CONNECTION_VIEW(window->priv->current_view), HISTORY_DOWN); + + gtk_text_buffer_set_text(buffer, text, strlen(text)); + gtk_text_buffer_get_bounds(buffer, &start, &end); + gtk_text_buffer_select_range(buffer, &start, &end); + + return TRUE; + } return FALSE; } Index: ChangeLog =================================================================== --- ChangeLog (revision 662) +++ ChangeLog (working copy) @@ -1,3 +1,7 @@ +2008-06-17 Les Harris <me@...> + * src/mud-window.c, src/mud-connection-view.c, src/mud-connection-view.h: + Added in input history support for our text entry widget. + 2007-07-13 Jordi Mallach <jordi@...> * configure.ac, Makefile.am: Prepare for icon changes. Index: MAINTAINERS =================================================================== --- MAINTAINERS (revision 662) +++ MAINTAINERS (working copy) @@ -8,7 +8,7 @@ Email: seven-nation@... Les Harris -Email: lescom@... +Email: me@... Mart Raudsepp Email: leio@... _______________________________________________ gnome-mud-list mailing list gnome-mud-list@... http://mail.gnome.org/mailman/listinfo/gnome-mud-list |
|
|
Re: Input History PatchWoa!
On Tue, Jun 17, 2008 at 11:58:34PM -0700, Les Harris wrote: > Here's a small patch that adds support for input history to gmud. Definitely looks useful. > The keys are bound to Up and Down for the moment. It works something > like a shell in as much as you hit the up key to go back through the > input history and down to go forward through it. I think up and down are the expected keybinds. But anyway, wth! You came back, welcome! -- Jordi Mallach Pérez -- Debian developer http://www.debian.org/ jordi@... jordi@... http://www.sindominio.net/ GnuPG public key information available at http://oskuro.net/ _______________________________________________ gnome-mud-list mailing list gnome-mud-list@... http://mail.gnome.org/mailman/listinfo/gnome-mud-list |
| Free embeddable forum powered by Nabble | Forum Help |