menus.el 11.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
;;;;; the Free Software Foundation; either version 2, or (at your option) 
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: menus.el
;;;; Author: Niels Mller
;;;;
;;;;

33 34 35 36 37 38 39 40
(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

(lyskom-external-function set-buffer-menubar)
(lyskom-external-function popup-menu)
(lyskom-external-function add-submenu)

41

David Byers's avatar
X  
David Byers committed
42 43 44 45 46
(defvar lyskom-current-menu-category nil
  "Category of menus currently used in buffer")
(make-variable-buffer-local 'lyskom-current-menu-category)

(defvar lyskom-menu-template
47 48 49 50 51 52 53 54 55
  '((menu read
	  ((item kom-view-next-text)
	   (item kom-list-news)
	   (hline review-separator)
	   (item kom-view-commented-text)
	   (item kom-view-previous-commented-text)
	   (item kom-review-comments)
	   (item kom-review-tree)
	   (item kom-find-root)
David Byers's avatar
David Byers committed
56 57
           (item kom-find-root-review)
           (item kom-review-clear)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	   (hline jump-separator)
	   (item kom-jump)
	   (item kom-super-jump)
	   (item kom-set-unread)))
    (menu write
	  ((item kom-write-text)
	   (item kom-send-letter)
	   (item kom-write-comment)
	   (item kom-private-answer)
	   (item kom-comment-previous)
	   (hline send-separator)
	   (item kom-send-message)))
    (menu conference
	  ((item kom-go-to-conf)
	   (item kom-go-to-next-conf)
	   (hline info-separator)
	   (item kom-membership)
	   (item kom-list-conferences)
	   (item kom-status-conf)
	   (item kom-review-presentation)
	   (hline member-separator)
	   (item kom-add-self)
	   (item kom-sub-self)
	   (item kom-prioritize)))
    (menu person
	  ((item kom-who-is-on)
	   (item kom-status-session)
	   (hline info-separator)
	   (item kom-list-persons)
	   (item kom-status-person)
	   (item kom-review-presentation)
	   (hline change-separator)
	   (item kom-change-name)
David Byers's avatar
David Byers committed
91 92 93
	   (item kom-change-password)))
    (menu other
          ((item kom-customize))))
94
  "The menus used in LysKOM.")
Niels Möller's avatar
Niels Möller committed
95

David Byers's avatar
X  
David Byers committed
96 97
(defvar lyskom-popup-menu-template
  (` (menu lyskom ((,@ lyskom-menu-template))))
98 99
  "Popup-menu in the backgrouond of the LysKOM window")

David Byers's avatar
X  
David Byers committed
100 101

(defvar lyskom-edit-menu-template
102
  '((menu lyskom
103 104
	  ((item kom-ispell-message)
           (item kom-edit-send)
105 106 107 108 109 110 111 112 113
;	   (item kom-edit-send-anonymous)
	   (hline reciever-separator)
	   (item kom-edit-add-recipient)
	   (item kom-edit-add-copy)
	   (hline comment-separator)
	   (item kom-edit-show-commented)
;	   (item kom-edit-insert-commented)
	   (hline send-separator)
	   (item kom-edit-quit))))
114
  "The menus for editing LysKOM messages.")
115

David Byers's avatar
X  
David Byers committed
116 117 118 119 120
(defvar lyskom-menu-list '((lyskom-mode . lyskom-menu)
                           (lyskom-edit-mode . lyskom-edit-menu))
  "List of menu sets in LysKOM")

(defvar lyskom-menu nil
121
  "A keymap describing the LysKOM top menu.")
122

David Byers's avatar
X  
David Byers committed
123 124
;(when (not lyskom-menu) 
;  (setq lyskom-menu (make-sparse-keymap)))
Niels Möller's avatar
Niels Möller committed
125

David Byers's avatar
X  
David Byers committed
126
(defvar lyskom-edit-menu nil
127 128
  "A keymap the LysKOM menu in the edit buffer.")

David Byers's avatar
X  
David Byers committed
129 130
;(when (not lyskom-edit-menu)
;  (setq lyskom-edit-menu (make-sparse-keymap)))
Niels Möller's avatar
Niels Möller committed
131

David Byers's avatar
X  
David Byers committed
132
(defvar lyskom-popup-menu nil
133 134
  "A keymap the LysKOM menu in the edit buffer.")

David Byers's avatar
X  
David Byers committed
135 136
;(when (not lyskom-popup-menu)
;  (setq lyskom-popup-menu (make-sparse-keymap)))
137

Niels Möller's avatar
Niels Möller committed
138
(defun lyskom-build-menus ()
David Byers's avatar
X  
David Byers committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
  "Create menus according to LYSKOM-MENUS"
  (lyskom-xemacs-or-gnu (lyskom-build-menus-xemacs)
                        (lyskom-build-menus-gnu)))


(defun lyskom-build-menus-xemacs ()
  (setq lyskom-edit-menu (lyskom-define-menu-xemacs lyskom-edit-menu-template))
  (setq lyskom-popup-menu (lyskom-define-menu-xemacs
                               lyskom-popup-menu-template))
  (setq lyskom-menu (lyskom-define-menu-xemacs lyskom-menu-template)))


(defun lyskom-build-menus-gnu ()
  "Rebuilds the LysKOM menus"
  (setq lyskom-menu (make-sparse-keymap))
  (setq lyskom-edit-menu (make-sparse-keymap))
  (setq lyskom-popup-menu (make-sparse-keymap))
  (lyskom-define-menu-gnu lyskom-menu lyskom-menu-template)
  (lyskom-define-menu-gnu lyskom-edit-menu lyskom-edit-menu-template)
  (lyskom-define-menu-gnu lyskom-popup-menu
                          (list lyskom-popup-menu-template))
  (setq lyskom-popup-menu (lookup-key lyskom-popup-menu [lyskom])))

(defun lyskom-define-menu-xemacs (menus)
  (let ((type nil)
        (parameters nil))
David Byers's avatar
David Byers committed
165
    (ignore type parameters)            ; Are they ever used?
David Byers's avatar
X  
David Byers committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    (cond ((null (car menus)))
          ((listp (car menus))          ; Menu bar
           (mapcar 'lyskom-define-menu-xemacs
                   menus))

          ((eq (car menus) 'menu)       ; A menu
           (let ((menu-title (car (cdr menus)))
                 (menu-items (car (cdr (cdr menus)))))
             (cons (lyskom-get-menu-string menu-title)
                   (mapcar
                    (function
                     (lambda (item)
                       (cond ((eq (car item) 'item)
                              (vector (lyskom-get-menu-string 
                                       (car (cdr item)))
                                       (car (cdr item))
                                       ':active
                                       t))
                             ((eq (car item) 'hline)
                              (vector "--:shadowEtchedIn" nil ':active nil) )
                             ((eq (car item) 'menu)
                              (lyskom-define-menu-xemacs item))
                             (t
                              (error "Bad menu item: %S"
                                     item)))))
                    menu-items))))

          (t nil))))


(defun lyskom-define-menu-gnu (map menus)
Niels Möller's avatar
Niels Möller committed
197
  (when menus
David Byers's avatar
X  
David Byers committed
198
    (lyskom-define-menu-gnu map (cdr menus))
199 200 201 202 203 204 205 206 207
    (let ((type (car (car menus)))
	  (symbol (car (cdr (car menus)))))
      (cond ((eq 'hline type)
	     (define-key map (vector symbol) '("--")))
	    ((eq 'menu type)
	     (let* ((name (lyskom-get-menu-string symbol))
		    (submap (make-sparse-keymap name)))
	       (define-key map (vector symbol)
		 (cons name submap))
David Byers's avatar
X  
David Byers committed
208
	       (lyskom-define-menu-gnu submap
209 210
				   (car (cdr (cdr (car menus)))))))
	    ((eq 'item type)
Niels Möller's avatar
Niels Möller committed
211
	     (define-key map (vector symbol)
212 213
	       (cons (lyskom-get-menu-string symbol) symbol)))
	    (t (error "Menu description invalid in lyskom-define-menu"))))))
Niels Möller's avatar
Niels Möller committed
214

David Byers's avatar
X  
David Byers committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

(defun lyskom-get-menu-category (menu-category)
  (symbol-value (cdr (assq menu-category lyskom-menu-list))))

(defun lyskom-update-menus ()
  (lyskom-build-menus)
  (when (and (boundp 'lyskom-current-menu-category)
             lyskom-current-menu-category)
    (mapcar (function
             (lambda (mc)
               (lyskom-set-menus mc (current-local-map))))
            lyskom-current-menu-category)))

(defun lyskom-set-menus (menu-category  keymap)
  (lyskom-xemacs-or-gnu (lyskom-set-menus-xemacs menu-category)
                        (lyskom-set-menus-gnu menu-category keymap)))

(defun lyskom-set-menus-gnu (menu-category keymap)
  "Update the menus"
  (define-key keymap [menu-bar] (lyskom-get-menu-category menu-category))
  (make-local-variable 'lyskom-current-menu-category)
  (if (not (boundp 'lyskom-current-menu-category))
      (setq lyskom-current-menu-category (list menu-category))
    (add-to-list 'lyskom-current-menu-category menu-category)))

David Byers's avatar
David Byers committed
240 241
(eval-when-compile (defvar default-menubar nil))

David Byers's avatar
X  
David Byers committed
242 243 244 245 246 247 248 249 250 251 252
(defun lyskom-set-menus-xemacs (menu-category)
  "Update the menus"
  (make-local-variable 'current-menubar)
  (make-local-variable 'lyskom-current-menu-category)
  (set-buffer-menubar default-menubar)
  (mapcar (function
           (lambda (menu)
             (add-submenu nil menu)))
          (lyskom-get-menu-category menu-category))
  (setq lyskom-current-menu-category (list menu-category)))

David Byers's avatar
David Byers committed
253 254 255 256 257 258 259 260 261 262 263 264 265
;;;
;;; This function would have been completely unnecessary if Gnu Emacs
;;; didn't carry around an ancient version of popup-menu that is
;;; completely incompatible with XEmacs version of the same function. 
;;; Sometimes I hate elisp.
;;;

(defun lyskom-do-popup-menu (menu event)
  "Pop up a menu"
  (lyskom-xemacs-or-gnu 
   (popup-menu menu event)
   (let* ((result (nreverse (x-popup-menu (or event t)
                                          (list menu)))))
David Byers's avatar
David Byers committed
266 267
     (cond ((null result))
           ((listp (car result)) 
David Byers's avatar
David Byers committed
268 269 270 271 272 273 274 275
            (apply (car (car result))
                   (cdr (car result))))
           ((commandp (car result))
            (call-interactively (car (nreverse result))))
           ((functionp (car result))
            (funcall (car result)))
           (t nil)))))

David Byers's avatar
X  
David Byers committed
276

277 278
(defun lyskom-background-menu (pos event)
  "Pop up a menu with LysKOM commands and execute the selected command."
David Byers's avatar
X  
David Byers committed
279
  (let* ((menu lyskom-popup-menu)
David Byers's avatar
David Byers committed
280
	 (result (lyskom-do-popup-menu menu event)))))
281

Niels Möller's avatar
Niels Möller committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339



;;;;(terse) Baklnges		   Addera extra kopiemottagare
;;;;Addera kommentar		   Addera medlem
;;;;Addera mottagare		   Automatsvar
;;;;Avmarkera (inlgg)		   Bli medlem i mte
;;;;Brja med nytt namn		   Endast lsa senaste
;;;;Filtrera frfattare		   Filtrera innehll
;;;;Filtrera rende			   Fjrrkontrollera automatsvar
;;;;Fjrrkontrollera avsluta	   Fjrrkontrollera lista meddelanden
;;;;Fjrrkontrollera radera meddelanden
;;;;Fjrrkontrollera ndra svarsmeddelande
;;;;Flytta inlgg			   Fotnot till inlgg
;;;;F skll			   F uppmuntran
;;;;G till mte			   G till nsta mte
;;;;Hjlp				   Hoppa ver alla kommentarer
;;;;Kasta ut en session		   Kommentera fregende inlgg
;;;;Kommentera inlgget		   Ladda ner fil
;;;;Ladda upp fil			   Lista (med) regexpar
;;;;Lista filarean			   Lista filter
;;;;Lista klienter			   Lista meddelanden
;;;;Lista medlemsskap		   Lista mten
;;;;Lista nyheter			   Lista personer
;;;;Lista renden			   Lsa nsta inlgg
;;;;Lngsamma kommandon		   Markera (inlgg)
;;;;Personligt svar			   Personligt svar p fregende inlgg
;;;;Prioritera mten		   Radera inlgg
;;;;Radera meddelanden		   Se tiden
;;;;Skapa mte			   Skicka brev
;;;;Skriva ett inlgg		   Sluta
;;;;Snabba kommandon		   Spara text (p fil)
;;;;Spara variabler			   Status (fr) mte
;;;;Status (fr) person		   Status (fr) session
;;;;Subtrahera kommentar		   Subtrahera mottagare
;;;;Superhoppa			   Snda meddelande
;;;;Stt lapp p drren		   Stt lsniv
;;;;Ta bort lapp p drren		   Uppskjuta lsning
;;;;Uteslut medlem			   Utplna
;;;;Uttrda ur mte			   Var (r) jag
;;;;Vilka r inloggade		   Visa user-arean
;;;;Vnta p ett inlgg		   ndra filter
;;;;ndra livslngd			   ndra lsenord
;;;;ndra mtestyp			   ndra namn
;;;;ndra organisatr		   ndra presentation
;;;;ndra supermte			   ndra svarsmeddelande
;;;;ndra tilltna frfattare	   ndra variabler
;;;;terse alla			   terse alla kommentarer
;;;;terse alla kommentarer rekursivt  terse alla markerade
;;;;terse det fregende kommenterade
;;;;terse det kommenterade		   terse frsta
;;;;terse hoppa			   terse igen
;;;;terse inlgg			   terse lista
;;;;terse markerade		   terse nsta
;;;;terse omodifierat		   terse presentation
;;;;terse senaste			   terse trd
;;;;terse urinlgget		   terstarta kom
;;;;verg till administratrsmod
David Kågedal's avatar
David Kågedal committed
340 341 342 343

(provide 'lyskom-menus)

;;; menus.el ends here