diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | embed/mozilla/FilePicker.cpp | 12 | ||||
-rw-r--r-- | lib/ephy-file-chooser.c | 81 | ||||
-rw-r--r-- | lib/ephy-file-chooser.h | 15 |
4 files changed, 82 insertions, 39 deletions
@@ -1,3 +1,16 @@ +2003-11-01 Christian Persch <chpe@cvs.gnome.org> + + * embed/mozilla/FilePicker.cpp: + * lib/ephy-file-chooser.c: (current_folder_changed_cb), + (ephy_file_chooser_init), (ephy_file_chooser_set_persist_key), + (ephy_file_chooser_get_persist_key), + (ephy_file_chooser_get_property), (ephy_file_chooser_class_init), + (ephy_file_chooser_new): + * lib/ephy-file-chooser.h: + + Don't set the persist key on object construction time. + Fixes bug #125589. + 2003-10-31 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/MozillaPrivate.cpp: diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp index 7c761e980..8b498ede9 100644 --- a/embed/mozilla/FilePicker.cpp +++ b/embed/mozilla/FilePicker.cpp @@ -68,9 +68,9 @@ GFilePicker::GFilePicker() LOG ("GFilePicker constructor") - mDialog = EPHY_FILE_CHOOSER (g_object_new (EPHY_TYPE_FILE_CHOOSER, - "persist-key", CONF_STATE_UPLOAD_DIR, - NULL)); + mDialog = EPHY_FILE_CHOOSER (g_object_new (EPHY_TYPE_FILE_CHOOSER, NULL)); + + ephy_file_chooser_set_persist_key (mDialog, CONF_STATE_UPLOAD_DIR); mMode = nsIFilePicker::modeOpen; } @@ -112,6 +112,8 @@ NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *t GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, EPHY_RESPONSE_OPEN, NULL); + gtk_dialog_set_default_response (GTK_DIALOG (mDialog), EPHY_RESPONSE_OPEN); + break; case nsIFilePicker::modeSave: gtk_file_chooser_set_action (GTK_FILE_CHOOSER (mDialog), @@ -121,6 +123,10 @@ NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *t GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, EPHY_RESPONSE_SAVE, NULL); + gtk_dialog_set_default_response (GTK_DIALOG (mDialog), EPHY_RESPONSE_SAVE); + break; + default: + g_assert_not_reached (); break; } diff --git a/lib/ephy-file-chooser.c b/lib/ephy-file-chooser.c index 819661876..ec8cf2d27 100644 --- a/lib/ephy-file-chooser.c +++ b/lib/ephy-file-chooser.c @@ -85,6 +85,7 @@ current_folder_changed_cb (GtkFileChooser *chooser, EphyFileChooser *dialog) char *dir, *converted; dir = gtk_file_chooser_get_current_folder (chooser); + if (dir != NULL) { converted = g_filename_to_utf8 (dir, -1, NULL, NULL, NULL); @@ -104,9 +105,6 @@ ephy_file_chooser_init (EphyFileChooser *dialog) dialog->priv->persist_key = NULL; - g_signal_connect (dialog, "current-folder-changed", - G_CALLBACK (current_folder_changed_cb), dialog); - ephy_state_add_window (GTK_WIDGET (dialog), "file_chooser", 400, 300, EPHY_STATE_WINDOW_SAVE_SIZE | @@ -125,37 +123,45 @@ ephy_file_chooser_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } -static void +void ephy_file_chooser_set_persist_key (EphyFileChooser *dialog, const char *key) { + char *dir, *expanded, *converted; + + g_return_if_fail (key != NULL && key[0] != '\0'); + dialog->priv->persist_key = g_strdup (key); - if (key != NULL) + dir = eel_gconf_get_string (key); + if (dir != NULL) { - char *dir; + converted = g_filename_from_utf8 + (dir, -1, NULL, NULL, NULL); - dir = eel_gconf_get_string (key); + expanded = gnome_vfs_expand_initial_tilde (converted); - if (dir != NULL) + if (expanded != NULL) { - char *expanded, *converted; + gtk_file_chooser_set_current_folder + (GTK_FILE_CHOOSER (dialog), expanded); + } - converted = g_filename_from_utf8 - (dir, -1, NULL, NULL, NULL); + g_free (expanded); + g_free (converted); + g_free (dir); + } - expanded = gnome_vfs_expand_initial_tilde (converted); + g_signal_connect (dialog, "current-folder-changed", + G_CALLBACK (current_folder_changed_cb), dialog); - if (expanded != NULL) - { - gtk_file_chooser_set_current_folder - (GTK_FILE_CHOOSER (dialog), expanded); - } +} - g_free (expanded); - g_free (converted); - g_free (dir); - } - } +const char * +ephy_file_chooser_get_persist_key (EphyFileChooser *dialog) +{ + g_return_val_if_fail (EPHY_IS_FILE_CHOOSER (dialog), NULL); + + return dialog->priv->persist_key; } static void @@ -185,7 +191,7 @@ ephy_file_chooser_get_property (GObject *object, switch (prop_id) { case PROP_PERSIST_KEY: - g_value_set_string (value, dialog->priv->persist_key); + g_value_set_string (value, ephy_file_chooser_get_persist_key (dialog)); break; } } @@ -207,8 +213,7 @@ ephy_file_chooser_class_init (EphyFileChooserClass *klass) "Persist Key", "The gconf key to which to persist the selected directory", NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READWRITE)); g_type_class_add_private (object_class, sizeof (EphyFileChooserPrivate)); } @@ -222,11 +227,17 @@ ephy_file_chooser_new (const char *title, EphyFileChooser *dialog; dialog = EPHY_FILE_CHOOSER (g_object_new (EPHY_TYPE_FILE_CHOOSER, - "local-only", TRUE, - "title", title, - "action", action, - "persist-key", persist_key, - NULL)); + "title", title, + "action", action, + NULL)); + + /* NOTE: We cannot set this property on object construction time. + * This is because GtkFileChooserDialog overrides the gobject + * constructor; the GtkFileChooser delegate will only be set + * _after_ our instance_init and construct-param setters will have + * run. + */ + ephy_file_chooser_set_persist_key (dialog, persist_key); if (action == GTK_FILE_CHOOSER_ACTION_OPEN) { @@ -234,6 +245,8 @@ ephy_file_chooser_new (const char *title, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, EPHY_RESPONSE_OPEN, NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + EPHY_RESPONSE_OPEN); } else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) { @@ -241,9 +254,15 @@ ephy_file_chooser_new (const char *title, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, EPHY_RESPONSE_SAVE, NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + EPHY_RESPONSE_SAVE); } - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); + if (parent != NULL) + { + gtk_window_set_transient_for (GTK_WINDOW (dialog), + GTK_WINDOW (parent)); + } return dialog; } diff --git a/lib/ephy-file-chooser.h b/lib/ephy-file-chooser.h index f4061e9fc..7702c41d2 100644 --- a/lib/ephy-file-chooser.h +++ b/lib/ephy-file-chooser.h @@ -54,12 +54,17 @@ typedef struct GtkFileChooserDialogClass parent_class; } EphyFileChooserClass; -GType ephy_file_chooser_get_type (void); +GType ephy_file_chooser_get_type (void); -EphyFileChooser *ephy_file_chooser_new (const char *title, - GtkWidget *parent, - GtkFileChooserAction action, - const char *persist_key); +EphyFileChooser *ephy_file_chooser_new (const char *title, + GtkWidget *parent, + GtkFileChooserAction action, + const char *persist_key); + +void ephy_file_chooser_set_persist_key (EphyFileChooser *dialog, + const char *key); + +const char *ephy_file_chooser_get_persist_key (EphyFileChooser *dialog); G_END_DECLS |