[gtkhtml] Let GtkFileChooser track its own last-used-folder.



commit 28e2d2826e20d8e232235677d449feda2a7eb940
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Sep 4 14:12:51 2011 -0400

    Let GtkFileChooser track its own last-used-folder.
    
    GtkFileChooser in GTK+ 3.2 now keeps track of the last-used-folder
    itself, even across applications, so get out of its way and let it
    handle it.
    
    This is an API break for libgtkhtml-editor, but Evolution should by
    now be the only consumer of this library.

 components/editor/gtkhtml-editor-actions.c       |    6 --
 components/editor/gtkhtml-editor-private.c       |   19 +----
 components/editor/gtkhtml-editor-private.h       |    1 -
 components/editor/gtkhtml-editor.c               |   81 -----------------
 components/editor/gtkhtml-editor.h               |    8 --
 components/editor/gtkhtml-image-chooser-dialog.c |  101 ----------------------
 components/editor/gtkhtml-image-chooser-dialog.h |    5 -
 components/editor/main.c                         |    5 +-
 8 files changed, 3 insertions(+), 223 deletions(-)
---
diff --git a/components/editor/gtkhtml-editor-actions.c b/components/editor/gtkhtml-editor-actions.c
index 4769410..f01676a 100644
--- a/components/editor/gtkhtml-editor-actions.c
+++ b/components/editor/gtkhtml-editor-actions.c
@@ -627,12 +627,6 @@ action_insert_image_cb (GtkAction *action,
 	dialog = gtkhtml_image_chooser_dialog_new (
 		_("Insert Image"), GTK_WINDOW (editor));
 
-	g_object_bind_property (
-		editor, "current-folder",
-		dialog, "current-folder",
-		G_BINDING_BIDIRECTIONAL |
-		G_BINDING_SYNC_CREATE);
-
 	file = gtkhtml_image_chooser_dialog_run (
 		GTKHTML_IMAGE_CHOOSER_DIALOG (dialog));
 
diff --git a/components/editor/gtkhtml-editor-private.c b/components/editor/gtkhtml-editor-private.c
index d09eb53..f9c5d3d 100644
--- a/components/editor/gtkhtml-editor-private.c
+++ b/components/editor/gtkhtml-editor-private.c
@@ -433,7 +433,6 @@ gtkhtml_editor_private_finalize (GtkhtmlEditor *editor)
 	g_hash_table_destroy (priv->spell_suggestion_menus);
 
 	g_free (priv->filename);
-	g_free (priv->current_folder);
 }
 
 gchar *
@@ -495,7 +494,6 @@ gtkhtml_editor_run_open_dialog (GtkhtmlEditor *editor,
 	GtkFileChooser *file_chooser;
 	GFile *chosen_file = NULL;
 	GtkWidget *dialog;
-	gchar *uri;
 
 	g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), NULL);
 
@@ -512,26 +510,13 @@ gtkhtml_editor_run_open_dialog (GtkhtmlEditor *editor,
 
 	gtk_file_chooser_set_local_only (file_chooser, FALSE);
 
-	/* Restore the current folder from the previous file chooser. */
-	uri = (gchar *) gtkhtml_editor_get_current_folder (editor);
-	if (uri != NULL)
-		gtk_file_chooser_set_current_folder_uri (file_chooser, uri);
-
 	/* Allow further customizations before running the dialog. */
 	if (customize_func != NULL)
 		customize_func (dialog, customize_data);
 
-	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
-		goto exit;
-
-	chosen_file = gtk_file_chooser_get_file (file_chooser);
-
-	/* Save the current folder for subsequent file choosers. */
-	uri = gtk_file_chooser_get_current_folder_uri (file_chooser);
-	gtkhtml_editor_set_current_folder (editor, uri);
-	g_free (uri);
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+		chosen_file = gtk_file_chooser_get_file (file_chooser);
 
-exit:
 	gtk_widget_destroy (dialog);
 
 	return chosen_file;
diff --git a/components/editor/gtkhtml-editor-private.h b/components/editor/gtkhtml-editor-private.h
index e18aa08..62502ee 100644
--- a/components/editor/gtkhtml-editor-private.h
+++ b/components/editor/gtkhtml-editor-private.h
@@ -172,7 +172,6 @@ struct _GtkhtmlEditorPrivate {
 	 * a file. */
 
 	gchar *filename;
-	gchar *current_folder;
 	GtkhtmlColorPalette *palette;
 	GtkhtmlColorState *text_color;
 	guint ignore_style_change;
diff --git a/components/editor/gtkhtml-editor.c b/components/editor/gtkhtml-editor.c
index a15c0f5..6881c41 100644
--- a/components/editor/gtkhtml-editor.c
+++ b/components/editor/gtkhtml-editor.c
@@ -26,7 +26,6 @@
 
 enum {
 	PROP_0,
-	PROP_CURRENT_FOLDER,
 	PROP_FILENAME,
 	PROP_HTML,
 	PROP_HTML_MODE,
@@ -616,12 +615,6 @@ editor_set_property (GObject *object,
                      GParamSpec *pspec)
 {
 	switch (property_id) {
-		case PROP_CURRENT_FOLDER:
-			gtkhtml_editor_set_current_folder (
-				GTKHTML_EDITOR (object),
-				g_value_get_string (value));
-			return;
-
 		case PROP_FILENAME:
 			gtkhtml_editor_set_filename (
 				GTKHTML_EDITOR (object),
@@ -674,12 +667,6 @@ editor_get_property (GObject *object,
                      GParamSpec *pspec)
 {
 	switch (property_id) {
-		case PROP_CURRENT_FOLDER:
-			g_value_set_string (
-				value, gtkhtml_editor_get_current_folder (
-				GTKHTML_EDITOR (object)));
-			return;
-
 		case PROP_FILENAME:
 			g_value_set_string (
 				value, gtkhtml_editor_get_filename (
@@ -816,17 +803,6 @@ editor_class_init (GtkhtmlEditorClass *class)
 
 	g_object_class_install_property (
 		object_class,
-		PROP_CURRENT_FOLDER,
-		g_param_spec_string (
-			"current-folder",
-			"Current Folder",
-			"The initial folder for file chooser dialogs",
-			g_get_home_dir (),
-			G_PARAM_READWRITE |
-			G_PARAM_CONSTRUCT));
-
-	g_object_class_install_property (
-		object_class,
 		PROP_FILENAME,
 		g_param_spec_string (
 			"filename",
@@ -1168,29 +1144,6 @@ gtkhtml_editor_set_changed (GtkhtmlEditor *editor,
 }
 
 const gchar *
-gtkhtml_editor_get_current_folder (GtkhtmlEditor *editor)
-{
-	g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), NULL);
-
-	return editor->priv->current_folder;
-}
-
-void
-gtkhtml_editor_set_current_folder (GtkhtmlEditor *editor,
-                                   const gchar *current_folder)
-{
-	g_return_if_fail (GTKHTML_IS_EDITOR (editor));
-
-	if (current_folder == NULL)
-		current_folder = g_get_home_dir ();
-
-	g_free (editor->priv->current_folder);
-	editor->priv->current_folder = g_strdup (current_folder);
-
-	g_object_notify (G_OBJECT (editor), "current-folder");
-}
-
-const gchar *
 gtkhtml_editor_get_filename (GtkhtmlEditor *editor)
 {
 	g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), NULL);
@@ -1378,40 +1331,6 @@ gtkhtml_editor_set_spell_languages (GtkhtmlEditor *editor,
 	}
 }
 
-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_uri (
-		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_uri (
-			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,
diff --git a/components/editor/gtkhtml-editor.h b/components/editor/gtkhtml-editor.h
index 6a8d5df..2746112 100644
--- a/components/editor/gtkhtml-editor.h
+++ b/components/editor/gtkhtml-editor.h
@@ -103,11 +103,6 @@ GtkWidget *	gtkhtml_editor_get_managed_widget
 gboolean	gtkhtml_editor_get_changed	(GtkhtmlEditor *editor);
 void		gtkhtml_editor_set_changed	(GtkhtmlEditor *editor,
 						 gboolean changed);
-const gchar *	gtkhtml_editor_get_current_folder
-						(GtkhtmlEditor *editor);
-void		gtkhtml_editor_set_current_folder
-						(GtkhtmlEditor *editor,
-						 const gchar *current_folder);
 const gchar *	gtkhtml_editor_get_filename	(GtkhtmlEditor *editor);
 void		gtkhtml_editor_set_filename	(GtkhtmlEditor *editor,
 						 const gchar *filename);
@@ -132,9 +127,6 @@ GList *		gtkhtml_editor_get_spell_languages
 void		gtkhtml_editor_set_spell_languages
 						(GtkhtmlEditor *editor,
 						 GList *spell_languages);
-gint		gtkhtml_editor_file_chooser_dialog_run
-						(GtkhtmlEditor *editor,
-						 GtkWidget *dialog);
 
 /*****************************************************************************
  * High-Level Editing Interface
diff --git a/components/editor/gtkhtml-image-chooser-dialog.c b/components/editor/gtkhtml-image-chooser-dialog.c
index cadf90a..90d4bc4 100644
--- a/components/editor/gtkhtml-image-chooser-dialog.c
+++ b/components/editor/gtkhtml-image-chooser-dialog.c
@@ -25,7 +25,6 @@ typedef struct _Context Context;
 
 struct _GtkhtmlImageChooserDialogPrivate {
 	GCancellable *cancellable;
-	gchar *current_folder;
 };
 
 struct _Context {
@@ -33,11 +32,6 @@ struct _Context {
 	GCancellable *cancellable;
 };
 
-enum {
-	PROP_0,
-	PROP_CURRENT_FOLDER
-};
-
 G_DEFINE_TYPE (
 	GtkhtmlImageChooserDialog,
 	gtkhtml_image_chooser_dialog,
@@ -132,41 +126,6 @@ image_chooser_dialog_update_preview (GtkFileChooser *file_chooser)
 }
 
 static void
-image_chooser_dialog_set_property (GObject *object,
-                                   guint property_id,
-                                   const GValue *value,
-                                   GParamSpec *pspec)
-{
-	switch (property_id) {
-		case PROP_CURRENT_FOLDER:
-			gtkhtml_image_chooser_dialog_set_current_folder (
-				GTKHTML_IMAGE_CHOOSER_DIALOG (object),
-				g_value_get_string (value));
-			return;
-	}
-
-	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-image_chooser_dialog_get_property (GObject *object,
-                                   guint property_id,
-                                   GValue *value,
-                                   GParamSpec *pspec)
-{
-	switch (property_id) {
-		case PROP_CURRENT_FOLDER:
-			g_value_set_string (
-				value,
-				gtkhtml_image_chooser_dialog_get_current_folder (
-				GTKHTML_IMAGE_CHOOSER_DIALOG (object)));
-			return;
-	}
-
-	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
 image_chooser_dialog_dispose (GObject *object)
 {
 	GtkhtmlImageChooserDialogPrivate *priv;
@@ -185,20 +144,6 @@ image_chooser_dialog_dispose (GObject *object)
 }
 
 static void
-image_chooser_dialog_finalize (GObject *object)
-{
-	GtkhtmlImageChooserDialogPrivate *priv;
-
-	priv = GTKHTML_IMAGE_CHOOSER_DIALOG (object)->priv;
-
-	g_free (priv->current_folder);
-
-	/* Chain up to parent's finalize() method. */
-	G_OBJECT_CLASS (gtkhtml_image_chooser_dialog_parent_class)->
-		finalize (object);
-}
-
-static void
 image_chooser_dialog_constructed (GObject *object)
 {
 	GtkFileChooser *file_chooser;
@@ -232,22 +177,8 @@ gtkhtml_image_chooser_dialog_class_init (GtkhtmlImageChooserDialogClass *class)
 		class, sizeof (GtkhtmlImageChooserDialogPrivate));
 
 	object_class = G_OBJECT_CLASS (class);
-	object_class->set_property = image_chooser_dialog_set_property;
-	object_class->get_property = image_chooser_dialog_get_property;
 	object_class->dispose = image_chooser_dialog_dispose;
-	object_class->finalize = image_chooser_dialog_finalize;
 	object_class->constructed = image_chooser_dialog_constructed;
-
-	g_object_class_install_property (
-		object_class,
-		PROP_CURRENT_FOLDER,
-		g_param_spec_string (
-			"current-folder",
-			"Current Folder",
-			"The initial folder for file chooser dialogs",
-			g_get_home_dir (),
-			G_PARAM_READWRITE |
-			G_PARAM_CONSTRUCT));
 }
 
 static void
@@ -277,46 +208,14 @@ GFile *
 gtkhtml_image_chooser_dialog_run (GtkhtmlImageChooserDialog *dialog)
 {
 	GtkFileChooser *file_chooser;
-	gchar *uri;
 
 	g_return_val_if_fail (GTKHTML_IS_IMAGE_CHOOSER_DIALOG (dialog), NULL);
 
 	file_chooser = GTK_FILE_CHOOSER (dialog);
 
-	uri = (gchar *)
-		gtkhtml_image_chooser_dialog_get_current_folder (dialog);
-	if (uri != NULL)
-		gtk_file_chooser_set_current_folder_uri (file_chooser, uri);
-
 	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
 		return NULL;
 
-	uri = gtk_file_chooser_get_current_folder_uri (file_chooser);
-	gtkhtml_image_chooser_dialog_set_current_folder (dialog, uri);
-	g_free (uri);
-
 	return gtk_file_chooser_get_file (file_chooser);
 }
 
-const gchar *
-gtkhtml_image_chooser_dialog_get_current_folder (GtkhtmlImageChooserDialog *dialog)
-{
-	g_return_val_if_fail (GTKHTML_IS_IMAGE_CHOOSER_DIALOG (dialog), NULL);
-
-	return dialog->priv->current_folder;
-}
-
-void
-gtkhtml_image_chooser_dialog_set_current_folder (GtkhtmlImageChooserDialog *dialog,
-                                                 const gchar *current_folder)
-{
-	g_return_if_fail (GTKHTML_IS_IMAGE_CHOOSER_DIALOG (dialog));
-
-	if (current_folder == NULL)
-		current_folder = g_get_home_dir ();
-
-	g_free (dialog->priv->current_folder);
-	dialog->priv->current_folder = g_strdup (current_folder);
-
-	g_object_notify (G_OBJECT (dialog), "current-folder");
-}
diff --git a/components/editor/gtkhtml-image-chooser-dialog.h b/components/editor/gtkhtml-image-chooser-dialog.h
index 4f2e077..771b493 100644
--- a/components/editor/gtkhtml-image-chooser-dialog.h
+++ b/components/editor/gtkhtml-image-chooser-dialog.h
@@ -62,11 +62,6 @@ GtkWidget *	gtkhtml_image_chooser_dialog_new
 					 GtkWindow *parent);
 GFile *		gtkhtml_image_chooser_dialog_run
 					(GtkhtmlImageChooserDialog *dialog);
-const gchar *	gtkhtml_image_chooser_dialog_get_current_folder
-					(GtkhtmlImageChooserDialog *dialog);
-void		gtkhtml_image_chooser_dialog_set_current_folder
-					(GtkhtmlImageChooserDialog *dialog,
-					 const gchar *current_folder);
 
 G_END_DECLS
 
diff --git a/components/editor/main.c b/components/editor/main.c
index 70431a8..9f84da8 100644
--- a/components/editor/main.c
+++ b/components/editor/main.c
@@ -104,12 +104,9 @@ save_dialog (GtkhtmlEditor *editor)
 	if (filename != NULL)
 		gtk_file_chooser_set_filename (
 			GTK_FILE_CHOOSER (dialog), filename);
-	else {
-		gtk_file_chooser_set_current_folder (
-			GTK_FILE_CHOOSER (dialog), g_get_home_dir ());
+	else
 		gtk_file_chooser_set_current_name (
 			GTK_FILE_CHOOSER (dialog), _("Untitled document"));
-	}
 
 	response = gtk_dialog_run (GTK_DIALOG (dialog));
 



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