File gtk2-bnc355503-file-chooser-remember-geometry.diff of Package gtk2

From 048a63053003854a380b5dd4aaf0cdf939d893f4 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Thu, 23 Oct 2008 16:41:35 -0500
Subject: [PATCH 01/23] Add GtkFileChooserSettings for the dialog's geometry

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechoosersettings.c |   68 ++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkfilechoosersettings.h |   16 ++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechoosersettings.c b/gtk/gtkfilechoosersettings.c
index b80d362..37985c6 100644
--- a/gtk/gtkfilechoosersettings.c
+++ b/gtk/gtkfilechoosersettings.c
@@ -41,6 +41,10 @@
 #define LOCATION_MODE_KEY	"LocationMode"
 #define SHOW_HIDDEN_KEY		"ShowHidden"
 #define EXPAND_FOLDERS_KEY	"ExpandFolders"
+#define GEOMETRY_X_KEY		"GeometryX"
+#define GEOMETRY_Y_KEY		"GeometryY"
+#define GEOMETRY_WIDTH_KEY	"GeometryWidth"
+#define GEOMETRY_HEIGHT_KEY	"GeometryHeight"
 
 #define MODE_PATH_BAR          "path-bar"
 #define MODE_FILENAME_ENTRY    "filename-entry"
@@ -60,6 +64,24 @@ get_config_filename (void)
 }
 
 static void
+get_int_key (GKeyFile *key_file, const char *group, const char *key, int *out_value)
+{
+  GError *error;
+  int val;
+
+  error = NULL;
+  val = g_key_file_get_integer (key_file, group, key, &error);
+
+  if (val == 0 && error != NULL)
+    {
+      *out_value = -1;
+      g_error_free (error);
+    }
+  else
+    *out_value = val;
+}
+
+static void
 ensure_settings_read (GtkFileChooserSettings *settings)
 {
   GError *error;
@@ -127,6 +149,11 @@ ensure_settings_read (GtkFileChooserSettings *settings)
   else
     settings->expand_folders = value != FALSE;
 
+  get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_X_KEY, &settings->geometry_x);
+  get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_Y_KEY, &settings->geometry_y);
+  get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_WIDTH_KEY, &settings->geometry_width);
+  get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_HEIGHT_KEY, &settings->geometry_height);
+
  out:
 
   g_key_file_free (key_file);
@@ -148,6 +175,11 @@ _gtk_file_chooser_settings_init (GtkFileChooserSettings *settings)
   settings->location_mode = LOCATION_MODE_PATH_BAR;
   settings->show_hidden = FALSE;
   settings->expand_folders = FALSE;
+
+  settings->geometry_x	    = -1;
+  settings->geometry_y	    = -1;
+  settings->geometry_width  = -1;
+  settings->geometry_height = -1;
 }
 
 GtkFileChooserSettings *
@@ -198,6 +230,34 @@ _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
   settings->expand_folders = expand_folders != FALSE;
 }
 
+void
+_gtk_file_chooser_settings_get_geometry (GtkFileChooserSettings *settings,
+					 int                    *out_x,
+					 int                    *out_y,
+					 int                    *out_width,
+					 int                    *out_heigth)
+{
+  ensure_settings_read (settings);
+
+  *out_x      = settings->geometry_x;
+  *out_y      = settings->geometry_y;
+  *out_width  = settings->geometry_width;
+  *out_height = settings->geometry_height;
+}
+
+void
+_gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings,
+					 int                     x,
+					 int                     y,
+					 int                     width,
+					 int                     heigth)
+{
+  settings->geometry_x	    = x;
+  settings->geometry_y	    = y;
+  settings->geometry_width  = width;
+  settings->geometry_height = height;
+}
+
 gboolean
 _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
 				 GError                **error)
@@ -238,6 +298,14 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
 			  SHOW_HIDDEN_KEY, settings->show_hidden);
   g_key_file_set_boolean (key_file, SETTINGS_GROUP,
 			  EXPAND_FOLDERS_KEY, settings->expand_folders);
+  g_key_file_set_integer (key_file, SETTINGS_GROUP,
+			  GEOMETRY_X_KEY, settings->geometry_x);
+  g_key_file_set_integer (key_file, SETTINGS_GROUP,
+			  GEOMETRY_Y_KEY, settings->geometry_y);
+  g_key_file_set_integer (key_file, SETTINGS_GROUP,
+			  GEOMETRY_WIDTH_KEY, settings->geometry_width);
+  g_key_file_set_integer (key_file, SETTINGS_GROUP,
+			  GEOMETRY_HEIGHT_KEY, settings->geometry_height);
 
   contents = g_key_file_to_data (key_file, &len, error);
   g_key_file_free (key_file);
diff --git a/gtk/gtkfilechoosersettings.h b/gtk/gtkfilechoosersettings.h
index c7c4179..94d2e3a 100644
--- a/gtk/gtkfilechoosersettings.h
+++ b/gtk/gtkfilechoosersettings.h
@@ -38,6 +38,11 @@ struct _GtkFileChooserSettings
 
   LocationMode location_mode;
 
+  int geometry_x;
+  int geometry_y;
+  int geometry_width;
+  int geometry_height;
+
   guint settings_read : 1;
 
   guint show_hidden : 1;
@@ -66,6 +71,17 @@ gboolean _gtk_file_chooser_settings_get_expand_folders (GtkFileChooserSettings *
 void     _gtk_file_chooser_settings_set_expand_folders (GtkFileChooserSettings *settings,
 							gboolean                expand_folders);
 
+void _gtk_file_chooser_settings_get_geometry (GtkFileChooserSettings *settings,
+					      int                    *out_x,
+					      int                    *out_y,
+					      int                    *out_width,
+					      int                    *out_heigth);
+void _gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings,
+					      int                     x,
+					      int                     y,
+					      int                     width,
+					      int                     heigth);
+
 gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
 					  GError                **error);
 
-- 
1.5.6


From 5fc9269c2e92d2d3c46c01e9a7e29826d950ef5e Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Thu, 23 Oct 2008 16:42:27 -0500
Subject: [PATCH 02/23] Save the dialog geometry when the file chooser unmaps

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 16759a1..63ac9e7 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5986,6 +5986,23 @@ settings_load (GtkFileChooserDefault *impl)
 }
 
 static void
+save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *settings)
+{
+  GtkWindow *toplevel;
+  int x, y, width, heigth;
+
+  toplevel = get_toplevel (GTK_WIDGET (impl));
+
+  if (!(toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel)))
+    return;
+
+  gtk_window_get_position (toplevel, &x, &y);
+  gtk_window_get_size (toplevel, &width, &height);
+
+  _gtk_file_chooser_settings_set_geometry (settings, x, y, width, height);
+}
+
+static void
 settings_save (GtkFileChooserDefault *impl)
 {
   GtkFileChooserSettings *settings;
@@ -5996,6 +6013,8 @@ settings_save (GtkFileChooserDefault *impl)
   _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
   _gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
 
+  save_dialog_geometry (impl, settings);
+
   /* NULL GError */
   _gtk_file_chooser_settings_save (settings, NULL);
 
-- 
1.5.6


From 66937f842a0199a01e872c27a9fe68f9159f8ee7 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Wed, 29 Oct 2008 12:05:12 -0600
Subject: [PATCH 03/23] Move/resize the file chooser dialog when the settings get loaded

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 63ac9e7..74bc138 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5969,6 +5969,7 @@ settings_load (GtkFileChooserDefault *impl)
   LocationMode location_mode;
   gboolean show_hidden;
   gboolean expand_folders;
+  int x, y, width, heigth;
 
   settings = _gtk_file_chooser_settings_new ();
 
@@ -5976,6 +5977,20 @@ settings_load (GtkFileChooserDefault *impl)
   show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
   expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
 
+  _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
+  if (x >= 0 && y >= 0 && width > 0 && height > 0)
+    {
+      GtkWindow *toplevel;
+
+      toplevel = get_toplevel (GTK_WIDGET (impl));
+
+      if (toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel))
+	{
+	  gtk_window_move (toplevel, x, y);
+	  gtk_window_resize (toplevel, width, heigth);
+	}
+    }
+
   g_object_unref (settings);
 
   location_mode_set (impl, location_mode, TRUE);
-- 
1.5.6


From e1f3aa1cf60f940c2823916bd4f123ab668c2481 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 4 Nov 2008 14:50:26 -0600
Subject: [PATCH 04/23] FIX: settings_load

---
 gtk/gtkfilechooserdefault.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 74bc138..5c53d48 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5969,7 +5969,7 @@ settings_load (GtkFileChooserDefault *impl)
   LocationMode location_mode;
   gboolean show_hidden;
   gboolean expand_folders;
-  int x, y, width, heigth;
+  int x, y, width, height;
 
   settings = _gtk_file_chooser_settings_new ();
 
-- 
1.5.6


From 83cff057f0f758c58346ec2a09f2bc4e5589026a Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 4 Nov 2008 14:50:31 -0600
Subject: [PATCH 05/23] FIX: include file

---
 gtk/gtkfilechooserdefault.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 5c53d48..5cd3dba 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -34,6 +34,7 @@
 #include "gtkexpander.h"
 #include "gtkfilechooserprivate.h"
 #include "gtkfilechooserdefault.h"
+#include "gtkfilechooserdialog.h"
 #include "gtkfilechooserembed.h"
 #include "gtkfilechooserentry.h"
 #include "gtkfilechoosersettings.h"
-- 
1.5.6


From 66f240ec4a37d275c4cc6e8069386c5aefa71146 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 4 Nov 2008 14:52:15 -0600
Subject: [PATCH 06/23] FIX: height misspellings

---
 gtk/gtkfilechooserdefault.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 5cd3dba..e795ba5 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5988,7 +5988,7 @@ settings_load (GtkFileChooserDefault *impl)
       if (toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel))
 	{
 	  gtk_window_move (toplevel, x, y);
-	  gtk_window_resize (toplevel, width, heigth);
+	  gtk_window_resize (toplevel, width, height);
 	}
     }
 
@@ -6005,7 +6005,7 @@ static void
 save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *settings)
 {
   GtkWindow *toplevel;
-  int x, y, width, heigth;
+  int x, y, width, height;
 
   toplevel = get_toplevel (GTK_WIDGET (impl));
 
-- 
1.5.6


From 83df5f40b1cfa13c731f28abdf414e05d9be15e4 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 4 Nov 2008 15:55:24 -0600
Subject: [PATCH 07/23] FIX: settings misspellings

---
 gtk/gtkfilechoosersettings.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gtk/gtkfilechoosersettings.c b/gtk/gtkfilechoosersettings.c
index 37985c6..c887928 100644
--- a/gtk/gtkfilechoosersettings.c
+++ b/gtk/gtkfilechoosersettings.c
@@ -235,7 +235,7 @@ _gtk_file_chooser_settings_get_geometry (GtkFileChooserSettings *settings,
 					 int                    *out_x,
 					 int                    *out_y,
 					 int                    *out_width,
-					 int                    *out_heigth)
+					 int                    *out_height)
 {
   ensure_settings_read (settings);
 
@@ -250,7 +250,7 @@ _gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings,
 					 int                     x,
 					 int                     y,
 					 int                     width,
-					 int                     heigth)
+					 int                     height)
 {
   settings->geometry_x	    = x;
   settings->geometry_y	    = y;
-- 
1.5.6


From 023c89c70e96643c137816618c625970c59a912c Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 4 Nov 2008 16:45:08 -0600
Subject: [PATCH 08/23] Set the position in GtkFileChooserDialog

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   30 +++++++++++++++---------------
 gtk/gtkfilechooserdialog.c  |   19 +++++++++++++++++++
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index e795ba5..ca9991e 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5970,7 +5970,6 @@ settings_load (GtkFileChooserDefault *impl)
   LocationMode location_mode;
   gboolean show_hidden;
   gboolean expand_folders;
-  int x, y, width, height;
 
   settings = _gtk_file_chooser_settings_new ();
 
@@ -5978,20 +5977,6 @@ settings_load (GtkFileChooserDefault *impl)
   show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
   expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
 
-  _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
-  if (x >= 0 && y >= 0 && width > 0 && height > 0)
-    {
-      GtkWindow *toplevel;
-
-      toplevel = get_toplevel (GTK_WIDGET (impl));
-
-      if (toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel))
-	{
-	  gtk_window_move (toplevel, x, y);
-	  gtk_window_resize (toplevel, width, height);
-	}
-    }
-
   g_object_unref (settings);
 
   location_mode_set (impl, location_mode, TRUE);
@@ -7853,9 +7838,24 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
 {
   GtkFileChooserDefault *impl;
   GtkRequisition req;
+  GtkFileChooserSettings *settings;
+  int x, y, width, height;
 
   impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
 
+  settings = _gtk_file_chooser_settings_new ();
+  _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
+  g_object_unref (settings);
+
+  if (x >= 0 && y >= 0 && width > 0 && height > 0)
+    {
+      GtkWindow *toplevel;
+
+      *default_width = width;
+      *default_height = height;
+      return;
+    }
+
   if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
       || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
       || impl->expand_folders)
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index ec42374..5ebfdd9 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -25,6 +25,7 @@
 #include "gtkfilechooserwidget.h"
 #include "gtkfilechooserutils.h"
 #include "gtkfilechooserembed.h"
+#include "gtkfilechoosersettings.h"
 #include "gtkfilesystem.h"
 #include "gtktypebuiltins.h"
 #include "gtkintl.h"
@@ -178,6 +179,20 @@ clamp_to_screen (GtkWidget *widget,
 }
 
 static void
+load_position (int *out_xpos, int *out_ypos)
+{
+  GtkFileChooserSettings *settings;
+  int x, y, width, height;
+
+  settings = _gtk_file_chooser_settings_new ();
+  _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
+  g_object_unref (settings);
+
+  *out_xpos = x;
+  *out_ypos = y;
+}
+
+static void
 file_chooser_widget_default_size_changed (GtkWidget            *widget,
 					  GtkFileChooserDialog *dialog)
 {
@@ -185,6 +200,7 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
   gint width, height;
   gint default_width, default_height;
   GtkRequisition req, widget_req;
+  int xpos, ypos;
 
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
@@ -209,6 +225,7 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 
   _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
 					    &default_width, &default_height);
+  load_position (&xpos, &ypos);
 
   /* Ideal target size plus any extra size */
   width = default_width + width + (2 * GTK_CONTAINER (dialog)->border_width);
@@ -218,6 +235,8 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
     clamp_to_screen (GTK_WIDGET (dialog), &width, &height);
 
   gtk_window_resize (GTK_WINDOW (dialog), width, height);
+  if (xpos >= 0 && ypos >= 0)
+    gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
 }
 
 static void
-- 
1.5.6


From 324775cdf637227bac573287959e537bfb221803 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 4 Nov 2008 18:03:54 -0600
Subject: [PATCH 09/23] Don't clamp the loaded size to the screen; just reuse it

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c |   26 --------------------------
 1 files changed, 0 insertions(+), 26 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 5ebfdd9..e095366 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -156,29 +156,6 @@ file_chooser_widget_file_activated (GtkFileChooser       *chooser,
 }
 
 static void
-clamp_to_screen (GtkWidget *widget,
-		 gint      *width,
-		 gint      *height)
-{
-  GdkScreen *screen;
-  int monitor_num;
-  GdkRectangle monitor;
-
-  g_return_if_fail (GTK_WIDGET_REALIZED (widget));
-  
-  screen = gtk_widget_get_screen (widget);
-  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
-
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
-
-  if (width)
-    *width = MIN (*width, (monitor.width * 3) / 4);
-
-  if (height)
-    *height = MIN (*height, (monitor.height * 3) / 4);
-}
-
-static void
 load_position (int *out_xpos, int *out_ypos)
 {
   GtkFileChooserSettings *settings;
@@ -231,9 +208,6 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
   width = default_width + width + (2 * GTK_CONTAINER (dialog)->border_width);
   height = default_height + height + (2 * GTK_CONTAINER (dialog)->border_width);
 
-  if (GTK_WIDGET_REALIZED (dialog))
-    clamp_to_screen (GTK_WIDGET (dialog), &width, &height);
-
   gtk_window_resize (GTK_WINDOW (dialog), width, height);
   if (xpos >= 0 && ypos >= 0)
     gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
-- 
1.5.6


From 142a1abf88a80689e2d7ff1b9f64292cf8acd737 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Wed, 5 Nov 2008 11:48:03 -0600
Subject: [PATCH 10/23] Don't add the dialog's border width to the final window size

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c |   15 +--------------
 1 files changed, 1 insertions(+), 14 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index e095366..dcba623 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -174,7 +174,6 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 					  GtkFileChooserDialog *dialog)
 {
   GtkFileChooserDialogPrivate *priv;
-  gint width, height;
   gint default_width, default_height;
   GtkRequisition req, widget_req;
   int xpos, ypos;
@@ -190,25 +189,13 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
        * that widget->requisition is meaningful. */
       gtk_widget_size_request (GTK_WIDGET (dialog), &req);
       gtk_widget_size_request (widget, &widget_req);
-
-      width = req.width - widget_req.width;
-      height = req.height - widget_req.height;
-    }
-  else
-    {
-      width = GTK_WIDGET (dialog)->allocation.width - widget->allocation.width;
-      height = GTK_WIDGET (dialog)->allocation.height - widget->allocation.height;
     }
 
   _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
 					    &default_width, &default_height);
   load_position (&xpos, &ypos);
 
-  /* Ideal target size plus any extra size */
-  width = default_width + width + (2 * GTK_CONTAINER (dialog)->border_width);
-  height = default_height + height + (2 * GTK_CONTAINER (dialog)->border_width);
-
-  gtk_window_resize (GTK_WINDOW (dialog), width, height);
+  gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
   if (xpos >= 0 && ypos >= 0)
     gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
 }
-- 
1.5.6


From b78f1fdb89a6cb73410443f92b1f7e888a6770f6 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Wed, 5 Nov 2008 18:24:51 -0600
Subject: [PATCH 11/23] Don't use GTK_WIN_POS_CENTER on the dialog so our position will be used

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index dcba623..27e8225 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -197,7 +197,10 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 
   gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
   if (xpos >= 0 && ypos >= 0)
-    gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
+    {
+      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_NONE);
+      gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
+    }
 }
 
 static void
-- 
1.5.6


From 3156cbe47b5a725c576be18c8fa599c546148def Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Wed, 5 Nov 2008 19:21:16 -0600
Subject: [PATCH 12/23] Only return the loaded size for the expanded modes

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   31 ++++++++++++++++---------------
 1 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index ca9991e..436246f 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -7838,28 +7838,29 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
 {
   GtkFileChooserDefault *impl;
   GtkRequisition req;
-  GtkFileChooserSettings *settings;
-  int x, y, width, height;
 
   impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
 
-  settings = _gtk_file_chooser_settings_new ();
-  _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
-  g_object_unref (settings);
-
-  if (x >= 0 && y >= 0 && width > 0 && height > 0)
-    {
-      GtkWindow *toplevel;
-
-      *default_width = width;
-      *default_height = height;
-      return;
-    }
-
   if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
       || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
       || impl->expand_folders)
     {
+      GtkFileChooserSettings *settings;
+      int x, y, width, height;
+
+      settings = _gtk_file_chooser_settings_new ();
+      _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
+      g_object_unref (settings);
+
+      if (x >= 0 && y >= 0 && width > 0 && height > 0)
+	{
+	  GtkWindow *toplevel;
+
+	  *default_width = width;
+	  *default_height = height;
+	  return;
+	}
+
       find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
 
       if (impl->preview_widget_active &&
-- 
1.5.6


From b96ebba55f3c00cf8cbc3eafdcd5113ba6de6570 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Fri, 19 Dec 2008 12:39:18 -0600
Subject: [PATCH 13/23] Utility functions to print indented messages from the file chooser

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c  |   36 ++++++++++++++++++++++++++++++++++++
 gtk/gtkfilechooserprivate.h |    3 +++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 27e8225..a9e91d9 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -485,5 +485,41 @@ gtk_file_chooser_dialog_new_with_backend (const gchar          *title,
   return result;
 }
 
+static int indentation = 0;
+
+void
+_gtk_file_chooser_msg (const char *format, ...)
+{
+  int i;
+  va_list args;
+
+  printf ("FILE_CHOOSER: ");
+
+  for (i = 0; i < indentation; i++)
+    putchar (' ');
+
+  va_start (args, format);
+  vprintf (format, args);
+  va_end (args);
+
+  printf ("\n");
+  fflush (stdout);
+}
+
+void
+_gtk_file_chooser_indent (gboolean do_indent)
+{
+  if (do_indent)
+    indentation += 4;
+  else
+    indentation -= 4;
+
+  if (indentation < 0)
+    {
+      printf ("FILE_CHOOSER: You screwed up your indentation; resetting to zero\n");
+      indentation = 0;
+    }
+}
+
 #define __GTK_FILE_CHOOSER_DIALOG_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index ef60734..2728c9d 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -361,6 +361,9 @@ struct _FileModelNode
   guint load_pending : 1;
 };
 
+void _gtk_file_chooser_msg (const char *format, ...);
+void _gtk_file_chooser_msg_indent (gboolean do_indent);
+
 
 G_END_DECLS
 
-- 
1.5.6


From 7c259362a03d563f20080de1c11f9a25e13e7a25 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Fri, 19 Dec 2008 12:46:12 -0600
Subject: [PATCH 14/23] Debug messages for GtkFileChooserDialog

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index a9e91d9..b73695f 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -178,6 +178,9 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
   GtkRequisition req, widget_req;
   int xpos, ypos;
 
+  _gtk_file_chooser_msg ("dialog - default_size_changed callback {");
+  _gtk_file_chooser_msg_indent (TRUE);
+
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
   /* Unset any previously set size */
@@ -195,12 +198,17 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 					    &default_width, &default_height);
   load_position (&xpos, &ypos);
 
+  _gtk_file_chooser_msg ("Resizing dialog to %dx%d", default_width, default_height);
   gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
   if (xpos >= 0 && ypos >= 0)
     {
       gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_NONE);
       gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
+      _gtk_file_chooser_msg ("Moving dialog to (%d, %d)", xpos, ypos);
     }
+
+  _gtk_file_chooser_msg_indent (FALSE);
+  _gtk_file_chooser_msg ("}");
 }
 
 static void
@@ -334,6 +342,9 @@ gtk_file_chooser_dialog_map (GtkWidget *widget)
   GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
+  _gtk_file_chooser_msg ("dialog - map {");
+  _gtk_file_chooser_msg_indent (TRUE);
+
   ensure_default_response (dialog);
 
   if (!GTK_WIDGET_MAPPED (priv->widget))
@@ -342,6 +353,9 @@ gtk_file_chooser_dialog_map (GtkWidget *widget)
   _gtk_file_chooser_embed_initial_focus (GTK_FILE_CHOOSER_EMBED (priv->widget));
 
   GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->map (widget);
+
+  _gtk_file_chooser_msg_indent (FALSE);
+  _gtk_file_chooser_msg ("}");
 }
 
 /* GtkWidget::unmap handler */
@@ -507,7 +521,7 @@ _gtk_file_chooser_msg (const char *format, ...)
 }
 
 void
-_gtk_file_chooser_indent (gboolean do_indent)
+_gtk_file_chooser_msg_indent (gboolean do_indent)
 {
   if (do_indent)
     indentation += 4;
-- 
1.5.6


From a8c678d2fe7c9ca5202f084712f6e01729dcbcda Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Fri, 19 Dec 2008 13:12:04 -0600
Subject: [PATCH 15/23] Debug messages for GtkFileChooserDefault

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 436246f..4fbfae2 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -1158,7 +1158,10 @@ static void
 emit_default_size_changed (GtkFileChooserDefault *impl)
 {
   if (!GTK_WIDGET_MAPPED (impl))
-    return;
+    {
+      _gtk_file_chooser_msg ("emit_default_size_changed - bailing out since we are not mapped");
+      return;
+    }
 
   profile_msg ("    emit default-size-changed start", NULL);
   g_signal_emit_by_name (impl, "default-size-changed");
@@ -1193,6 +1196,7 @@ update_preview_widget_visibility (GtkFileChooserDefault *impl)
   else
     gtk_widget_hide (impl->preview_box);
 
+  _gtk_file_chooser_msg ("update_preview_widget_visibility - emitting default-size-changed");
   emit_default_size_changed (impl);
 }
 
@@ -5461,6 +5465,7 @@ update_appearance (GtkFileChooserDefault *impl)
    */
   gtk_widget_queue_draw (impl->browse_files_tree_view);
 
+  _gtk_file_chooser_msg ("update_apperance - emitting default-size-changed");
   emit_default_size_changed (impl);
 }
 
@@ -5880,6 +5885,7 @@ gtk_file_chooser_default_style_set (GtkWidget *widget,
   if (gtk_widget_has_screen (GTK_WIDGET (impl)))
     change_icon_theme (impl);
 
+  _gtk_file_chooser_msg ("gtk_file_chooser_default_style_set - emitting default-size-changed");
   emit_default_size_changed (impl);
 
   profile_end ("end", NULL);
@@ -5901,6 +5907,7 @@ gtk_file_chooser_default_screen_changed (GtkWidget *widget,
   remove_settings_signal (impl, previous_screen);
   check_icon_theme (impl);
 
+  _gtk_file_chooser_msg ("gtk_file_chooser_default_screen_changed - emitting default-size-changed");
   emit_default_size_changed (impl);
 
   profile_end ("end", NULL);
@@ -6031,6 +6038,9 @@ gtk_file_chooser_default_map (GtkWidget *widget)
 
   profile_start ("start", NULL);
 
+  _gtk_file_chooser_msg ("default - map {");
+  _gtk_file_chooser_msg_indent (TRUE);
+
   impl = GTK_FILE_CHOOSER_DEFAULT (widget);
 
   GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->map (widget);
@@ -6075,8 +6085,12 @@ gtk_file_chooser_default_map (GtkWidget *widget)
 
   settings_load (impl);
 
+  _gtk_file_chooser_msg ("gtk_file_chooser_default_map - emitting default-size-changed");
   emit_default_size_changed (impl);
 
+  _gtk_file_chooser_msg_indent (FALSE);
+  _gtk_file_chooser_msg ("}");
+
   profile_end ("end", NULL);
 }
 
-- 
1.5.6


From 36a79f8916eab470525a5097a04ec3e1a5aadbb2 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Fri, 19 Dec 2008 23:29:36 -0600
Subject: [PATCH 16/23] bnc458120 - Don't change GtkFileChooserDialog's geometry from the settings while it is mapped

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c  |   11 +++++++++++
 gtk/gtkfilechooserprivate.h |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index b73695f..fdacdb1 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -183,6 +183,13 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
+  if (priv->have_set_geometry)
+    {
+      _gtk_file_chooser_msg_indent (FALSE);
+      _gtk_file_chooser_msg ("}");
+      return;
+    }
+
   /* Unset any previously set size */
   gtk_widget_set_size_request (GTK_WIDGET (dialog), -1, -1);
 
@@ -209,6 +216,8 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 
   _gtk_file_chooser_msg_indent (FALSE);
   _gtk_file_chooser_msg ("}");
+
+  priv->have_set_geometry = TRUE;
 }
 
 static void
@@ -374,6 +383,8 @@ gtk_file_chooser_dialog_unmap (GtkWidget *widget)
    * a new file chooser every time they need one.
    */
   gtk_widget_unmap (priv->widget);
+
+  priv->have_set_geometry = FALSE;
 }
 
 /* GtkDialog::response handler */
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 2728c9d..eee5b4e 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -112,6 +112,7 @@ struct _GtkFileChooserDialogPrivate
 
   /* for use with GtkFileChooserEmbed */
   gboolean response_requested;
+  gboolean have_set_geometry;
 };
 
 
-- 
1.5.6


From 7a8cab3e1d27f499827e6ea51ec31d4772b08673 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Sat, 20 Dec 2008 00:38:27 -0600
Subject: [PATCH 17/23] Emit default-size-changed in realize, not in map, so that we don't resize the already-shown window

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 4fbfae2..99d2992 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -275,6 +275,7 @@ static void     gtk_file_chooser_default_get_property (GObject               *ob
 static void     gtk_file_chooser_default_dispose      (GObject               *object);
 static void     gtk_file_chooser_default_show_all       (GtkWidget             *widget);
 static void     gtk_file_chooser_default_map            (GtkWidget             *widget);
+static void     gtk_file_chooser_default_realize        (GtkWidget             *widget);
 static void     gtk_file_chooser_default_unmap          (GtkWidget             *widget);
 static void     gtk_file_chooser_default_hierarchy_changed (GtkWidget          *widget,
 							    GtkWidget          *previous_toplevel);
@@ -567,6 +568,7 @@ _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
 
   widget_class->show_all = gtk_file_chooser_default_show_all;
   widget_class->map = gtk_file_chooser_default_map;
+  widget_class->realize = gtk_file_chooser_default_realize;
   widget_class->unmap = gtk_file_chooser_default_unmap;
   widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
   widget_class->style_set = gtk_file_chooser_default_style_set;
@@ -1157,12 +1159,6 @@ change_folder_and_display_error (GtkFileChooserDefault *impl,
 static void
 emit_default_size_changed (GtkFileChooserDefault *impl)
 {
-  if (!GTK_WIDGET_MAPPED (impl))
-    {
-      _gtk_file_chooser_msg ("emit_default_size_changed - bailing out since we are not mapped");
-      return;
-    }
-
   profile_msg ("    emit default-size-changed start", NULL);
   g_signal_emit_by_name (impl, "default-size-changed");
   profile_msg ("    emit default-size-changed end", NULL);
@@ -6029,6 +6025,27 @@ settings_save (GtkFileChooserDefault *impl)
   g_object_unref (settings);
 }
 
+/* GtkWidget::realize method */
+static void
+gtk_file_chooser_default_realize (GtkWidget *widget)
+{
+  GtkFileChooserDefault *impl;
+  char *current_working_dir;
+
+  _gtk_file_chooser_msg ("default - realize {");
+  _gtk_file_chooser_msg_indent (TRUE);
+
+  impl = GTK_FILE_CHOOSER_DEFAULT (widget);
+
+  GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->realize (widget);
+
+  _gtk_file_chooser_msg ("gtk_file_chooser_default_realize - emitting default-size-changed");
+  emit_default_size_changed (impl);
+
+  _gtk_file_chooser_msg_indent (FALSE);
+  _gtk_file_chooser_msg ("}");
+}
+
 /* GtkWidget::map method */
 static void
 gtk_file_chooser_default_map (GtkWidget *widget)
@@ -6085,9 +6102,6 @@ gtk_file_chooser_default_map (GtkWidget *widget)
 
   settings_load (impl);
 
-  _gtk_file_chooser_msg ("gtk_file_chooser_default_map - emitting default-size-changed");
-  emit_default_size_changed (impl);
-
   _gtk_file_chooser_msg_indent (FALSE);
   _gtk_file_chooser_msg ("}");
 
-- 
1.5.6


From b922387cd50494856fc8987263c0676b10ecd195 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Sat, 20 Dec 2008 01:34:01 -0600
Subject: [PATCH 18/23] Remove debug messages

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |   17 -------------
 gtk/gtkfilechooserdialog.c  |   56 +------------------------------------------
 gtk/gtkfilechooserprivate.h |    2 -
 3 files changed, 1 insertions(+), 74 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 99d2992..7a0069b 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -1192,7 +1192,6 @@ update_preview_widget_visibility (GtkFileChooserDefault *impl)
   else
     gtk_widget_hide (impl->preview_box);
 
-  _gtk_file_chooser_msg ("update_preview_widget_visibility - emitting default-size-changed");
   emit_default_size_changed (impl);
 }
 
@@ -5461,7 +5460,6 @@ update_appearance (GtkFileChooserDefault *impl)
    */
   gtk_widget_queue_draw (impl->browse_files_tree_view);
 
-  _gtk_file_chooser_msg ("update_apperance - emitting default-size-changed");
   emit_default_size_changed (impl);
 }
 
@@ -5881,7 +5879,6 @@ gtk_file_chooser_default_style_set (GtkWidget *widget,
   if (gtk_widget_has_screen (GTK_WIDGET (impl)))
     change_icon_theme (impl);
 
-  _gtk_file_chooser_msg ("gtk_file_chooser_default_style_set - emitting default-size-changed");
   emit_default_size_changed (impl);
 
   profile_end ("end", NULL);
@@ -5903,7 +5900,6 @@ gtk_file_chooser_default_screen_changed (GtkWidget *widget,
   remove_settings_signal (impl, previous_screen);
   check_icon_theme (impl);
 
-  _gtk_file_chooser_msg ("gtk_file_chooser_default_screen_changed - emitting default-size-changed");
   emit_default_size_changed (impl);
 
   profile_end ("end", NULL);
@@ -6032,18 +6028,11 @@ gtk_file_chooser_default_realize (GtkWidget *widget)
   GtkFileChooserDefault *impl;
   char *current_working_dir;
 
-  _gtk_file_chooser_msg ("default - realize {");
-  _gtk_file_chooser_msg_indent (TRUE);
-
   impl = GTK_FILE_CHOOSER_DEFAULT (widget);
 
   GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->realize (widget);
 
-  _gtk_file_chooser_msg ("gtk_file_chooser_default_realize - emitting default-size-changed");
   emit_default_size_changed (impl);
-
-  _gtk_file_chooser_msg_indent (FALSE);
-  _gtk_file_chooser_msg ("}");
 }
 
 /* GtkWidget::map method */
@@ -6055,9 +6044,6 @@ gtk_file_chooser_default_map (GtkWidget *widget)
 
   profile_start ("start", NULL);
 
-  _gtk_file_chooser_msg ("default - map {");
-  _gtk_file_chooser_msg_indent (TRUE);
-
   impl = GTK_FILE_CHOOSER_DEFAULT (widget);
 
   GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->map (widget);
@@ -6102,9 +6088,6 @@ gtk_file_chooser_default_map (GtkWidget *widget)
 
   settings_load (impl);
 
-  _gtk_file_chooser_msg_indent (FALSE);
-  _gtk_file_chooser_msg ("}");
-
   profile_end ("end", NULL);
 }
 
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index fdacdb1..8ea0ecc 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -178,17 +178,10 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
   GtkRequisition req, widget_req;
   int xpos, ypos;
 
-  _gtk_file_chooser_msg ("dialog - default_size_changed callback {");
-  _gtk_file_chooser_msg_indent (TRUE);
-
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
   if (priv->have_set_geometry)
-    {
-      _gtk_file_chooser_msg_indent (FALSE);
-      _gtk_file_chooser_msg ("}");
-      return;
-    }
+    return;
 
   /* Unset any previously set size */
   gtk_widget_set_size_request (GTK_WIDGET (dialog), -1, -1);
@@ -205,18 +198,13 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 					    &default_width, &default_height);
   load_position (&xpos, &ypos);
 
-  _gtk_file_chooser_msg ("Resizing dialog to %dx%d", default_width, default_height);
   gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
   if (xpos >= 0 && ypos >= 0)
     {
       gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_NONE);
       gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
-      _gtk_file_chooser_msg ("Moving dialog to (%d, %d)", xpos, ypos);
     }
 
-  _gtk_file_chooser_msg_indent (FALSE);
-  _gtk_file_chooser_msg ("}");
-
   priv->have_set_geometry = TRUE;
 }
 
@@ -351,9 +339,6 @@ gtk_file_chooser_dialog_map (GtkWidget *widget)
   GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
-  _gtk_file_chooser_msg ("dialog - map {");
-  _gtk_file_chooser_msg_indent (TRUE);
-
   ensure_default_response (dialog);
 
   if (!GTK_WIDGET_MAPPED (priv->widget))
@@ -362,9 +347,6 @@ gtk_file_chooser_dialog_map (GtkWidget *widget)
   _gtk_file_chooser_embed_initial_focus (GTK_FILE_CHOOSER_EMBED (priv->widget));
 
   GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->map (widget);
-
-  _gtk_file_chooser_msg_indent (FALSE);
-  _gtk_file_chooser_msg ("}");
 }
 
 /* GtkWidget::unmap handler */
@@ -510,41 +492,5 @@ gtk_file_chooser_dialog_new_with_backend (const gchar          *title,
   return result;
 }
 
-static int indentation = 0;
-
-void
-_gtk_file_chooser_msg (const char *format, ...)
-{
-  int i;
-  va_list args;
-
-  printf ("FILE_CHOOSER: ");
-
-  for (i = 0; i < indentation; i++)
-    putchar (' ');
-
-  va_start (args, format);
-  vprintf (format, args);
-  va_end (args);
-
-  printf ("\n");
-  fflush (stdout);
-}
-
-void
-_gtk_file_chooser_msg_indent (gboolean do_indent)
-{
-  if (do_indent)
-    indentation += 4;
-  else
-    indentation -= 4;
-
-  if (indentation < 0)
-    {
-      printf ("FILE_CHOOSER: You screwed up your indentation; resetting to zero\n");
-      indentation = 0;
-    }
-}
-
 #define __GTK_FILE_CHOOSER_DIALOG_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index eee5b4e..7369475 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -362,8 +362,6 @@ struct _FileModelNode
   guint load_pending : 1;
 };
 
-void _gtk_file_chooser_msg (const char *format, ...);
-void _gtk_file_chooser_msg_indent (gboolean do_indent);
 
 
 G_END_DECLS
-- 
1.5.6


From cfb3795f5f6f828ce5e71d1d75f68ce58a5f44ce Mon Sep 17 00:00:00 2001
From: bratsche <bratsche@7eb1c76a-c725-0410-a3b5-a37faf6256f8>
Date: Mon, 13 Oct 2008 15:15:23 +0000
Subject: [PATCH 19/23] Fix --action parsing in testfilechooser
 2008-10-13  Cody Russell <cody@jhu.edu>

        * test/testfilechooser.c: Fix option parsing so that -a and
        --action work correctly.

git-svn-id: svn+ssh://svn.gnome.org/svn/gtk+/trunk@21645 7eb1c76a-c725-0410-a3b5-a37faf6256f8
---
 tests/testfilechooser.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tests/testfilechooser.c b/tests/testfilechooser.c
index 57b27f8..7c00805 100644
--- a/tests/testfilechooser.c
+++ b/tests/testfilechooser.c
@@ -491,7 +491,7 @@ main (int argc, char **argv)
   char *backend = NULL;
   GError *error = NULL;
   GOptionEntry options[] = {
-    { "action", 'a', 0, G_OPTION_ARG_STRING, &action, "Filechooser action", "ACTION" },
+    { "action", 'a', 0, G_OPTION_ARG_STRING, &action_arg, "Filechooser action", "ACTION" },
     { "backend", 'b', 0, G_OPTION_ARG_STRING, &backend, "Filechooser backend (default: gtk+)", "BACKEND" },
     { "multiple", 'm', 0, G_OPTION_ARG_NONE, &multiple, "Select-multiple", NULL },
     { "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
-- 
1.5.6


From de8ab1248afe19cca93c273e186b97c7e70a5951 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 23 Dec 2008 13:16:41 -0600
Subject: [PATCH 20/23] Don't keep a flag about geometry being set; instead, just don't reposition the dialog if it is mapped

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdialog.c  |   20 ++++++++------------
 gtk/gtkfilechooserprivate.h |    1 -
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 8ea0ecc..c80ed91 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -180,9 +180,6 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
-  if (priv->have_set_geometry)
-    return;
-
   /* Unset any previously set size */
   gtk_widget_set_size_request (GTK_WIDGET (dialog), -1, -1);
 
@@ -196,16 +193,17 @@ file_chooser_widget_default_size_changed (GtkWidget            *widget,
 
   _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
 					    &default_width, &default_height);
-  load_position (&xpos, &ypos);
-
   gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
-  if (xpos >= 0 && ypos >= 0)
+
+  if (!GTK_WIDGET_MAPPED (dialog))
     {
-      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_NONE);
-      gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
+      load_position (&xpos, &ypos);
+      if (xpos >= 0 && ypos >= 0)
+	{
+	  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_NONE);
+	  gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
+	}
     }
-
-  priv->have_set_geometry = TRUE;
 }
 
 static void
@@ -365,8 +363,6 @@ gtk_file_chooser_dialog_unmap (GtkWidget *widget)
    * a new file chooser every time they need one.
    */
   gtk_widget_unmap (priv->widget);
-
-  priv->have_set_geometry = FALSE;
 }
 
 /* GtkDialog::response handler */
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 7369475..a200bd7 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -112,7 +112,6 @@ struct _GtkFileChooserDialogPrivate
 
   /* for use with GtkFileChooserEmbed */
   gboolean response_requested;
-  gboolean have_set_geometry;
 };
 
 
-- 
1.5.6


From 619adb2286a5230c8e83f31b0c37fc7270e77dcc Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 23 Dec 2008 13:53:09 -0600
Subject: [PATCH 21/23] Don't save geometry in non-expanded mode so future Open dialogs won't appear too small

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 7a0069b..6ae4b73 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -5991,6 +5991,14 @@ save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *setti
   GtkWindow *toplevel;
   int x, y, width, height;
 
+  /* We don't save the geometry in non-expanded "save" mode, so that the "little
+   * dialog" won't make future Open dialogs too small.
+   */
+  if (!(impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
+	|| impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
+	|| impl->expand_folders))
+    return;
+
   toplevel = get_toplevel (GTK_WIDGET (impl));
 
   if (!(toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel)))
-- 
1.5.6


From 995e4cbde85cf90bc9a47a7854906616be7c3424 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 23 Dec 2008 14:08:40 -0600
Subject: [PATCH 22/23] Remove unused variable

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 6ae4b73..72fc21c 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -7873,8 +7873,6 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
 
       if (x >= 0 && y >= 0 && width > 0 && height > 0)
 	{
-	  GtkWindow *toplevel;
-
 	  *default_width = width;
 	  *default_height = height;
 	  return;
-- 
1.5.6


From 37fc08eafd9b80674bc1f4f090bad7e6073fac68 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@novell.com>
Date: Tue, 23 Dec 2008 14:33:28 -0600
Subject: [PATCH 23/23] bnc445923 - Don't change the default size when the preview changes if the widget is already mapped
 Keeps the file chooser from changing size when you click on a file and the preview widget
 is updated (even if its state stays the same as before).

Signed-off-by: Federico Mena Quintero <federico@novell.com>
---
 gtk/gtkfilechooserdefault.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 72fc21c..20f087b 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -1192,7 +1192,8 @@ update_preview_widget_visibility (GtkFileChooserDefault *impl)
   else
     gtk_widget_hide (impl->preview_box);
 
-  emit_default_size_changed (impl);
+  if (!GTK_WIDGET_MAPPED (impl))
+    emit_default_size_changed (impl);
 }
 
 static void
-- 
1.5.6