X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=edit.c;h=aed24c6da6e2a606723510f90fe13ce8abc7f375;hb=7c54e85b04f6d030ae47dd880d0391f6e35d1634;hp=7b719d28d2eb828f2ae301e0bbc500be6f2e09a5;hpb=addc54efb596b39b0e4e6ce219ee0f1506337475;p=pkg%2Fabook.git diff --git a/edit.c b/edit.c index 7b719d2..aed24c6 100644 --- a/edit.c +++ b/edit.c @@ -1,6 +1,6 @@ /* - * $Id: edit.c,v 1.38 2005/08/13 10:49:25 jheinonen Exp $ + * $Id: edit.c,v 1.43 2005/10/20 13:59:30 cduval Exp $ * * by JH * @@ -14,6 +14,7 @@ #include "ui.h" #include "abook.h" #include "database.h" +#include "gettext.h" #include "list.h" #include "edit.h" #include "misc.h" @@ -37,33 +38,45 @@ WINDOW *editw; static void editor_tab(const int tab) { - int i; - const int spacing = 12; + int i, j; + int x_pos = 2; /* current x pos */ static char *tab_names[] = { - "CONTACT", - "ADDRESS", - " PHONE ", - " OTHER ", - "CUSTOM " + N_("CONTACT"), + N_("ADDRESS"), + N_(" PHONE "), + N_(" OTHER "), + N_("CUSTOM ") }; mvwhline(editw, TABLINE + 1, 0, UI_HLINE_CHAR, EDITW_COLS); - for(i = 0; i < TABS; i++) { - mvwaddch(editw, TABLINE+1, spacing * i + 2, UI_TEE_CHAR); - mvwaddch(editw, TABLINE+1, spacing * i + 12, UI_TEE_CHAR); - } for(i = 0; i < TABS; i++) { - mvwaddch(editw, TABLINE, spacing * i + 2, UI_ULCORNER_CHAR); - mvwaddch(editw, TABLINE, spacing * i + 3, UI_LBOXLINE_CHAR); - mvwaddstr(editw, TABLINE, spacing * i + 4, tab_names[i]); - mvwaddch(editw, TABLINE, spacing * i + 11, UI_RBOXLINE_CHAR); - mvwaddch(editw, TABLINE, spacing * i + 12, UI_URCORNER_CHAR); - } + int width = strwidth(gettext(tab_names[i])) + 5; + + if(x_pos + width + 1 > EDITW_COLS) { + statusline_msg(_("Tab name too wide for screen")); + break; + } - mvwaddch(editw, TABLINE+1, spacing * tab + 2, UI_LRCORNER_CHAR); - mvwaddstr(editw, TABLINE+1, spacing * tab + 3, " "); - mvwaddch(editw, TABLINE+1, spacing * tab + 12, UI_LLCORNER_CHAR); + mvwaddch(editw, TABLINE + 1, x_pos, UI_TEE_CHAR); + mvwaddch(editw, TABLINE + 1, x_pos + width - 2, UI_TEE_CHAR); + + mvwaddch(editw, TABLINE, x_pos, UI_ULCORNER_CHAR); + mvwaddch(editw, TABLINE, x_pos + 1, UI_LBOXLINE_CHAR); + mvwaddstr(editw, TABLINE, x_pos + 2, gettext(tab_names[i])); + mvwaddch(editw, TABLINE, x_pos + width - 3, UI_RBOXLINE_CHAR); + mvwaddch(editw, TABLINE, x_pos + width - 2, UI_URCORNER_CHAR); + + if(i == tab) { + mvwaddch(editw, TABLINE + 1, x_pos, UI_LRCORNER_CHAR); + for(j = 0; j < width - 3; j++) + mvwaddstr(editw, + TABLINE + 1, x_pos + j + 1, " "); + mvwaddch(editw, TABLINE + 1, x_pos + width - 2, + UI_LLCORNER_CHAR); + } + x_pos += width; + } } void @@ -78,7 +91,7 @@ get_first_email(char *str, int item) strncpy(str, database[item][EMAIL], MAX_EMAIL_LEN); if( (tmp = strchr(str, ',')) ) - *tmp=0; + *tmp = 0; else str[MAX_EMAIL_LEN-1] = 0; } @@ -94,7 +107,7 @@ roll_emails(int item) if( !(p = strchr(tmp, ',')) ) return; else - *p=0; + *p = 0; strcpy(database[item][EMAIL], p+1); strcat(database[item][EMAIL], ","); @@ -116,11 +129,12 @@ enum { CLEAR_UNDO }; -static void +static int edit_undo(int item, int mode) { int i; static list_item *backup = NULL; + static int backed_up_item = -1; switch(mode) { case CLEAR_UNDO: @@ -141,17 +155,21 @@ edit_undo(int item, int mode) else backup[0][i] = xstrdup(database[item][i]); + backed_up_item = item; break; case RESTORE_ITEM: if(backup) { - free_list_item(database[item]); - itemcpy(database[item], backup[0]); + free_list_item(database[backed_up_item]); + itemcpy(database[backed_up_item], backup[0]); xfree(backup); + return backed_up_item; } break; default: assert(0); } + + return item; } @@ -203,7 +221,7 @@ editor_print_data(int tab, int item) split_emailstr(item, emails); getyx(editw, y, x); mvwaddstr(editw, y+1, FIELDS_START_X, - "E-mail addresses:"); + _("E-mail addresses:")); for(k = 0; k < MAX_EMAILS; k++) { getyx(editw, y, x); mvwprintw(editw, y+1, FIELDS_START_X, @@ -222,7 +240,7 @@ editor_print_data(int tab, int item) mvwprintw(editw, y, FIELDS_START_X, "%d - %s", j, - abook_fields[i].name); + gettext(abook_fields[i].name)); mvwaddch(editw, y, TAB_COLON_POS, ':'); mvwaddstr(editw, y, TAB_COLON_POS + 2, safe_str(database[item][i])); @@ -370,7 +388,7 @@ edit_field(int tab, char c, int item) if(j != n) return 0; - str = mkstr("%s: ", abook_fields[i].name); + str = strdup_printf("%s: ", gettext(abook_fields[i].name)); change_field(str, &database[item][i]); free(str); @@ -385,7 +403,7 @@ edit_loop(int item) int c; werase(editw); - headerline(EDITOR_HELPLINE); + headerline(gettext(EDITOR_HELPLINE)); refresh_statusline(); print_editor_header(item); editor_tab(tab); @@ -415,7 +433,7 @@ edit_loop(int item) case 'j': if(is_valid_item(item + 1)) item++; break; case 'r': roll_emails(item); break; case '?': display_help(HELP_EDITOR); break; - case 'u': edit_undo(item, RESTORE_ITEM); break; + case 'u': item = edit_undo(item, RESTORE_ITEM); break; 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) */