2007-10-10 [holger] 3.0.2cvs48
authorHolger Berndt <hb@claws-mail.org>
Wed, 10 Oct 2007 07:38:06 +0000 (07:38 +0000)
committerHolger Berndt <hb@claws-mail.org>
Wed, 10 Oct 2007 07:38:06 +0000 (07:38 +0000)
* src/addrduplicates.c
* src/editaddress.c
Improvements to the addressbook duplicate finder
feature:
 - add an edit button to the button bar
 - display the whole bookname (with iface) and
   use this for same-book checking
 - after editing, try to keep selections if the
   entries are still present
 - sort the email column alphabetically
 - put results in a scrolled window
 - support embedded editing
 - make columns in detail view resizable
 - add keyboard shortcuts

ChangeLog
PATCHSETS
configure.ac
src/addrduplicates.c
src/editaddress.c

index 21a0d17f7c0b45bdb16a286f873f4734f7a70604..05678a3da82917b488021e692f6146d9dc8a394f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-10-10 [holger]    3.0.2cvs48
+
+       * src/addrduplicates.c
+       * src/editaddress.c
+               Improvements to the addressbook duplicate finder
+               feature:
+                - add an edit button to the button bar
+                - display the whole bookname (with iface) and
+                  use this for same-book checking
+                - after editing, try to keep selections if the
+                  entries are still present
+                - sort the email column alphabetically
+                - put results in a scrolled window
+                - support embedded editing
+                - make columns in detail view resizable
+                - add keyboard shortcuts
+
 2007-10-10 [wwp]       3.0.2cvs47
 
        * src/addrindex.c
index b1d59f89e9fe25e5f200d1266dbbfe24396e9ba8..256a05d90c962975c7389d91087e418615412f0c 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.14.2.31 -r 1.14.2.32 src/editaddress.c;  cvs diff -u -r 1.8.2.23 -r 1.8.2.24 src/headerview.c;  cvs diff -u -r 1.96.2.183 -r 1.96.2.184 src/textview.c;  ) > 3.0.2cvs45.patchset
 ( cvs diff -u -r 1.94.2.156 -r 1.94.2.157 src/messageview.c;  cvs diff -u -r 1.395.2.328 -r 1.395.2.329 src/summaryview.c;  cvs diff -u -r 1.96.2.184 -r 1.96.2.185 src/textview.c;  ) > 3.0.2cvs46.patchset
 ( cvs diff -u -r 1.28.2.34 -r 1.28.2.35 src/addrindex.c;  ) > 3.0.2cvs47.patchset
+( cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/addrduplicates.c;  cvs diff -u -r 1.14.2.32 -r 1.14.2.33 src/editaddress.c;  ) > 3.0.2cvs48.patchset
index bbd9a318ddbf225314e92db52349ecba66e93895..c5d65f3ceae2c2f1a518cc67ce9f76f3ec3f41d3 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=47
+EXTRA_VERSION=48
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 34a2411f2204154bade4bcdb04da581a6b63383f..bf9ef77a631ea5f93415afa97e6239af4d79dc87 100644 (file)
@@ -20,6 +20,8 @@
 #  include "config.h"
 #endif
 
+#include <gdk/gdk.h>
+#include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 #include <string.h>
 
 #include "gtkutils.h"
 #include "inc.h"
 #include "utils.h"
+#include "prefs_common.h"
 
 typedef struct
 {
        ItemPerson        *person;
        AddressDataSource *ds;
+       gchar             *book_path;
 }
 AddrDupListEntry;
 
 enum {
-    COL_BOOK = 0,
+    COL_BOOKPATH = 0,
     COL_NAME,
     COL_ITEM,
     COL_DS,
@@ -56,9 +60,11 @@ enum {
 
 static gboolean create_dialog();
 static void refresh_addr_hash(void);
-static void refresh_stores(void);
+static void refresh_stores(gchar*,GSList*);
 static void present_finder_results(GtkWindow*);
 static void cb_finder_results_dialog_destroy(GtkWindow*, gpointer);
+static gboolean cb_finder_results_dialog_key_pressed(GtkWidget*, GdkEventKey*,
+        gpointer);
 static void destroy_addr_hash_val(gpointer);
 static GSList* deep_copy_hash_val(GSList*);
 static void fill_hash_table();
@@ -73,8 +79,15 @@ static void detail_selection_changed(GtkTreeSelection*,gpointer);
 static void detail_row_activated(GtkTreeView*,GtkTreePath*,
                                  GtkTreeViewColumn*,
                                  gpointer);
+static gboolean detail_focus_in(GtkWidget*,GdkEventFocus*,gpointer);
+static gboolean detail_focus_out(GtkWidget*,GdkEventFocus*,gpointer);
+
 static void cb_del_btn_clicked(GtkButton *, gpointer);
+static void cb_edit_btn_clicked(GtkButton *, gpointer);
 static gboolean delete_item(ItemPerson*, AddressDataSource*);
+static gchar* get_bookpath(ItemPerson*,AddressDataSource*);
+static gboolean is_editing_entry_only_selection(void);
+static void edit_post_update_cb(ItemPerson*);
 
 static GHashTable *addr_hash;
 static gboolean include_same_book = TRUE;
@@ -82,8 +95,16 @@ static gboolean include_other_books = TRUE;
 
 static GtkListStore *email_store;
 static GtkListStore *detail_store;
+static GtkWidget    *email_view;
+static GtkWidget    *detail_view;
+static GtkWidget    *inline_edit_vbox;
 
 static GtkWidget *del_btn;
+static GtkWidget *edit_btn;
+
+static GtkWidget *dialog;
+static gchar *editing_uid;
+static gboolean detail_view_has_focus;
 
 void addrduplicates_find(GtkWindow *parent)
 {
@@ -158,6 +179,8 @@ static void destroy_addr_hash_val(gpointer value)
 
        for(walk = list; walk; walk = walk->next) {
                AddrDupListEntry *entry = (AddrDupListEntry*) walk->data;
+               if(entry->book_path)
+                       g_free(entry->book_path);
                if(entry)
                        g_free(entry);
        }
@@ -178,6 +201,7 @@ static GSList* deep_copy_hash_val(GSList *in)
                out_entry = g_new0(AddrDupListEntry,1);
                out_entry->person = in_entry->person;
                out_entry->ds     = in_entry->ds;
+               out_entry->book_path = g_strdup(in_entry->book_path);
                walk->data = out_entry;
        }
 
@@ -267,6 +291,7 @@ static gint collect_emails(ItemPerson *itemperson, AddressDataSource *ds)
                entry = g_new0(AddrDupListEntry,1);
                entry->person = itemperson;
                entry->ds     = ds;
+               entry->book_path = get_bookpath(itemperson, ds);
 
                new_val = g_slist_prepend(new_val, entry);
                g_hash_table_insert(addr_hash, addr, new_val);
@@ -282,19 +307,18 @@ static gint books_compare(gconstpointer a, gconstpointer b)
        const AddrDupListEntry *entry2;
        entry1 = a;
        entry2 = b;
-       return strcmp(addrindex_ds_get_name(entry1->ds),
-                     addrindex_ds_get_name(entry2->ds));
+       return strcmp(entry1->book_path, entry2->book_path);
 }
 
 static void present_finder_results(GtkWindow *parent)
 {
-       GtkWidget *email_view;
-       GtkWidget *detail_view;
-       GtkWidget *dialog = NULL;
+       GtkWidget *scrolled_win;
        GtkWidget *vbox;
        GtkWidget *hbox;
        GtkWidget *hpaned;
+       GtkWidget *vpaned;
        GtkWidget *close;
+       gint pos;
        GtkTreeSelection *email_select;
        GtkTreeSelection *detail_select;
        static GdkGeometry geometry;
@@ -305,7 +329,7 @@ static void present_finder_results(GtkWindow *parent)
        }
 
        email_store = gtk_list_store_new(1, G_TYPE_STRING);
-       refresh_stores();
+       refresh_stores(NULL,NULL);
        email_view = create_email_view(email_store);
        email_select = gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view));
        gtk_tree_selection_set_mode(email_select,GTK_SELECTION_SINGLE);
@@ -333,32 +357,72 @@ static void present_finder_results(GtkWindow *parent)
                                      GDK_HINT_MIN_SIZE);
        gtk_window_set_title(GTK_WINDOW(dialog), _("Duplicate email addresses"));
 
-
        vbox = gtk_vbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER(dialog), vbox);
 
        hpaned = gtk_hpaned_new();
        gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0);
 
-       gtk_paned_add1(GTK_PANED(hpaned), email_view);
-       gtk_paned_add2(GTK_PANED(hpaned), detail_view);
+       scrolled_win = gtk_scrolled_window_new(NULL,NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win),
+                                      GTK_POLICY_AUTOMATIC,
+                                      GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_win),
+                                             email_view);
+
+       gtk_paned_add1(GTK_PANED(hpaned), scrolled_win);
+
+       scrolled_win = gtk_scrolled_window_new(NULL,NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win),
+                                      GTK_POLICY_AUTOMATIC,
+                                      GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_win),
+                                             detail_view);
+
+       if (prefs_common.addressbook_use_editaddress_dialog) {
+               gtk_paned_add2(GTK_PANED(hpaned), scrolled_win);
+               inline_edit_vbox = NULL;
+       } else {
+               inline_edit_vbox = gtk_vbox_new(FALSE, 4);
+               vpaned = gtk_vpaned_new();
+               gtk_paned_pack1(GTK_PANED(vpaned), scrolled_win, FALSE, FALSE);
+               gtk_paned_pack2(GTK_PANED(vpaned), inline_edit_vbox, TRUE, FALSE);
+               gtk_paned_pack2(GTK_PANED(hpaned), vpaned, TRUE, FALSE);
+       }
 
-       hbox = gtk_hbox_new (FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+       g_object_get(G_OBJECT(hpaned),
+                    "position", &pos, NULL);
+       if(pos < 200)
+               gtk_paned_set_position(GTK_PANED(hpaned), 200);
 
-       close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
-       gtk_box_pack_end(GTK_BOX(hbox), close, FALSE, FALSE, 5);
+       hbox = gtk_hbutton_box_new();
+       gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
+       gtk_box_set_spacing(GTK_BOX(hbox), 2);
+       gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
+       gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+       edit_btn = gtk_button_new_from_stock(GTK_STOCK_EDIT);
+       gtk_box_pack_start(GTK_BOX(hbox), edit_btn, TRUE, TRUE, 0);
+       gtk_widget_set_sensitive(edit_btn, FALSE);
 
        del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
-       gtk_box_pack_end(GTK_BOX(hbox), del_btn, FALSE, FALSE, 5);
+       gtk_box_pack_start(GTK_BOX(hbox), del_btn, TRUE, TRUE, 0);
        gtk_widget_set_sensitive(del_btn, FALSE);
 
+       close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+       gtk_box_pack_start(GTK_BOX(hbox), close, TRUE, TRUE, 0);
+
        g_signal_connect(dialog, "destroy",
                         G_CALLBACK(cb_finder_results_dialog_destroy), NULL);
+       g_signal_connect(G_OBJECT(dialog), "key-press-event",
+                        G_CALLBACK(cb_finder_results_dialog_key_pressed), NULL);
        g_signal_connect_swapped(close, "clicked",
                                 G_CALLBACK(gtk_widget_destroy), dialog);
        g_signal_connect(del_btn, "clicked",
                         G_CALLBACK(cb_del_btn_clicked), detail_view);
+       g_signal_connect(edit_btn, "clicked",
+                        G_CALLBACK(cb_edit_btn_clicked), detail_view);
+
        inc_lock();
        gtk_widget_show_all(dialog);
 }
@@ -367,11 +431,14 @@ static void cb_finder_results_dialog_destroy(GtkWindow *win, gpointer data)
 {
        email_store = NULL;
        detail_store = NULL;
+       email_view = NULL;
+       inline_edit_vbox = NULL;
 
        if(addr_hash) {
                g_hash_table_destroy(addr_hash);
                addr_hash = NULL;
        }
+       dialog = NULL;
        addressbook_refresh();
        inc_unlock();
 }
@@ -397,6 +464,8 @@ static GtkWidget* create_detail_view(GtkListStore *store)
 {
        GtkWidget *view;
        GtkCellRenderer *renderer;
+       GList *cols;
+       GList *walk;
 
        view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
        renderer = gtk_cell_renderer_text_new();
@@ -404,9 +473,9 @@ static GtkWidget* create_detail_view(GtkListStore *store)
        /* col 1 */
        gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
                -1,
-               _("Bookname"),
+               _("Addressbook path"),
                renderer,
-               "text", COL_BOOK,
+               "text", COL_BOOKPATH,
                NULL);
        /* col 2 */
        gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
@@ -416,8 +485,20 @@ static GtkWidget* create_detail_view(GtkListStore *store)
                "text", COL_NAME,
                NULL);
 
+       cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
+       for(walk = cols; walk; walk = walk->next)
+               gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(walk->data),
+                                                  TRUE);
+       g_list_free(cols);
+
        g_signal_connect(view, "row-activated",
-                        (GCallback)detail_row_activated, NULL);
+                        G_CALLBACK(detail_row_activated), NULL);
+
+       g_signal_connect(view, "focus-in-event",
+                        G_CALLBACK(detail_focus_in), NULL);
+       g_signal_connect(view, "focus-out-event",
+                        G_CALLBACK(detail_focus_out), NULL);
+
 
        return view;
 }
@@ -431,12 +512,52 @@ static void append_to_email_store(gpointer key,gpointer value,gpointer data)
        gtk_list_store_set(store, &iter, 0, (gchar*) key, -1);
 }
 
+static gboolean is_editing_entry_only_selection(void)
+{
+       GtkTreeSelection *sel_detail;
+       GtkTreeIter iter;
+       GList *selected;
+       GtkTreeModel *model;
+       ItemPerson *item;
+
+       sel_detail = gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view));
+
+       if(gtk_tree_selection_count_selected_rows(sel_detail) > 1)
+               return FALSE;
+
+       selected = gtk_tree_selection_get_selected_rows(sel_detail,&model);
+       if(!selected)
+               return FALSE;
+
+       gtk_tree_model_get_iter(model, &iter, (GtkTreePath*)selected->data);
+       g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
+       g_list_free(selected);
+
+       gtk_tree_model_get(model, &iter, COL_ITEM, &item,-1);
+       if(ADDRITEM_ID(item) && editing_uid &&
+               strcmp(ADDRITEM_ID(item),editing_uid) == 0)
+               return TRUE;
+       else
+               return FALSE;
+}
+
 static void detail_selection_changed(GtkTreeSelection *selection, gpointer data)
 {
-       if(gtk_tree_selection_count_selected_rows(selection) > 0)
+       gint num_selected;
+       num_selected = gtk_tree_selection_count_selected_rows(selection);
+
+       if(num_selected > 0)
                gtk_widget_set_sensitive(del_btn,TRUE);
        else
                gtk_widget_set_sensitive(del_btn,FALSE);
+
+       if(num_selected == 1)
+               gtk_widget_set_sensitive(edit_btn,TRUE);
+       else
+               gtk_widget_set_sensitive(edit_btn,FALSE);
+
+       if(!is_editing_entry_only_selection())
+               addressbook_edit_person_widgetset_hide();
 }
 
 static void email_selection_changed(GtkTreeSelection *selection, gpointer data)
@@ -459,7 +580,7 @@ static void email_selection_changed(GtkTreeSelection *selection, gpointer data)
                                continue;
                        gtk_list_store_append(detail_store, &iter);
                        gtk_list_store_set(detail_store, &iter,
-                                          COL_BOOK, addrindex_ds_get_name(entry->ds),
+                                          COL_BOOKPATH, entry->book_path,
                                           COL_NAME, ADDRITEM_NAME(entry->person),
                                           COL_ITEM, entry->person,
                                           COL_DS, entry->ds,
@@ -469,7 +590,40 @@ static void email_selection_changed(GtkTreeSelection *selection, gpointer data)
        }
 }
 
-static void refresh_stores(void)
+static gchar* get_bookpath(ItemPerson *itemPerson, AddressDataSource *ds)
+{
+       gchar *path;
+       gchar *tmp;
+       AddrItemObject *item;
+
+       item = (AddrItemObject*)itemPerson;
+       path = g_strdup("");
+       while((item = ADDRITEM_PARENT(item)) != NULL) {
+
+               if(ADDRITEM_TYPE(item) == ITEMTYPE_FOLDER) {
+                       ItemFolder *folder = (ItemFolder*) item;
+                       tmp = path;
+                       path = g_strdup_printf("%s%s%s",
+                                              folder->isRoot ? addrindex_ds_get_name(ds) :
+                                              ADDRITEM_NAME(folder),
+                                              (*tmp == '\0') ? "" : "/", tmp);
+                       g_free(tmp);
+               }
+
+       }
+
+       /* prepend bookpath */
+       if(ds && ds->interface && ds->interface->name) {
+               tmp = path;
+               path = g_strdup_printf("%s%s%s", ds->interface->name,
+                                      (*tmp == '\0') ? "" : "/", tmp);
+               g_free(tmp);
+       }
+
+       return path;
+}
+
+static void refresh_stores(gchar *email_to_select, GSList *detail_to_select)
 {
        refresh_addr_hash();
        if(email_store)
@@ -477,6 +631,57 @@ static void refresh_stores(void)
        if(detail_store)
                gtk_list_store_clear(detail_store);
        g_hash_table_foreach(addr_hash,append_to_email_store,email_store);
+
+       /* sort the email store */
+       gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(email_store),
+                                            0, GTK_SORT_ASCENDING);
+
+       /* try to select email address */
+       if(email_to_select) {
+               /* Search email in email store */
+               GtkTreeIter iter;
+               GtkTreeSelection *selection;
+
+               if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(email_store), &iter))
+                       return;
+               selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view));
+
+               do {
+                       gint retVal;
+                       gchar *email;
+
+                       gtk_tree_model_get(GTK_TREE_MODEL(email_store), &iter, 0, &email, -1);
+                       retVal = g_ascii_strncasecmp(email,email_to_select,strlen(email));
+                       g_free(email);
+                       if(retVal == 0) {
+                               gtk_tree_selection_select_iter(selection,&iter);
+                               break;
+                       }
+               } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(email_store), &iter));
+
+       }
+
+       /* try to select detail rows */
+       if(detail_to_select) {
+               GtkTreeIter iter;
+               GtkTreeSelection *sel;
+               if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(detail_store), &iter))
+                       return;
+               sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view));
+
+               do {
+                       GSList *walk;
+                       ItemPerson *person;
+                       gtk_tree_model_get(GTK_TREE_MODEL(detail_store), &iter,
+                                          COL_ITEM, &person, -1);
+                       for(walk = detail_to_select; walk; walk = walk->next) {
+                               gchar *uid = walk->data;
+                               if(uid && ADDRITEM_ID(person) &&
+                                       (strcmp(uid,ADDRITEM_ID(person)) == 0))
+                                       gtk_tree_selection_select_iter(sel,&iter);
+                       }
+               } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(detail_store), &iter));
+       }
 }
 
 static void detail_row_activated(GtkTreeView       *tree_view,
@@ -504,13 +709,79 @@ static void detail_row_activated(GtkTreeView       *tree_view,
        }
 
        abf = ds->rawDataSource;
-       if(addressbook_edit_person(abf,NULL,person,FALSE,NULL,NULL,TRUE))
-               refresh_stores();
+       if(inline_edit_vbox)
+               gtk_widget_show_all(inline_edit_vbox);
+       if(editing_uid)
+               g_free(editing_uid);
+       editing_uid = g_strdup(ADDRITEM_ID(person));
+       addressbook_edit_person(abf,NULL,person,FALSE,inline_edit_vbox,
+                               edit_post_update_cb,FALSE);
 }
 
-void cb_del_btn_clicked(GtkButton *button, gpointer data)
+static void edit_post_update_cb(ItemPerson *item)
+{
+       GtkTreeSelection *sel;
+       gchar *email;
+       GList *detail_sel;
+       GList *walk;
+       GSList *detail;
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       ItemPerson *person;
+
+       /* save selection for after the update */
+
+       /* email -> string of email address */
+       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view));
+       if(gtk_tree_selection_get_selected(sel,NULL,&iter))
+               gtk_tree_model_get(GTK_TREE_MODEL(email_store), &iter, 0, &email, -1);
+       else
+               email = NULL;
+
+       /* detail -> GSList of ItemPerson UIDs */
+       detail = NULL;
+       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view));
+       detail_sel = gtk_tree_selection_get_selected_rows(sel, &model);
+       for(walk = detail_sel; walk; walk = walk->next) {
+               GtkTreePath *path = walk->data;
+               if(!gtk_tree_model_get_iter(model,&iter,path))
+                       continue;
+               gtk_tree_model_get(model, &iter, COL_ITEM, &person,-1);
+               detail = g_slist_prepend(detail, g_strdup(ADDRITEM_ID(person)));
+       }
+       g_list_foreach(detail_sel, (GFunc)gtk_tree_path_free, NULL);
+       g_list_free(detail_sel);
+
+       /* now refresh the stores, trying to keep the selections active */
+       refresh_stores(email,detail);
+
+       /* cleanup */
+       if(email)
+               g_free(email);
+       g_slist_foreach(detail, (GFunc)g_free, NULL);
+       g_slist_free(detail);
+}
+
+static void cb_edit_btn_clicked(GtkButton *button, gpointer data)
+{
+       GtkTreeSelection *selection;
+       GList *selected;
+       GtkTreeModel *model;
+
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view));
+       selected = gtk_tree_selection_get_selected_rows(selection,&model);
+       g_return_if_fail(selected);
+
+       /* we are guaranteed to have exactly one row selected */
+       gtk_tree_view_row_activated(GTK_TREE_VIEW(detail_view),(GtkTreePath*)selected->data,
+                                   gtk_tree_view_get_column(GTK_TREE_VIEW(detail_view),0));
+
+       g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
+       g_list_free(selected);
+}
+
+static void cb_del_btn_clicked(GtkButton *button, gpointer data)
 {
-       GtkTreeView *detail_view;
        GtkTreeIter iter;
        GtkTreeModel *model;
        GtkTreeSelection *selection;
@@ -521,8 +792,8 @@ void cb_del_btn_clicked(GtkButton *button, gpointer data)
        GList *walk;
        GtkTreeRowReference *ref;
        AlertValue aval;
-
-       detail_view = data;
+       GtkTreeSelection *sel;
+       gchar *email;
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view));
 
@@ -561,7 +832,14 @@ void cb_del_btn_clicked(GtkButton *button, gpointer data)
        g_list_foreach(ref_list, (GFunc)gtk_tree_row_reference_free, NULL);
        g_list_free(ref_list);
 
-       refresh_stores();
+       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view));
+       if(gtk_tree_selection_get_selected(sel,NULL,&iter))
+               gtk_tree_model_get(GTK_TREE_MODEL(email_store), &iter, 0, &email, -1);
+       else
+               email = NULL;
+       refresh_stores(email,NULL);
+       if(email)
+               g_free(email);
 }
 
 static gboolean delete_item(ItemPerson *item, AddressDataSource *ds)
@@ -601,6 +879,33 @@ static gboolean delete_item(ItemPerson *item, AddressDataSource *ds)
                g_free(filename);
                addritem_free_item_person(item);
        }
-
        return TRUE;
 }
+
+static gboolean cb_finder_results_dialog_key_pressed(GtkWidget *widget,
+        GdkEventKey *event,
+        gpointer data)
+{
+       if(event) {
+               if(event->keyval == GDK_Delete && detail_view_has_focus)
+                       cb_del_btn_clicked(NULL,NULL);
+               else if(event->keyval == GDK_Escape)
+                       gtk_widget_destroy(dialog);
+       }
+
+       return FALSE;
+}
+
+static gboolean detail_focus_in(GtkWidget *widget,
+                                GdkEventFocus *event,gpointer data)
+{
+       detail_view_has_focus = TRUE;
+       return FALSE;
+}
+
+static gboolean detail_focus_out(GtkWidget *widget,
+                                 GdkEventFocus *event,gpointer data)
+{
+       detail_view_has_focus = FALSE;
+       return FALSE;
+}
index 976cb4b6136b252c9689c1e33881585d391cde66..9b24078e2a0338aa118563e20a015fa1df599dc8 100644 (file)
@@ -1492,8 +1492,12 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo
        current_parent_folder = parent_folder;
        edit_person_close_post_update_cb = post_update_cb;
        personeditdlg.ldap = (abf && abf->type == ADBOOKTYPE_LDAP)? TRUE : FALSE;
-       if( !personeditdlg.container )
-               addressbook_edit_person_create(parent_container, &cancelled);
+
+       if( personeditdlg.container ) {
+               gtk_widget_destroy(personeditdlg.container);
+               personeditdlg.container = NULL;
+       }
+       addressbook_edit_person_create(parent_container, &cancelled);
 
        /* typically, get focus when dialog mode is enabled, or when editing a new address */
        if( get_focus ) {