[gtk+/gtk-2-24] filechooserbutton: Keep track of the current_folder while the dialog is inactive



commit ea3a1ecbd1259f1bb95b5482106344587cb47119
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Feb 13 11:47:35 2013 -0600

    filechooserbutton: Keep track of the current_folder while the dialog is inactive
    
    This is analogous to keeping the selection while the dialog is inactive.
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 gtk/gtkfilechooserbutton.c |   87 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 80 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index 6a08183..13a552f 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -139,6 +139,7 @@ struct _GtkFileChooserButtonPrivate
 
   GtkFileSystem *fs;
   GFile *selection_while_inactive;
+  GFile *current_folder_while_inactive;
 
   gulong combo_box_changed_id;
   gulong dialog_file_activated_id;
@@ -186,6 +187,10 @@ enum
 
 /* GtkFileChooserIface Functions */
 static void     gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface);
+static gboolean gtk_file_chooser_button_set_current_folder (GtkFileChooser    *chooser,
+							    GFile             *file,
+							    GError           **error);
+static GFile *gtk_file_chooser_button_get_current_folder (GtkFileChooser    *chooser);
 static gboolean gtk_file_chooser_button_select_file (GtkFileChooser *chooser,
 						     GFile          *file,
 						     GError        **error);
@@ -532,6 +537,8 @@ gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface)
 {
   _gtk_file_chooser_delegate_iface_init (iface);
 
+  iface->set_current_folder = gtk_file_chooser_button_set_current_folder;
+  iface->get_current_folder = gtk_file_chooser_button_get_current_folder;
   iface->select_file = gtk_file_chooser_button_select_file;
   iface->unselect_file = gtk_file_chooser_button_unselect_file;
   iface->unselect_all = gtk_file_chooser_button_unselect_all;
@@ -541,6 +548,54 @@ gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface)
 }
 
 static gboolean
+gtk_file_chooser_button_set_current_folder (GtkFileChooser    *chooser,
+					    GFile             *file,
+					    GError           **error)
+{
+  GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
+  GtkFileChooserButtonPrivate *priv = button->priv;
+  GtkFileChooser *delegate;
+
+  delegate = g_object_get_qdata (G_OBJECT (chooser),
+				 GTK_FILE_CHOOSER_DELEGATE_QUARK);
+
+  if (priv->active)
+    return gtk_file_chooser_set_current_folder_file (delegate, file, error);
+  else
+    {
+      if (priv->current_folder_while_inactive)
+	g_object_unref (priv->current_folder_while_inactive);
+
+      priv->current_folder_while_inactive = g_object_ref (file);
+
+      g_signal_emit_by_name (button, "current-folder-changed");
+
+      return TRUE;
+    }
+}
+
+static GFile *
+gtk_file_chooser_button_get_current_folder (GtkFileChooser *chooser)
+{
+  GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
+  GtkFileChooserButtonPrivate *priv = button->priv;
+  GtkFileChooser *delegate;
+
+  delegate = g_object_get_qdata (G_OBJECT (chooser),
+				 GTK_FILE_CHOOSER_DELEGATE_QUARK);
+
+  if (priv->active)
+    return gtk_file_chooser_get_current_folder_file (delegate);
+  else
+    {
+      if (priv->current_folder_while_inactive)
+	return g_object_ref (priv->current_folder_while_inactive);
+      else
+	return NULL;
+    }
+}
+
+static gboolean
 gtk_file_chooser_button_select_file (GtkFileChooser *chooser,
 				     GFile          *file,
 				     GError        **error)
@@ -990,6 +1045,9 @@ gtk_file_chooser_button_finalize (GObject *object)
   if (priv->selection_while_inactive)
     g_object_unref (priv->selection_while_inactive);
 
+  if (priv->current_folder_while_inactive)
+    g_object_unref (priv->current_folder_while_inactive);
+
   G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->finalize (object);
 }
 
@@ -2533,10 +2591,28 @@ fs_bookmarks_changed_cb (GtkFileSystem *fs,
 }
 
 static void
-restore_inactive_selection (GtkFileChooserButton *button)
+save_inactive_state (GtkFileChooserButton *button)
 {
   GtkFileChooserButtonPrivate *priv = button->priv;
 
+  if (priv->current_folder_while_inactive)
+    g_object_unref (priv->current_folder_while_inactive);
+
+  if (priv->selection_while_inactive)
+    g_object_unref (priv->selection_while_inactive);
+
+  priv->current_folder_while_inactive = gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER (priv->dialog));
+  priv->selection_while_inactive = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
+}
+
+static void
+restore_inactive_state (GtkFileChooserButton *button)
+{
+  GtkFileChooserButtonPrivate *priv = button->priv;
+
+  if (priv->current_folder_while_inactive)
+    gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->dialog), priv->current_folder_while_inactive, NULL);
+
   if (priv->selection_while_inactive)
     gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->dialog), priv->selection_while_inactive, NULL);
   else
@@ -2577,7 +2653,7 @@ open_dialog (GtkFileChooserButton *button)
       g_signal_handler_block (priv->dialog,
 			      priv->dialog_selection_changed_id);
 
-      restore_inactive_selection (button);
+      restore_inactive_state (button);
 
       priv->active = TRUE;
     }
@@ -2749,10 +2825,7 @@ dialog_response_cb (GtkDialog *dialog,
   if (response == GTK_RESPONSE_ACCEPT ||
       response == GTK_RESPONSE_OK)
     {
-      if (priv->selection_while_inactive)
-	g_object_unref (priv->selection_while_inactive);
-
-      priv->selection_while_inactive = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
+      save_inactive_state (button);
 
       g_signal_emit_by_name (button, "current-folder-changed");
       g_signal_emit_by_name (button, "selection-changed");
@@ -2762,7 +2835,7 @@ dialog_response_cb (GtkDialog *dialog,
     }
   else
     {
-      restore_inactive_selection (button);
+      restore_inactive_state (button);
     }
 
   if (priv->active)


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