[evolution-patches] Make GtkHTML_Editor control implement Bonobo::PersistFile interface completely



Hi

The following patch does what the 'subject' says. Also it fixes the perms
used to write a file by the control and a minor bug-fix in the control's test
program. So there are 3 things in all.

Review and reply so I can commit (if possible).
Archit Baweja

===File ~/Projects/gnome2/patches/gtkhtml3-persist-file-fix.patch===
? stamp-h1
? components/html-editor/GNOME_GtkHTML_Editor-emacs.xml
? components/html-editor/test_editor
Index: components/html-editor/ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/ChangeLog,v
retrieving revision 1.420
diff -u -r1.420 ChangeLog
--- components/html-editor/ChangeLog	5 Sep 2003 06:02:53 -0000	1.420
+++ components/html-editor/ChangeLog	11 Sep 2003 21:25:35 -0000
@@ -1,3 +1,21 @@
+2003-09-10  Archit Baweja  <bighead users sourceforge net>
+
+	* persist-file.c (impl_save): call to open, mode should be 0666 instead
+	of 0600.
+	(gtk_html_persist_file_new): initialize new member, uri.
+	(finalize): free the file->uri field.
+	(gtk_html_persist_file_class_init): setup the 2 new methods. isDirty()
+	and getCurrentFile().
+	(impl_isDirty, impl_getCurrentFile): new.
+	(impl_save): call gtk_html_command (html, "saved"). Also save the
+	uri/path to which data is saved.
+	(impl_load): likewise for the uri.
+
+	* test-html-editor-control.c (file_selection_cancel_cb): new callback.
+	Destroy the whole filesel widget. Previously only the cancel_button
+	was destroyed.
+	(open_or_save_as_dialog): setup cancel callback correctly.
+
 2003-09-05  Antonio Xu  <antonio xu sun com>
 
 	* editor-control-factory.c (load_from_file): use
Index: components/html-editor/persist-file.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/persist-file.c,v
retrieving revision 1.4
diff -u -r1.4 persist-file.c
--- components/html-editor/persist-file.c	12 May 2003 20:46:48 -0000	1.4
+++ components/html-editor/persist-file.c	11 Sep 2003 21:25:40 -0000
@@ -36,6 +36,8 @@
 
 static void impl_save (PortableServer_Servant servant, const CORBA_char *path, CORBA_Environment * ev);
 static void impl_load (PortableServer_Servant servant, const CORBA_char *path, CORBA_Environment * ev);
+static CORBA_boolean impl_isDirty (PortableServer_Servant servant, CORBA_Environment *ev);
+static CORBA_char *  impl_getCurrentFile (PortableServer_Servant servant, CORBA_Environment *ev);
 
 static void
 finalize (GObject *object)
@@ -47,6 +49,11 @@
 		file->html = NULL;
 	}
 
+	if (file->uri) {
+		g_free (file->uri);
+		file->uri = NULL;
+	}
+
 	G_OBJECT_CLASS (gtk_html_persist_file_parent_class)->finalize (object);
 }
 
@@ -67,9 +74,11 @@
 
 	epv->load = impl_load;
 	epv->save = impl_save;
+	epv->getCurrentFile = impl_getCurrentFile;
 
 	object_class->finalize = finalize;
 	persist_class->get_content_types = get_content_types;
+	persist_class->epv.isDirty = impl_isDirty;
 }
 
 GType
@@ -110,6 +119,10 @@
 
 	g_object_ref (html);
 	GTK_HTML_PERSIST_FILE (file)->html = html;
+	GTK_HTML_PERSIST_FILE (file)->uri = NULL;
+	
+	/* Initially we are saved. */
+	gtk_html_command (html, "saved");
 
 	return file;
 }
@@ -160,6 +173,13 @@
 		if (was_editable)
 			gtk_html_set_editable (file->html, TRUE);
 	}
+
+	/* Free old uri. */
+	if (file->uri)
+		g_free (file->uri);
+
+	/* Save the file's uri. */
+	file->uri = g_strdup (path);
 }
 
 static gboolean
@@ -189,7 +209,7 @@
 	GtkHTMLPersistFile *file = GTK_HTML_PERSIST_FILE (bonobo_object_from_servant (servant));
 	int fd;
 
-	fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+	fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
 
 	if (fd == -1)
 		return;
@@ -197,4 +217,37 @@
 	gtk_html_save (file->html, (GtkHTMLSaveReceiverFn) save_receiver, GINT_TO_POINTER (fd));
 
 	close (fd);
+
+	/* File has been saved. */
+	gtk_html_command (file->html, "saved");
+
+	/* Free old uri. */
+	if (file->uri)
+		g_free (file->uri);
+
+	/* Save the file's uri. */
+	file->uri = g_strdup (path);
+}
+
+static CORBA_boolean
+impl_isDirty (PortableServer_Servant servant, CORBA_Environment *ev)
+{
+	GtkHTMLPersistFile *file = GTK_HTML_PERSIST_FILE (bonobo_object_from_servant (servant));
+
+	/* I don't think we drop Undos on Save-ing. */
+	return ( gtk_html_command (file->html, "is-saved") ? FALSE : TRUE );
+}
+
+static CORBA_char *
+impl_getCurrentFile (PortableServer_Servant servant, CORBA_Environment *ev)
+{
+	GtkHTMLPersistFile *file = GTK_HTML_PERSIST_FILE (bonobo_object_from_servant (servant));
+
+	/* Raise NoCurrentName exception. */
+	if (!file->uri) {
+		CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_Bonobo_PersistFile_NoCurrentName, NULL);
+		return NULL;
+	}
+
+	return g_strdup (file->uri);
 }
Index: components/html-editor/persist-file.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/persist-file.h,v
retrieving revision 1.2
diff -u -r1.2 persist-file.h
--- components/html-editor/persist-file.h	1 Nov 2002 15:35:39 -0000	1.2
+++ components/html-editor/persist-file.h	11 Sep 2003 21:25:40 -0000
@@ -44,6 +44,9 @@
 	BonoboPersist parent;
 
 	GtkHTML *html;
+
+	/* The uri of the current file this corresponds to. */
+	gchar *uri;
 };
 
 typedef struct {
Index: components/html-editor/test-html-editor-control.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/components/html-editor/test-html-editor-control.c,v
retrieving revision 1.46
diff -u -r1.46 test-html-editor-control.c
--- components/html-editor/test-html-editor-control.c	12 May 2003 20:46:48 -0000	1.46
+++ components/html-editor/test-html-editor-control.c	11 Sep 2003 21:25:49 -0000
@@ -248,6 +248,12 @@
 }
 
 static void
+file_selection_cancel_cb (GtkWidget *widget, gpointer data)
+{
+	gtk_widget_destroy (GTK_WIDGET (data));
+}
+
+static void
 file_selection_ok_cb (GtkWidget *widget,
 		      gpointer data)
 {
@@ -270,7 +276,7 @@
 		g_warning ("The Control does not seem to support `%s'.", interface_name);
 	} else 	 {
 		const gchar *fname;
-	
+
 		fname = gtk_file_selection_get_filename
 			(GTK_FILE_SELECTION (file_selection_info.widget));
 
@@ -325,8 +331,7 @@
 	file_selection_info.control = control;
 	file_selection_info.operation = op;
 
-	g_signal_connect_object (GTK_FILE_SELECTION (widget)->cancel_button,
-				 "clicked", G_CALLBACK (gtk_widget_destroy), widget, G_CONNECT_AFTER);
+	g_signal_connect (GTK_FILE_SELECTION (widget)->cancel_button, "clicked", G_CALLBACK (file_selection_cancel_cb), widget);
 	g_signal_connect (GTK_FILE_SELECTION (widget)->ok_button, "clicked", G_CALLBACK (file_selection_ok_cb), NULL);
 	g_signal_connect (file_selection_info.widget, "destroy", G_CALLBACK (file_selection_destroy_cb), NULL);
 
============================================================



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