void goto_end() { if(db_n_items() > 0) curitem = last_item(); refresh_list(); }
void goto_home() { if(db_n_items() > 0) curitem = 0; refresh_list(); }
void ui_print_number_of_items() { char *str = strdup_printf(" " "|%3d/%3d", selected_items(), db_n_items()); mvaddstr(0, COLS-strlen(str), str); free(str); }
void scroll_down() { if(curitem > db_n_items() - 2) return; curitem++; refresh_list(); }
void invert_selection() { int i; if(list_is_empty()) return; for(i = 0; i < db_n_items(); i++) selected[i] = !selected[i]; }
int selected_items() { int i, n = 0; for(i = 0; i < db_n_items(); i++) if(selected[i]) n++; return n; }
void scroll_list_down() { if(LAST_LIST_ITEM > db_n_items() - 2) { if(curitem < LAST_LIST_ITEM) { curitem++; refresh_list(); } return; } first_list_item += scroll_speed; if(LAST_LIST_ITEM > db_n_items() - 1) { first_list_item = db_n_items() - LIST_LINES; } if(curitem < first_list_item) { curitem = first_list_item; } refresh_list(); }
void page_down() { if(curitem > db_n_items() - 2) return; if(curitem == LAST_LIST_ITEM) { if((curitem += LIST_LINES) > last_item()) curitem = last_item(); } else { curitem = min(LAST_LIST_ITEM, last_item()); } refresh_list(); }
void refresh_list() { int i, line; werase(list); ui_print_number_of_items(); if(list_is_empty()) { refresh(); wrefresh(list); return; } if(curitem < 0) curitem = 0; if(first_list_item < 0) first_list_item = 0; if(curitem < first_list_item) first_list_item = curitem; else if(curitem > LAST_LIST_ITEM) first_list_item = max(curitem - LIST_LINES + 1, 0); for(line = 0, i = first_list_item; i <= LAST_LIST_ITEM && i < db_n_items(); line++, i++) { print_list_line(i, line, i == curitem); } if(opt_get_bool(BOOL_SHOW_CURSOR)) { wmove(list, curitem - first_list_item, 0); /* need to call refresh() to update the cursor positions */ refresh(); } wrefresh(list); }
int list_is_empty() { return db_n_items() < 1; }
void select_all() { memset(selected, 1, db_n_items()); }
void select_none() { memset(selected, 0, db_n_items()); }