From c1378e4c6060acb53ff9743839f5ee631256c17f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 7 Nov 2019 11:49:45 +0100 Subject: [View] Add two widgets num-rows/num-filtered-rows Issue: #1026 --- doc/rofi-theme-selector.1 | 2 +- doc/rofi-theme.5 | 8 +++++++- doc/rofi-theme.5.markdown | 2 ++ include/view-internal.h | 6 ++++++ source/view.c | 23 +++++++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/doc/rofi-theme-selector.1 b/doc/rofi-theme-selector.1 index 74712e74..47d0bff7 100644 --- a/doc/rofi-theme-selector.1 +++ b/doc/rofi-theme-selector.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI\-THEME\-SELECTOR" "1" "May 2019" "" "" +.TH "ROFI\-THEME\-SELECTOR" "1" "January 2018" "" "" . .SH "NAME" \fBrofi\-theme\-selector\fR \- Preview and apply themes for \fBrofi\fR diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index 40e1a80a..a5dd1b58 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI\-THEME" "5" "September 2019" "" "" +.TH "ROFI\-THEME" "5" "November 2019" "" "" . .SH "NAME" \fBrofi\-theme\fR \- Rofi theme format files @@ -1153,6 +1153,12 @@ listview .IP "\(bu" 4 mode\-switcher . +.IP "\(bu" 4 +num\-rows +. +.IP "\(bu" 4 +num\-filtered\-rows +. .IP "" 0 . .P diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 1b435fec..7a333fbf 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -741,6 +741,8 @@ The following widgets are fixed, as they provide core **rofi** functionality: * message * listview * mode-switcher + * num-rows + * num-filtered-rows The following keywords are defined and can be used to automatically pack a subset of the widgets. These are used in the default theme as depicted in the figure above. diff --git a/include/view-internal.h b/include/view-internal.h index db253f6b..21e048e2 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -101,6 +101,12 @@ struct RofiViewState unsigned int num_modi; /** Array of #textbox that act as buttons for switching modi */ textbox **modi; + + /** Total rows. */ + textbox *tb_total_rows; + /** filtered rows */ + textbox *tb_filtered_rows; + /** Settings of the menu */ MenuFlags menu_flags; /** If mouse was within view previously */ diff --git a/source/view.c b/source/view.c index b44d9ab4..03b3aedb 100644 --- a/source/view.c +++ b/source/view.c @@ -1102,6 +1102,19 @@ static void rofi_view_refilter ( RofiViewState *state ) } listview_set_num_elements ( state->list_view, state->filtered_lines ); + if ( state->tb_filtered_rows ) { + char *r = g_strdup_printf("%u", state->filtered_lines); + textbox_text( state->tb_filtered_rows, r ); + g_free(r); + } + if ( state->tb_total_rows ) { + char *r = g_strdup_printf("%u", state->num_lines); + textbox_text( state->tb_total_rows, r ); + g_free(r); + } + + + if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) { ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; state->retv = MENU_OK; @@ -1616,6 +1629,16 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE ); defaults = NULL; } + else if ( strcmp ( name, "num-rows" ) == 0 ){ + state->tb_total_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); + box_add ( (box *) parent_widget, WIDGET ( state->tb_total_rows ), FALSE ); + defaults = NULL; + } + else if ( strcmp ( name, "num-filtered-rows" ) == 0 ){ + state->tb_filtered_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); + box_add ( (box *) parent_widget, WIDGET ( state->tb_filtered_rows), FALSE ); + defaults = NULL; + } /** * CASE INDICATOR */ -- cgit v1.2.3