From ad0b2ac077905898f3830f1346c8d80f875a8ad3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Enrico=20Tr=C3=B6ger?= Date: Wed, 3 Jun 2009 01:15:36 +0200 Subject: [PATCH] Remember last folder of the Save As dialog when downloading files This is done by creating the dialog only once and holding a reference to it in memory. When the dialog is closed, it is only hidden instead of destroyed. So, the next time we just re-show the dialog with the previously used directory. It is destroyed when the parent MidoriBrowser instance is destroyed. --- midori/midori-browser.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 6d1ae847..4f27c223 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1238,12 +1238,12 @@ midori_browser_add_download_item (MidoriBrowser* browser, static void midori_view_download_save_as_response_cb (GtkWidget* dialog, gint response, - WebKitDownload* download) + MidoriBrowser* browser) { + WebKitDownload* download = g_object_get_data (G_OBJECT (dialog), "download"); if (response == GTK_RESPONSE_ACCEPT) { gchar* uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); - MidoriBrowser* browser = midori_browser_get_for_widget (dialog); webkit_download_set_destination_uri (download, uri); midori_browser_add_download_item (browser, download); g_free (uri); @@ -1251,7 +1251,7 @@ midori_view_download_save_as_response_cb (GtkWidget* dialog, } else g_object_unref (download); - gtk_widget_destroy (dialog); + gtk_widget_hide (dialog); } static gboolean @@ -1262,27 +1262,35 @@ midori_view_download_requested_cb (GtkWidget* view, g_signal_emit (browser, signals[ADD_DOWNLOAD], 0, download); if (!webkit_download_get_destination_uri (download)) { + gchar* folder; if (g_object_get_data (G_OBJECT (download), "save-as-download")) { - GtkWidget* dialog = gtk_file_chooser_dialog_new ( - _("Save file"), GTK_WINDOW (browser), - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_SAVE); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser)); - /* FIXME: Remember the last folder - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir); */ + static GtkWidget* dialog = NULL; + + if (!dialog) + { + dialog = gtk_file_chooser_dialog_new ( + _("Save file"), GTK_WINDOW (browser), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_SAVE); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (browser)); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); + folder = katze_object_get_string (browser->settings, "download-folder"); + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), folder); + g_free (folder); + g_signal_connect (dialog, "response", + G_CALLBACK (midori_view_download_save_as_response_cb), browser); + } + g_object_set_data (G_OBJECT (dialog), "download", download); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), webkit_download_get_suggested_filename (download)); gtk_widget_show (dialog); - g_signal_connect (dialog, "response", - G_CALLBACK (midori_view_download_save_as_response_cb), download); } else { - gchar* folder; gchar* filename; gchar* uri; -- 2.39.5