diff -r -u freeciv/client/gui-gtk/chatline.c freeciv-new/client/gui-gtk/chatline.c --- freeciv/client/gui-gtk/chatline.c Mon Apr 23 10:32:55 2001 +++ freeciv-new/client/gui-gtk/chatline.c Fri Jun 15 09:58:21 2001 @@ -35,13 +35,34 @@ void inputline_return(GtkWidget *w, gpointer data) { struct packet_generic_message apacket; - char *theinput; - + char *theinput, *buffer; + GList *cache; + int *newindex; theinput = gtk_entry_get_text(GTK_ENTRY(w)); + /* get the cache */ + cache = gtk_object_get_data( GTK_OBJECT(w), "cache"); - if(GTK_WIDGET_IS_SENSITIVE(top_vbox) && *theinput) { + if(GTK_WIDGET_IS_SENSITIVE(top_vbox) && *theinput) { mystrlcpy(apacket.message, theinput, MAX_LEN_MSG-MAX_LEN_USERNAME+1); send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket); + + /* add to the cache */ + buffer = fc_malloc( strlen(theinput) + 1); + newindex = gtk_object_get_data( GTK_OBJECT(w), "cache_current" ); + strcpy(buffer,theinput); + cache = g_list_prepend(cache, buffer); + /* don't save more than 20 messages */ + if( g_list_length(cache) > 20 ) { + char *data = g_list_last(cache)->data; + cache = g_list_remove( cache, g_list_last(cache)->data ); + printf("removing '%s'\n", data); + if(data) free(data); + } + /* save the list again (in case the pointer changed */ + (*newindex) = -1; + gtk_object_set_data (GTK_OBJECT(w), "cache", cache); + gtk_object_set_data (GTK_OBJECT(w), "cache_current", newindex ); + } gtk_entry_set_text(GTK_ENTRY(w), ""); diff -r -u freeciv/client/gui-gtk/gui_main.c freeciv-new/client/gui-gtk/gui_main.c --- freeciv/client/gui-gtk/gui_main.c Mon Apr 23 10:32:56 2001 +++ freeciv-new/client/gui-gtk/gui_main.c Fri Jun 15 13:14:08 2001 @@ -119,6 +119,7 @@ GtkWidget * unit_info_label, *unit_info_frame; GtkWidget * text_scrollbar; GtkWidget * inputline; +int inputline_cache = -1; GtkWidget * map_horizontal_scrollbar, *map_vertical_scrollbar; gint gdk_input_id; @@ -170,8 +171,38 @@ **************************************************************************/ static gint keyboard_handler(GtkWidget *widget, GdkEventKey *event) { - if (GTK_WIDGET_HAS_FOCUS(inputline) || !GTK_WIDGET_IS_SENSITIVE(top_vbox)) - return FALSE; + int *cache_index; + GList *cache = gtk_object_get_data( GTK_OBJECT(inputline), "cache" ); + + cache_index = gtk_object_get_data( GTK_OBJECT(inputline), "cache_current"); + + if (GTK_WIDGET_HAS_FOCUS(inputline) || !GTK_WIDGET_IS_SENSITIVE(top_vbox)) { + /* handle the up-arrow keypress to display history */ + if( event->keyval == GDK_Up ) { + if( (g_list_length(cache) - 1) != (*cache_index) ) { + GList *item = g_list_nth(cache, ++(*cache_index) ); + gtk_entry_set_text( GTK_ENTRY(inputline), item->data ); + } + /* run the other signal handlers */ + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event"); + /* return TRUE to avoid the focus is lost (propagates to other widgets) */ + return TRUE; + } + + /* handle the down-arrow keypress to display history */ + if( event->keyval == GDK_Down ) { + if( *cache_index ) { + GList *item = g_list_nth(cache, --(*cache_index)); + gtk_entry_set_text( GTK_ENTRY(inputline), item->data ); + } + /* run the other signal handlers */ + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event"); + /* return TRUE to avoid the focus is lost (propagates to other widgets) */ + return TRUE; + } + + return FALSE; + } if (is_isometric) { switch (event->keyval) { @@ -618,6 +649,10 @@ /* the chat line */ inputline = gtk_entry_new(); gtk_box_pack_start( GTK_BOX( avbox ), inputline, FALSE, FALSE, 0 ); + gtk_object_set_data( GTK_OBJECT (inputline), "cache", + NULL ); + gtk_object_set_data( GTK_OBJECT (inputline), "cache_current", + &inputline_cache ); } gtk_signal_connect(GTK_OBJECT(toplevel), "key_press_event", GTK_SIGNAL_FUNC(keyboard_handler), NULL);