[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] emacs should use GtkFileChooser widget
From: |
Sven Neumann |
Subject: |
[PATCH] emacs should use GtkFileChooser widget |
Date: |
Sun, 18 Jul 2004 22:21:51 +0200 |
Hi,
Please excuse if this is the wrong way to submit patches. I just
recently started to use the CVS build of emacs because of its use of
the GTK+-2.x toolkit. I find it convenient but I think that there are
a couple of issues and would like to submit patches for them. As a
first start, here's a patch against CVS that makes emacs use the
GtkFileChooser widget if compiled against GTK+ version 2.4 or newer.
-----------------------------------------------------------------------
Index: src/gtkutil.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/gtkutil.c,v
retrieving revision 1.41
diff -u -p -r1.41 gtkutil.c
--- src/gtkutil.c 28 Jun 2004 14:36:48 -0000 1.41
+++ src/gtkutil.c 18 Jul 2004 20:21:08 -0000
@@ -1159,6 +1159,10 @@ create_dialog (wv, select_cb, deactivate
}
+/* Use GtkFileSelection for gtk+ version < 2.4 */
+
+#if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4
+
enum
{
XG_FILE_NOT_DONE,
@@ -1205,7 +1209,7 @@ xg_file_sel_destroy (w, arg)
*(int*)arg = XG_FILE_DESTROYED;
}
-/* Read a file name from the user using a file dialog.
+/* Read a file name from the user using a file selection dialog.
F is the current frame.
PROMPT is a prompt to show to the user. May not be NULL.
DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
@@ -1275,6 +1279,58 @@ xg_get_file_name (f, prompt, default_fil
return fn;
}
+#else /* gtk+ version < 2.4 */
+
+/* Read a file name from the user using a file chooser dialog.
+ F is the current frame.
+ PROMPT is a prompt to show to the user. May not be NULL.
+ DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
+ If MUSTMATCH_P is non-zero, the returned file name must be an existing
+ file.
+
+ Returns a file name or NULL if no file was selected.
+ The returned string must be freed by the caller. */
+char *
+xg_get_file_name (f, prompt, default_filename, mustmatch_p)
+ FRAME_PTR f;
+ char *prompt;
+ char *default_filename;
+ int mustmatch_p;
+{
+ GtkWidget *dialog;
+ char *fn = NULL;
+
+ dialog = gtk_file_chooser_dialog_new (prompt,
+ GTK_WINDOW (FRAME_GTK_OUTER_WIDGET
(f)),
+ (mustmatch_p ?
+ GTK_FILE_CHOOSER_ACTION_OPEN :
+ GTK_FILE_CHOOSER_ACTION_SAVE),
+
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+
+ NULL);
+
+ xg_set_screen (dialog, f);
+
+ gtk_widget_set_name (dialog, "emacs-filedialog");
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+
+ if (default_filename)
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog),
default_filename);
+
+ gtk_widget_show (dialog);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+ fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ return fn;
+}
+
+#endif
+
/***********************************************************************
Menu functions.
-----------------------------------------------------------------------
In GNU Emacs 21.3.50.5 (i386-pc-linux-gnu, GTK+ Version 2.4.3)
of 2004-07-18 on bender, modified by Debian
configured using `configure '--build' 'i386-linux' '--host' 'i386-linux'
'--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
'--localstatedir=/var' '--infodir=/usr/share/info' '--mandir=/usr/share/man'
'--with-pop=yes' '--with-gif' '--with-gtk' 'build_alias=i386-linux'
'host_alias=i386-linux''
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: C
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: nil
locale-coding-system: nil
default-enable-multibyte-characters: t
Major mode: Lisp Interaction
Minor modes in effect:
show-paren-mode: t
mouse-wheel-mode: t
menu-bar-mode: t
global-font-lock-mode: t
font-lock-mode: t
unify-8859-on-encoding-mode: t
utf-translate-cjk-mode: t
column-number-mode: true
line-number-mode: t
Recent input:
<help-echo> M-x r e p o r <tab> <return>
Recent messages:
Loading 50psgml-init (source)...
Error while loading 50psgml-init
Loading 50sawfish (source)...done
Loading 50tdtd (source)...done
Toggling tool-bar-mode off; better pass an explicit argument.
Loading paren...done
Loading font-lock (compiled; note, source file is newer)...done
Loading jit-lock...done
Loading emacsbug...done
call-interactively: End of buffer [3 times]