Re: [PATCH] : address-entry



	Hi all,
here is (I hope) the last patch to cure all cut problems. To be applied 
against current CVS.
It replaces the address-entry.c-cvs-4.patch.txt and 
address-entry.c-cvs-cut.patch.txt patches (previous are unrelated cleanups 
and bugfixes and seem to be OK AFAICS).
I sum up the changes :
	- rewrite of libbalsa_cut_clipboard to use 
gtk_editable_cut_clipboard so we only have to put the entry structures in 
sync with edited text, gtk takes care of the actual "cut" (this is just 
the same as what was implemented for libbalsa_paste_clipboard, I don't 
even know why cut/paste functions were not the same before!?!). This 
reduces drastically the size of the function and seems to remove a lot of 
misbehaves (without introducing new bugs ;-)

	- change order of test in libbalsa_keystroke_add_key so that if we 
have to cut we do it before. This is far better for input coherency.

Apologies for the hidden (more or less) bugs, these patches introduce 
before.
Bye
Manu
--- ../balsa-cvs/balsa/libbalsa/address-entry.c	Wed Feb  6 07:47:22 2002
+++ balsa-cvs/balsa/libbalsa/address-entry.c	Wed Feb  6 17:50:24 2002
@@ -1338,7 +1338,7 @@
     addy = address_entry->input->active->data;
     if (addy->match != NULL)
 	libbalsa_alias_accept_match(addy);
-    address_entry->input->active = g_list_first(address_entry->input->list);
+    address_entry->input->active = address_entry->input->list;
     addy = address_entry->input->active->data;
     addy->cursor = 0;
 }
@@ -1551,6 +1551,11 @@
     g_return_if_fail(LIBBALSA_IS_ADDRESS_ENTRY(address_entry));
     g_return_if_fail(add != NULL);
 
+    editable = GTK_EDITABLE(address_entry);
+    if (editable->selection_start_pos != editable->selection_end_pos) {
+	libbalsa_cut_clipboard(address_entry);
+    }
+
     /*
      * User typed a key, so cancel any matches we may have had.
      */
@@ -1562,18 +1567,13 @@
      * If this is at the beginning, and the user pressed ' ',
      * ignore it.
      */
-    if ((addy->cursor == 0) && (add[0] == (gchar) ' ')) return;
+    if (!addy->cursor && (add[0] == (gchar) ' ')) return;
     
-    editable = GTK_EDITABLE(address_entry);
-    if (editable->selection_start_pos != editable->selection_end_pos) {
-	libbalsa_cut_clipboard(address_entry);
-    }
-
-    /*
+     /*
      * Split the string at the correct cursor position.
      */
     left = g_strndup(addy->user, addy->cursor);
-    right = & addy->user[addy->cursor];
+    right = addy->user+addy->cursor;
     
     /*
      * Add the keystroke to the end of user input.
@@ -1751,8 +1751,9 @@
 
 /*************************************************************
  * libbalsa_cut_clipboard:
- *     Cuts the current selection out of the
- *     LibBalsaAddressEntry.
+ *     Wraps around gtk_editable_paste_clipboard to ensure
+ *     that user data gets reloaded into the correct
+ *     data structures.
  *
  *   arguments:
  *     address_entry: the widget.
@@ -1764,101 +1765,12 @@
 libbalsa_cut_clipboard(LibBalsaAddressEntry *address_entry)
 {
     GtkEditable *editable;
-    GList *start, *end, *list;
-    gint start_pos, end_pos;
-    gchar *str, *left, *right, *new;
-    emailData *addy;
-    gint i;
-    size_t tmp;
 
-    g_return_if_fail(address_entry != NULL);
-    g_return_if_fail(LIBBALSA_IS_ADDRESS_ENTRY(address_entry));
-    
     editable = GTK_EDITABLE(address_entry);
-    if (editable->selection_start_pos == editable->selection_end_pos)
-	return;
-    else if (editable->selection_start_pos < editable->selection_end_pos) {
-	start_pos = editable->selection_start_pos;
-	end_pos = editable->selection_end_pos;
-    } else {
-	start_pos = editable->selection_end_pos;
-	end_pos = editable->selection_start_pos;
-    }
-
-    /*
-     * First find out which addy selection_start|end_pos is in.
-     */
-    start = libbalsa_find_list_entry(address_entry, &start_pos);
-    end = libbalsa_find_list_entry(address_entry, &end_pos);
-    
-    g_assert(start != NULL);
-    g_assert(end != NULL);
-
-    if (start == end) {
-	addy = start->data;
-	str = libbalsa_make_address_string(addy);
-	libbalsa_force_no_match(addy);
-	left = g_strndup(str, start_pos);
-	right = str;
-	for (i = 0; i < end_pos; i++) right++;
-	new = g_strconcat(left, right, NULL);
-	g_free(str); /* also does g_free(right); */
-	g_free(left);
-	g_free(addy->user);
-	addy->user = new;
-	addy->cursor = start_pos;
-	if (addy->cursor > (tmp = strlen(addy->user)))
-	    addy->cursor = tmp;
-	if (addy->cursor < 0)
-	    addy->cursor = 0;
-    } else {
-	/*
-	 * Set the Start data.
-	 */
-	addy = start->data;
-	str = libbalsa_make_address_string(addy);
-	libbalsa_force_no_match(addy);
-	left = g_strndup(str, start_pos);
-	g_free(str);
-	g_free(addy->user);
-	addy->user = left;
-	addy->cursor = start_pos;
-	address_entry->input->active = start;
-	if (addy->cursor > (tmp = strlen(addy->user)))
-	    addy->cursor = tmp;
-	
-	/*
-	 * Set the end data.
-	 */
-	addy = end->data;
-	str = libbalsa_make_address_string(addy);
-	libbalsa_force_no_match(addy);
-	right = str;
-	for (i = 0; i < end_pos; i++) right++;
-	g_free(addy->user);
-	addy->user = g_strdup(right);
-	g_free(str);
-
-	/*
-	 * Set the right entry as active.
-	 */
-	addy = address_entry->input->active->data;
-	libbalsa_force_no_match(addy);
-	address_entry->input->active = start;
-
-	/*
-	 * Delete the GList inbetween(!)
-	 */
-	for (list = g_list_next(start);
-	     list != end;
-	     list = g_list_next(start)) {
-	    libbalsa_emailData_free(list->data);
-	    g_list_remove_link(address_entry->input->list, list);
-            g_list_free_1(list);
-	}
-    }
-
-    editable->selection_start_pos = editable->selection_end_pos = 0;
+    gtk_editable_cut_clipboard(editable);
+    if (address_entry->input)
+	libbalsa_inputData_free(address_entry->input);
+    address_entry->input = libbalsa_fill_input(address_entry);
 }
 
 
@@ -2144,8 +2056,8 @@
     show = g_string_new("");
     cursor = start = end = 0;
     found = FALSE;
-    for (list = g_list_first(input->list);
-	 list != NULL;
+    for (list = input->list;
+	 list;
 	 list = g_list_next(list)) {
 	/*
 	 * Is it a normal string, or is it a match that requires ()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]