[PATCH] : address-entry



	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.
Bye
Manu
--- balsa-cvs/balsa-curr/libbalsa/address-entry.c	Mon Feb  4 19:07:26 2002
+++ balsa-cvs/balsa/libbalsa/address-entry.c	Tue Feb  5 12:54:25 2002
@@ -679,7 +679,7 @@
      * We have to match the cursor in GtkEntry to the list.
      */
     g_assert(input->list != NULL);
-    list = g_list_first(input->list);
+    list = input->list;
     size = 0;
     while (list) {
 	prev=size;
@@ -1328,7 +1328,7 @@
     addy = address_entry->input->active->data;
     if (addy->match)
 	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;
 }
@@ -1757,14 +1757,14 @@
  *   results:
  *     modifies address_entry
  *************************************************************/
-static void /* FIXME : ARRET */
+static void
 libbalsa_cut_clipboard(LibBalsaAddressEntry *address_entry)
 {
     GtkEditable *editable;
-    GList *start, *end, *list;
+    GList *start, *end,*delete;
     gint start_pos, end_pos;
-    gchar *str, *left, *right, *new;
-    emailData *addy;
+    gchar *left, *right, *new;
+    emailData *addy,*addy_end;
     gint i;
     size_t tmp;
 
@@ -1791,70 +1791,63 @@
     g_assert(start != NULL);
     g_assert(end != NULL);
 
+    /* Yes this can occur : just selecting only the space preceding an address :( */
+    if (start_pos==end_pos) return;
+
+    /*
+     * Set the Start data.
+     */
+    addy = start->data;
+    left = libbalsa_make_address_string(addy);
+    /* We cut at the start pos */
+    left[start_pos]='\0';
+
+    /* Clear start address */
+    libbalsa_force_no_match(addy);
+    g_free(addy->user);
+
     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); */
+	/* concatenate both ends */
+	new = g_strconcat(left, left + end_pos, NULL);
 	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;
+	/* FIXME : should be impossible
+	   if (addy->cursor > (tmp = strlen(addy->user)))
+	   addy->cursor = tmp;
+	*/
     } 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);
+	addy_end = end->data;
+	right = libbalsa_make_address_string(addy_end);
 
-	/*
-	 * Set the right entry as active.
-	 */
-	addy = address_entry->input->active->data;
-	libbalsa_force_no_match(addy);
-	address_entry->input->active = start;
+	/* Concatenate both ends */
+	addy->user = g_strconcat(left, right + end_pos, NULL);
+	g_free(right);
 
 	/*
-	 * Delete the GList inbetween(!)
+	 * Delete the GList from the address following start to
+	 * end address
 	 */
-	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);
-	}
+	delete = g_list_next(start);
+
+	/* Unlink the part of the list that is to be deleted */
+	delete->prev=NULL;
+	start->next = end->next;
+	end->next=NULL;
+	
+	/* Free the delete list */
+	g_list_foreach(delete, (GFunc) libbalsa_emailData_free, NULL);
+	g_list_free(delete);
     }
+    
+    /* position active address */
+    address_entry->input->active = start;
 
+    /* Setup start address with new content */
+    addy->cursor = start_pos;
+    
     editable->selection_start_pos = editable->selection_end_pos = 0;
 }
 
@@ -2141,7 +2134,7 @@
     show = g_string_new("");
     cursor = start = end = 0;
     found = FALSE;
-    for (list = g_list_first(input->list);
+    for (list = input->list;
 	 list != NULL;
 	 list = g_list_next(list)) {
 	/*


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