From: Patrick Hallen Date: Wed, 11 Feb 2009 19:07:03 +0000 (+0100) Subject: list_window: Added new function, which finds the beginning of a string X-Git-Tag: release-0.14~107 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2256978f32f961f18de696d15e77160be9414f53;p=ncmpc.git list_window: Added new function, which finds the beginning of a string Added a new function which finds a string in a listwindow which begins with the given characters. --- diff --git a/src/list_window.c b/src/list_window.c index 688ae8b..4cd9a8f 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -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) diff --git a/src/list_window.h b/src/list_window.h index e996039..fd087bb 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -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