From 90a9df8d5cf975b9ef0c276f6d951b99d8f8bbc4 Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 13 Apr 2012 02:37:56 +0000 Subject: preserve the last selected folders between sessions. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3043 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 6 ++++ libsylph/prefs_common.c | 7 ++++- libsylph/prefs_common.h | 6 +++- src/filesel.c | 84 +++++++++++++++++++++++++++++++++++++++++-------- src/filesel.h | 2 +- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b94dafb..d778bd81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-04-13 + + * libsylph/prefs_common.[ch] + src/filesel.[ch]: preserve the last selected folders between + sessions. + 2012-04-12 * src/inc.c: show the detail of new messages on the trayicon tooltip. diff --git a/libsylph/prefs_common.c b/libsylph/prefs_common.c index c121ecd7..7bcd0cae 100644 --- a/libsylph/prefs_common.c +++ b/libsylph/prefs_common.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2011 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -497,6 +497,11 @@ static PrefParam param[] = { P_BOOL}, {"io_timeout_secs", "60", &prefs_common.io_timeout_secs, P_INT}, + /* File selector */ + {"filesel_prev_open_dir", NULL, &prefs_common.prev_open_dir, P_STRING}, + {"filesel_prev_save_dir", NULL, &prefs_common.prev_save_dir, P_STRING}, + {"filesel_prev_folder_dir", NULL, &prefs_common.prev_folder_dir, P_STRING}, + {NULL, NULL, NULL, P_OTHER} }; diff --git a/libsylph/prefs_common.h b/libsylph/prefs_common.h index f3210630..6c62609c 100644 --- a/libsylph/prefs_common.h +++ b/libsylph/prefs_common.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2011 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -330,6 +330,10 @@ struct _PrefsCommon gint addressbook_col_name; gint addressbook_col_addr; gint addressbook_col_rem; + + gchar *prev_open_dir; + gchar *prev_save_dir; + gchar *prev_folder_dir; }; extern PrefsCommon prefs_common; diff --git a/src/filesel.c b/src/filesel.c index 3cceec61..b8733800 100644 --- a/src/filesel.c +++ b/src/filesel.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2007 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include "prefs_common.h" #include "inc.h" + static GSList *filesel_select_file_full (const gchar *title, const gchar *file, GtkFileChooserAction action, @@ -51,6 +52,7 @@ static GtkFileChooserConfirmation filesel_confirm_overwrite_cb gpointer data); #endif + gchar *filesel_select_file(const gchar *title, const gchar *file, GtkFileChooserAction action) { @@ -73,27 +75,82 @@ GSList *filesel_select_files(const gchar *title, const gchar *file, return filesel_select_file_full(title, file, action, TRUE); } +static void filesel_change_dir_for_action(GtkFileChooserAction action) +{ + const gchar *cwd = NULL; + + switch (action) { + case GTK_FILE_CHOOSER_ACTION_OPEN: + if (prefs_common.prev_open_dir && + is_dir_exist(prefs_common.prev_open_dir)) + cwd = prefs_common.prev_open_dir; + else { + g_free(prefs_common.prev_open_dir); + prefs_common.prev_open_dir = NULL; + } + break; + case GTK_FILE_CHOOSER_ACTION_SAVE: + if (prefs_common.prev_save_dir && + is_dir_exist(prefs_common.prev_save_dir)) + cwd = prefs_common.prev_save_dir; + else { + g_free(prefs_common.prev_save_dir); + prefs_common.prev_save_dir = NULL; + } + break; + case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: + if (prefs_common.prev_folder_dir && + is_dir_exist(prefs_common.prev_folder_dir)) + cwd = prefs_common.prev_folder_dir; + else { + g_free(prefs_common.prev_folder_dir); + prefs_common.prev_folder_dir = NULL; + } + break; + default: + break; + } + + if (cwd) + change_dir(cwd); + else + change_dir(get_document_dir()); +} + +static void filesel_save_dir_for_action(GtkFileChooserAction action, + const gchar *cwd) +{ + switch (action) { + case GTK_FILE_CHOOSER_ACTION_OPEN: + g_free(prefs_common.prev_open_dir); + prefs_common.prev_open_dir = g_strdup(cwd); + break; + case GTK_FILE_CHOOSER_ACTION_SAVE: + g_free(prefs_common.prev_save_dir); + prefs_common.prev_save_dir = g_strdup(cwd); + break; + case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: + g_free(prefs_common.prev_folder_dir); + prefs_common.prev_folder_dir = g_strdup(cwd); + break; + default: + break; + } +} + static GSList *filesel_select_file_full(const gchar *title, const gchar *file, GtkFileChooserAction action, gboolean multiple) { - static GHashTable *path_table = NULL; gchar *cwd; GtkWidget *dialog; gchar *prev_dir; static gboolean save_expander_expanded = FALSE; GSList *list = NULL; - if (!path_table) - path_table = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, g_free); - prev_dir = g_get_current_dir(); - if ((cwd = g_hash_table_lookup(path_table, title)) != NULL) - change_dir(cwd); - else - change_dir(get_document_dir()); + filesel_change_dir_for_action(action); dialog = filesel_create(title, action); @@ -133,9 +190,10 @@ static GSList *filesel_select_file_full(const gchar *title, const gchar *file, if (list) { cwd = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(dialog)); - if (cwd) - g_hash_table_replace - (path_table, g_strdup(title), cwd); + if (cwd) { + filesel_save_dir_for_action(action, cwd); + g_free(cwd); + } } } diff --git a/src/filesel.h b/src/filesel.h index 43b48ec8..b089a89a 100644 --- a/src/filesel.h +++ b/src/filesel.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- cgit v1.2.3