]> git.deb.at Git - pkg/abook.git/blob - edit.c
Upload 0.6.1-2 to unstable
[pkg/abook.git] / edit.c
1
2 /*
3  * $Id$
4  *
5  * by JH <jheinonen@users.sourceforge.net>
6  *
7  * Copyright (C) Jaakko Heinonen
8  */
9
10 #include <string.h>
11 #include <stdlib.h>
12 #include <ctype.h>
13 #include <assert.h>
14 #include "abook_curses.h"
15 #include "ui.h"
16 #include "abook.h"
17 #include "database.h"
18 #include "gettext.h"
19 #include "list.h"
20 #include "edit.h"
21 #include "misc.h"
22 #include "views.h"
23 #include "xmalloc.h"
24 #include "color.h"
25 #ifdef HAVE_CONFIG_H
26 #       include "config.h"
27 #endif
28 #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
29 #       include <locale.h>
30 #endif 
31
32
33 static void locale_date(char *str, size_t str_len, int year, int month, int day);
34
35 /*
36  * some extern variables
37  */
38
39 extern int views_count;
40
41 WINDOW *editw;
42
43
44 static void
45 editor_tab(const int tab)
46 {
47         int i, j;
48         int x_pos = 2; /* current x pos */
49         char *tab_name;
50
51         wattrset(editw, COLOR_PAIR(CP_TAB_BORDER));
52         mvwhline(editw, TABLINE + 1, 0, UI_HLINE_CHAR, EDITW_COLS);
53
54         for(i = 0; i < views_count; i++) {
55                 view_info(i, &tab_name, NULL);
56                 int width = strwidth(tab_name) + 5;
57
58                 if(x_pos + width + 1 > EDITW_COLS) {
59                         statusline_addstr(_("Tab name too wide for screen"));
60                         break;
61                 }
62
63                 mvwaddch(editw,  TABLINE + 1, x_pos,  UI_TEE_CHAR);
64                 mvwaddch(editw,  TABLINE + 1, x_pos + width - 2, UI_TEE_CHAR);
65
66                 mvwaddch(editw,  TABLINE, x_pos,  UI_ULCORNER_CHAR);
67                 mvwaddch(editw,  TABLINE, x_pos + 1,  UI_LBOXLINE_CHAR);
68                 wattrset(editw, COLOR_PAIR(CP_TAB_LABEL));
69                 mvwaddstr(editw, TABLINE, x_pos + 2,  tab_name);
70                 wattrset(editw, COLOR_PAIR(CP_TAB_BORDER));
71                 mvwaddch(editw,  TABLINE, x_pos + width - 3, UI_RBOXLINE_CHAR);
72                 mvwaddch(editw,  TABLINE, x_pos + width - 2, UI_URCORNER_CHAR);
73
74                 if(i == tab) {
75                         mvwaddch(editw,  TABLINE + 1, x_pos, UI_LRCORNER_CHAR);
76                         for(j = 0; j < width - 3; j++)
77                                 mvwaddstr(editw,
78                                         TABLINE + 1, x_pos + j + 1, " ");
79                         mvwaddch(editw,  TABLINE + 1, x_pos + width - 2,
80                                 UI_LLCORNER_CHAR);
81                 }
82                 x_pos += width;
83         }
84 }
85
86 void
87 get_first_email(char *str, int item)
88 {
89         char *tmp, *emails = db_email_get(item);
90
91         if(!*emails) {
92                 *str = 0;
93                 return;
94         }
95
96         strncpy(str, emails, MAX_EMAIL_LEN);
97         free(emails);
98         if( (tmp = strchr(str, ',')) )
99                 *tmp = 0;
100         else
101                 str[MAX_EMAIL_LEN - 1] = 0;
102 }
103
104 /* This only rolls emails from the 'email' field, not emails from any
105  * field of type FIELD_EMAILS.
106  * TODO: expand to ask for which field to roll if several are present? */
107 void
108 roll_emails(int item, enum rotate_dir dir)
109 {
110         abook_list *emails = csv_to_abook_list(db_fget(item, EMAIL));
111
112         if(!emails)
113                 return;
114
115         free(db_fget(item, EMAIL));
116         abook_list_rotate(&emails, dir);
117         db_fput(item, EMAIL, abook_list_to_csv(emails));
118         abook_list_free(&emails);
119 }
120
121 static void
122 init_editor()
123 {
124         clear();
125         editw = newwin(EDITW_LINES, EDITW_COLS, EDITW_TOP, EDITW_X);
126         notimeout(editw, TRUE); /* handling of escape key */
127
128         refresh_statusline();
129 }
130
131 enum {
132         BACKUP_ITEM,
133         RESTORE_ITEM,
134         CLEAR_UNDO
135 };
136
137 static int
138 edit_undo(int item, int mode)
139 {
140         static list_item backup = NULL;
141         static int backed_up_item = -1;
142
143         switch(mode) {
144                 case CLEAR_UNDO:
145                         if(backup) {
146                                 item_empty(backup);
147                                 item_free(&backup);
148                         }
149                         break;
150                 case BACKUP_ITEM:
151                         if(backup) {
152                                 item_empty(backup);
153                                 item_free(&backup);
154                         }
155                         backup = item_create();
156                         item_duplicate(backup, db_item_get(item));
157                         backed_up_item = item;
158                         break;
159                 case RESTORE_ITEM:
160                         if(backup) {
161                                 item_empty(db_item_get(backed_up_item));
162                                 item_copy(db_item_get(backed_up_item), backup);
163                                 item_free(&backup);
164                                 return backed_up_item;
165                         }
166                         break;
167                 default:
168                         assert(0);
169         }
170         return item;
171 }
172
173 static void
174 close_editor()
175 {
176         edit_undo(-1, CLEAR_UNDO);
177         delwin(editw);
178         refresh_screen();
179 }
180
181 static void
182 print_editor_header(int item)
183 {
184         char *header;
185         char email[MAX_EMAIL_LEN];
186
187         if((header = xmalloc(EDITW_COLS)) == NULL)
188                 return;
189
190         get_first_email(email, item);
191
192         if(*email)
193                 snprintf(header, EDITW_COLS, "%s <%s>",
194                                 db_name_get(item),
195                                 email);
196         else
197                 snprintf(header, EDITW_COLS, "%s", db_name_get(item));
198
199         wattrset(editw, COLOR_PAIR(CP_TAB_LABEL));
200         mvwaddstr(editw, 0, (EDITW_COLS - strwidth(header)) / 2, header);
201
202         free(header);
203 }
204
205 static void
206 editor_print_data(int tab, int item)
207 {
208         int j = 1, nb;
209         int y, x;
210         abook_field_list *cur;
211         char *str;
212
213         view_info(tab, NULL, &cur);
214
215         for(; cur; cur = cur->next) {
216
217                 if(j > 1) {
218                         getyx(editw, y, x);
219                         y++;
220                 } else
221                         y = FIELDS_START_Y;
222
223                 wattrset(editw, COLOR_PAIR(CP_FIELD_NAME));
224                 mvwprintw(editw, y, FIELDS_START_X, "%c - ",
225                                 (j < 10) ? '0' + j : 'A' + j - 10);
226                 mvwaddnstr(editw, y, FIELDS_START_X + 4, cur->field->name,
227                                 bytes2width(cur->field->name,
228                                         FIELDNAME_MAX_WIDTH));
229                 mvwaddch(editw, y, TAB_COLON_POS, ':');
230
231                 wattrset(editw, COLOR_PAIR(CP_FIELD_VALUE));
232                 if((cur->field->type == FIELD_EMAILS) ||
233                                 (cur->field->type == FIELD_LIST)) {
234                         abook_list *emails, *e;
235                         
236                         find_field_number(cur->field->key, &nb);
237                         emails = csv_to_abook_list(db_fget_byid(item, nb));
238
239                         for(e = emails; e; e = e->next) {
240                                 getyx(editw, y, x);
241                                 mvwaddnstr(editw, y + 1, TAB_COLON_POS + 2,
242                                                 e->data,
243                                                 bytes2width(e->data,
244                                                         FIELD_MAX_WIDTH));
245                                 mvwaddch(editw, y + 1, TAB_COLON_POS,
246                                                 UI_VLINE_CHAR);
247                         }
248                         if(emails) {
249                                 mvwaddch(editw, y + 2, TAB_COLON_POS,
250                                                 UI_LLCORNER_CHAR);
251                                 mvwhline(editw, y + 2, TAB_COLON_POS + 1,
252                                                 UI_HLINE_CHAR,
253                                                 EDITW_COLS - TAB_COLON_POS - 2);
254                         }
255                         abook_list_free(&emails);
256                 } else if(cur->field->type == FIELD_DATE) {
257                         int day, month, year;
258                         char buf[64];
259
260                         find_field_number(cur->field->key, &nb);
261                         str = db_fget_byid(item, nb);
262                         
263                         if(parse_date_string(str, &day, &month, &year)) {
264                                 /* put locale representation of date in buf */
265                                 locale_date(buf, sizeof(buf), year, month, day);
266                                 mvwaddnstr(editw, y, TAB_COLON_POS + 2, buf,
267                                         bytes2width(buf, FIELD_MAX_WIDTH));
268                         }
269                 } else {
270                         find_field_number(cur->field->key, &nb);
271                         str = safe_str(db_fget_byid(item, nb));
272                         mvwaddnstr(editw, y, TAB_COLON_POS + 2, str,
273                                 bytes2width(str, FIELD_MAX_WIDTH));
274                 }
275
276                 j++;
277         }
278 }
279
280 /*
281  * function: change_field
282  *
283  * parameters:
284  *  (char *msg)
285  *   message to display as a prompt
286  *  (char **field)
287  *   a pointer to a pointer which will point a new string. if the latter
288  *   pointer != NULL it will be freed (if user doesn't cancel)
289  *  (size_t max_len)
290  *   maximum length of field to read from user
291  *
292  * returns (int)
293  *  a nonzero value if user has cancelled and zero if user has typed a
294  *  valid string
295  */
296 static int
297 change_field(char *msg, char **field, size_t max_len)
298 {
299         char *old;
300         int ret = 0;
301
302         old = *field;
303
304         *field = ui_readline(msg, old, max_len - 1, 0);
305
306         if(*field) {
307                 xfree(old);
308                 if(!**field)
309                         xfree(*field);
310         } else {
311                 *field = old;
312                 ret = 1;
313         }
314
315         clear_statusline();
316         refresh_statusline();
317
318         return ret;
319 }
320
321 static int
322 change_name_field(char *msg, char **field, size_t max_len)
323 {
324         char *tmp;
325         int ret;
326
327         tmp = xstrdup(*field);
328         ret = change_field(msg, field, max_len);
329
330         if(*field == NULL || ! **field) {
331                 xfree(*field);
332                 *field = xstrdup(tmp);
333         }
334
335         xfree(tmp);
336
337         return ret;
338 }
339
340 static void
341 fix_email_str(char *str)
342 {
343         for(; *str; str++)
344                 *str = *str == ',' ? '_' : *str;
345 }
346
347 static void
348 edit_list(int item, int nb, int isemail)
349 {
350         char *field, *msg, *keys;
351         abook_list *list, *e;
352         int choice = 1, elem_count;
353
354         list = csv_to_abook_list(db_fget_byid(item, nb));
355
356         for(e = list, elem_count = 0; e; e = e->next, elem_count++)
357                 ;
358
359         if(elem_count) {
360                 keys = xstrndup(S_("keybindings_new_123456789|n123456789"),
361                                 elem_count + 1);
362                 msg = strdup_printf(_("Choose %s to modify (<1>%s%c%s%s."),
363                                 isemail ? _("email") : _("item"),
364                                 (elem_count > 1) ? "-<" : "",
365                                 (elem_count > 1) ?  '0' + elem_count : ')',
366                                 (elem_count > 1) ? ">)" : "",
367                                 (elem_count < MAX_LIST_ITEMS) ?
368                                         _(" or <n>ew") : ""
369                                 );
370                 choice = statusline_askchoice(
371                                 msg,
372                                 keys,
373                                 (elem_count < MAX_LIST_ITEMS) ? 1 : 2
374                                 );
375                 free(keys);
376                 free(msg);
377         }
378
379         if(choice == 0)
380                 return;
381
382         field = (choice > 1) ?
383                 xstrdup(abook_list_get(list, choice - 2)->data) :
384                 NULL;
385
386         if(change_field(isemail ? _("E-mail: ") : _("Item: "),
387                                 &field, MAX_EMAIL_LEN))
388                 return; /* user cancelled ( C-g ) */
389
390         /* TODO if list item contains commas, should use quotes instead */
391         if(field)
392                 fix_email_str(field);
393
394         if(choice == 1)
395                 abook_list_append(&list, field);
396         else
397                 abook_list_replace(&list, choice - 2, field);
398
399         if(field)
400                 xfree(field);
401
402         field = abook_list_to_csv(list);
403         db_fput_byid(item, nb, field ? field : xstrdup(""));
404         abook_list_free(&list);
405 }
406
407 /*
408  * available %-sequences:
409  *   - %y, %Y, %m, %M, %d, %D represent year, month, and day
410  *     (the uppercase version telling to fill with leading zeros
411  *     if necessary)
412  *   - %I for ISO 8601 representation
413  */
414 static size_t
415 format_date(char *str, size_t str_len, char *fmt, int year, int month, int day)
416 {
417         char *s = str;
418         size_t len;
419
420         while(*fmt && (s - str + 1 < str_len)) {
421                 if(*fmt != '%') {
422                         *s++ = *fmt++;
423                         continue;
424                 }
425
426                 len = str_len - (str - s);
427                 switch(*++fmt) {
428                         case 'y': s += snprintf(s, len, "%d", year); break;
429                         case 'Y': s += snprintf(s, len, "%04d", year); break;
430                         case 'm': s += snprintf(s, len, "%d", month); break;
431                         case 'M': s += snprintf(s, len, "%02d", month); break;
432                         case 'd': s += snprintf(s, len, "%d", day); break;
433                         case 'D': s += snprintf(s, len, "%02d", day); break;
434                         case 'I': s += format_date(s, len,
435                                                   year ? "%Y-%M-%D" : "--%M-%D",
436                                                   year, month, day);
437                                   break;
438                         case '%': *s++ = '%'; break;
439                         default: *s++ = '%'; *s++ = *fmt; break;
440                 }
441                 fmt++;
442         }
443         *s = 0;
444         return s - str;
445 }
446
447 /*
448  * str is a buffer of max length str_len, which, after calling, will
449  * contain a representation of the given [y, m, d] date using the
450  * current locale (as defined by LC_TIME).
451  *
452  * In the absence of any localization, use an ISO 8601 representation.
453  */
454 static void
455 locale_date(char *str, size_t str_len, int year, int month, int day)
456 {
457         char *fmt;
458
459 #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
460         fmt = year ?    dcgettext(PACKAGE, "%Y-%M-%D", LC_TIME) :
461                         dcgettext(PACKAGE, "--%M-%D", LC_TIME);
462 #else
463         fmt = "%I";
464 #endif
465         format_date(str, str_len, fmt, year, month, day);
466 }
467
468 static int is_valid_date(const int day, const int month, const int year)
469 {
470         int valid = 1;
471         int month_length[13] =
472                 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
473
474         /*
475          * leap year
476          */
477         if ((!(year % 4)) && ((year % 100) || !(year % 400)))
478                 month_length[2] = 29;
479
480         if (month < 1 || month > 12)
481                 valid = 0;
482         else if (day < 1 || day > month_length[month])
483                 valid = 0;
484         else if (year < 0) /* we don't accept negative year numbers */
485                 valid = 0;
486
487         return valid;
488 }
489
490 int
491 parse_date_string(char *str, int *day, int *month, int *year)
492 {
493         int i = 0;
494         char buf[12], *s, *p;
495
496         assert(day && month && year);
497
498         if(!str || !*str)
499                 return FALSE;
500
501         p = s = strncpy(buf, str, sizeof(buf));
502
503         if(*s == '-' && *s++ == '-') { /* omitted year */
504                 *year = 0;
505                 p = ++s;
506                 i++;
507         }
508
509         while(*s) {
510                 if(isdigit(*s)) {
511                         s++;
512                         continue;
513                 } else if(*s == '-') {
514                         if(++i > 3)
515                                 return FALSE;
516                         *s++ = '\0';
517                         switch(i) {
518                                 case 1: *year = safe_atoi(p); break;
519                                 case 2: *month = safe_atoi(p); break;
520                         }
521                         p = s;
522                 } else
523                         return FALSE;
524         }
525
526         if (i != 2 || !*p)
527                 return FALSE;
528
529         *day = atoi(p);
530
531         return is_valid_date(*day, *month, *year);
532 }
533
534 static void
535 edit_date(int item, int nb)
536 {
537         int i, date[3], old;
538         char *s = db_fget_byid(item, nb);
539         char *field[] = { N_("Day: "), N_("Month: "), N_("Year (optional): ") };
540
541         old = parse_date_string(s, &date[0], &date[1], &date[2]);
542
543         for(i = 0; i < 3; i++) {
544                 s = (old && date[i]) ? strdup_printf("%d", date[i]) : NULL;
545                 if(change_field(gettext(field[i]), &s, 5))
546                         return; /* user aborted with ^G */
547
548                 date[i] = (s && is_number(s)) ? atoi(s) : 0;
549
550                 if(!s) {
551                         switch(i) {
552                                 case 0: db_fput_byid(item, nb, NULL); /*delete*/
553                                 case 1: /* fall through */ return;
554                         }
555                 } else
556                         xfree(s);
557         }
558
559         /* ISO 8601 date, of the YYYY-MM-DD or --MM-DD format */
560         if(is_valid_date(date[0], date[1], date[2])) {
561                 if(date[2])
562                         s = strdup_printf("%04d-%02d-%02d",
563                                 date[2], date[1], date[0]);
564                 else
565                         s = strdup_printf("--%02d-%02d", date[1], date[0]);
566
567                 db_fput_byid(item, nb, xstrdup(s));
568         } else
569                 statusline_msg(_("Invalid date"));
570 }
571
572 /* input range: 1-9A-Z
573  * output range: 0-34 */
574 static int
575 key_to_field_number(char c)
576 {
577         int n = c - '1';
578         if(n >= 0 && n < 9)
579                 return n;
580
581         n = c - 'A' + 9;
582         if(n > 8 && n < 35)
583                 return n;
584
585         return -1;
586 }
587
588 static void
589 edit_field(int tab, char c, int item_number)
590 {
591         ui_enable_mouse(FALSE);
592         int i = 0, number, idx;
593         char *msg;
594         abook_field_list *f;
595         list_item item;
596
597         if((number = key_to_field_number(c)) < 0)
598                 goto detachfield;
599
600         edit_undo(item_number, BACKUP_ITEM);
601
602         view_info(tab, NULL, &f);
603
604         while(1) {
605                 if(!f)
606                         goto detachfield;
607
608                 if(i == number)
609                         break;
610
611                 f = f->next;
612                 i++;
613         }
614
615         find_field_number(f->field->key, &idx);
616         
617         switch(f->field->type) {
618                 case FIELD_STRING:
619                         msg = strdup_printf("%s: ", f->field->name);
620                         item = db_item_get(item_number);
621                         if(strcmp(f->field->key, "name") == 0)
622                                 change_name_field(msg,&item[idx],MAX_FIELD_LEN);
623                         else
624                                 change_field(msg,&item[idx],MAX_FIELD_LEN);
625                         free(msg);
626                         break;
627                 case FIELD_LIST:
628                         edit_list(item_number, idx, 0);
629                         break;
630                 case FIELD_EMAILS:
631                         edit_list(item_number, idx, 1);
632                         break;
633                 case FIELD_DATE:
634                         edit_date(item_number, idx);
635                         goto detachfield;
636                 default:
637                         assert(0);
638         }
639
640  detachfield:
641         if(opt_get_bool(BOOL_USE_MOUSE))
642           ui_enable_mouse(TRUE);
643 }
644
645 static int
646 edit_loop(int item)
647 {
648         static int tab = 0; /* first tab */
649         int c;
650
651         werase(editw);
652         headerline(gettext(EDITOR_HELPLINE));
653         refresh_statusline();
654         print_editor_header(item);
655         editor_tab(tab);
656         editor_print_data(tab, item);
657         wmove(editw, EDITW_LINES - 1, EDITW_COLS - 1);
658
659         refresh();
660         wrefresh(editw);
661
662         c = getch();
663         if(c == '\033') {
664                 statusline_addstr("ESC-");
665                 c = getch();
666                 clear_statusline();
667
668                 /* Escaped bindings */
669                 switch(c) {
670                         case 'r': roll_emails(item, ROTATE_RIGHT); break;
671                         default: break;
672                 }
673
674                 return item;
675         }
676         if(c == KEY_MOUSE) {
677                 MEVENT event;
678                 if(getmouse(&event) == OK) {
679                         if(event.bstate & BUTTON1_CLICKED
680                            || event.bstate & BUTTON1_DOUBLE_CLICKED) {
681                                 int window_y, window_x;
682                                 getbegyx(editw, window_y, window_x);
683                                 if(event.y == 0) {
684                                         /* if first row is selected, then go back to list */
685                                         return -1;
686                                 } else if(event.y == window_y + TABLINE
687                                    || event.y == window_y + TABLINE + 1) {
688                                         char* tab_name;
689                                         int mouse_x = event.x;
690                                         int xpos = 2 + 1; /* look at editor_tab() and try out */
691                                         int clicked_tab = 0;
692                                         while(clicked_tab < views_count) {
693                                                 view_info(clicked_tab, &tab_name, NULL);
694                                                 xpos += strwidth(tab_name) + 5;
695                                                 /* fprintf(stderr, "trying tab %d\n", clicked_tab); */
696                                                 if(xpos >= mouse_x) {
697                                                         break; /* clicked tab was found */
698                                                 } else {
699                                                         /* try next tab */
700                                                         clicked_tab++;
701                                                 }
702                                         }
703                                         if(clicked_tab < views_count) {
704                                                 tab = clicked_tab;
705                                         }
706                                 } else if(event.y >= window_y + FIELDS_START_Y) {
707                                         /* is mouse in field area? */
708                                         int j = 1 + event.y - window_y - FIELDS_START_Y;
709                                         /* field numbers start with 1, but if j='0', then char='0' */
710                                         /* so fix this, by adding 1 to j */
711                                         int field_char = (j < 10) ? '0' + j : 'A' + j - 10;
712                                         edit_field(tab, field_char, item);
713                                 }
714                         } else if(event.bstate & BUTTON4_PRESSED) {
715                                 tab = tab == 0 ? views_count - 1 : tab - 1;
716                         }
717                         else if(event.bstate & BUTTON5_PRESSED) {
718                                 tab = tab == views_count - 1 ? 0 : tab + 1;
719                         }
720                         return item;
721                 }
722         }
723
724         /* No uppercase nor numeric key should be used in this menu,
725          * as they are reserved for field selection */
726         switch(c) {
727                 case 'h':
728                 case KEY_LEFT: tab = tab == 0 ? views_count - 1 : tab - 1;
729                                break;
730                 case 'l':
731                 case KEY_RIGHT: tab = tab == views_count - 1 ? 0 : tab + 1;
732                                 break;
733                 case KEY_UP:
734                 case '<':
735                 case 'k': if(is_valid_item(item - 1)) item--; break;
736                 case KEY_DOWN:
737                 case '>':
738                 case 'j': if(is_valid_item(item + 1)) item++; break;
739                 case 'r': roll_emails(item, ROTATE_LEFT); break;
740                 case '?': display_help(HELP_EDITOR); break;
741                 case 'u': item = edit_undo(item, RESTORE_ITEM); break;
742                 case 'm': launch_mutt(item); clearok(stdscr, 1); break;
743                 case 'v': launch_wwwbrowser(item); clearok(stdscr, 1); break;
744                 case 12 : clearok(stdscr, 1); break; /* ^L (refresh screen) */
745                 case 'q': return -1;
746                 default: edit_field(tab, c, item);
747         }
748
749         return item;
750 }
751
752 void
753 edit_item(int item)
754 {
755         if(item < 0) {
756                 if(list_get_curitem() < 0)
757                         return;
758                 else
759                         item = list_get_curitem();
760         }
761
762         init_editor();
763
764         while((item = edit_loop(item)) >= 0)
765                 list_set_curitem(item); /* this is not very clean way to go */
766
767         close_editor();
768 }
769
770 void
771 add_item()
772 {
773         char *field = NULL;
774         list_item item = item_create();
775
776         change_field(_("Name: "), &field, MAX_FIELD_LEN);
777
778         if( field == NULL )
779                 return;
780
781         item_fput(item, NAME, field);
782
783         add_item2database(item);
784         item_free(&item);
785
786         list_set_curitem(last_item());
787
788         edit_item(last_item());
789 }
790