]> git.deb.at Git - pkg/abook.git/blobdiff - edit.c
Upload 0.6.1-2 to unstable
[pkg/abook.git] / edit.c
diff --git a/edit.c b/edit.c
index d2cba627229680b7dc7068d36bf01a6e95f033ad..9a76c8a8970aadda843bd1b7ab7638f3e2c84ec1 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -21,6 +21,7 @@
 #include "misc.h"
 #include "views.h"
 #include "xmalloc.h"
+#include "color.h"
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
@@ -47,6 +48,7 @@ editor_tab(const int tab)
        int x_pos = 2; /* current x pos */
        char *tab_name;
 
+       wattrset(editw, COLOR_PAIR(CP_TAB_BORDER));
        mvwhline(editw, TABLINE + 1, 0, UI_HLINE_CHAR, EDITW_COLS);
 
        for(i = 0; i < views_count; i++) {
@@ -63,7 +65,9 @@ editor_tab(const int tab)
 
                mvwaddch(editw,  TABLINE, x_pos,  UI_ULCORNER_CHAR);
                mvwaddch(editw,  TABLINE, x_pos + 1,  UI_LBOXLINE_CHAR);
+               wattrset(editw, COLOR_PAIR(CP_TAB_LABEL));
                mvwaddstr(editw, TABLINE, x_pos + 2,  tab_name);
+               wattrset(editw, COLOR_PAIR(CP_TAB_BORDER));
                mvwaddch(editw,  TABLINE, x_pos + width - 3, UI_RBOXLINE_CHAR);
                mvwaddch(editw,  TABLINE, x_pos + width - 2, UI_URCORNER_CHAR);
 
@@ -192,6 +196,7 @@ print_editor_header(int item)
        else
                snprintf(header, EDITW_COLS, "%s", db_name_get(item));
 
+       wattrset(editw, COLOR_PAIR(CP_TAB_LABEL));
        mvwaddstr(editw, 0, (EDITW_COLS - strwidth(header)) / 2, header);
 
        free(header);
@@ -215,6 +220,7 @@ editor_print_data(int tab, int item)
                } else
                        y = FIELDS_START_Y;
 
+               wattrset(editw, COLOR_PAIR(CP_FIELD_NAME));
                mvwprintw(editw, y, FIELDS_START_X, "%c - ",
                                (j < 10) ? '0' + j : 'A' + j - 10);
                mvwaddnstr(editw, y, FIELDS_START_X + 4, cur->field->name,
@@ -222,6 +228,7 @@ editor_print_data(int tab, int item)
                                        FIELDNAME_MAX_WIDTH));
                mvwaddch(editw, y, TAB_COLON_POS, ':');
 
+               wattrset(editw, COLOR_PAIR(CP_FIELD_VALUE));
                if((cur->field->type == FIELD_EMAILS) ||
                                (cur->field->type == FIELD_LIST)) {
                        abook_list *emails, *e;
@@ -581,13 +588,14 @@ key_to_field_number(char c)
 static void
 edit_field(int tab, char c, int item_number)
 {
+       ui_enable_mouse(FALSE);
        int i = 0, number, idx;
        char *msg;
        abook_field_list *f;
        list_item item;
 
        if((number = key_to_field_number(c)) < 0)
-               return;
+               goto detachfield;
 
        edit_undo(item_number, BACKUP_ITEM);
 
@@ -595,7 +603,7 @@ edit_field(int tab, char c, int item_number)
 
        while(1) {
                if(!f)
-                       return;
+                       goto detachfield;
 
                if(i == number)
                        break;
@@ -624,10 +632,14 @@ edit_field(int tab, char c, int item_number)
                        break;
                case FIELD_DATE:
                        edit_date(item_number, idx);
-                       return;
+                       goto detachfield;
                default:
                        assert(0);
        }
+
+ detachfield:
+       if(opt_get_bool(BOOL_USE_MOUSE))
+         ui_enable_mouse(TRUE);
 }
 
 static int
@@ -661,6 +673,53 @@ edit_loop(int item)
 
                return item;
        }
+       if(c == KEY_MOUSE) {
+               MEVENT event;
+               if(getmouse(&event) == OK) {
+                       if(event.bstate & BUTTON1_CLICKED
+                          || event.bstate & BUTTON1_DOUBLE_CLICKED) {
+                               int window_y, window_x;
+                               getbegyx(editw, window_y, window_x);
+                               if(event.y == 0) {
+                                       /* if first row is selected, then go back to list */
+                                       return -1;
+                               } else if(event.y == window_y + TABLINE
+                                  || event.y == window_y + TABLINE + 1) {
+                                       char* tab_name;
+                                       int mouse_x = event.x;
+                                       int xpos = 2 + 1; /* look at editor_tab() and try out */
+                                       int clicked_tab = 0;
+                                       while(clicked_tab < views_count) {
+                                               view_info(clicked_tab, &tab_name, NULL);
+                                               xpos += strwidth(tab_name) + 5;
+                                               /* fprintf(stderr, "trying tab %d\n", clicked_tab); */
+                                               if(xpos >= mouse_x) {
+                                                       break; /* clicked tab was found */
+                                               } else {
+                                                       /* try next tab */
+                                                       clicked_tab++;
+                                               }
+                                       }
+                                       if(clicked_tab < views_count) {
+                                               tab = clicked_tab;
+                                       }
+                               } else if(event.y >= window_y + FIELDS_START_Y) {
+                                       /* is mouse in field area? */
+                                       int j = 1 + event.y - window_y - FIELDS_START_Y;
+                                       /* field numbers start with 1, but if j='0', then char='0' */
+                                       /* so fix this, by adding 1 to j */
+                                       int field_char = (j < 10) ? '0' + j : 'A' + j - 10;
+                                       edit_field(tab, field_char, item);
+                               }
+                       } else if(event.bstate & BUTTON4_PRESSED) {
+                               tab = tab == 0 ? views_count - 1 : tab - 1;
+                       }
+                       else if(event.bstate & BUTTON5_PRESSED) {
+                               tab = tab == views_count - 1 ? 0 : tab + 1;
+                       }
+                       return item;
+               }
+       }
 
        /* No uppercase nor numeric key should be used in this menu,
         * as they are reserved for field selection */