Re: [evolution-patches] Improvements to the e-name-selector-entry



On Tue, 2005-06-07 at 11:29 +0530, Sushma Rai wrote:
> Looks fine for me.. Commit it to cvs head with the Changelog
> Also add a check for NULL EDestination.
> 
> It'll be easier to review patches if you use cvs diff with "-up"
> 

I attached a new patch against the ChangeLog, test-name-selector.c (the
modal stuff) and e-name-selector-entry.c (with some anti-crash
improvements).



-- 
Philip Van Hoof, Software Developer @ Cronos
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: philip dot vanhoof at cronos dot be
junk: philip dot vanhoof at gmail dot com
http://www.pvanhoof.be/
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserverui/ChangeLog,v
retrieving revision 1.43
diff -u -p -r1.43 ChangeLog
--- ChangeLog	7 Jun 2005 06:31:50 -0000	1.43
+++ ChangeLog	7 Jun 2005 08:06:50 -0000
@@ -1,3 +1,7 @@
+2005-06-06  Philip Van Hoof  <pvanhoof gnome org
+
+	* e-name-selector-entry.c: Making it more easy to remove destinations
+
 2005-06-07  Sushma Rai  <rsushma novell com>
 
 	* e-name-selector-dialog.c (e_name_selector_dialog_init): Making the
Index: test-name-selector.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserverui/test-name-selector.c,v
retrieving revision 1.5
diff -u -p -r1.5 test-name-selector.c
--- test-name-selector.c	20 Dec 2004 15:31:29 -0000	1.5
+++ test-name-selector.c	7 Jun 2005 08:06:50 -0000
@@ -67,6 +67,8 @@ start_test (void)
  	g_signal_connect (name_selector_dialog, "response", G_CALLBACK (close_dialog), name_selector_dialog);
 	gtk_widget_show (GTK_WIDGET (name_selector_dialog));
 
+	gtk_window_set_modal (GTK_WINDOW(name_selector_dialog), FALSE);
+	
 	container = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 	gtk_container_add (GTK_CONTAINER (container), GTK_WIDGET (name_selector_entry));
 	gtk_widget_show_all (container);
Index: e-name-selector-entry.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserverui/e-name-selector-entry.c,v
retrieving revision 1.17
diff -u -p -r1.17 e-name-selector-entry.c
--- e-name-selector-entry.c	4 May 2005 08:43:58 -0000	1.17
+++ e-name-selector-entry.c	7 Jun 2005 08:06:54 -0000
@@ -906,14 +906,17 @@ remove_destination_at_position (ENameSel
 	EDestination *destination;
 
 	destination = find_destination_at_position (name_selector_entry, pos);
-	g_assert (destination);
+	if (destination)
+	{
+		g_assert (destination);
 
-	g_signal_handlers_block_by_func (name_selector_entry->destination_store,
+		g_signal_handlers_block_by_func (name_selector_entry->destination_store,
 					 destination_row_deleted, name_selector_entry);
-	e_destination_store_remove_destination (name_selector_entry->destination_store,
+		e_destination_store_remove_destination (name_selector_entry->destination_store,
 						destination);
-	g_signal_handlers_unblock_by_func (name_selector_entry->destination_store,
+		g_signal_handlers_unblock_by_func (name_selector_entry->destination_store,
 					   destination_row_deleted, name_selector_entry);
+	}
 }
 
 static void
@@ -967,14 +970,17 @@ remove_destination_by_index (ENameSelect
 	EDestination *destination;
 
 	destination = find_destination_by_index (name_selector_entry, index);
-	g_assert (destination);
+	if (destination)
+	{
+		g_assert (destination);
 
-	g_signal_handlers_block_by_func (name_selector_entry->destination_store,
+		g_signal_handlers_block_by_func (name_selector_entry->destination_store,
 					 destination_row_deleted, name_selector_entry);
-	e_destination_store_remove_destination (name_selector_entry->destination_store,
+		e_destination_store_remove_destination (name_selector_entry->destination_store,
 						destination);
-	g_signal_handlers_unblock_by_func (name_selector_entry->destination_store,
+		g_signal_handlers_unblock_by_func (name_selector_entry->destination_store,
 					   destination_row_deleted, name_selector_entry);
+	}
 }
 
 /* Returns the number of characters inserted */
@@ -1123,7 +1129,7 @@ user_delete_text (ENameSelectorEntry *na
 {
 	const gchar *text;
 	gint         index_start, index_end;
-	gunichar     str_context [2];
+	gunichar     str_context [2], str_b_context [2];
 	gchar        buf [7];
 	gint         len;
 	gint         i;
@@ -1134,6 +1140,7 @@ user_delete_text (ENameSelectorEntry *na
 	text = gtk_entry_get_text (GTK_ENTRY (name_selector_entry));
 	len = g_utf8_strlen (text, -1);
 	get_utf8_string_context (text, start_pos, str_context, 2);
+	get_utf8_string_context (text, end_pos-1, str_b_context, 2);
 
 	g_signal_handlers_block_by_func (name_selector_entry, user_delete_text, name_selector_entry);
 
@@ -1146,13 +1153,53 @@ user_delete_text (ENameSelectorEntry *na
 		}
 	}
 
-	if (str_context [0] == ',' && str_context [1] == ' ') {
-		/* If we're deleting the trailing space in ", ", delete the whole ", " sequence. */
-		start_pos--;
-	}
-
 	index_start = get_index_at_position (text, start_pos);
 	index_end   = get_index_at_position (text, end_pos);
+	
+	g_signal_stop_emission_by_name (name_selector_entry, "delete_text");
+	
+	/* If the user is trying to delete a ','-character, we assume the user 
+	 * wants to remove the entire destination.
+	 */
+	
+	if ((str_b_context [0] == ',' && str_b_context [1] == ' ') || str_b_context [1] == ',') {
+	
+	  EDestination *dest = find_destination_at_position (name_selector_entry, end_pos-1);
+	  const char *email = e_destination_get_email (dest);
+	  if (email && (strcmp (email, "")!=0)) {
+	  
+		/* Therefore, in case it's a real destination, we select it. 
+		 * Deleting this selection afterwards will leave the destination
+		 * empty. */
+	 
+		gint t = (str_b_context [1]==',')?end_pos-1:end_pos-2, b=t;
+		do {
+			t--;
+		} while (t >= 1 && text[t-1] != ',');
+		
+		gtk_editable_select_region (GTK_EDITABLE(name_selector_entry), t, b);
+		
+	  } else {
+	  
+		/* However, if the destination was emptied, we allow the user to
+		 * remove the placeholder too (else the ','-characters aren't
+		 * removable anymore) */
+		 
+		for (i = index_end; i > index_start; i--)
+			remove_destination_by_index (name_selector_entry, i);
+		gtk_editable_delete_text (GTK_EDITABLE (name_selector_entry),
+				  start_pos, end_pos);
+	  }
+	  
+	  /* Since this is a special-case, we don't want the rest of this method
+	   * to happen. However, we do need to reenable the signal which we
+	   * disabled above! */
+	   
+	  goto end_of_user_delete_text;
+
+	}
+	
+
 
 	/* If the deletion touches more than one destination, the first one is changed
 	 * and the rest are removed. If the last destination wasn't completely deleted,
@@ -1162,11 +1209,13 @@ user_delete_text (ENameSelectorEntry *na
 	 * Here, we let the model know about removals. */
 	for (i = index_end; i > index_start; i--)
 		remove_destination_by_index (name_selector_entry, i);
-
+	
 	/* Do the actual deletion */
+	
+	
 	gtk_editable_delete_text (GTK_EDITABLE (name_selector_entry),
 				  start_pos, end_pos);
-	g_signal_stop_emission_by_name (name_selector_entry, "delete_text");
+	
 
 	/* Let model know about changes */
 	text = gtk_entry_get_text (GTK_ENTRY (name_selector_entry));
@@ -1187,7 +1236,8 @@ user_delete_text (ENameSelectorEntry *na
 		g_source_remove (name_selector_entry->type_ahead_complete_cb_id);
 		name_selector_entry->type_ahead_complete_cb_id = 0;
 	}
-
+	
+end_of_user_delete_text:
 	g_signal_handlers_unblock_by_func (name_selector_entry, user_delete_text, name_selector_entry);
 }
 


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