[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[gftp] Re: patch for type-ahead searching



hi

I would like to submit an improved version of the
type-ahead patch and a patch for shortcuts.

The improved type-ahead patch now support
more than 1 keys (as long as the next key is
typed within 0.5 second).

For the shortcuts, gftp 0.2.19 uses Ctrl+V for
view file in remote, this is annoying because you
can not copy/paste with Ctrl+C/V. So, I changed
it to Ctrl+L. Also, gftp has duplicated shortcuts
for Ctrl+P, for "Permissions ..." and "Put files", I
change the later one to Ctrl+U (for "Upload").

the combined patch as "svn diff" output is attached.

Qianqian


On 03/17/2010 05:08 PM, Qianqian Fang wrote:
hi list

the following is a message I sent earlier to Brian
to share a patch I wrote for type-ahead file searching.
I haven't heard back from him and not sure if he is
still maintaining the project. Today I worked on this
a little bit more and it now accepts more than one keys.
I attached my patch in form of "svn diff" under the
src/gtk directory.

Can someone review&test it and see if there is any issue
to add this to the upstream? I hope this will be useful to
other people.

please let me know, thanks.

Qianqian

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,51 @@
       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)<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);
+	      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)