/*
- * $Id: ui.c,v 1.54.4.1 2006/04/09 18:57:34 jheinonen Exp $
+ * $Id: ui.c,v 1.58 2006/09/06 02:24:33 cduval Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
* external variables
*/
-extern int items, curitem;
extern char *datafile;
extern bool alternative_datafile;
char *s;
int ch;
- assert((dflt < 0) || (dflt > strlen(choices)));
+ assert((dflt >= 0) && (dflt <= strlen(choices)));
if(dflt) {
s = strdup_printf("%s [%c]", msg, choices[dflt - 1]);
*/
extern char *selected;
-extern int curitem;
void
get_commands()
case 'q': return;
case 'Q': quit_abook(QUIT_DONTSAVE); break;
case 'P': print_stderr(selected_items() ?
- -1 : list_current_item());
+ -1 : list_get_curitem());
return;
case '?':
display_help(HELP_MAIN);
case 'o': ui_open_datafile(); break;
- case 's': sort_by_field(NAME); break;
+ case 's': sort_by_field("name");break;
case 'S': sort_surname(); break;
- case 'F': sort_by_field(-1); break;
+ case 'F': sort_by_field(NULL); break;
case '/': ui_find(0); break;
case '\\': ui_find(1); break;
- case ' ': if(curitem >= 0) {
- selected[curitem] = !selected[curitem];
+ case ' ': if(list_get_curitem() >= 0) {
+ list_invert_curitem_selection();
ui_print_number_of_items();
refresh_list();
}
break;
case 'm': launch_mutt(selected_items() ?
- -1 : list_current_item());
+ -1 : list_get_curitem());
refresh_screen();
break;
case 'p': ui_print_database(); break;
- case 'v': launch_wwwbrowser(list_current_item());
+ case 'v': launch_wwwbrowser(list_get_curitem());
refresh_screen();
break;
}
} else {
char *s;
s = ui_readline("/", findstr, MAX_FIELD_LEN - 1, 0);
- strncpy(findstr, s, MAX_FIELD_LEN);
- free(s);
refresh_screen();
+ if(s == NULL) {
+ return; /* user cancelled (ctrl-G) */
+ } else {
+ strncpy(findstr, s, MAX_FIELD_LEN);
+ free(s);
+ }
}
- if( (item = find_item(findstr, curitem + !!next, search_fields)) < 0 &&
+ if( (item = find_item(findstr, list_get_curitem() + !!next,
+ search_fields)) < 0 &&
(item = find_item(findstr, 0, search_fields)) >= 0)
statusline_addstr(_("Search hit bottom, continuing at top"));
if(item >= 0) {
- curitem = item;
+ list_set_curitem(item);
refresh_list();
}
}
-
void
ui_print_number_of_items()
{
- char *str = strdup_printf(" " "|%3d/%3d", selected_items(), items);
+ char *str = strdup_printf(" " "|%3d/%3d",
+ selected_items(), db_n_items());
mvaddstr(0, COLS-strlen(str), str);
{
char *msg;
- if(items > 0) {
+ if(!list_is_empty()) {
msg = strdup_printf(_("Your current data will be lost - "
"Press '%c' to continue"),
*(S_("keybinding for yes|y")));
load_database(filename);
- if(items == 0) {
+ if(list_is_empty()) {
statusline_msg(_("Sorry, the specified file appears not to be a valid abook addressbook"));
load_database(datafile);
} else {