gtkhtml r8725 - branches/mbarnes-composer/components/editor



Author: mbarnes
Date: Sat Feb  9 06:05:03 2008
New Revision: 8725
URL: http://svn.gnome.org/viewvc/gtkhtml?rev=8725&view=rev

Log:
Add a handy public function for running file chooser dialogs.
It takes care of loading and saving the "current-folder" property.


Modified:
   branches/mbarnes-composer/components/editor/gtkhtml-editor-private.c
   branches/mbarnes-composer/components/editor/gtkhtml-editor.c
   branches/mbarnes-composer/components/editor/gtkhtml-editor.h

Modified: branches/mbarnes-composer/components/editor/gtkhtml-editor-private.c
==============================================================================
--- branches/mbarnes-composer/components/editor/gtkhtml-editor-private.c	(original)
+++ branches/mbarnes-composer/components/editor/gtkhtml-editor-private.c	Sat Feb  9 06:05:03 2008
@@ -375,22 +375,9 @@
 	gtk_dialog_set_default_response (
 		GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
-	gtk_file_chooser_set_current_folder (
-		GTK_FILE_CHOOSER (dialog),
-		gtkhtml_editor_get_current_folder (editor));
-
 	g_signal_connect (dialog, "response", response_cb, editor);
 
-	response = gtk_dialog_run (GTK_DIALOG (dialog));
-
-	if (response == GTK_RESPONSE_OK) {
-		gchar *current_folder;
-
-		current_folder = gtk_file_chooser_get_current_folder (
-			GTK_FILE_CHOOSER (dialog));
-		gtkhtml_editor_set_current_folder (editor, current_folder);
-		g_free (current_folder);
-	}
+	response = gtkhtml_editor_file_chooser_dialog_run (editor, dialog);
 
 	gtk_widget_destroy (dialog);
 

Modified: branches/mbarnes-composer/components/editor/gtkhtml-editor.c
==============================================================================
--- branches/mbarnes-composer/components/editor/gtkhtml-editor.c	(original)
+++ branches/mbarnes-composer/components/editor/gtkhtml-editor.c	Sat Feb  9 06:05:03 2008
@@ -832,6 +832,40 @@
 	g_object_notify (G_OBJECT (editor), "current-folder");
 }
 
+gint
+gtkhtml_editor_file_chooser_dialog_run (GtkhtmlEditor *editor,
+                                        GtkWidget *dialog)
+{
+	gint response = GTK_RESPONSE_NONE;
+	gboolean save_folder;
+
+	g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), response);
+	g_return_val_if_fail (GTK_IS_FILE_CHOOSER_DIALOG (dialog), response);
+
+	gtk_file_chooser_set_current_folder (
+		GTK_FILE_CHOOSER (dialog),
+		gtkhtml_editor_get_current_folder (editor));
+
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+	save_folder =
+		(response == GTK_RESPONSE_ACCEPT) ||
+		(response == GTK_RESPONSE_OK) ||
+		(response == GTK_RESPONSE_YES) ||
+		(response == GTK_RESPONSE_APPLY);
+
+	if (save_folder) {
+		gchar *folder;
+
+		folder = gtk_file_chooser_get_current_folder (
+			GTK_FILE_CHOOSER (dialog));
+		gtkhtml_editor_set_current_folder (editor, folder);
+		g_free (folder);
+	}
+
+	return response;
+}
+
 /* Helper for gtkhtml_editor_get_text_[html/plain]() */
 static gboolean
 editor_save_receiver (HTMLEngine *engine,

Modified: branches/mbarnes-composer/components/editor/gtkhtml-editor.h
==============================================================================
--- branches/mbarnes-composer/components/editor/gtkhtml-editor.h	(original)
+++ branches/mbarnes-composer/components/editor/gtkhtml-editor.h	Sat Feb  9 06:05:03 2008
@@ -91,6 +91,9 @@
 void		gtkhtml_editor_set_current_folder
 						(GtkhtmlEditor *editor,
 						 const gchar *current_folder);
+gint		gtkhtml_editor_file_chooser_dialog_run
+						(GtkhtmlEditor *editor,
+						 GtkWidget *dialog);
 
 /*****************************************************************************
  * High-Level Editing Interface



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