[listview] Optional don't show elements when not filtered (#1079)

This commit is contained in:
Dave Davenport 2022-04-20 13:06:14 +02:00
parent 9f0a8c9e36
commit 06a50910e7
3 changed files with 25 additions and 0 deletions

View File

@ -267,6 +267,13 @@ void listview_toggle_ellipsizing(listview *lv);
*/
void listview_set_ellipsize_start(listview *lv);
/**
* @param lv Handler to the listview object.
* @param filtered boolean indicating if list is filtered.
*
*/
void listview_set_filtered ( listview *lv, gboolean filtered );
/** @} */
#endif // ROFI_LISTVIEW_H

View File

@ -1119,6 +1119,8 @@ static void rofi_view_refilter(RofiViewState *state) {
}
TICK_N("Filter tokenize");
if (state->text && strlen(state->text->text) > 0) {
listview_set_filtered(state->list_view, TRUE);
unsigned int j = 0;
gchar *pattern = mode_preprocess_input(state->sw, state->text->text);
glong plen = pattern ? g_utf8_strlen(pattern, -1) : 0;
@ -1181,6 +1183,7 @@ static void rofi_view_refilter(RofiViewState *state) {
state->filtered_lines = j;
g_free(pattern);
} else {
listview_set_filtered(state->list_view, FALSE);
for (unsigned int i = 0; i < state->num_lines; i++) {
state->line_map[i] = i;
}

View File

@ -98,6 +98,9 @@ struct _listview {
unsigned int dynamic;
unsigned int eh;
unsigned int reverse;
gboolean require_input;
gboolean filtered;
gboolean cycle;
gboolean multi_select;
@ -559,6 +562,9 @@ void listview_set_num_elements(listview *lv, unsigned int rows) {
}
TICK_N("listview_set_num_elements");
lv->req_elements = rows;
if ( lv->req_elements && !lv->filtered ) {
lv->req_elements = 0;
}
listview_set_selected(lv, lv->selected);
TICK_N("Set selected");
listview_recompute_elements(lv);
@ -748,6 +754,8 @@ listview *listview_create(widget *parent, const char *name,
lv->fixed_columns =
rofi_theme_get_boolean(WIDGET(lv), "fixed-columns", FALSE);
lv->require_input =
rofi_theme_get_boolean(WIDGET(lv), "require-input", FALSE);
lv->type = rofi_theme_get_orientation(WIDGET(lv), "layout",
ROFI_ORIENTATION_VERTICAL);
if (lv->type == LISTVIEW) {
@ -1081,3 +1089,10 @@ void listview_toggle_ellipsizing(listview *lv) {
}
}
}
void listview_set_filtered ( listview *lv, gboolean filtered )
{
if ( lv ) {
lv->filtered = filtered;
}
}