/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
*
- * Copyright (c) 2000-2003 by Alfons Hoogervorst <alfons@proteus.demon.nl>
+ * Copyright (C) 2000-2006 by Alfons Hoogervorst & The Sylpheed Claws Team.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include "intl.h"
#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkeditable.h>
-#include <gtk/gtkclist.h>
#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtktreeview.h>
+#include <gtk/gtktreemodel.h>
+#include <gtk/gtkliststore.h>
#include <string.h>
#include <ctype.h>
#include "addrindex.h"
#include "addr_compl.h"
#include "utils.h"
+#include "prefs_common.h"
+#include "sylpheed.h"
#include <pthread.h>
+/*!
+ *\brief For the GtkListStore
+ */
+enum {
+ ADDR_COMPL_ADDRESS,
+ N_ADDR_COMPL_COLUMNS
+};
+
/*
* How it works:
*
* because the prefix passed to g_completion
* is g_strdown()'ed */
+static gchar *completion_folder_path = NULL;
+
/*******************************************************************************/
+/*
+ * Define the structure of the completion window.
+ */
+typedef struct _CompletionWindow CompletionWindow;
+struct _CompletionWindow {
+ gint listCount;
+ gchar *searchTerm;
+ GtkWidget *window;
+ GtkWidget *entry;
+ GtkWidget *list_view;
+
+ gboolean in_mouse; /*!< mouse press pending... */
+ gboolean destroying; /*!< destruction in progress */
+};
+
+static GtkListStore *addr_compl_create_store (void);
+
+static GtkWidget *addr_compl_list_view_create (CompletionWindow *window);
+
+static void addr_compl_create_list_view_columns (GtkWidget *list_view);
+
+static gboolean list_view_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ CompletionWindow *window);
+
+static gboolean list_view_button_release (GtkWidget *widget,
+ GdkEventButton *event,
+ CompletionWindow *window);
+
+static gboolean addr_compl_selected (GtkTreeSelection *selector,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean currently_selected,
+ gpointer data);
+
+static gboolean addr_compl_defer_select_destruct(CompletionWindow *window);
+
/**
* Function used by GTK to find the string data to be used for completion.
* \param data Pointer to data being processed.
{
completion_entry *ce1;
ce1 = g_new0(completion_entry, 1),
- ce1->string = g_utf8_strdown(str, -1);
/* GCompletion list is case sensitive */
- g_strdown(ce1->string);
+ ce1->string = g_utf8_strdown(str, -1);
ce1->ref = ae;
g_completion_list = g_list_prepend(g_completion_list, ce1);
* \return <code>0</code> if entry appended successfully, or <code>-1</code>
* if failure.
*/
-static gint add_address(const gchar *name, const gchar *address, const gchar *alias)
+static gint add_address(const gchar *name, const gchar *address,
+ const gchar *nick, const gchar *alias)
{
address_entry *ae;
add_address1(name, ae);
add_address1(address, ae);
- add_address1(alias, ae);
+
+ if (nick != NULL)
+ add_address1(nick, ae);
+
+ if ( alias != NULL ) {
+ add_address1(alias, ae);
+ }
return 0;
}
/**
* Read address book, creating all entries in the completion index.
*/
-static void read_address_book(void) {
- addrindex_load_completion( add_address );
+static void read_address_book(gchar *folderpath) {
+ addrindex_load_completion( add_address, folderpath );
g_address_list = g_list_reverse(g_address_list);
g_completion_list = g_list_reverse(g_completion_list);
}
static void clear_completion_cache(void)
{
if (is_completion_pending()) {
- if (g_completion_prefix)
- g_free(g_completion_prefix);
+ g_free(g_completion_prefix);
if (g_completion_addresses) {
g_slist_free(g_completion_addresses);
* address completion.
* \return The number of addresses in the completion list.
*/
-gint start_address_completion(void)
+gint start_address_completion(gchar *folderpath)
{
clear_completion_cache();
+
+ if ((completion_folder_path == NULL && folderpath != NULL) ||
+ (completion_folder_path != NULL && folderpath == NULL) ||
+ (completion_folder_path != NULL && folderpath != NULL &&
+ strcmp(completion_folder_path, folderpath) != 0)) {
+
+ debug_print("start_address_completion: resetting\n");
+
+ /* TODO: wwp: optimize: only reset when the new folderpath is MORE restrictive than the old one
+ (the most easy case is when folderpath is NULL and completion_folder_path is != NULL */
+ if (g_ref_count) {
+ free_all();
+ g_ref_count = 0;
+ }
+ }
+
+ g_free(completion_folder_path);
+ if (folderpath != NULL)
+ completion_folder_path = g_strdup(folderpath);
+ else
+ completion_folder_path = NULL;
+
if (!g_ref_count) {
init_all();
/* open the address book */
- read_address_book();
+ read_address_book(folderpath);
/* merge the completion entry list into g_completion */
if (g_completion_list)
g_completion_add_items(g_completion, g_completion_list);
}
g_ref_count++;
- debug_print("start_address_completion ref count %d\n", g_ref_count);
+ debug_print("start_address_completion(%s) ref count %d\n",
+ folderpath, g_ref_count);
return g_list_length(g_completion_list);
}
return NULL;
#define IS_VALID_CHAR(x) \
- (isalnum(x) || (x) == '"' || (x) == '<' || (((unsigned char)(x)) > 0x7f))
+ (g_ascii_isalnum(x) || (x) == '"' || (x) == '<' || (((unsigned char)(x)) > 0x7f))
/* now scan back until we hit a valid character */
for (; *p && !IS_VALID_CHAR(*p); p = g_utf8_next_char(p))
*/
guint complete_address(const gchar *str)
{
- GList *result;
- gchar *d;
- guint count, cpl;
- completion_entry *ce;
+ GList *result = NULL;
+ gchar *d = NULL;
+ guint count = 0;
+ guint cpl = 0;
+ completion_entry *ce = NULL;
g_return_val_if_fail(str != NULL, 0);
debug_print("Invalidation request for address completion\n");
free_all();
init_all();
- read_address_book();
+ read_address_book(completion_folder_path);
+ if (g_completion_list)
g_completion_add_items(g_completion, g_completion_list);
clear_completion_cache();
}
return g_ref_count;
}
-/*
- * Define the structure of the completion window.
- */
-typedef struct _CompletionWindow CompletionWindow;
-struct _CompletionWindow {
- gint listCount;
- gchar *searchTerm;
- GtkWidget *window;
- GtkWidget *entry;
- GtkWidget *clist;
-};
-
/**
* Completion window.
*/
gboolean next);
static void address_completion_create_completion_window (GtkEntry *entry);
-static void completion_window_select_row(GtkCList *clist,
- gint row,
- gint col,
- GdkEvent *event,
- CompletionWindow *compWin );
-
static gboolean completion_window_button_press
(GtkWidget *widget,
GdkEventButton *event,
cw->searchTerm = NULL;
cw->window = NULL;
cw->entry = NULL;
- cw->clist = NULL;
+ cw->list_view = NULL;
+ cw->in_mouse = FALSE;
+ cw->destroying = FALSE;
return cw;
}
if( cw ) {
/* Clear references to widgets */
cw->entry = NULL;
- cw->clist = NULL;
+ cw->list_view = NULL;
/* Free objects */
if( cw->window ) {
gtk_widget_destroy( cw->window );
}
cw->window = NULL;
+ cw->destroying = FALSE;
+ cw->in_mouse = FALSE;
}
+
}
/**
/**
* Advance selection to previous/next item in list.
- * \param clist List to process.
+ * \param list_view List to process.
* \param forward Set to <i>TRUE</i> to select next or <i>FALSE</i> for
* previous entry.
*/
-static void completion_window_advance_selection(GtkCList *clist, gboolean forward)
+static void completion_window_advance_selection(GtkTreeView *list_view, gboolean forward)
{
- int row;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
- g_return_if_fail(clist != NULL);
+ g_return_if_fail(list_view != NULL);
- if( clist->selection ) {
- row = GPOINTER_TO_INT(clist->selection->data);
- row = forward ? ( row + 1 ) : ( row - 1 );
- gtk_clist_freeze(clist);
- gtk_clist_select_row(clist, row, 0);
- gtk_clist_thaw(clist);
- }
-}
-
-#if 0
-/* completion_window_accept_selection() - accepts the current selection in the
- * clist, and destroys the window */
-static void completion_window_accept_selection(GtkWidget **window,
- GtkCList *clist,
- GtkEntry *entry)
-{
- gchar *address = NULL, *text = NULL;
- gint cursor_pos, row;
+ selection = gtk_tree_view_get_selection(list_view);
+ if (!gtk_tree_selection_get_selected(selection, &model, &iter))
+ return;
- g_return_if_fail(window != NULL);
- g_return_if_fail(*window != NULL);
- g_return_if_fail(clist != NULL);
- g_return_if_fail(entry != NULL);
- g_return_if_fail(clist->selection != NULL);
+ if (forward) {
+ forward = gtk_tree_model_iter_next(model, &iter);
+ if (forward)
+ gtk_tree_selection_select_iter(selection, &iter);
+ } else {
+ GtkTreePath *prev;
- /* FIXME: I believe it's acceptable to access the selection member directly */
- row = GPOINTER_TO_INT(clist->selection->data);
+ prev = gtk_tree_model_get_path(model, &iter);
+ if (!prev)
+ return;
- /* we just need the cursor position */
- address = get_address_from_edit(entry, &cursor_pos);
- g_free(address);
- gtk_clist_get_text(clist, row, 0, &text);
- replace_address_in_edit(entry, text, cursor_pos);
-
- clear_completion_cache();
- gtk_widget_destroy(*window);
- *window = NULL;
+ if (gtk_tree_path_prev(prev))
+ gtk_tree_selection_select_path(selection, prev);
+
+ gtk_tree_path_free(prev);
+ }
}
-#endif
/**
* Resize window to accommodate maximum number of address entries.
/* Get current geometry of window */
gdk_window_get_geometry( cw->window->window, &x, &y, &width, &height, &depth );
- gtk_widget_size_request( cw->clist, &r );
- gtk_widget_set_size_request( cw->window, width, r.height );
+ gtk_widget_hide_all( cw->window );
gtk_widget_show_all( cw->window );
- gtk_widget_size_request( cw->clist, &r );
+ gtk_widget_size_request( cw->list_view, &r );
/* Adjust window height to available screen space */
if( ( y + r.height ) > gdk_screen_height() ) {
- gtk_window_set_policy( GTK_WINDOW( cw->window ), TRUE, FALSE, FALSE );
+ gtk_window_set_resizable(GTK_WINDOW(cw->window), FALSE);
gtk_widget_set_size_request( cw->window, width, gdk_screen_height() - y );
- }
+ } else
+ gtk_widget_set_size_request(cw->window, width, r.height);
}
/**
* \param address Address to add.
*/
static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
- gchar *text[] = { NULL, NULL };
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+
+ store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cw->list_view)));
+ gtk_list_store_append(store, &iter);
/* printf( "\t\tAdding :%s\n", address ); */
- text[0] = address;
- gtk_clist_append( GTK_CLIST(cw->clist), text );
+ gtk_list_store_set(store, &iter, ADDR_COMPL_ADDRESS, address, -1);
cw->listCount++;
/* Resize window */
addrcompl_resize_window( cw );
gtk_grab_add( cw->window );
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cw->list_view));
+ gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+
if( cw->listCount == 1 ) {
/* Select first row for now */
- gtk_clist_select_row( GTK_CLIST(cw->clist), 0, 0);
+ gtk_tree_selection_select_iter(selection, &iter);
}
else if( cw->listCount == 2 ) {
+ gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
/* Move off first row */
- gtk_clist_select_row( GTK_CLIST(cw->clist), 1, 0);
+ gtk_tree_selection_select_iter(selection, &iter);
}
}
_displayQueue_ = NULL;
}
pthread_mutex_unlock( & _completionMutex_ );
+ sylpheed_do_idle();
return TRUE;
}
/**
* Apply the current selection in the list to the entry field. Focus is also
* moved to the next widget so that Tab key works correctly.
- * \param clist List to process.
+ * \param list_view List to process.
* \param entry Address entry field.
*/
-static void completion_window_apply_selection(GtkCList *clist, GtkEntry *entry)
+static void completion_window_apply_selection(GtkTreeView *list_view, GtkEntry *entry)
{
gchar *address = NULL, *text = NULL;
- gint cursor_pos, row;
+ gint cursor_pos;
GtkWidget *parent;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
- g_return_if_fail(clist != NULL);
+ g_return_if_fail(list_view != NULL);
g_return_if_fail(entry != NULL);
- g_return_if_fail(clist->selection != NULL);
+
+ selection = gtk_tree_view_get_selection(list_view);
+ if (! gtk_tree_selection_get_selected(selection, &model, &iter))
+ return;
/* First remove the idler */
if( _completionIdleID_ != 0 ) {
}
/* Process selected item */
- row = GPOINTER_TO_INT(clist->selection->data);
+ gtk_tree_model_get(model, &iter, ADDR_COMPL_ADDRESS, &text, -1);
address = get_address_from_edit(entry, &cursor_pos);
g_free(address);
- gtk_clist_get_text(clist, row, 0, &text);
replace_address_in_edit(entry, text, cursor_pos);
+ g_free(text);
/* Move focus to next widget */
parent = GTK_WIDGET(entry)->parent;
*/
void address_completion_start(GtkWidget *mainwindow)
{
- start_address_completion();
+ start_address_completion(NULL);
/* register focus change hook */
g_signal_connect(G_OBJECT(mainwindow), "set_focus",
/* add keypress event */
g_signal_connect_closure
- (GTK_OBJECT(entry), "key_press_event",
+ (G_OBJECT(entry), "key_press_event",
g_cclosure_new(G_CALLBACK(address_completion_entry_key_pressed),
COMPLETION_UNIQUE_DATA,
NULL),
entry_obj = g_object_get_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
g_return_if_fail(entry_obj);
- g_return_if_fail(entry_obj == GTK_OBJECT(entry));
+ g_return_if_fail(G_OBJECT(entry_obj) == G_OBJECT(entry));
/* has the hooked property? */
g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
/* printf( "search for :::%s:::\n", searchTerm ); */
/* Clear any existing search */
- if( _compWindow_->searchTerm ) {
- g_free( _compWindow_->searchTerm );
- }
+ g_free( _compWindow_->searchTerm );
_compWindow_->searchTerm = g_strdup( searchTerm );
/* Perform search on local completion index */
g_free( new );
}
+#ifndef USE_LDAP
+ /* Select the address if there is only one match */
+ if (ncount == 2) {
+ /* Display selected address in entry field */
+ gchar *addr = get_complete_address(1);
+
+ if (addr) {
+ replace_address_in_edit(entry, addr, cursor_pos);
+ g_free(addr);
+ }
+
+ /* Discard the window */
+ clear_completion_cache();
+ }
/* Make sure that drop-down appears uniform! */
+ else
+#endif
if( ncount == 0 ) {
addrcompl_add_queue( g_strdup( searchTerm ) );
}
static void address_completion_create_completion_window( GtkEntry *entry_ )
{
gint x, y, height, width, depth;
- GtkWidget *scroll, *clist;
+ GtkWidget *scroll, *list_view;
GtkRequisition r;
GtkWidget *window;
GtkWidget *entry = GTK_WIDGET(entry_);
/* Create new window and list */
window = gtk_window_new(GTK_WINDOW_POPUP);
- clist = gtk_clist_new(1);
+ list_view = addr_compl_list_view_create(_compWindow_);
/* Destroy any existing window */
addrcompl_destroy_window( _compWindow_ );
/* Create new object */
- _compWindow_->window = window;
- _compWindow_->entry = entry;
- _compWindow_->clist = clist;
+ _compWindow_->window = window;
+ _compWindow_->entry = entry;
+ _compWindow_->list_view = list_view;
_compWindow_->listCount = 0;
+ _compWindow_->in_mouse = FALSE;
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(window), scroll);
- gtk_container_add(GTK_CONTAINER(scroll), clist);
- gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_SINGLE);
+ gtk_container_add(GTK_CONTAINER(scroll), list_view);
/* Use entry widget to create initial window */
gdk_window_get_geometry(entry->window, &x, &y, &width, &height, &depth);
gtk_window_move(GTK_WINDOW(window), x, y);
/* Resize window to fit initial (empty) address list */
- gtk_widget_size_request( clist, &r );
+ gtk_widget_size_request( list_view, &r );
gtk_widget_set_size_request( window, width, r.height );
gtk_widget_show_all( window );
- gtk_widget_size_request( clist, &r );
+ gtk_widget_size_request( list_view, &r );
/* Setup handlers */
- g_signal_connect(G_OBJECT(clist), "select_row",
- G_CALLBACK(completion_window_select_row),
- _compWindow_ );
+ g_signal_connect(G_OBJECT(list_view), "button_press_event",
+ G_CALLBACK(list_view_button_press),
+ _compWindow_);
+
+ g_signal_connect(G_OBJECT(list_view), "button_release_event",
+ G_CALLBACK(list_view_button_release),
+ _compWindow_);
+
g_signal_connect(G_OBJECT(window),
"button-press-event",
G_CALLBACK(completion_window_button_press),
NULL, NULL, GDK_CURRENT_TIME);
gtk_grab_add( window );
- /* this gets rid of the irritating focus rectangle that doesn't
+ /* XXX: GTK2 too???
+ *
+ * GTK1: this gets rid of the irritating focus rectangle that doesn't
* follow the selection */
- GTK_WIDGET_UNSET_FLAGS(clist, GTK_CAN_FOCUS);
-}
-
-/**
- * Respond to select row event in clist object. selection sends completed
- * address to entry. Note: event is NULL if selected by anything else than a
- * mouse button.
- * \param widget Window object.
- * \param event Event.
- * \param compWind Reference to completion window.
- */
-static void completion_window_select_row(GtkCList *clist, gint row, gint col,
- GdkEvent *event,
- CompletionWindow *compWin )
-{
- GtkEntry *entry;
-
- g_return_if_fail(compWin != NULL);
-
- entry = GTK_ENTRY(compWin->entry);
- g_return_if_fail(entry != NULL);
-
- /* Don't update unless user actually selects ! */
- if (!event || event->type != GDK_BUTTON_RELEASE)
- return;
-
- /* User selected address by releasing the mouse in drop-down list*/
- completion_window_apply_selection( clist, entry );
-
- clear_completion_cache();
- addrcompl_destroy_window( _compWindow_ );
+ GTK_WIDGET_UNSET_FLAGS(list_view, GTK_CAN_FOCUS);
}
/**
GtkWidget *entry;
gchar *searchTerm;
gint cursor_pos;
- GtkWidget *clist;
+ GtkWidget *list_view;
GtkWidget *parent;
g_return_val_if_fail(compWin != NULL, FALSE);
entry = compWin->entry;
- clist = compWin->clist;
+ list_view = compWin->list_view;
g_return_val_if_fail(entry != NULL, FALSE);
- /* allow keyboard navigation in the alternatives clist */
+ /* allow keyboard navigation in the alternatives tree view */
if (event->keyval == GDK_Up || event->keyval == GDK_Down ||
event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down) {
completion_window_advance_selection
- (GTK_CLIST(clist),
+ (GTK_TREE_VIEW(list_view),
event->keyval == GDK_Down ||
event->keyval == GDK_Page_Down ? TRUE : FALSE);
return FALSE;
}
-#if 0
- /* also make tab / shift tab go to next previous completion entry. we're
- * changing the key value */
- if (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab) {
- event->keyval = (event->state & GDK_SHIFT_MASK)
- ? GDK_Up : GDK_Down;
- /* need to reset shift state if going up */
- if (event->state & GDK_SHIFT_MASK)
- event->state &= ~GDK_SHIFT_MASK;
- completion_window_advance_selection(GTK_CLIST(clist),
- event->keyval == GDK_Down ? TRUE : FALSE);
- return FALSE;
- }
-#endif
-
/* make tab move to next field */
if( event->keyval == GDK_Tab ) {
/* Reference to parent */
/* Display selected address in entry field */
completion_window_apply_selection(
- GTK_CLIST(clist), GTK_ENTRY(entry) );
+ GTK_TREE_VIEW(list_view), GTK_ENTRY(entry) );
/* Discard the window */
clear_completion_cache();
/* printf( "addrcompl_teardown...done\n" ); */
}
+/*
+ * tree view functions
+ */
+
+static GtkListStore *addr_compl_create_store(void)
+{
+ return gtk_list_store_new(N_ADDR_COMPL_COLUMNS,
+ G_TYPE_STRING,
+ -1);
+}
+
+static GtkWidget *addr_compl_list_view_create(CompletionWindow *window)
+{
+ GtkTreeView *list_view;
+ GtkTreeSelection *selector;
+ GtkTreeModel *model;
+
+ model = GTK_TREE_MODEL(addr_compl_create_store());
+ list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
+ g_object_unref(model);
+
+ gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
+ gtk_tree_view_set_headers_visible(list_view, FALSE);
+
+ selector = gtk_tree_view_get_selection(list_view);
+ gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
+ gtk_tree_selection_set_select_function(selector, addr_compl_selected,
+ window, NULL);
+
+ /* create the columns */
+ addr_compl_create_list_view_columns(GTK_WIDGET(list_view));
+
+ return GTK_WIDGET(list_view);
+}
+
+static void addr_compl_create_list_view_columns(GtkWidget *list_view)
+{
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes
+ ("", renderer, "text", ADDR_COMPL_ADDRESS, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
+}
+
+static gboolean list_view_button_press(GtkWidget *widget, GdkEventButton *event,
+ CompletionWindow *window)
+{
+ if (window && event && event->type == GDK_BUTTON_PRESS) {
+ window->in_mouse = TRUE;
+ }
+ return FALSE;
+}
+
+static gboolean list_view_button_release(GtkWidget *widget, GdkEventButton *event,
+ CompletionWindow *window)
+{
+ if (window && event && event->type == GDK_BUTTON_RELEASE) {
+ window->in_mouse = FALSE;
+ }
+ return FALSE;
+}
+
+static gboolean addr_compl_selected(GtkTreeSelection *selector,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean currently_selected,
+ gpointer data)
+{
+ CompletionWindow *window = data;
+
+ if (currently_selected)
+ return TRUE;
+
+ if (!window->in_mouse)
+ return TRUE;
+
+ /* XXX: select the entry and kill window later... select is called before
+ * any other mouse events handlers including the tree view internal one;
+ * not using a time out would result in a crash. if this doesn't work
+ * safely, maybe we should set variables when receiving button presses
+ * in the tree view. */
+ if (!window->destroying) {
+ window->destroying = TRUE;
+ g_idle_add((GSourceFunc) addr_compl_defer_select_destruct, data);
+ }
+
+ return TRUE;
+}
+
+static gboolean addr_compl_defer_select_destruct(CompletionWindow *window)
+{
+ GtkEntry *entry = GTK_ENTRY(window->entry);
+
+ completion_window_apply_selection(GTK_TREE_VIEW(window->list_view),
+ entry);
+
+ clear_completion_cache();
+
+ addrcompl_destroy_window(window);
+ return FALSE;
+}
+
+
/*
* End of Source.
*/