[gnome-latex: 101/205] File choosers: save the folder
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 101/205] File choosers: save the folder
- Date: Fri, 14 Dec 2018 10:55:22 +0000 (UTC)
commit 2a5e09d725b0967bff7b3b1820cbc122c6176e12
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Sat Oct 17 15:05:17 2009 +0200
File choosers: save the folder
File choosers are used for opening a file or saving a file. The folder
is saved in the preferences so when the user want to open/save a file,
the file chooser is in the last directory saved.
TODO | 18 ------------------
src/callbacks.c | 36 +++++++++++++++++++++++++++++++++++-
src/main.h | 2 ++
src/prefs.c | 20 ++++++++++++++++++++
4 files changed, 57 insertions(+), 19 deletions(-)
---
diff --git a/TODO b/TODO
index 17e148d..df21b85 100644
--- a/TODO
+++ b/TODO
@@ -1,23 +1,5 @@
TODO LaTeXila
-Sat Oct 10, 2009 to Fri Oct 16, 2009
-
-[x] execution of the actions
- x sensitivity of the actions when an action is running
-
-[x] log zone
- x keep only the 5 last actions
-
-[x] symbol tables
- x mathematical sets (N, Z, Q, R, C) in misc math
-
-[x] save as
- x confirmation before replacing a file which already exists
-
-[x] bugs correction
-
-[x] update French translation
-
[-] undo/redo and the "saved" document property
- detect when the buffer is the same as in the file currently saved
diff --git a/src/callbacks.c b/src/callbacks.c
index 28cf376..d188302 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -73,6 +73,10 @@ cb_open (void)
NULL
);
+ if (! latexila.prefs.file_chooser_dir_is_empty)
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
+ latexila.prefs.file_chooser_dir);
+
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
gchar *filename = gtk_file_chooser_get_filename (
@@ -85,6 +89,17 @@ cb_open (void)
g_free (filename);
g_free (uri);
}
+
+ /* save the current folder */
+ if (! latexila.prefs.file_chooser_dir_is_empty)
+ g_free (latexila.prefs.file_chooser_dir);
+
+ latexila.prefs.file_chooser_dir = gtk_file_chooser_get_current_folder_uri (
+ GTK_FILE_CHOOSER (dialog));
+
+ if (latexila.prefs.file_chooser_dir != NULL)
+ latexila.prefs.file_chooser_dir_is_empty = FALSE;
+
gtk_widget_destroy (dialog);
}
@@ -1004,10 +1019,16 @@ save_as_dialog (void)
NULL
);
+ if (! latexila.prefs.file_chooser_dir_is_empty)
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
+ latexila.prefs.file_chooser_dir);
+
while (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
- gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ gchar *filename = gtk_file_chooser_get_filename (
+ GTK_FILE_CHOOSER (dialog));
+ /* if the file exists, ask the user whether the file can be replaced */
if (g_file_test (filename, G_FILE_TEST_EXISTS))
{
GtkWidget *confirmation = gtk_message_dialog_new (
@@ -1052,6 +1073,16 @@ save_as_dialog (void)
break;
}
+ /* save the current folder */
+ if (! latexila.prefs.file_chooser_dir_is_empty)
+ g_free (latexila.prefs.file_chooser_dir);
+
+ latexila.prefs.file_chooser_dir = gtk_file_chooser_get_current_folder_uri (
+ GTK_FILE_CHOOSER (dialog));
+
+ if (latexila.prefs.file_chooser_dir != NULL)
+ latexila.prefs.file_chooser_dir_is_empty = FALSE;
+
gtk_widget_destroy (dialog);
}
@@ -1288,6 +1319,9 @@ free_latexila (void)
g_free (latexila.prefs.command_dvipdf);
g_free (latexila.prefs.command_dvips);
+ if (! latexila.prefs.file_chooser_dir_is_empty)
+ g_free (latexila.prefs.file_chooser_dir);
+
for (int i = 0 ; i < 7 ; i++)
g_object_unref (latexila.symbols.list_stores[i]);
}
diff --git a/src/main.h b/src/main.h
index 34034e1..b6ad125 100644
--- a/src/main.h
+++ b/src/main.h
@@ -82,6 +82,8 @@ typedef struct
gchar *command_pdflatex;
gchar *command_dvipdf;
gchar *command_dvips;
+ gboolean file_chooser_dir_is_empty;
+ gchar *file_chooser_dir;
} preferences_t;
typedef struct
diff --git a/src/prefs.c b/src/prefs.c
index b24b80d..a0e7105 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -250,6 +250,19 @@ load_preferences (preferences_t *prefs)
error = NULL;
}
+ prefs->file_chooser_dir = g_key_file_get_string (key_file, PROGRAM_NAME,
+ "file_chooser_directory", &error);
+ if (error != NULL)
+ {
+ print_warning ("%s", error->message);
+ prefs->file_chooser_dir_is_empty = TRUE;
+ prefs->file_chooser_dir = NULL;
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ prefs->file_chooser_dir_is_empty = FALSE;
+
print_info ("load user preferences: OK");
g_key_file_free (key_file);
}
@@ -278,6 +291,10 @@ save_preferences (preferences_t *prefs)
g_key_file_set_string (key_file, PROGRAM_NAME, "command_dvips",
prefs->command_dvips);
+ if (! prefs->file_chooser_dir_is_empty)
+ g_key_file_set_string (key_file, PROGRAM_NAME, "file_chooser_directory",
+ prefs->file_chooser_dir);
+
/* set the keys that must be taken from the widgets */
GdkWindowState flag = gdk_window_get_state (gtk_widget_get_window (
GTK_WIDGET (latexila.main_window)));
@@ -364,6 +381,8 @@ load_default_preferences (preferences_t *prefs)
prefs->command_pdflatex = g_strdup (command_pdflatex_);
prefs->command_dvipdf = g_strdup (command_dvipdf_);
prefs->command_dvips = g_strdup (command_dvips_);
+ prefs->file_chooser_dir_is_empty = TRUE;
+ prefs->file_chooser_dir = NULL;
set_current_font_prefs (prefs);
}
@@ -371,6 +390,7 @@ load_default_preferences (preferences_t *prefs)
static gchar *
get_rc_file (void)
{
+ // rc_file must be freed
gchar *rc_file = g_build_filename (g_get_home_dir (), ".config", "latexila",
"latexilarc", NULL);
return rc_file;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]