Commit 9d759fed authored by Rafaël Carré's avatar Rafaël Carré

ncurses: don't erase search box content

split out open box function
parent e982db92
...@@ -206,7 +206,6 @@ struct intf_sys_t ...@@ -206,7 +206,6 @@ struct intf_sys_t
/* Search Box context */ /* Search Box context */
char search_chain[20]; char search_chain[20];
char *old_search;
int before_search; int before_search;
/* Open Box Context */ /* Open Box Context */
...@@ -1132,13 +1131,12 @@ static int DrawStatus(intf_thread_t *intf) ...@@ -1132,13 +1131,12 @@ static int DrawStatus(intf_thread_t *intf)
static void FillTextBox(intf_sys_t *sys) static void FillTextBox(intf_sys_t *sys)
{ {
int width = COLS - 2; int width = COLS - 2;
const char *title = sys->box_type == BOX_OPEN ? "Open: %s" : "Find: %s";
char *chain = sys->box_type == BOX_OPEN ? sys->open_chain :
sys->old_search ? sys->old_search :
sys->search_chain;
DrawEmptyLine(7, 1, width); DrawEmptyLine(7, 1, width);
mvnprintw(7, 1, width, _(title), chain); if (sys->box_type == BOX_OPEN)
mvnprintw(7, 1, width, _("Open: %s"), sys->open_chain);
else
mvnprintw(7, 1, width, _("Find: %s"), sys->search_chain);
} }
static void FillBox(intf_thread_t *intf) static void FillBox(intf_thread_t *intf)
...@@ -1441,34 +1439,12 @@ static bool HandleBrowseKey(intf_thread_t *intf, int key) ...@@ -1441,34 +1439,12 @@ static bool HandleBrowseKey(intf_thread_t *intf, int key)
return false; return false;
} }
static void HandleEditBoxKey(intf_thread_t *intf, int key, int box) static void OpenSelection(intf_thread_t *intf)
{ {
intf_sys_t *sys = intf->p_sys; intf_sys_t *sys = intf->p_sys;
bool search = box == BOX_SEARCH;
char *str = search ? sys->search_chain: sys->open_chain;
size_t len = strlen(str);
assert(box == BOX_SEARCH || box == BOX_OPEN);
switch(key)
{
case 0x0c: /* ^l */
case KEY_CLEAR: clear(); return;
case KEY_ENTER:
case '\r':
case '\n':
if (search) {
if (len)
sys->old_search = strdup(sys->search_chain);
else if (sys->old_search)
SearchPlaylist(sys, sys->old_search);
} else if (len) {
char *uri = make_URI(sys->open_chain, NULL); char *uri = make_URI(sys->open_chain, NULL);
if (uri == NULL) { if (uri == NULL)
sys->box_type = BOX_PLAYLIST;
return; return;
}
playlist_t *p_playlist = pl_Get(intf); playlist_t *p_playlist = pl_Get(intf);
vlc_mutex_lock(&sys->pl_lock); vlc_mutex_lock(&sys->pl_lock);
...@@ -1493,9 +1469,32 @@ static void HandleEditBoxKey(intf_thread_t *intf, int key, int box) ...@@ -1493,9 +1469,32 @@ static void HandleEditBoxKey(intf_thread_t *intf, int key, int box)
p_parent->p_input == p_playlist->p_local_onelevel->p_input, p_parent->p_input == p_playlist->p_local_onelevel->p_input,
false); false);
free(uri);
sys->plidx_follow = true; sys->plidx_follow = true;
} free(uri);
}
static void HandleEditBoxKey(intf_thread_t *intf, int key, int box)
{
intf_sys_t *sys = intf->p_sys;
bool search = box == BOX_SEARCH;
char *str = search ? sys->search_chain: sys->open_chain;
size_t len = strlen(str);
assert(box == BOX_SEARCH || box == BOX_OPEN);
switch(key)
{
case 0x0c: /* ^l */
case KEY_CLEAR: clear(); return;
case KEY_ENTER:
case '\r':
case '\n':
if (search)
SearchPlaylist(sys, sys->search_chain);
else
OpenSelection(intf);
sys->box_type = BOX_PLAYLIST; sys->box_type = BOX_PLAYLIST;
return; return;
...@@ -1534,11 +1533,8 @@ static void HandleEditBoxKey(intf_thread_t *intf, int key, int box) ...@@ -1534,11 +1533,8 @@ static void HandleEditBoxKey(intf_thread_t *intf, int key, int box)
} }
} }
if (search) { if (search)
free(sys->old_search);
sys->old_search = NULL;
SearchPlaylist(sys, str); SearchPlaylist(sys, str);
}
} }
static void InputNavigate(input_thread_t* p_input, const char *var) static void InputNavigate(input_thread_t* p_input, const char *var)
...@@ -1575,7 +1571,6 @@ static void HandleCommonKey(intf_thread_t *intf, int key) ...@@ -1575,7 +1571,6 @@ static void HandleCommonKey(intf_thread_t *intf, int key)
case 'S': BoxSwitch(sys, BOX_STATS); return; case 'S': BoxSwitch(sys, BOX_STATS); return;
case '/': /* Search */ case '/': /* Search */
sys->search_chain[0] = '\0';
sys->plidx_follow = false; sys->plidx_follow = false;
if (sys->box_type == BOX_PLAYLIST) { if (sys->box_type == BOX_PLAYLIST) {
sys->before_search = sys->box_idx; sys->before_search = sys->box_idx;
...@@ -1853,7 +1848,6 @@ static void Close(vlc_object_t *p_this) ...@@ -1853,7 +1848,6 @@ static void Close(vlc_object_t *p_this)
DirsDestroy(sys); DirsDestroy(sys);
free(sys->current_dir); free(sys->current_dir);
free(sys->old_search);
if (sys->p_input) if (sys->p_input)
vlc_object_release(sys->p_input); vlc_object_release(sys->p_input);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment