Re: [PATCH] : address-entry



On 06.02.2002 10:07 Pawel Salek wrote:
> On 2002.02.05 13:00 Emmanuel wrote:
>> 	Hi all,
>> here is the next patch for address-entry.c : it corrects the unbehaves 
>> of cut on address-entry : eg the patch fix the bug that occurs when you 
>> select the whole text and cut it (before it will remain a comma and a 
>> space in case there were several addresses selected).
>> This patch is to be applied after snake-3 + 
>> address-entry.c-cvs-3.patch.txt.
> 
> I do not think I can apply this patch in the present form because it 
> basically breaks cutting text from the AddressEntry. Initially, cutting 
> does not appear to work, (I recall non-functional cutting the text from 
> the middle of the entry) and after few deletions one gets infinitely 
> scrolling messages:
> 
> ** CRITICAL **: file address-entry.c: line 356 
> (libbalsa_emailData_free): assertion `addy != NULL' failed.

Aie. It seems like I didn't test it enough. Here you can find another 
version of the patch (much much cleaner and simpler because it relies on 
gtk_editable_cut_clipboard to make the job and just wraps like we do it 
for paste). This should correct all issues you mentionned (I hope). I have 
tested it OK on 1.2.4.
I also corrected a bug in keyboard event handler function that was 
assuming that the active address would not change after a cut.

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 13:23:09 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;
 }
@@ -1567,6 +1567,8 @@
     editable = GTK_EDITABLE(address_entry);
     if (editable->selection_start_pos != editable->selection_end_pos) {
 	libbalsa_cut_clipboard(address_entry);
+	/* Reload active address, this could have changed */
+	addy = input->active->data;	
     }
 
     /*
@@ -1751,8 +1753,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 +1767,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 +2058,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]