From 9fe2718a3350e44c7cfbcdfe4285192c119bb729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Thu, 26 Jan 2006 21:32:46 +0000 Subject: [PATCH] set the Open File dialog directory to the same directory as the current file (thanks to Nick Treleaven for this patch) git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@155 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/dialogs.c | 13 +++++++++++++ src/utils.c | 23 +++++++++++++++++++++++ src/utils.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/src/dialogs.c b/src/dialogs.c index bf4e1e2ac..a4a9c7e7a 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -70,6 +70,19 @@ void dialogs_show_open_file () g_signal_connect((gpointer)app->open_filesel, "selection-changed", G_CALLBACK(on_file_open_selection_changed), NULL); } + + // set dialog directory to the current file's directory, if present + { + gchar *initdir = utils_get_current_file_dir(); + + if (initdir != NULL) + { + gtk_file_chooser_set_current_folder( + GTK_FILE_CHOOSER(app->open_filesel), initdir); + g_free(initdir); + } + } + gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(app->open_filesel)); /* We make sure the dialog is visible. */ gtk_window_present(GTK_WINDOW(app->open_filesel)); diff --git a/src/utils.c b/src/utils.c index 31506fc99..fa0aab059 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2119,3 +2119,26 @@ void utils_treeviews_showhide(void) else gtk_widget_show(app->treeview_notebook); } + + +/* Get directory from current file in the notebook. + * Returns dir string that should be freed or NULL, depending on whether current file is valid. + * (thanks to Nick Treleaven for this patch) */ +gchar *utils_get_current_file_dir() +{ + gint cur_idx = document_get_cur_idx(); + + if (cur_idx >= 0) // if valid page found + { + // get current filename + const gchar *cur_fname = doc_list[cur_idx].file_name; + + if (cur_fname != NULL) + { + // get folder part from current filename + return g_path_get_dirname(cur_fname); // returns "." if no path + } + } + + return NULL; // no file open +} diff --git a/src/utils.h b/src/utils.h index d9dee3ed3..bf4c52d0d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -199,4 +199,6 @@ gint utils_get_int_from_hexcolor(const gchar *hex); void utils_treeviews_showhide(void); +gchar *utils_get_current_file_dir(); + #endif