Bug 616612 - Remember last location of File Open/Save dialog, partial solution

This commit remembers the last directory for
* Open
* Save
* Export chart of accounts
* Save Report
This only stores file based paths, not db based paths.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19408 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens
2010-08-05 21:27:45 +00:00
parent 0f35cc18be
commit 749fdbe0a8
4 changed files with 72 additions and 36 deletions

View File

@@ -45,6 +45,10 @@ typedef QofSession * (*QofSessionCB) (void);
gboolean gnc_reverse_balance(const Account *account);
gboolean gnc_reverse_balance_type(GNCAccountType type);
/* Default directory sections ***************************************/
#define GCONF_DIR_OPEN_SAVE "dialogs/open_save"
#define GCONF_DIR_EXPORT "dialogs/export_accounts"
#define GCONF_DIR_REPORT "dialogs/report"
/* Default directories **********************************************/

View File

@@ -29,10 +29,12 @@
#include <glade/glade.h>
#include "gnc-ui.h"
#include "gnc-ui-util.h"
#include "gnc-uri-utils.h"
#include "dialog-utils.h"
#include "dialog-file-access.h"
#include "gnc-file.h"
#include "gnc-plugin-file-history.h"
#include "gnc-session.h"
static QofLogModule log_module = GNC_MOD_GUI;
@@ -248,6 +250,9 @@ gnc_ui_file_access( int type )
gint active_access_method_index = -1;
const gchar* default_db;
const gchar *button_label = NULL;
const gchar *gconf_section;
gchar *last;
gchar *starting_dir = NULL;
g_return_if_fail( type == FILE_ACCESS_OPEN || type == FILE_ACCESS_SAVE_AS || type == FILE_ACCESS_EXPORT );
@@ -278,18 +283,21 @@ gnc_ui_file_access( int type )
gtk_window_set_title(GTK_WINDOW(faw->dialog), _("Open..."));
button_label = "gtk-open";
fileChooserAction = GTK_FILE_CHOOSER_ACTION_OPEN;
gconf_section = GCONF_DIR_OPEN_SAVE;
break;
case FILE_ACCESS_SAVE_AS:
gtk_window_set_title(GTK_WINDOW(faw->dialog), _("Save As..."));
button_label = "gtk-save-as";
fileChooserAction = GTK_FILE_CHOOSER_ACTION_SAVE;
gconf_section = GCONF_DIR_OPEN_SAVE;
break;
case FILE_ACCESS_EXPORT:
gtk_window_set_title(GTK_WINDOW(faw->dialog), _("Export"));
button_label = "gtk-save-as";
fileChooserAction = GTK_FILE_CHOOSER_ACTION_SAVE;
gconf_section = GCONF_DIR_EXPORT;
break;
}
@@ -304,6 +312,22 @@ gnc_ui_file_access( int type )
fileChooser = GTK_FILE_CHOOSER_WIDGET(gtk_file_chooser_widget_new( fileChooserAction ));
faw->fileChooser = GTK_FILE_CHOOSER(fileChooser);
gtk_container_add( GTK_CONTAINER(align), GTK_WIDGET(fileChooser) );
/* Set the default directory */
if (type == FILE_ACCESS_OPEN || type == FILE_ACCESS_SAVE_AS)
{
last = gnc_history_get_last();
if ( last && gnc_uri_is_file_uri ( last ) )
{
gchar *filepath = gnc_uri_get_path ( last );
starting_dir = g_path_get_dirname( filepath );
g_free ( filepath );
}
}
if (!starting_dir)
starting_dir = gnc_get_default_directory(gconf_section);
gtk_file_chooser_set_current_folder(faw->fileChooser, starting_dir);
g_object_connect( G_OBJECT(faw->fileChooser), "signal::file-activated",
gnc_ui_file_access_file_activated_cb, faw, NULL );

View File

@@ -48,7 +48,6 @@
#include "gnc-session.h"
#include "gnc-autosave.h"
#define GCONF_SECTION "dialogs/export_accounts"
/** GLOBALS *********************************************************/
/* This static indicates the debugging module that this .o belongs to. */
@@ -618,6 +617,14 @@ gnc_post_file_open (const char * filename)
username, password, path);
}
/* For file based uri's, remember the directory as the default. */
if (gnc_uri_is_file_protocol(protocol))
{
gchar *default_dir = g_path_get_dirname(path);
gnc_set_default_directory (GCONF_DIR_OPEN_SAVE, default_dir);
g_free(default_dir);
}
/* disable events while moving over to the new set of accounts;
* the mass deletion of accounts and transactions during
* switchover would otherwise cause excessive redraws. */
@@ -849,23 +856,26 @@ gnc_post_file_open (const char * filename)
gboolean
gnc_file_open (void)
{
const char * newfile;
gchar *lastpath = NULL;
gchar *lastfile = NULL;
gchar *last_file_dir = NULL;
const gchar * newfile;
gchar *last = NULL;
gchar *default_dir = NULL;
gboolean result;
if (!gnc_file_query_save (TRUE))
return FALSE;
lastpath = gnc_history_get_last();
lastfile = gnc_uri_get_path ( lastpath );
if ( lastfile )
last_file_dir = g_path_get_dirname(lastfile);
newfile = gnc_file_dialog (_("Open"), NULL, last_file_dir, GNC_FILE_DIALOG_OPEN);
g_free ( lastpath );
g_free ( lastfile );
g_free ( last_file_dir );
if ( last && gnc_uri_is_file_uri ( last ) )
{
gchar *filepath = gnc_uri_get_path ( last );
default_dir = g_path_get_dirname( filepath );
g_free ( filepath );
}
else
default_dir = gnc_get_default_directory(GCONF_DIR_OPEN_SAVE);
newfile = gnc_file_dialog (_("Open"), NULL, default_dir, GNC_FILE_DIALOG_OPEN);
g_free ( last );
g_free ( default_dir );
result = gnc_post_file_open ( newfile );
@@ -915,9 +925,8 @@ gnc_file_export (void)
g_free ( filepath );
}
else
{
default_dir = gnc_get_default_directory(GCONF_SECTION);
}
default_dir = gnc_get_default_directory(GCONF_DIR_EXPORT);
filename = gnc_file_dialog (_("Save"), NULL, default_dir,
GNC_FILE_DIALOG_SAVE);
g_free ( last );
@@ -935,7 +944,6 @@ gnc_file_do_export(const char * filename)
QofSession *current_session, *new_session;
gboolean ok;
QofBackendError io_err = ERR_BACKEND_NO_ERR;
gchar *default_dir = NULL;
gchar *norm_file;
gchar *newfile;
const gchar *oldfile;
@@ -980,8 +988,8 @@ gnc_file_do_export(const char * filename)
/* For file based uri's, remember the directory as the default. */
if (gnc_uri_is_file_protocol(protocol))
{
default_dir = g_path_get_dirname(path);
gnc_set_default_directory (GCONF_SECTION, default_dir);
gchar *default_dir = g_path_get_dirname(path);
gnc_set_default_directory (GCONF_DIR_EXPORT, default_dir);
g_free(default_dir);
}
@@ -1113,14 +1121,9 @@ gnc_file_save (void)
void
gnc_file_save_as (void)
{
QofSession *new_session;
QofSession *session;
const char *filename;
char *default_dir = NULL; /* Default to last open */
char *last;
char *newfile;
const char *oldfile;
QofBackendError io_err = ERR_BACKEND_NO_ERR;
const gchar *filename;
gchar *default_dir = NULL; /* Default to last open */
gchar *last;
ENTER(" ");
@@ -1132,9 +1135,8 @@ gnc_file_save_as (void)
g_free ( filepath );
}
else
{
default_dir = gnc_get_default_directory(GCONF_SECTION);
}
default_dir = gnc_get_default_directory(GCONF_DIR_OPEN_SAVE);
filename = gnc_file_dialog (_("Save"), NULL, default_dir,
GNC_FILE_DIALOG_SAVE);
g_free ( last );
@@ -1151,8 +1153,6 @@ gnc_file_do_save_as (const char* filename)
{
QofSession *new_session;
QofSession *session;
gchar *default_dir = NULL; /* Default to last open */
gchar *last;
gchar *norm_file;
gchar *newfile;
const gchar *oldfile;
@@ -1200,8 +1200,8 @@ gnc_file_do_save_as (const char* filename)
/* For file based uri's, remember the directory as the default. */
if (gnc_uri_is_file_protocol(protocol))
{
default_dir = g_path_get_dirname(path);
gnc_set_default_directory (GCONF_SECTION, default_dir);
gchar *default_dir = g_path_get_dirname(path);
gnc_set_default_directory (GCONF_DIR_OPEN_SAVE, default_dir);
g_free(default_dir);
}

View File

@@ -57,6 +57,7 @@
#include "gnc-file.h"
#include "gnc-plugin.h"
#include "gnc-plugin-page-report.h"
#include "gnc-plugin-file-history.h"
#include "gnc-report.h"
#include "gnc-session.h"
#include "gnc-ui-util.h"
@@ -1390,6 +1391,7 @@ gnc_get_export_filename (SCM choice)
char * title;
const gchar * type;
int rc;
char * default_dir;
if (choice == SCM_BOOL_T)
type = _("HTML");
@@ -1400,17 +1402,23 @@ gnc_get_export_filename (SCM choice)
/* %s is the type of what is about to be saved, e.g. "HTML". */
title = g_strdup_printf (_("Save %s To File"), type);
default_dir = gnc_get_default_directory(GCONF_DIR_REPORT);
filepath = gnc_file_dialog (title, NULL, NULL, GNC_FILE_DIALOG_EXPORT);
filepath = gnc_file_dialog (title, NULL, default_dir, GNC_FILE_DIALOG_EXPORT);
g_free (title);
g_free (default_dir);
if (!filepath)
return NULL;
default_dir = g_path_get_dirname(filepath);
gnc_set_default_directory (GCONF_DIR_REPORT, default_dir);
g_free(default_dir);
rc = g_stat (filepath, &statbuf);
/* Check for an error that isn't a non-existant file. */
/* Check for an error that isn't a non-existent file. */
if (rc != 0 && errno != ENOENT)
{
/* %s is the strerror(3) string of the error that occurred. */