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
This commit is contained in:
Enrico Tröger 2006-01-26 21:32:46 +00:00
parent 97099a920d
commit 9fe2718a33
3 changed files with 38 additions and 0 deletions

View File

@ -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));

View File

@ -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
}

View File

@ -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