annotate lisp/prim/menubar.el @ 164:4e0740e5aab2

Added tag r20-3b8 for changeset 0132846995bd
author cvs
date Mon, 13 Aug 2007 09:43:39 +0200
parents 131b0175ea99
children 2d532a89d707
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; Menubar support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
20 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: Not in FSF. (Completely divergent from FSF menu-bar.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Some stuff in FSF menu-bar.el is in x-menubar.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (defvar default-menubar nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; this function is considered "part of the lexicon" by many,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; so we'll leave it here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defun kill-this-buffer () ; for the menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "Kill the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (kill-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun set-menubar-dirty-flag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Tell XEmacs that the menubar has to be updated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 NOTE: XEmacs now recognizes when you set a different value for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 `current-menubar'. You *only* need to call this function if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 destructively modify a part of the menubar and don't set `current-menubar'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Note that all the functions that modify a menu call this automatically."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (setq-default current-menubar (default-value 'current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; #### shouldn't this perhaps be `copy-tree'?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun set-menubar (menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Set the default menubar to be MENUBAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 See `current-menubar' for a description of the syntax of a menubar."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (check-menu-syntax menubar t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq-default current-menubar (copy-sequence menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defun set-buffer-menubar (menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "Set the buffer-local menubar to be MENUBAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 See `current-menubar' for a description of the syntax of a menubar."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (check-menu-syntax menubar t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (make-local-variable 'current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq current-menubar (copy-sequence menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defun check-menu-syntax (menu &optional menubar-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; The C code does syntax checking on the value of `current-menubar',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; but it's better to do it early, before things have gotten messed up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if menubar-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (or (stringp (car menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (list "menu name (first element) must be a string" menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;(or (cdr menu) (signal 'error (list "menu is empty" menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq menu (cdr menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (let (menuitem item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (while (keywordp (setq item (car menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (or (memq item '(:config :included :filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (list "menu keyword must be :config, :included, or :filter"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (if (or (not (cdr menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (vectorp (nth 1 menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (keywordp (nth 1 menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (signal 'error (list "strange keyword value" item (nth 1 menu))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (setq menu (nthcdr 2 menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (while menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq menuitem (car menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ((stringp menuitem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (and (string-match "^\\(-+\\|=+\\):\\(.*\\)" menuitem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (setq item (match-string 2 menuitem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (or (member item '(;; Motif-compatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "singleLine"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "doubleLine"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "singleDashedLine"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "doubleDashedLine"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "noLine"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "shadowEtchedIn"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "shadowEtchedOut"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "shadowEtchedInDash"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "shadowEtchedOutDash"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; non-Motif (Lucid menubar widget only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "shadowDoubleEtchedIn"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "shadowDoubleEtchedOut"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "shadowDoubleEtchedInDash"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "shadowDoubleEtchedOutDash"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (signal 'error (list "bogus separator style in menu item" item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ((null menuitem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (or menubar-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (signal 'error (list "nil is only permitted in the top level of menubars"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ((consp menuitem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (check-menu-syntax menuitem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ((vectorp menuitem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let ((L (length menuitem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 plistp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (and (< L 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (list "button descriptors must be at least 3 long"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 menuitem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq plistp (or (>= L 5) (keywordp (aref menuitem 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (or (stringp (aref menuitem 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "first element of a button must be a string (the label)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 menuitem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (or plistp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (< L 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (null (aref menuitem 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (stringp (aref menuitem 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "fourth element of a button must be a string (the label suffix)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 menuitem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if plistp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let ((i 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 selp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (while (< i L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (setq item (aref menuitem i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (cond ((not (memq item '(:active :suffix :keys :style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 :full :included :selected)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (list (if (keywordp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "unknown menu item keyword"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "not a keyword")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 item menuitem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ((eq item :style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq style (aref menuitem (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (or (memq style '(nil toggle radio button text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (signal 'error (list "unknown style" style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 menuitem))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ((eq item :selected) (setq selp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq i (+ i (if (eq item :full) 1 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (and selp (not (memq style '(toggle button radio))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (signal 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ":selected only makes sense with :style toggle, radio, or button"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 menuitem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (t (signal 'error (list "unrecognised menu descriptor" menuitem))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq menu (cdr menu)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; menu manipulation functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defun find-menu-item (menubar item-path-list &optional parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 "Search MENUBAR for item given by ITEM-PATH-LIST starting from PARENT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Returns (ITEM . PARENT), where PARENT is the immediate parent of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 the item found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 If the item does not exist, the car of the returned value is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 If some menu in the ITEM-PATH-LIST does not exist, an error is signalled."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (or (listp item-path-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (signal 'wrong-type-argument (list 'listp item-path-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (or parent (setq item-path-list (mapcar 'downcase item-path-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (if (not (consp menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (let ((rest menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (if (stringp (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (while (keywordp (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (setq rest (cddr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (if (and (car rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (equal (car item-path-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (downcase (if (vectorp (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (aref (car rest) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (if (stringp (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (car rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (car (car rest)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (setq result (car rest) rest nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq rest (cdr rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (cdr item-path-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (if (consp result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (find-menu-item (cdr result) (cdr item-path-list) result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (signal 'error (list (gettext "not a submenu") result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (signal 'error (list (gettext "no such submenu") (car item-path-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (cons result parent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defun add-menu-item-1 (leaf-p menu-path new-item before)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
199 ;; This code looks like it could be cleaned up some more
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
200 ;; Do we really need 6 calls to find-menu-item?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
201 (when before (setq before (downcase before)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
202 (let* ((item-name
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
203 (cond ((vectorp new-item) (aref new-item 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
204 ((consp new-item) (car new-item))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
205 (t nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (menubar current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (menu (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (car (find-menu-item menubar menu-path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (error nil)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
210 (item-found (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
211 ((null item-name)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
212 nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
213 ((not (listp menu))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
214 (signal 'error (list (gettext "not a submenu")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
215 menu-path)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
216 (menu
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
217 (find-menu-item (cdr menu) (list item-name)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
218 (t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
219 (find-menu-item menubar (list item-name)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
220 )))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
221 (unless menubar
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
222 (error "`current-menubar' is nil: can't add menus to it."))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
223 (unless menu
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
224 (let ((rest menu-path)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
225 (so-far menubar))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
226 (while rest
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
227 ;;; (setq menu (car (find-menu-item (cdr so-far) (list (car rest)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
228 (setq menu
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
229 (if (eq so-far menubar)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
230 (car (find-menu-item so-far (list (car rest))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
231 (car (find-menu-item (cdr so-far) (list (car rest))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
232 (unless menu
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
233 (let ((rest2 so-far))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
234 (while (and (cdr rest2) (car (cdr rest2)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
235 (setq rest2 (cdr rest2)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
236 (setcdr rest2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
237 (nconc (list (setq menu (list (car rest))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
238 (cdr rest2)))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
239 (setq so-far menu)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
240 (setq rest (cdr rest)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (if (and item-found (car item-found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; hack the item in place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (if menu
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
244 ;; Isn't it very bad form to use nsubstitute for side effects?
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (nsubstitute new-item (car item-found) menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (setq current-menubar (nsubstitute new-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (car item-found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;; OK, we have to add the whole thing...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; if BEFORE is specified, try to add it there.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
251 (unless menu (setq menu current-menubar))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
252 (when before
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
253 (setq before (car (find-menu-item menu (list before)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (let ((rest menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (added-before nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (if (eq before (car (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (setcdr rest (cons new-item (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq rest nil added-before t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq rest (cdr rest))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
262 (when (not added-before)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
263 ;; adding before the first item on the menubar itself is harder
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
264 (if (and (eq menu menubar) (eq before (car menu)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
265 (setq menu (cons new-item menu)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
266 current-menubar menu)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
267 ;; otherwise, add the item to the end.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
268 (nconc menu (list new-item))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (set-menubar-dirty-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 new-item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (defun add-menu-button (menu-path menu-leaf &optional before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "Add a menu item to some menu, creating the menu first if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 If the named item exists already, it is changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 MENU-PATH identifies the menu under which the new menu item should be inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 It is a list of strings; for example, (\"File\") names the top-level \"File\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 MENU-LEAF is a menubar leaf node. See the documentation of `current-menubar'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 BEFORE, if provided, is the name of a menu item before which this item should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 be added, if this item is not on the menu already. If the item is already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 present, it will not be moved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (add-menu-item-1 t menu-path menu-leaf before))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; I actually liked the old name better, but the interface has changed too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; drastically to keep it. --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (defun add-submenu (menu-path submenu &optional before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 "Add a menu to the menubar or one of its submenus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 If the named menu exists already, it is changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 MENU-PATH identifies the menu under which the new menu should be inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 It is a list of strings; for example, (\"File\") names the top-level \"File\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 If MENU-PATH is nil, then the menu will be added to the menubar itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 SUBMENU is the new menu to add.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 See the documentation of `current-menubar' for the syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 BEFORE, if provided, is the name of a menu before which this menu should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 be added, if this menu is not on its parent already. If the menu is already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 present, it will not be moved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (check-menu-syntax submenu nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (add-menu-item-1 nil menu-path submenu before))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun purecopy-menubar (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; this calls purecopy on the strings, and the contents of the vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; but not on the vectors themselves, or the conses - those must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;; writable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (cond ((vectorp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (let ((i (length x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (while (> i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (aset x (1- i) (purecopy (aref x (1- i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq i (1- i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ((consp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let ((rest x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (setcar rest (purecopy-menubar (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (setq rest (cdr rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (purecopy x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (defun delete-menu-item (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 "Remove the named menu item from the menu hierarchy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 PATH is a list of strings which identify the position of the menu item in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 the menu hierarchy. The documentation of `add-submenu' describes menu-paths."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (let* ((pair (condition-case nil (find-menu-item current-menubar path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (item (car pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (parent (or (cdr pair) current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (if (not item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; the menubar is the only special case, because other menus begin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; with their name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (if (eq parent current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (setq current-menubar (delq item parent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (delq item parent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (set-menubar-dirty-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (defun relabel-menu-item (path new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 "Change the string of the specified menu item.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 PATH is a list of strings which identify the position of the menu item in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 NEW-NAME is the string that the menu item will be printed as from now on."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (or (stringp new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (setq new-name (signal 'wrong-type-argument (list 'stringp new-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (let* ((menubar current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (pair (find-menu-item menubar path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (item (car pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (menu (cdr pair)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (or item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (signal 'error (list (if menu (gettext "No such menu item")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (gettext "No such menu"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (if (and (consp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (stringp (car item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setcar item new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (aset item 0 new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (set-menubar-dirty-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;; these are all bad style. Why in the world would we put evaluable forms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; into the menubar if we didn't want people to use 'em?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; x-font-menu.el is the only known offender right now and that ought to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ;; rehashed a bit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defun enable-menu-item-1 (path toggle-p on-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (let (menu item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (if (and (vectorp path) (> (length path) 2)) ; limited syntax checking...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (setq item path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (let* ((menubar current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (pair (find-menu-item menubar path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq item (car pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 menu (cdr pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (or item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (signal 'error (list (if menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "No such menu item"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 "No such menu")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (if (consp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (error "%S is a menu, not a menu item" path))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (if (or (> (length item) 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (and (symbolp (aref item 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (= ?: (aref (symbol-name (aref item 2)) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; plist-like syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (let ((i 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (keyword (if toggle-p :selected :active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (ok nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (while (< i (length item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (cond ((eq (aref item i) keyword)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (aset item (1+ i) on-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (setq ok t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq i (+ i 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (cond (ok nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (toggle-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (signal 'error (list "not a toggle menu item" item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 ;; Need to copy the item to extend it, sigh...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (let ((cons (memq item menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (new-item (vconcat item (list keyword on-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (if cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (setcar cons (setq item new-item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (if menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (error "couldn't find %S on its parent?" item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (error "no %S slot to set: %S" keyword item)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;; positional syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if toggle-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (signal 'error (list "not a toggle menu item" item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (aset item 2 on-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (set-menubar-dirty-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defun enable-menu-item (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 "Make the named menu item be selectable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 PATH is a list of strings which identify the position of the menu item in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (enable-menu-item-1 path nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defun disable-menu-item (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 "Make the named menu item be unselectable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 PATH is a list of strings which identify the position of the menu item in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (enable-menu-item-1 path nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defun select-toggle-menu-item (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 "Make the named toggle- or radio-style menu item be in the `selected' state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 PATH is a list of strings which identify the position of the menu item in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (enable-menu-item-1 path t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (defun deselect-toggle-menu-item (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 "Make the named toggle- or radio-style menu item be in the `unselected' state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 PATH is a list of strings which identify the position of the menu item in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (enable-menu-item-1 path t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (defun get-popup-menu-response (menu-desc &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 "Pop up the given menu and wait for a response.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 This blocks until the response is received, and returns the misc-user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 event that encapsulates the response. To execute it, you can do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (funcall (event-function response) (event-object response))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 If no response was received, nil is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 MENU-DESC and EVENT are as in the call to `popup-menu'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; partially stolen from w3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (let ((echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 new-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (popup-menu menu-desc event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (catch 'popup-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (setq new-event (next-command-event new-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (cond ((misc-user-event-p new-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (throw 'popup-done new-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ((not (popup-up-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (setq unread-command-events (cons new-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 unread-command-events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (throw 'popup-done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ((button-release-event-p new-event);; don't beep twice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ((event-matches-key-specifier-p (quit-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (signal 'quit nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (message "please make a choice from the menu.")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (defun popup-menu-and-execute-in-window (menu-desc event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 "Pop up the given menu and execute its response in EVENT's window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 This blocks until the response is received, temporarily selects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 EVENT's window, and executes the command specified in the response.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 EVENT can also be a window. See `popup-menu' for the semantics of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 MENU-DESC."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (let ((response
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (get-popup-menu-response menu-desc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (and (eventp event) event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (and (misc-user-event-p response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (save-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (select-window (if (windowp event) event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (event-window event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (funcall (event-function response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (event-object response))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (provide 'menubar)