Make Open, Save As dialogs start in project base path (or default
path pref) when the current file has no filename. Split up widget setup code for dialogs_show_open_file(), dialogs_show_save_as(). Add initial_dir argument for win32_show_file_dialog(). Add utils_get_default_dir_utf8(). Rename utils_get_current_file_dir() to utils_get_current_file_dir_utf8(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2122 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
4e262328bd
commit
39738f90ca
10
ChangeLog
10
ChangeLog
@ -9,6 +9,16 @@
|
||||
* src/utils.c:
|
||||
Make utils_get_utf8_from_locale(), utils_get_locale_from_utf8()
|
||||
NULL-safe.
|
||||
* src/utils.c, src/win32.c, src/utils.h, src/win32.h, src/dialogs.c,
|
||||
src/search.c:
|
||||
Make Open, Save As dialogs start in project base path (or default
|
||||
path pref) when the current file has no filename.
|
||||
Split up widget setup code for dialogs_show_open_file(),
|
||||
dialogs_show_save_as().
|
||||
Add initial_dir argument for win32_show_file_dialog().
|
||||
Add utils_get_default_dir_utf8().
|
||||
Rename utils_get_current_file_dir() to
|
||||
utils_get_current_file_dir_utf8().
|
||||
|
||||
|
||||
2007-12-19 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
121
src/dialogs.c
121
src/dialogs.c
@ -157,17 +157,8 @@ on_file_open_check_hidden_toggled (GtkToggleButton *togglebutton,
|
||||
#endif
|
||||
|
||||
|
||||
/* This shows the file selection dialog to open a file. */
|
||||
void dialogs_show_open_file ()
|
||||
{
|
||||
#if GEANY_USE_WIN32_DIALOG
|
||||
win32_show_file_dialog(TRUE);
|
||||
#else /* X11, not win32: use GTK_FILE_CHOOSER */
|
||||
gchar *initdir;
|
||||
|
||||
/* We use the same file selection widget each time, so first
|
||||
of all we create it if it hasn't already been created. */
|
||||
if (ui_widgets.open_filesel == NULL)
|
||||
#if ! GEANY_USE_WIN32_DIALOG
|
||||
static void create_open_file_dialog()
|
||||
{
|
||||
GtkWidget *filetype_combo, *encoding_combo;
|
||||
GtkWidget *viewbtn;
|
||||
@ -238,34 +229,44 @@ void dialogs_show_open_file ()
|
||||
g_signal_connect((gpointer) ui_widgets.open_filesel, "response",
|
||||
G_CALLBACK(on_file_open_dialog_response), NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* This shows the file selection dialog to open a file. */
|
||||
void dialogs_show_open_file()
|
||||
{
|
||||
gchar *initdir;
|
||||
|
||||
// set dialog directory to the current file's directory, if present
|
||||
initdir = utils_get_current_file_dir();
|
||||
initdir = utils_get_current_file_dir_utf8();
|
||||
|
||||
// use project or default startup directory (if set) if no files are open
|
||||
/// TODO should it only be used when initally open the dialog and not on every show?
|
||||
if (! initdir)
|
||||
initdir = g_strdup(utils_get_default_dir_utf8());
|
||||
|
||||
setptr(initdir, utils_get_locale_from_utf8(initdir));
|
||||
|
||||
#if GEANY_USE_WIN32_DIALOG
|
||||
win32_show_file_dialog(TRUE, initdir);
|
||||
#else /* X11, not win32: use GTK_FILE_CHOOSER */
|
||||
|
||||
/* We use the same file selection widget each time, so first
|
||||
of all we create it if it hasn't already been created. */
|
||||
if (ui_widgets.open_filesel == NULL)
|
||||
create_open_file_dialog();
|
||||
|
||||
if (initdir != NULL)
|
||||
{
|
||||
gchar *locale_filename;
|
||||
|
||||
locale_filename = utils_get_locale_from_utf8(initdir);
|
||||
|
||||
if (g_path_is_absolute(locale_filename))
|
||||
if (g_path_is_absolute(initdir))
|
||||
gtk_file_chooser_set_current_folder(
|
||||
GTK_FILE_CHOOSER(ui_widgets.open_filesel), locale_filename);
|
||||
|
||||
g_free(initdir);
|
||||
g_free(locale_filename);
|
||||
}
|
||||
// use default startup directory(if set) if no files are open
|
||||
/// TODO should it only be used when initally open the dialog and not on every show?
|
||||
else if (prefs.default_open_path != NULL && *prefs.default_open_path != '\0')
|
||||
{
|
||||
if (g_path_is_absolute(prefs.default_open_path))
|
||||
gtk_file_chooser_set_current_folder(
|
||||
GTK_FILE_CHOOSER(ui_widgets.open_filesel), prefs.default_open_path);
|
||||
GTK_FILE_CHOOSER(ui_widgets.open_filesel), initdir);
|
||||
}
|
||||
|
||||
gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(ui_widgets.open_filesel));
|
||||
gtk_widget_show(ui_widgets.open_filesel);
|
||||
#endif
|
||||
g_free(initdir);
|
||||
}
|
||||
|
||||
|
||||
@ -443,16 +444,8 @@ on_file_save_dialog_response (GtkDialog *dialog,
|
||||
#endif
|
||||
|
||||
|
||||
/* Show the Save As dialog for the current notebook page.
|
||||
* Returns: TRUE if the file was saved. */
|
||||
gboolean dialogs_show_save_as()
|
||||
{
|
||||
#if GEANY_USE_WIN32_DIALOG
|
||||
return win32_show_file_dialog(FALSE);
|
||||
#else
|
||||
gint idx = document_get_cur_idx(), resp;
|
||||
|
||||
if (ui_widgets.save_filesel == NULL)
|
||||
#if ! GEANY_USE_WIN32_DIALOG
|
||||
static void create_save_file_dialog()
|
||||
{
|
||||
GtkWidget *vbox, *check_open_new_tab, *rename_btn;
|
||||
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
|
||||
@ -499,6 +492,20 @@ gboolean dialogs_show_save_as()
|
||||
|
||||
gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.save_filesel), GTK_WINDOW(app->window));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ! GEANY_USE_WIN32_DIALOG
|
||||
static gboolean gtk_show_save_as(const gchar *initdir)
|
||||
{
|
||||
gint idx = document_get_cur_idx(), resp;
|
||||
|
||||
if (ui_widgets.save_filesel == NULL)
|
||||
create_save_file_dialog();
|
||||
|
||||
if (initdir && g_path_is_absolute(initdir))
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(ui_widgets.save_filesel),
|
||||
initdir);
|
||||
|
||||
// If the current document has a filename we use that as the default.
|
||||
if (doc_list[idx].file_name != NULL)
|
||||
@ -525,23 +532,39 @@ gboolean dialogs_show_save_as()
|
||||
gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(ui_widgets.save_filesel));
|
||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(ui_widgets.save_filesel), fname);
|
||||
|
||||
// use default startup directory(if set) if no files are open
|
||||
if (prefs.default_open_path != NULL && *prefs.default_open_path != '\0')
|
||||
{
|
||||
if (g_path_is_absolute(prefs.default_open_path))
|
||||
{
|
||||
gchar *def_path = utils_get_locale_from_utf8(prefs.default_open_path);
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(ui_widgets.save_filesel), def_path);
|
||||
g_free(def_path);
|
||||
}
|
||||
}
|
||||
g_free(fname);
|
||||
}
|
||||
|
||||
// Run the dialog synchronously, pausing this function call
|
||||
resp = gtk_dialog_run(GTK_DIALOG(ui_widgets.save_filesel));
|
||||
return (resp == GTK_RESPONSE_ACCEPT);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Show the Save As dialog for the current notebook page.
|
||||
* Returns: TRUE if the file was saved. */
|
||||
gboolean dialogs_show_save_as()
|
||||
{
|
||||
gboolean result;
|
||||
gchar *initdir = NULL;
|
||||
|
||||
initdir = utils_get_current_file_dir_utf8();
|
||||
|
||||
// use project or default startup directory (if set) if no files are open
|
||||
/// TODO should it only be used when initally open the dialog and not on every show?
|
||||
if (! initdir)
|
||||
initdir = g_strdup(utils_get_default_dir_utf8());
|
||||
|
||||
setptr(initdir, utils_get_locale_from_utf8(initdir));
|
||||
|
||||
#if GEANY_USE_WIN32_DIALOG
|
||||
result = win32_show_file_dialog(FALSE, initdir);
|
||||
#else
|
||||
result = gtk_show_save_as(initdir);
|
||||
#endif
|
||||
g_free(initdir);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -717,7 +717,7 @@ void search_show_find_in_files_dialog(const gchar *dir)
|
||||
if (NZV(dir))
|
||||
cur_dir = g_strdup(dir);
|
||||
else
|
||||
cur_dir = utils_get_current_file_dir();
|
||||
cur_dir = utils_get_current_file_dir_utf8();
|
||||
if (cur_dir)
|
||||
{
|
||||
gtk_entry_set_text(GTK_ENTRY(entry), cur_dir);
|
||||
|
19
src/utils.c
19
src/utils.c
@ -52,6 +52,7 @@
|
||||
#include "sciwrappers.h"
|
||||
#include "dialogs.h"
|
||||
#include "win32.h"
|
||||
#include "project.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
@ -1040,7 +1041,7 @@ gchar *utils_get_hex_from_color(GdkColor *color)
|
||||
/* Get directory from current file in the notebook.
|
||||
* Returns dir string that should be freed or NULL, depending on whether current file is valid.
|
||||
* Returned string is in UTF-8 encoding */
|
||||
gchar *utils_get_current_file_dir()
|
||||
gchar *utils_get_current_file_dir_utf8()
|
||||
{
|
||||
gint cur_idx = document_get_cur_idx();
|
||||
|
||||
@ -1658,3 +1659,19 @@ gboolean utils_string_replace_all(GString *str, const gchar *needle, const gchar
|
||||
}
|
||||
|
||||
|
||||
/* Get project or default startup directory (if set), or NULL. */
|
||||
const gchar *utils_get_default_dir_utf8()
|
||||
{
|
||||
if (app->project && NZV(app->project->base_path))
|
||||
{
|
||||
return app->project->base_path;
|
||||
}
|
||||
|
||||
if (NZV(prefs.default_open_path))
|
||||
{
|
||||
return prefs.default_open_path;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,7 +115,9 @@ void utils_replace_filename(gint idx);
|
||||
|
||||
gchar *utils_get_hex_from_color(GdkColor *color);
|
||||
|
||||
gchar *utils_get_current_file_dir();
|
||||
const gchar *utils_get_default_dir_utf8();
|
||||
|
||||
gchar *utils_get_current_file_dir_utf8();
|
||||
|
||||
void utils_beep();
|
||||
|
||||
|
@ -260,13 +260,13 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
|
||||
}
|
||||
|
||||
|
||||
// return TRUE if the dialog was not cancelled.
|
||||
gboolean win32_show_file_dialog(gboolean file_open)
|
||||
/* initial_dir can be NULL to use the current working directory.
|
||||
* Returns: TRUE if the dialog was not cancelled. */
|
||||
gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
|
||||
{
|
||||
OPENFILENAME of;
|
||||
gint retval;
|
||||
gchar *fname = g_malloc(2048);
|
||||
gchar *current_dir = utils_get_current_file_dir();
|
||||
gchar *filters = win32_get_file_filters();
|
||||
|
||||
fname[0] = '\0';
|
||||
@ -284,7 +284,7 @@ gboolean win32_show_file_dialog(gboolean file_open)
|
||||
of.lpstrCustomFilter = NULL;
|
||||
of.nFilterIndex = GEANY_FILETYPES_ALL + 1;
|
||||
of.lpstrFile = fname;
|
||||
of.lpstrInitialDir = current_dir;
|
||||
of.lpstrInitialDir = initial_dir;
|
||||
of.nMaxFile = 2048;
|
||||
of.lpstrFileTitle = NULL;
|
||||
of.lpstrTitle = NULL;
|
||||
@ -300,7 +300,6 @@ gboolean win32_show_file_dialog(gboolean file_open)
|
||||
retval = GetSaveFileName(&of);
|
||||
}
|
||||
|
||||
g_free(current_dir);
|
||||
g_free(filters);
|
||||
|
||||
if (!retval)
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
void win32_show_pref_file_dialog(GtkEntry *item);
|
||||
|
||||
gboolean win32_show_file_dialog(gboolean file_open);
|
||||
gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir);
|
||||
|
||||
void win32_show_font_dialog(void);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user