[evolution-patches] Re: [Evolution-hackers] Patch for GtkHTML and Composer, take two



Hi Federico!

On Fri, 2003-08-29 at 14:15 -0500, Federico Mena Quintero wrote:
> Hi,
> 
> I'm re-sending these patches so they won't be forgotten.  Libbonoboui is
> fixed and released now, so we can do in-process menu merging reliably.
> 
> GtkHTML's editor control and the Evolution composer do not merge/unmerge
> their menu items appropriately, and this patch fixes it.
> 
> The most visible bug that gets fixed with this is when you hit
> Edit/Paste while on the subject line, and the clipboard contents get
> pasted in the message body.
> 
> OK to commit?

Thanks very much for your patch. I looked over gtkhtml part and fixed
few more things - languages submenu items were not set, I also moved
spell_has_control checking to menubar_setup and cache it's value as it's
pretty expensive - I think there's some bug with complaints about that.
I am attaching an extended patch.

One thing I noticed is this warning when closing composer:

(evolution:3906): Bonobo-CRITICAL **: file bonobo-ui-component.c: line 853 (impl_xml_rm): assertion `container != CORBA_OBJECT_NIL' failed
 
it happens in menubar_detach:bonobo_ui_component_rm (uic, "/", NULL);. I
didn't look into this because I think you may know why it happens. (I am
using libbonoboui-2.2.4 from qa channel). Do you know how to fix/avoid
it?

Otherwise it works like a charm. Thanks again!

Cheers
Radek

Index: components/html-editor/ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/ChangeLog,v
retrieving revision 1.418
diff -u -p -r1.418 ChangeLog
--- components/html-editor/ChangeLog	2 Sep 2003 22:10:22 -0000	1.418
+++ components/html-editor/ChangeLog	3 Sep 2003 09:57:37 -0000
@@ -1,3 +1,32 @@
+2003-09-03  Radek Doulik  <rodo ximian com>
+
+	* menubar.c (menubar_set_languages): use control data languge
+
+	* spell.c (spell_set_language): set control data language
+
+	* control-data.c (gtk_html_control_data_new): added language
+	property
+
+	* menubar.c (menubar_setup): move spell control checking here from
+	activate callback, cache has_spell_control value - it's expensive
+	call
+	(menubar_setup): call menubar_set_languages
+
+2003-07-23  Federico Mena Quintero  <federico ximian com>
+
+	* menubar.c (menubar_setup): Save the signal ID that we connect.
+	(menubar_detach): New function, disconnects the appropriate
+	signals and removes our menu items.
+
+	* control-data.c (gtk_html_control_data_destroy): Disconnect the
+	menubar signal handler if it is present.
+
+	* editor-control-factory.c (activate_cb): In the deactivate case,
+	call menubar_detach().  Also, set the sensitivity of the
+	EditSpellCheck verb here.
+	(set_frame_cb): Don't set up the menubar here, nor the sensitivity
+	of the EditSpellCheck verb.
+
 2003-09-02  Larry Ewing  <lewing ximian com>
 
 	* GNOME_GtkHTML_Editor-emacs.xml.in: add file with emacs friendly
Index: components/html-editor/control-data.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/control-data.c,v
retrieving revision 1.21
diff -u -p -r1.21 control-data.c
--- components/html-editor/control-data.c	13 Jun 2003 21:45:01 -0000	1.21
+++ components/html-editor/control-data.c	3 Sep 2003 09:57:37 -0000
@@ -47,6 +47,8 @@ gtk_html_control_data_new (GtkHTML *html
 	ncd->search_text             = NULL;
 	ncd->replace_text_search     = NULL;
 	ncd->replace_text_replace    = NULL;
+	ncd->has_spell_control_set   = FALSE;
+	ncd->language                = NULL;
 
 	spell_init (html, ncd);
 
@@ -78,6 +80,11 @@ gtk_html_control_data_destroy (GtkHTMLCo
 
 	if (cd->languages)
 		CORBA_free (cd->languages);
+
+	if (cd->menubar_style_changed_id) {
+		g_signal_handler_disconnect (cd->html, cd->menubar_style_changed_id);
+		cd->menubar_style_changed_id = 0;
+	}
 
 	g_free (cd);
 }
Index: components/html-editor/control-data.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/control-data.h,v
retrieving revision 1.25
diff -u -p -r1.25 control-data.h
--- components/html-editor/control-data.h	14 Nov 2002 14:27:04 -0000	1.25
+++ components/html-editor/control-data.h	3 Sep 2003 09:57:39 -0000
@@ -94,6 +94,7 @@ struct _GtkHTMLControlData {
 
 	CORBA_sequence_GNOME_Spell_Language *languages;
 	gboolean                block_language_changes;
+	gchar                  *language;
 	GNOME_Spell_Dictionary  dict;
 	EditorEngine           *editor_bonobo_engine;
 	BonoboObject           *persist_stream;
@@ -103,10 +104,14 @@ struct _GtkHTMLControlData {
 	GtkWidget *spell_dialog;
 	Bonobo_PropertyBag spell_control_pb;
 	gboolean has_spell_control;
+	gboolean has_spell_control_set;
 	gboolean spell_check_next;
 
 	GtkWidget *file_dialog;
 	gboolean file_html;
+
+	/* Signal handler IDs that the menubar requires */
+	gulong menubar_style_changed_id;
 };
 
 GtkHTMLControlData * gtk_html_control_data_new       (GtkHTML *html, GtkWidget *vbox);
Index: components/html-editor/editor-control-factory.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/editor-control-factory.c,v
retrieving revision 1.134
diff -u -p -r1.134 editor-control-factory.c
--- components/html-editor/editor-control-factory.c	14 Jul 2003 22:16:55 -0000	1.134
+++ components/html-editor/editor-control-factory.c	3 Sep 2003 09:57:39 -0000
@@ -99,27 +99,28 @@ activate_cb (BonoboControl      *control
 	     gboolean            active,
 	     GtkHTMLControlData *cd)
 {
-	Bonobo_UIContainer remote_ui_container;
 	BonoboUIComponent *ui_component;
 
-	printf ("ACTIVATE\n");
+	ui_component = bonobo_control_get_ui_component (control);
 
 	if (active) {
+		Bonobo_UIContainer remote_ui_container;
+
+		cd->uic = ui_component;
+
 		remote_ui_container = bonobo_control_get_remote_ui_container (control, NULL);
-		cd->uic = ui_component = bonobo_control_get_ui_component (control);
 		bonobo_ui_component_set_container (ui_component, remote_ui_container, NULL);
 		bonobo_object_release_unref (remote_ui_container, NULL);
 
 		menubar_setup (ui_component, cd);
-	}
+	} else
+		menubar_detach (ui_component, cd);
 }
 
 static void
 set_frame_cb (BonoboControl *control,
 	      gpointer data)
 {
-	Bonobo_UIContainer remote_ui_container;
-	BonoboUIComponent *ui_component;
 	GtkHTMLControlData *control_data;
 	GtkWidget *toolbar;
 	GtkWidget *scrolled_window;
@@ -134,10 +135,7 @@ set_frame_cb (BonoboControl *control,
 		return;
 
 	CORBA_Object_release (frame, NULL);
-
-	remote_ui_container = bonobo_control_get_remote_ui_container (control, NULL);
-	control_data->uic = ui_component = bonobo_control_get_ui_component (control);
-	bonobo_ui_component_set_container (ui_component, remote_ui_container, NULL);
+	control_data->uic = bonobo_control_get_ui_component (control);
 
 	/* Setup the tool bar.  */
 
@@ -152,19 +150,7 @@ set_frame_cb (BonoboControl *control,
 
 	gtk_box_pack_start (GTK_BOX (control_data->vbox), scrolled_window, TRUE, TRUE, 0);
 
-	/* Setup the menu bar.  */
-
-	menubar_setup (ui_component, control_data);
-
-	if (!spell_has_control ()) {
-		control_data->has_spell_control = FALSE;
-		bonobo_ui_component_set_prop (ui_component, "/commands/EditSpellCheck", "sensitive", "0", NULL);
-	} else
-		control_data->has_spell_control = TRUE;
-
 	gtk_html_set_editor_api (GTK_HTML (control_data->html), editor_api, control_data);
-
-	bonobo_object_release_unref (remote_ui_container, NULL);
 }
 
 static gint
Index: components/html-editor/menubar.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/menubar.c,v
retrieving revision 1.93
diff -u -p -r1.93 menubar.c
--- components/html-editor/menubar.c	2 Sep 2003 22:10:22 -0000	1.93
+++ components/html-editor/menubar.c	3 Sep 2003 09:57:39 -0000
@@ -617,7 +617,7 @@ menubar_update_format (GtkHTMLControlDat
 }
 
 void
-menubar_set_languages (GtkHTMLControlData *cd, const gchar *lstr)
+menubar_set_languages (GtkHTMLControlData *cd)
 {
 	GString *str;
 	gboolean enabled;
@@ -629,7 +629,7 @@ menubar_set_languages (GtkHTMLControlDat
 	str = g_string_new (NULL);
 	cd->block_language_changes = TRUE;
 	for (i = 0; i < cd->languages->_length; i ++) {
-		enabled = strstr (lstr, cd->languages->_buffer [i].abbreviation) != NULL;
+		enabled = strstr (cd->language, cd->languages->_buffer [i].abbreviation) != NULL;
 		g_string_printf (str, "/commands/SpellLanguage%d", i + 1);
 		bonobo_ui_component_set_prop (cd->uic, str->str, "state", enabled ? "1" : "0", NULL);
 	}
@@ -703,11 +703,36 @@ menubar_setup (BonoboUIComponent  *uic,
 	}
 
 	spell_create_language_menu (cd);
+	menubar_set_languages (cd);
 	menubar_update_format (cd);
 
 	textdomain (domain);
 	g_free (domain);
 
 	menubar_paragraph_style_changed_cb (cd->html, gtk_html_get_paragraph_style (cd->html), cd);
-	g_signal_connect (cd->html, "current_paragraph_style_changed", G_CALLBACK (menubar_paragraph_style_changed_cb), cd);
+	cd->menubar_style_changed_id = g_signal_connect (cd->html, "current_paragraph_style_changed",
+							 G_CALLBACK (menubar_paragraph_style_changed_cb), cd);
+	if (!cd->has_spell_control_set) {
+		cd->has_spell_control = spell_has_control ();
+		cd->has_spell_control_set = TRUE;
+	}
+
+	if (!cd->has_spell_control) {
+		cd->has_spell_control = FALSE;
+		bonobo_ui_component_set_prop (uic, "/commands/EditSpellCheck", "sensitive", "0", NULL);
+	} else {
+		cd->has_spell_control = TRUE;
+		bonobo_ui_component_set_prop (uic, "/commands/EditSpellCheck", "sensitive", "1", NULL);
+	}
+}
+
+void
+menubar_detach (BonoboUIComponent  *uic,
+		GtkHTMLControlData *cd)
+{
+	g_signal_handler_disconnect (cd->html, cd->menubar_style_changed_id);
+	cd->menubar_style_changed_id = 0;
+
+	bonobo_ui_component_rm (uic, "/", NULL);
+	bonobo_ui_component_unset_container (uic, NULL);
 }
Index: components/html-editor/menubar.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/menubar.h,v
retrieving revision 1.6
diff -u -p -r1.6 menubar.h
--- components/html-editor/menubar.h	17 Dec 2001 18:34:12 -0000	1.6
+++ components/html-editor/menubar.h	3 Sep 2003 09:57:39 -0000
@@ -29,8 +29,9 @@
 
 void  menubar_setup          (BonoboUIComponent  *uic,
 			      GtkHTMLControlData *cd);
+void  menubar_detach         (BonoboUIComponent  *uic,
+			      GtkHTMLControlData *cd);
 void  menubar_update_format  (GtkHTMLControlData *cd);
-void  menubar_set_languages  (GtkHTMLControlData *cd,
-			      const gchar        *lstr);
+void  menubar_set_languages  (GtkHTMLControlData *cd);
 void  insert_table           (GtkHTMLControlData *cd);
 #endif /* _MENUBAR_H */
Index: components/html-editor/spell.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/spell.c,v
retrieving revision 1.41
diff -u -p -r1.41 spell.c
--- components/html-editor/spell.c	13 Jun 2003 21:45:01 -0000	1.41
+++ components/html-editor/spell.c	3 Sep 2003 09:57:39 -0000
@@ -133,7 +133,10 @@ spell_set_language (GtkHTML *html, const
 	GNOME_Spell_Dictionary_setLanguage (cd->dict, language, &ev);
 	CORBA_exception_free (&ev);
 
-	menubar_set_languages (cd, language);
+	g_free (cd->language);
+	cd->language = g_strdup (language);
+
+	menubar_set_languages (cd);
 }
 
 void
@@ -327,8 +330,10 @@ language_cb (BonoboUIComponent *uic, con
 	}
 
 	html_engine_set_language (cd->html->engine, str->str);
+	g_free (cd->language);
+	cd->language = str->str;
 
-	g_string_free (str, TRUE);
+	g_string_free (str, FALSE);
 	g_string_free (lang, TRUE);
 }
 


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