This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
swing.scm
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: kawa at sourceware dot org
- Date: Wed, 16 Feb 2011 18:53:22 -0500
- Subject: swing.scm
Hi Per,
Would you mind adding this check for #!void to the menu function in
swing.scm?
It would let me do things like this:
(menu label: "File"
...
(unless (mac-os-x?) (menuitem label: "Exit")))
where the contents of the menu -- specifically, the presence of a
particular
menu item -- should depend on some condition. Right now, every
argument to
menu, except for label: and its string, is assumed to be a JMenuItem,
which in
this case means I have to either do this:
(if (mac-os-x?)
(menuitem label: "I don't really want this menuitem here. :-(")
(menuitem label: "Exit"))
or have separate-but-almost-identical menu building code for each
possible
combinations of conditions.
Index: gnu/kawa/slib/swing.scm
===================================================================
--- gnu/kawa/slib/swing.scm (revision 6900)
+++ gnu/kawa/slib/swing.scm (working copy)
@@ -136,6 +136,7 @@
(as <String>
((primitive-array-get <object>) args (+ i 1))))
(loop (+ i 2)))
+ ((eq? #!void arg) (loop (+ i 1)))
(else
(invoke menu 'add (as <javax.swing.JMenuItem> arg))
(loop (+ i 1)))))))
Alternatively (or additionally), perform this type of check in the code
that automagically transforms
(javax.swing.JMenu text: "File" mi1 ...)
into the equivalent of
(let ((m (javax.swing.JMenu))) (invoke m 'setText "File") (invoke m
'add mi1) ...)
so that it only calls 'add if the argument is not #!void. I'm pretty
sure
that would be in CompileInvoke.java, but I'm not well-versed enough in
hand-crafting gnu.expr.Expressions to offer a suitable patch..
The latter is probably a better change to make, actually, because it's
more
general. It's probably pretty rare for someone to actually want to call
add(Values.empty) on some object.
Thanks,
Jamie
--
Jamison Hope
The PTR Group
www.theptrgroup.com