Code

list_window: Added new function, which finds the beginning of a string
authorPatrick Hallen <patrick.hallen@rwth-aachen.de>
Wed, 11 Feb 2009 19:07:03 +0000 (20:07 +0100)
committerPatrick Hallen <patrick.hallen@rwth-aachen.de>
Wed, 11 Feb 2009 19:07:03 +0000 (20:07 +0100)
Added a new function which finds a string in a listwindow which begins with
the given characters.

src/list_window.c
src/list_window.h

index 688ae8bd70600ced1c53c0fac83e6144e7143b8d..4cd9a8f6009c241d2ee56700b4f4fbd24b8aeef0 100644 (file)
@@ -321,6 +321,41 @@ list_window_rfind(struct list_window *lw,
        return false;
 }
 
+bool
+list_window_jump(struct list_window *lw,
+                list_window_callback_fn_t callback,
+                void *callback_data,
+                const char *str)
+{
+       bool h;
+       unsigned i = 0;
+       const char *label;
+
+       while ((label = callback(i,&h,callback_data))) {
+               if (label && label[0] != '[')
+               {
+                       if (str && label && g_ascii_strncasecmp(label, str, strlen(str)) == 0) {
+                               lw->selected = i;
+                               if(!lw->visual_selection || i > lw->selected_end)
+                                         lw->selected_end = i;
+                               if(!lw->visual_selection || i < lw->selected_start)
+                                         lw->selected_start = i;
+                               return true;
+                       }
+               }
+               else if (str && label && g_ascii_strncasecmp(label+1, str, strlen(str)) == 0) {
+                               lw->selected = i;
+                               if(!lw->visual_selection || i > lw->selected_end)
+                                         lw->selected_end = i;
+                               if(!lw->visual_selection || i < lw->selected_start)
+                                         lw->selected_start = i;
+                               return true;
+                       }
+               i++;
+       }
+       return false;
+}
+
 /* perform basic list window commands (movement) */
 bool
 list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
index e996039a739f4457356614aa634654888437a78a..fd087bbc34457de3a9a8d47980ded9ddabad5a28 100644 (file)
@@ -114,4 +114,11 @@ list_window_rfind(struct list_window *lw,
                  bool bell_on_wrap,
                  unsigned rows);
 
+/* find a string in a list window which begins with the given characters in *str */
+bool
+list_window_jump(struct list_window *lw,
+                list_window_callback_fn_t callback,
+                void *callback_data,
+                const char *str);
+
 #endif