/*
- * edit.c
+ * $Id$
+ *
* by JH <jheinonen@bigfoot.com>
*
* Copyright (C) Jaakko Heinonen
#include <string.h>
#include <stdlib.h>
#include "abook_curses.h"
+#include "ui.h"
#include "abook.h"
#include "database.h"
#include "list.h"
"/ OTHER \\"
};
- mvwhline(editw, TABLINE+1, 0, ACS_HLINE, EDITW_COLS);
+ mvwhline(editw, TABLINE+1, 0, UI_HLINE_CHAR, EDITW_COLS);
for(i=0; i < TABS; i++)
mvwaddstr(editw, TABLINE, 16 * i + 3, tab_names[i]);
get_first_email(email, item);
- if( snprintf(header, EDITW_COLS, "%s <%s>", database[item][NAME],
- email ) == -1 || !*database[item][EMAIL] )
- if( snprintf(header, EDITW_COLS, "%s", database[item][NAME]) == -1) {
- free(header);
- return;
- }
+ if( *database[item][EMAIL] )
+ snprintf(header, EDITW_COLS, "%s <%s>",
+ database[item][NAME],
+ email);
+ else
+ snprintf(header, EDITW_COLS, "%s", database[item][NAME]);
len = strlen(header);
x = (EDITW_COLS - len) / 2;
editor_print_data(int tab, int item)
{
const int pos_x = EDITW_COLS > 70 ? 8:4;
+ const int start_y = 5;
int i, j;
+ int y, x;
for(i = 0, j = 1; i < ITEM_FIELDS; i++) {
if(abook_fields[i].tab != tab)
int k;
char emails[MAX_EMAILS][MAX_EMAIL_LEN];
split_emailstr(item, emails);
- mvwaddstr(editw, (LINES > 21 ? 7:6), pos_x, "E-mail addresses:");
- for(k=0; k < MAX_EMAILS; k++)
- mvwprintw(editw, (LINES > 21 ? 9:7)+k*2, pos_x,
+ getyx(editw, y, x);
+ mvwaddstr(editw, y+1, pos_x, "E-mail addresses:");
+ for(k = 0; k < MAX_EMAILS; k++) {
+ getyx(editw, y, x);
+ mvwprintw(editw, y+1, pos_x,
"%c -\t\t%s", '2' + k, emails[k] );
+ }
continue;
}
- mvwprintw(editw, 3+j*2, pos_x, "%d - %s",
+ if(j > 1) {
+ getyx(editw, y, x); y++;
+ } else
+ y = start_y;
+
+ mvwprintw(editw, y, pos_x, "%d - %s",
j,
abook_fields[i].name);
- mvwaddch(editw, 3+j*2, 28, ':');
- mvwaddstr(editw, 3+j*2, 30, safe_str(database[item][i]));
+ mvwaddch(editw, y, 28, ':');
+ mvwaddstr(editw, y, 30, safe_str(database[item][i]));
+
j++;
}
}
split_emailstr(item, emails);
if(change_field("E-mail: ", &field)) {
+#ifdef DEBUG
fprintf(stderr, "change_field = TRUE\n");
+#endif
return; /* user cancelled ( C-g ) */
}
if(field) {
werase(editw);
headerline(EDITOR_HELPLINE);
+ refresh_statusline();
print_editor_header(item);
editor_tab(tab);
editor_print_data(tab, item);
break;
case KEY_RIGHT: tab = tab == MAX_TAB ? 0 : tab + 1;
break;
+ case '<':
+ case 'k': if(is_valid_item(item-1)) item--; break;
+ case '>':
+ case 'j': if(is_valid_item(item+1)) item++; break;
case 'r': roll_emails(item); break;
- case '?': display_editor_help(editw); break;
+ case '?': display_help(HELP_EDITOR); break;
case 'u': edit_undo(item, RESTORE_ITEM); break;
- default: return edit_field(tab, c, item);
+ case 'm': launch_mutt(item); clearok(stdscr, 1); break;
+ case 'v': launch_wwwbrowser(item); clearok(stdscr, 1); break;
+ case 12 : clearok(stdscr, 1); break; /* ^L (refresh screen) */
+ default: return edit_field(tab, c, item) ? item : -1;
}
- return 1;
+ return item;
}
void
}
init_editor();
- while( edit_loop(item) )
- ;
+
+ while( (item = edit_loop(item)) >= 0 )
+ curitem = item; /* hmm, this is not very clean way to go */
close_editor();
}