]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserbutton.c
cssimage: Return the loaded image from compute()
[~andy/gtk] / gtk / gtkfilechooserbutton.c
index 43da440632cf1e357c7b41e6f626c025f237c151..3c9e121a416c87e211865dffd22ddb5f9d7ee9ac 100644 (file)
@@ -15,9 +15,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -44,7 +42,7 @@
 #include "gtkliststore.h"
 #include "gtkstock.h"
 #include "gtktreemodelfilter.h"
-#include "gtkvseparator.h"
+#include "gtkseparator.h"
 #include "gtkfilechooserdialog.h"
 #include "gtkfilechooserprivate.h"
 #include "gtkfilechooserutils.h"
 
 #include "gtkfilechooserbutton.h"
 
+#include "gtkorientable.h"
+
 #include "gtktypebuiltins.h"
 #include "gtkprivate.h"
+#include "gtksettings.h"
+
+
+/**
+ * SECTION:gtkfilechooserbutton
+ * @Short_description: A button to launch a file selection dialog
+ * @Title: GtkFileChooserButton
+ * @See_also:#GtkFileChooserDialog
+ *
+ * The #GtkFileChooserButton is a widget that lets the user select a
+ * file.  It implements the #GtkFileChooser interface.  Visually, it is a
+ * file name with a button to bring up a #GtkFileChooserDialog.
+ * The user can then use that dialog to change the file associated with
+ * that button.  This widget does not support setting the
+ * #GtkFileChooser:select-multiple property to %TRUE.
+ *
+ * <example>
+ * <title>Create a button to let the user select a file in /etc</title>
+ * <programlisting>
+ * {
+ *   GtkWidget *button;
+ *
+ *   button = gtk_file_chooser_button_new (_("Select a file"),
+ *                                         GTK_FILE_CHOOSER_ACTION_OPEN);
+ *   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button),
+ *                                        "/etc");
+ * }
+ * </programlisting>
+ * </example>
+ *
+ * The #GtkFileChooserButton supports the #GtkFileChooserAction<!-- -->s
+ * %GTK_FILE_CHOOSER_ACTION_OPEN and %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
+ *
+ * <important>
+ * The #GtkFileChooserButton will ellipsize the label,
+ * and thus will thus request little horizontal space.  To give the button
+ * more space, you should call gtk_widget_get_preferred_size(),
+ * gtk_file_chooser_button_set_width_chars(), or pack the button in
+ * such a way that other interface elements give space to the widget.
+ * </important>
+ */
+
 
 /* **************** *
  *  Private Macros  *
@@ -301,7 +343,7 @@ static guint file_chooser_button_signals[LAST_SIGNAL] = { 0 };
  *  GType Declaration  *
  * ******************* */
 
-G_DEFINE_TYPE_WITH_CODE (GtkFileChooserButton, gtk_file_chooser_button, GTK_TYPE_HBOX, { \
+G_DEFINE_TYPE_WITH_CODE (GtkFileChooserButton, gtk_file_chooser_button, GTK_TYPE_BOX, { \
     G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER, gtk_file_chooser_button_file_chooser_iface_init) \
 })
 
@@ -436,9 +478,10 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
 
   /* Button */
   priv->button = gtk_button_new ();
-  g_signal_connect (priv->button, "clicked", G_CALLBACK (button_clicked_cb),
-                   button);
-  gtk_container_add (GTK_CONTAINER (button), priv->button);
+  g_signal_connect (priv->button, "clicked",
+                    G_CALLBACK (button_clicked_cb), button);
+  gtk_box_pack_start (GTK_BOX (button), priv->button, TRUE, TRUE, 0);
+  gtk_widget_set_halign (priv->button, GTK_ALIGN_FILL);
   gtk_widget_show (priv->button);
 
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
@@ -451,7 +494,8 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
 
   priv->label = gtk_label_new (_(FALLBACK_DISPLAY_NAME));
   gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
-  gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
+  gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
+  gtk_widget_set_valign (priv->label, GTK_ALIGN_CENTER);
   gtk_box_pack_start (GTK_BOX (box), priv->label, TRUE, TRUE, 0);
   //gtk_container_add (GTK_CONTAINER (box), priv->label);
   gtk_widget_show (priv->label);
@@ -460,8 +504,7 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
   gtk_box_pack_start (GTK_BOX (box), sep, FALSE, FALSE, 0);
   gtk_widget_show (sep);
 
-  image = gtk_image_new_from_stock (GTK_STOCK_OPEN,
-                                   GTK_ICON_SIZE_MENU);
+  image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
   gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
   gtk_widget_show (image);
 
@@ -480,7 +523,8 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
   priv->combo_box_changed_id =
     g_signal_connect (priv->combo_box, "changed",
                      G_CALLBACK (combo_box_changed_cb), button);
-  gtk_container_add (GTK_CONTAINER (button), priv->combo_box);
+  gtk_box_pack_start (GTK_BOX (button), priv->combo_box, TRUE, TRUE, 0);
+  gtk_widget_set_halign (priv->combo_box, GTK_ALIGN_FILL);
 
   priv->icon_cell = gtk_cell_renderer_pixbuf_new ();
   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box),
@@ -1399,7 +1443,7 @@ set_info_get_info_cb (GCancellable *cancellable,
   GdkPixbuf *pixbuf;
   GtkTreePath *path;
   GtkTreeIter iter;
-  GCancellable *model_cancellable;
+  GCancellable *model_cancellable = NULL;
   struct SetDisplayNameData *data = callback_data;
   gboolean is_folder;
 
@@ -1452,7 +1496,8 @@ out:
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
 
-  g_object_unref (cancellable);
+  if (model_cancellable)
+    g_object_unref (model_cancellable);
 }
 
 static void
@@ -1550,7 +1595,10 @@ model_free_row_data (GtkFileChooserButton *button,
                      -1);
 
   if (cancellable)
-    g_cancellable_cancel (cancellable);
+    {
+      g_cancellable_cancel (cancellable);
+      g_object_unref (cancellable);
+    }
 
   switch (type)
     {
@@ -1578,7 +1626,7 @@ model_add_special_get_info_cb (GCancellable *cancellable,
   GtkTreeIter iter;
   GtkTreePath *path;
   GdkPixbuf *pixbuf;
-  GCancellable *model_cancellable;
+  GCancellable *model_cancellable = NULL;
   struct ChangeIconThemeData *data = user_data;
   gchar *name;
 
@@ -1631,7 +1679,8 @@ out:
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
 
-  g_object_unref (cancellable);
+  if (model_cancellable)
+    g_object_unref (model_cancellable);
 }
 
 static inline void
@@ -1994,7 +2043,7 @@ model_add_other (GtkFileChooserButton *button)
   gtk_list_store_insert (store, &iter, pos);
   gtk_list_store_set (store, &iter,
                      ICON_COLUMN, NULL,
-                     DISPLAY_NAME_COLUMN, _("Other..."),
+                     DISPLAY_NAME_COLUMN, _("Other"),
                      TYPE_COLUMN, ROW_TYPE_OTHER,
                      DATA_COLUMN, NULL,
                      IS_FOLDER_COLUMN, FALSE,
@@ -2634,8 +2683,11 @@ dialog_response_cb (GtkDialog *dialog,
   if (response == GTK_RESPONSE_ACCEPT ||
       response == GTK_RESPONSE_OK)
     {
-      g_signal_emit_by_name (user_data, "current-folder-changed");
-      g_signal_emit_by_name (user_data, "selection-changed");
+      g_signal_emit_by_name (button, "current-folder-changed");
+      g_signal_emit_by_name (button, "selection-changed");
+
+      update_label_and_image (button);
+      update_combo_box (button);
     }
   else if (priv->old_file)
     {
@@ -2663,9 +2715,6 @@ dialog_response_cb (GtkDialog *dialog,
       priv->old_file = NULL;
     }
 
-  update_label_and_image (user_data);
-  update_combo_box (user_data);
-  
   if (priv->active)
     {
       g_signal_handler_unblock (priv->dialog,
@@ -2682,7 +2731,7 @@ dialog_response_cb (GtkDialog *dialog,
 
   if (response == GTK_RESPONSE_ACCEPT ||
       response == GTK_RESPONSE_OK)
-    g_signal_emit (user_data, file_chooser_button_signals[FILE_SET], 0);
+    g_signal_emit (button, file_chooser_button_signals[FILE_SET], 0);
 }
 
 
@@ -2773,7 +2822,7 @@ gtk_file_chooser_button_set_title (GtkFileChooserButton *button,
  * 
  * Since: 2.6
  **/
-G_CONST_RETURN gchar *
+const gchar *
 gtk_file_chooser_button_get_title (GtkFileChooserButton *button)
 {
   g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), NULL);