Fix crash on Windows when a project could not be opened. Remove prefix from win32_get_file_filters() and win32_get_filters(). Fix some encoding problems with filenames retrieved from the native Windows file dialogs.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2238 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2008-02-08 11:19:45 +00:00
parent 54b18cfb20
commit 05bff8f53d
3 changed files with 37 additions and 11 deletions

View File

@ -1,3 +1,13 @@
2008-02-08 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/project.c:
Fix crash on Windows when a project could not be opened.
* src/win32.c:
Remove prefix from win32_get_file_filters() and win32_get_filters().
Fix some encoding problems with filenames retrieved from the native
Windows file dialogs.
2008-02-07 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> 2008-02-07 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* plugins/Makefile.am: Fix typo (thanks Slava Semushin for reporting). * plugins/Makefile.am: Fix typo (thanks Slava Semushin for reporting).

View File

@ -247,7 +247,7 @@ void project_open()
{ {
SHOW_ERR1(_("Project file \"%s\" could not be loaded."), file); SHOW_ERR1(_("Project file \"%s\" could not be loaded."), file);
} }
if (project_prefs.project_session) else if (project_prefs.project_session)
{ {
configuration_open_files(); configuration_open_files();
// open a new file if no other file was opened // open a new file if no other file was opened

View File

@ -56,7 +56,7 @@
static gchar *win32_get_file_filters() static gchar *get_file_filters()
{ {
gchar *string; gchar *string;
gint i, j, len; gint i, j, len;
@ -97,7 +97,7 @@ static gchar *win32_get_file_filters()
} }
static gchar *win32_get_filters(gboolean project_files) static gchar *get_filters(gboolean project_files)
{ {
gchar *string; gchar *string;
gint i, len; gint i, len;
@ -188,7 +188,11 @@ gchar *win32_show_project_folder_dialog(GtkWidget *parent, const gchar *title,
// convert the strange Windows folder list item something into an usual path string ;-) // convert the strange Windows folder list item something into an usual path string ;-)
if (pidl != NULL && SHGetPathFromIDList(pidl, fname)) if (pidl != NULL && SHGetPathFromIDList(pidl, fname))
{
// convert the resulting filename into UTF-8 (from whatever encoding it has at this moment)
setptr(fname, g_locale_to_utf8(fname, -1, NULL, NULL, NULL));
return fname; return fname;
}
else else
{ {
g_free(fname); g_free(fname);
@ -209,7 +213,7 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
OPENFILENAME of; OPENFILENAME of;
gint retval; gint retval;
gchar *fname = g_malloc(2048); gchar *fname = g_malloc(2048);
gchar *filters = win32_get_filters(project_file_filter); gchar *filters = get_filters(project_file_filter);
gchar *dir = get_dir(initial_dir); gchar *dir = get_dir(initial_dir);
fname[0] = '\0'; fname[0] = '\0';
@ -256,7 +260,8 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
g_free(fname); g_free(fname);
return NULL; return NULL;
} }
// convert the resulting filename into UTF-8 (from whatever encoding it has at this moment)
setptr(fname, g_locale_to_utf8(fname, -1, NULL, NULL, NULL));
return fname; return fname;
} }
@ -268,7 +273,7 @@ gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
OPENFILENAME of; OPENFILENAME of;
gint retval; gint retval;
gchar *fname = g_malloc(2048); gchar *fname = g_malloc(2048);
gchar *filters = win32_get_file_filters(); gchar *filters = get_file_filters();
fname[0] = '\0'; fname[0] = '\0';
@ -323,6 +328,10 @@ gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
x = of.nFileOffset - 1; x = of.nFileOffset - 1;
if (x != strlen(fname)) if (x != strlen(fname))
{ // open a single file { // open a single file
// convert the resulting filename into UTF-8
setptr(fname, g_locale_to_utf8(fname, -1, NULL, NULL, NULL));
document_open_file(fname, of.Flags & OFN_READONLY, NULL, NULL); document_open_file(fname, of.Flags & OFN_READONLY, NULL, NULL);
} }
else else
@ -333,10 +342,15 @@ gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
{ {
if (! fname[x]) if (! fname[x])
{ {
gchar *utf8_filename;
if (! fname[x+1]) break; if (! fname[x+1]) break;
g_snprintf(file_name, 254, "%s\\%s", fname, fname + x + 1); g_snprintf(file_name, 254, "%s\\%s", fname, fname + x + 1);
document_open_file(file_name, of.Flags & OFN_READONLY, NULL, NULL);
// convert the resulting filename into UTF-8
utf8_filename = g_locale_to_utf8(file_name, -1, NULL, NULL, NULL);
document_open_file(utf8_filename, of.Flags & OFN_READONLY, NULL, NULL);
g_free(utf8_filename);
} }
x++; x++;
} }
@ -346,7 +360,8 @@ gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
else else
{ {
gint idx = document_get_cur_idx(); gint idx = document_get_cur_idx();
doc_list[idx].file_name = g_strdup(fname); // convert the resulting filename into UTF-8
doc_list[idx].file_name = g_locale_to_utf8(fname, -1, NULL, NULL, NULL);
document_save_file(idx, TRUE); document_save_file(idx, TRUE);
} }
g_free(fname); g_free(fname);
@ -424,7 +439,7 @@ void win32_show_pref_file_dialog(GtkEntry *item)
gint retval; gint retval;
gchar *fname = g_malloc(512); gchar *fname = g_malloc(512);
gchar **field, *filename, *tmp; gchar **field, *filename, *tmp;
gchar *filters = win32_get_filters(FALSE); gchar *filters = get_filters(FALSE);
fname[0] = '\0'; fname[0] = '\0';
@ -457,7 +472,7 @@ void win32_show_pref_file_dialog(GtkEntry *item)
of.lpstrInitialDir = NULL; of.lpstrInitialDir = NULL;
of.lpstrTitle = NULL; of.lpstrTitle = NULL;
of.lpstrDefExt = "exe"; of.lpstrDefExt = "exe";
of.Flags = OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER; of.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER;
retval = GetOpenFileName(&of); retval = GetOpenFileName(&of);
g_free(filters); g_free(filters);
@ -479,7 +494,8 @@ void win32_show_pref_file_dialog(GtkEntry *item)
{ {
tmp = g_strdup(fname); tmp = g_strdup(fname);
if (g_strv_length(field) > 1) if (g_strv_length(field) > 1)
// haha, pfad- und dateinamen mit leerzeichen?? // add the command line args of the old command
/// TODO this fails badly when the old command contained spaces, we need quoting here
filename = g_strconcat(tmp, " ", field[1], NULL); filename = g_strconcat(tmp, " ", field[1], NULL);
else else
{ {