From 4f3097d8bcc4faa2abda36177161e3d6caf3b433 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Sat, 2 Sep 2006 18:10:15 +0000 Subject: * gtkutil.c (xg_get_file_with_chooser): Change file chooser message for writing files. Call gtk_file_chooser_set_current_name to keep default filename. --- src/gtkutil.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index 2a6ed9d1524..172c7b94a64 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1327,8 +1327,12 @@ xg_get_file_with_chooser (f, prompt, default_filename, if (action != GTK_FILE_CHOOSER_ACTION_SAVE) strcat (message, "\nType C-l to display a file name text entry box.\n"); strcat (message, "\nIf you don't like this file selector, customize " - "use-file-dialog\nto turn it off, or type C-x C-f to visit files."); - + "use-file-dialog\nto turn it off, or type "); + if (action != GTK_FILE_CHOOSER_ACTION_SAVE) + strcat (message, "C-x C-f to visit files."); + else + strcat (message, "C-x C-w to write files."); + wmessage = gtk_label_new (message); gtk_widget_show (wmessage); gtk_box_pack_start (GTK_BOX (wbox), wtoggle, FALSE, FALSE, 0); @@ -1340,6 +1344,7 @@ xg_get_file_with_chooser (f, prompt, default_filename, Lisp_Object file; struct gcpro gcpro1; GCPRO1 (file); + char *utf8_filename; file = build_string (default_filename); @@ -1347,14 +1352,20 @@ xg_get_file_with_chooser (f, prompt, default_filename, an absolute name starting with /. */ if (default_filename[0] != '/') file = Fexpand_file_name (file, Qnil); - - default_filename = SSDATA (file); - if (Ffile_directory_p (file)) + + utf8_filename = SSDATA (ENCODE_UTF_8 (file)); + if (! NILP (Ffile_directory_p (file))) gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filewin), - default_filename); + utf8_filename); else - gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewin), - default_filename); + { + char *cp = strrchr (utf8_filename, '/'); + if (cp) ++cp; + else cp = utf8_filename; + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewin), + utf8_filename); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filewin), cp); + } UNGCPRO; } -- cgit v1.2.3 From ae6c1c19504fac2228f15125cdbcbddc0c67c0bf Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Mon, 4 Sep 2006 14:47:52 +0000 Subject: * gtkutil.c (xg_get_file_with_chooser): Don't mention specific keys in the file chooser message. Only call gtk_file_chooser_set_current_name when action is SAVE. --- src/ChangeLog | 6 ++++++ src/gtkutil.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/gtkutil.c') diff --git a/src/ChangeLog b/src/ChangeLog index b730c8d9889..e21593fbd45 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2006-09-04 Jan Dj,Ad(Brv + + * gtkutil.c (xg_get_file_with_chooser): Don't mention specific keys in + the file chooser message. Only call gtk_file_chooser_set_current_name + when action is SAVE. + 2006-09-04 Andreas Schwab * Makefile.in: Double all single and back quotes in C-style diff --git a/src/gtkutil.c b/src/gtkutil.c index 172c7b94a64..89b0f8b11c6 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1326,12 +1326,9 @@ xg_get_file_with_chooser (f, prompt, default_filename, message[0] = '\0'; if (action != GTK_FILE_CHOOSER_ACTION_SAVE) strcat (message, "\nType C-l to display a file name text entry box.\n"); - strcat (message, "\nIf you don't like this file selector, customize " - "use-file-dialog\nto turn it off, or type "); - if (action != GTK_FILE_CHOOSER_ACTION_SAVE) - strcat (message, "C-x C-f to visit files."); - else - strcat (message, "C-x C-w to write files."); + strcat (message, "\nIf you don't like this file selector, use the " + "corresponding\nkey binding or customize " + "use-file-dialog to turn it off."); wmessage = gtk_label_new (message); gtk_widget_show (wmessage); @@ -1359,12 +1356,15 @@ xg_get_file_with_chooser (f, prompt, default_filename, utf8_filename); else { - char *cp = strrchr (utf8_filename, '/'); - if (cp) ++cp; - else cp = utf8_filename; gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewin), utf8_filename); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filewin), cp); + if (action == GTK_FILE_CHOOSER_ACTION_SAVE) + { + char *cp = strrchr (utf8_filename, '/'); + if (cp) ++cp; + else cp = utf8_filename; + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filewin), cp); + } } UNGCPRO; -- cgit v1.2.3 From 9d7dda8a86aa2381f7717ab006fb45490ddc0c42 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Sun, 10 Sep 2006 12:17:19 +0000 Subject: * gtkutil.c (xg_display_close): Always change default display if needed, check for < Gtk+ version 2.10 before calling gdk_display_close. --- src/gtkutil.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index 89b0f8b11c6..cf6caafa942 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -131,14 +131,8 @@ xg_display_close (Display *dpy) #ifdef HAVE_GTK_MULTIDISPLAY GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy); - /* GTK 2.2 has a bug that makes gdk_display_close crash (bug - http://bugzilla.gnome.org/show_bug.cgi?id=85715). This way - we can continue running, but there will be memory leaks. */ - -#if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4 - /* If this is the default display, we must change it before calling - dispose, otherwise it will crash. */ + dispose, otherwise it will crash on some Gtk+ versions. */ if (gdk_display_get_default () == gdpy) { struct x_display_info *dpyinfo; @@ -160,10 +154,14 @@ xg_display_close (Display *dpy) gdpy_new); } - g_object_run_dispose (G_OBJECT (gdpy)); + /* GTK 2.2-2.8 has a bug that makes gdk_display_close crash (bug + http://bugzilla.gnome.org/show_bug.cgi?id=85715). This way + we can continue running, but there will be memory leaks. */ +#if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 10 + g_object_run_dispose (G_OBJECT (gdpy)); #else - /* I hope this will be fixed in GTK 2.4. It is what bug 85715 says. */ + /* This seems to be fixed in GTK 2.10. */ gdk_display_close (gdpy); #endif #endif /* HAVE_GTK_MULTIDISPLAY */ -- cgit v1.2.3 From 241ad3cab7ffbeaf83e724f639750714af60b192 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Sat, 16 Sep 2006 17:18:03 +0000 Subject: * gtkutil.c (get_utf8_string): Try harder to convert to UTF8. Gtk+ will simply crash if we fail. --- src/ChangeLog | 5 +++++ src/gtkutil.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) (limited to 'src/gtkutil.c') diff --git a/src/ChangeLog b/src/ChangeLog index f1c5996121b..1a6f6edeb33 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2006-09-16 Jan Dj,Ad(Brv + + * gtkutil.c (get_utf8_string): Try harder to convert to UTF8. Gtk+ + will simply crash if we fail. + 2006-09-16 Richard Stallman * regex.c (re_compile_pattern): Set gl_state.current_syntax_table. diff --git a/src/gtkutil.c b/src/gtkutil.c index cf6caafa942..35c2cc0ba18 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -507,10 +507,66 @@ get_utf8_string (str) { char *utf8_str = str; + if (!str) return NULL; + /* If not UTF-8, try current locale. */ - if (str && !g_utf8_validate (str, -1, NULL)) + if (!g_utf8_validate (str, -1, NULL)) utf8_str = g_locale_to_utf8 (str, -1, 0, 0, 0); + if (!utf8_str) + { + /* Probably some control characters in str. Escape them. */ + size_t nr_bad = 0; + gsize bytes_read; + gsize bytes_written; + unsigned char *p = (unsigned char *)str; + char *cp, *up; + GError *error = NULL; + + while (! (cp = g_locale_to_utf8 (p, -1, &bytes_read, + &bytes_written, &error)) + && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE) + { + ++nr_bad; + p += bytes_written+1; + g_error_free (error); + error = NULL; + } + + if (error) + { + g_error_free (error); + error = NULL; + } + if (cp) g_free (cp); + + up = utf8_str = xmalloc (strlen (str) + nr_bad * 4 + 1); + p = str; + + while (! (cp = g_locale_to_utf8 (p, -1, &bytes_read, + &bytes_written, &error)) + && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE) + { + strncpy (up, p, bytes_written); + sprintf (up + bytes_written, "\\%03o", p[bytes_written]); + up[bytes_written+4] = '\0'; + up += bytes_written+4; + p += bytes_written+1; + g_error_free (error); + error = NULL; + } + + if (cp) + { + strcat (utf8_str, cp); + g_free (cp); + } + if (error) + { + g_error_free (error); + error = NULL; + } + } return utf8_str; } -- cgit v1.2.3 From cf1e295ff572f813a19fd6cc1f71e1565954502d Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Sat, 16 Sep 2006 17:43:21 +0000 Subject: * gtkutil.c (xg_get_file_with_chooser): Check x-gtk-show-chooser-help-text before adding the help text. --- src/gtkutil.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index 35c2cc0ba18..f16d0aea80c 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1350,6 +1350,8 @@ xg_get_file_with_chooser (f, prompt, default_filename, GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE); extern int x_gtk_show_hidden_files; + extern int x_gtk_show_chooser_help_text; + if (only_dir_p) action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; @@ -1377,17 +1379,22 @@ xg_get_file_with_chooser (f, prompt, default_filename, g_signal_connect (G_OBJECT (filewin), "notify", G_CALLBACK (xg_toggle_notify_cb), wtoggle); - message[0] = '\0'; - if (action != GTK_FILE_CHOOSER_ACTION_SAVE) - strcat (message, "\nType C-l to display a file name text entry box.\n"); - strcat (message, "\nIf you don't like this file selector, use the " - "corresponding\nkey binding or customize " - "use-file-dialog to turn it off."); + if (x_gtk_show_chooser_help_text) + { + message[0] = '\0'; + if (action != GTK_FILE_CHOOSER_ACTION_SAVE) + strcat (message, "\nType C-l to display a file name text entry box.\n"); + strcat (message, "\nIf you don't like this file selector, use the " + "corresponding\nkey binding or customize " + "use-file-dialog to turn it off."); - wmessage = gtk_label_new (message); - gtk_widget_show (wmessage); + wmessage = gtk_label_new (message); + gtk_widget_show (wmessage); + } + gtk_box_pack_start (GTK_BOX (wbox), wtoggle, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (wbox), wmessage, FALSE, FALSE, 0); + if (x_gtk_show_chooser_help_text) + gtk_box_pack_start (GTK_BOX (wbox), wmessage, FALSE, FALSE, 0); gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (filewin), wbox); if (default_filename) -- cgit v1.2.3 From afd6c41297dd920b10843adbc93dd753f3f776e3 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Mon, 18 Sep 2006 16:41:49 +0000 Subject: * gtkutil.c (xg_uses_old_file_dialog): Rename x-use-old-gtk-file-dialog to x-gtk-use-old-file-dialog. --- src/gtkutil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index f16d0aea80c..5cc3f5834b8 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1212,8 +1212,8 @@ int xg_uses_old_file_dialog () { #ifdef HAVE_GTK_FILE_BOTH - extern int x_use_old_gtk_file_dialog; - return x_use_old_gtk_file_dialog; + extern int x_gtk_use_old_file_dialog; + return x_gtk_use_old_file_dialog; #else /* ! HAVE_GTK_FILE_BOTH */ #ifdef HAVE_GTK_FILE_SELECTION_NEW -- cgit v1.2.3 From a10fe8349d1414255cdb5e5accb52941cb40a072 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Mon, 18 Sep 2006 16:47:46 +0000 Subject: * gtkutil.c (xg_get_file_with_chooser): Rename x_gtk_show_chooser_help_text to x_gtk_file_dialog_help_text. --- src/gtkutil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index 5cc3f5834b8..cdc87044c81 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1350,7 +1350,7 @@ xg_get_file_with_chooser (f, prompt, default_filename, GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE); extern int x_gtk_show_hidden_files; - extern int x_gtk_show_chooser_help_text; + extern int x_gtk_file_dialog_help_text; if (only_dir_p) @@ -1379,7 +1379,7 @@ xg_get_file_with_chooser (f, prompt, default_filename, g_signal_connect (G_OBJECT (filewin), "notify", G_CALLBACK (xg_toggle_notify_cb), wtoggle); - if (x_gtk_show_chooser_help_text) + if (x_gtk_file_dialog_help_text) { message[0] = '\0'; if (action != GTK_FILE_CHOOSER_ACTION_SAVE) @@ -1393,7 +1393,7 @@ xg_get_file_with_chooser (f, prompt, default_filename, } gtk_box_pack_start (GTK_BOX (wbox), wtoggle, FALSE, FALSE, 0); - if (x_gtk_show_chooser_help_text) + if (x_gtk_file_dialog_help_text) gtk_box_pack_start (GTK_BOX (wbox), wmessage, FALSE, FALSE, 0); gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (filewin), wbox); -- cgit v1.2.3 From 7b7d4a7915edf6aabe29e0e0045439b3d8086337 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Fri, 22 Sep 2006 08:19:55 +0000 Subject: * gtkutil.c (xg_get_file_with_chooser): Only chow C-l help for Gtk+ versions < 2.10. --- src/gtkutil.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index cdc87044c81..19fb8ef69a3 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1382,7 +1382,9 @@ xg_get_file_with_chooser (f, prompt, default_filename, if (x_gtk_file_dialog_help_text) { message[0] = '\0'; - if (action != GTK_FILE_CHOOSER_ACTION_SAVE) + /* Gtk+ 2.10 has the file name text entry box integrated in the dialog. + Show the C-l help text only for versions < 2.10. */ + if (gtk_check_version(2, 10, 0) && action != GTK_FILE_CHOOSER_ACTION_SAVE) strcat (message, "\nType C-l to display a file name text entry box.\n"); strcat (message, "\nIf you don't like this file selector, use the " "corresponding\nkey binding or customize " -- cgit v1.2.3 From 7adfb96e729f42c3fe4a2edf48bf1100248621a2 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 23 Sep 2006 03:07:19 +0000 Subject: Whitespace fix. --- src/gtkutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gtkutil.c') diff --git a/src/gtkutil.c b/src/gtkutil.c index 19fb8ef69a3..fb3c9447f84 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1384,7 +1384,7 @@ xg_get_file_with_chooser (f, prompt, default_filename, message[0] = '\0'; /* Gtk+ 2.10 has the file name text entry box integrated in the dialog. Show the C-l help text only for versions < 2.10. */ - if (gtk_check_version(2, 10, 0) && action != GTK_FILE_CHOOSER_ACTION_SAVE) + if (gtk_check_version (2, 10, 0) && action != GTK_FILE_CHOOSER_ACTION_SAVE) strcat (message, "\nType C-l to display a file name text entry box.\n"); strcat (message, "\nIf you don't like this file selector, use the " "corresponding\nkey binding or customize " -- cgit v1.2.3