|
sorry, one more update, this one set the clist row focus properly, and fixed a string length bug. cheers Qianqian On 03/22/2010 05:12 PM, Qianqian Fang wrote: hi |
Index: gftp-gtk.c
===================================================================
--- gftp-gtk.c (revision 995)
+++ gftp-gtk.c (working copy)
@@ -302,7 +302,7 @@
{N_("/Local/_Delete..."), "<control><shift>D", delete_dialog, 0,
MN_(NULL)},
{N_("/Local/_Edit..."), "<control><shift>E", edit_dialog, 0, MN_(NULL)},
- {N_("/Local/_View..."), "<control><shift>V", view_dialog, 0, MN_(NULL)},
+ {N_("/Local/_View..."), "<control><shift>L", view_dialog, 0, MN_(NULL)},
{N_("/Local/_Refresh"), "<control><shift>R", gftp_gtk_refresh, 0,
MS_(GTK_STOCK_REFRESH)},
{N_("/_Remote"), NULL, 0, 0, MN_("<Branch>")},
@@ -329,7 +329,7 @@
MN_(NULL)},
{N_("/Remote/_Delete..."), "<control>D", delete_dialog, 0, MN_(NULL)},
{N_("/Remote/_Edit..."), "<control>E", edit_dialog, 0, MN_(NULL)},
- {N_("/Remote/_View..."), "<control>V", view_dialog, 0, MN_(NULL)},
+ {N_("/Remote/_View..."), "<control>L", view_dialog, 0, MN_(NULL)},
{N_("/Remote/_Refresh"), "<control>R", gftp_gtk_refresh, 0,
MS_(GTK_STOCK_REFRESH)},
{N_("/_Bookmarks"), NULL, 0, 0, MN_("<Branch>")},
@@ -353,7 +353,7 @@
MS_(GTK_STOCK_GO_DOWN)},
{N_("/Transfer/sep"), NULL, 0, 0, MN_("<Separator>")},
{N_("/Transfer/_Retrieve Files"), "<control>R", get_files, 0, MN_(NULL)},
- {N_("/Transfer/_Put Files"), "<control>P", put_files, 0, MN_(NULL)},
+ {N_("/Transfer/_Put Files"), "<control>U", put_files, 0, MN_(NULL)},
{N_("/L_og"), NULL, 0, 0, MN_("<Branch>")},
{N_("/Log/tearoff"), NULL, 0, 0, MN_("<Tearoff>")},
{N_("/Log/_Clear"), NULL, clearlog, 0, MS_(GTK_STOCK_CLEAR)},
@@ -730,6 +730,52 @@
list_doaction (wdata);
return (FALSE);
}
+ else
+ { /*simple type-ahead support in the file listbox - Qianqian Fang 03/08/2010 */
+ int i;
+ static gint typeaheadtime=0;
+ static gchar typeaheadbuf[GFTP_TYPEAHEAD_BUF_LEN]={'\0'};
+ gchar *text;
+ GtkWidget * lbox=GTK_CLIST ((wdata)->listbox);
+ gint startpos=0, rowcount=GTK_CLIST(lbox)->rows;
+
+ if(GTK_CLIST(lbox)->selection) /*search starts from the selected item*/
+ startpos=GPOINTER_TO_INT(GTK_CLIST(lbox)->selection->data)+1;
+
+ if (strlen(gdk_keyval_name(event->keyval))==1) /*only simple keys*/
+ {
+ if(event->time-typeaheadtime>GFTP_TYPEAHEAD_MAX_WAIT)
+ {
+ strcpy(typeaheadbuf,gdk_keyval_name(event->keyval));
+ typeaheadtime=event->time;
+ }
+ else
+ {
+ if(strlen(typeaheadbuf)+strlen(gdk_keyval_name(event->keyval))<GFTP_TYPEAHEAD_BUF_LEN)
+ strcpy(typeaheadbuf+strlen(typeaheadbuf),gdk_keyval_name(event->keyval));
+ if(GTK_CLIST(lbox)->selection) /*search starts from the selected item*/
+ startpos=GPOINTER_TO_INT(GTK_CLIST(lbox)->selection->data);
+ }
+ typeaheadtime=event->time;
+
+ for(i=0;i<rowcount;i++)
+ {
+ int idx=(i+startpos)%rowcount; /*wrap around and search the entire list*/
+ gtk_clist_get_text (GTK_CLIST(lbox),idx,1,&text);
+ if(strstr(text,typeaheadbuf)==text)/*match string beginning*/
+ {
+ gtk_clist_unselect_all (GTK_CLIST(lbox));
+ gtk_clist_select_row(GTK_CLIST(lbox),idx,1);
+ GTK_CLIST(lbox)->focus_row=idx;
+ if (gtk_clist_row_is_visible(GTK_CLIST(lbox),idx) == GTK_VISIBILITY_NONE)
+ gtk_clist_moveto(GTK_CLIST(lbox),idx, -1, 0.5, 0);
+
+ /*g_print("row=%d %d %s %s\n",idx,i,text,gdk_keyval_name(event->keyval));*/
+ break;
+ }
+ }
+ }
+ }
return (TRUE);
}
Index: gftp-gtk.h
===================================================================
--- gftp-gtk.h (revision 995)
+++ gftp-gtk.h (working copy)
@@ -33,6 +33,9 @@
#define GFTP_MENU_ITEM_WIN1 3
#define GFTP_MENU_ITEM_WIN2 4
+#define GFTP_TYPEAHEAD_BUF_LEN 32
+#define GFTP_TYPEAHEAD_MAX_WAIT 500 /*wait for 0.5 second*/
+
#define IS_ONE_SELECTED(wdata) (GTK_CLIST ((wdata)->listbox)->selection && GTK_CLIST ((wdata)->listbox)->selection->next == NULL)
#define IS_NONE_SELECTED(wdata) (GTK_CLIST ((wdata)->listbox)->selection == NULL)
#define gftp_gtk_get_list_selection(wdata) (GTK_CLIST ((wdata)->listbox)->selection)