menus.el 26.6 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
2 3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991-2002  Lysator Academic Computer Association.
5
;;;;;
6
;;;;; This file is part of the LysKOM Emacs LISP client.
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 33
;;;;; 
;;;;; 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
;;;;
;;;;

34 35 36 37 38 39 40 41
(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)

42

43 44 45 46
(def-kom-var lyskom-current-menu-category nil
  "Category of menus currently used in buffer"
  local)

David Byers's avatar
X  
David Byers committed
47 48

(defvar lyskom-menu-template
49
  '((menu read
David Byers's avatar
David Byers committed
50 51 52 53 54 55 56 57 58 59 60
          ((item kom-view-next-text)
           (item kom-list-news)
           (item kom-list-summary)
           (item kom-go-to-conf)
           (hline)
           (menu review
                 ((item kom-view)
                  (item kom-review-next)
                  (item kom-review-last-normally-read)
                  (item kom-review-noconversion)
                  (item kom-review-converted)
61
                  (item kom-review-rot13)
David Byers's avatar
David Byers committed
62 63 64 65 66
                  (item kom-review-mail-headers)
                  (hline)
                  (item kom-find-root)
                  (item kom-view-commented-text)
                  (item kom-review-comments)
David Byers's avatar
 
David Byers committed
67
                  (item kom-review-more-comments)
68
		  (item kom-review-cross-references)
David Byers's avatar
David Byers committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
                  (item kom-review-tree)
                  (item kom-find-root-review)
                  (hline)
                  (item kom-review-by-to)
                  (item kom-review-first)
                  (item kom-review-all)
                  (item kom-review-more)
                  (hline)
                  (item kom-make-review-mark-as-read)
                  (item kom-make-review-not-mark-as-read)
                  (hline)
                  (item kom-review-stack)
                  (item kom-review-backward)
                  (item kom-review-clear)))
           (menu unread
                 ((item kom-mark-unread)
                  (item kom-unread-last-normally-read)
                  (hline)
                  (item kom-unread-root)
                  (item kom-unread-commented-text)
                  (item kom-unread-comments)
                  (item kom-unread-tree)
                  (item kom-unread-root-review)
                  (hline)
                  (item kom-unread-by-to)
                  (item kom-unread-first)
                  (item kom-unread-all)
                  (item kom-unread-more)
                  (hline)
                  (item kom-unread-presentation)
                  (item kom-unread-faq)
                  (item kom-unread-server-faq)))
           (menu marks
                 ((item kom-mark-text)
                  (item kom-unmark-text)
                  (hline)
                  (item kom-list-marks)
                  (item kom-review-marked-texts)
                  (item kom-review-all-marked-texts)
                  (hline)
                  (item kom-unread-marked-texts)
                  (item kom-unread-all-marked-texts)))
           (menu filters
                 ((item kom-filter-author)
                  (item kom-filter-subject)
                  (item kom-filter-text)
                  (item kom-filter-recipient)
                  (hline)
                  (item kom-list-filters)
                  (item kom-filter-edit)))
           (hline)
           (item kom-save-text)
           (item kom-save-text-body)
           (hline)
           (item kom-compare-texts)
           (item kom-diff-texts)
           (hline)
           (item kom-postpone)
           (item kom-jump)
           (item kom-super-jump)
           (item kom-set-unread)))

131
    (menu write
David Byers's avatar
David Byers committed
132 133 134 135 136 137 138 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 165 166 167 168
          ((item kom-write-text)
           (item kom-send-letter)
           (item kom-write-comment)
           (item kom-private-answer)
           (item kom-write-footnote)
           (hline)
           (menu receivers
                 ((item kom-will-person-read-text)
                  (hline)
                  (item kom-add-recipient)
                  (item kom-add-copy)
                  (item kom-add-bcc)
                  (item kom-sub-recipient)
                  (hline)
                  (item kom-move-text)
                  (item kom-move-text-tree)))
           (menu commented
                 ((item kom-add-comment)
                  (item kom-sub-comment)
                  (item kom-add-footnote)
                  (item kom-sub-footnote)))
           (menu aux-items 
                 ((item kom-add-cross-reference)
                  (item kom-add-private-answer)
                  (item kom-add-no-comments)
                  (item kom-add-request-confirm)
                  (item kom-fast-reply)
                  (item kom-agree)))
           (hline)
           (item kom-next-kom)
           (item kom-next-unread-kom)
           (item kom-previous-kom)
           (hline)
           (item kom-set-session-priority)
           (hline)
           (item kom-send-message)))

169
    (menu conference
David Byers's avatar
David Byers committed
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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
          ((item kom-go-to-conf)
           (item kom-go-to-next-conf)
           (hline)
           (item kom-review-presentation)
           (item kom-status-conf)
           (item kom-review-faq)
           (item kom-list-faqs)
           (hline)
           (item kom-list-conferences)
           (item kom-list-re)
           (item kom-list-new-conferences)
           (hline)
           (menu conf-admin
                 ((item kom-change-presentation)
                  (item kom-set-presentation)
                  (item kom-remove-presentation)
                  (hline)
                  (item kom-change-name)
                  (item kom-change-supervisor)
                  (item kom-set-garb-nice)
                  (item kom-set-super-conf)
                  (item kom-set-permitted-submitters)
                  (item kom-change-conf-type)
                  (item kom-limit-import)
                  (hline)
                  (item kom-change-conf-motd)
                  (item kom-set-motd-text)
                  (item kom-unset-conf-motd)
                  (hline)
                  (item kom-change-conf-faq)
                  (item kom-add-faq)
                  (item kom-del-faq)
                  (hline)
                  (item kom-sub-member)
                  (hline)
                  (item kom-create-conf)
                  (item kom-delete-conf)
                  (item kom-list-created-conferences)))
           (hline)
           (item kom-add-self)
           (item kom-sub-self)
           (item kom-add-member)
           (item kom-prioritize)))

214
    (menu person
David Byers's avatar
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 240 241
          ((item kom-who-is-on)
           (item kom-who-is-on-in-conference)
           (item kom-who-is-present-in-conference)
           (item kom-who-is-on-and-friend)
           (hline)
           (item kom-list-persons)
           (item kom-list-re)
           (item kom-list-new-persons)
           (hline)
           (item kom-review-presentation)
           (item kom-status-person)
           (item kom-status-session)
           (item kom-list-created-conferences)
           (item kom-is-person-member-of-conference)
           (item kom-will-person-read-text)
           (hline)
           (menu membership
                 ((item kom-add-self)
                  (item kom-sub-self)
                  (hline)
                  (item kom-join-all-conferences)
                  (item kom-leave-all-conferences)
                  (hline)
                  (item kom-change-priority)
                  (item kom-change-message-flag)
                  (item kom-prioritize)))
           (menu pers-admin
242 243
                 ((item kom-change-presentation)
                  (item kom-change-name)
David Byers's avatar
David Byers committed
244 245 246 247 248
                  (item kom-change-parenthesis)
                  (item kom-change-password)
                  (item kom-redirect-comments)
                  (item kom-change-privileges)))
           (hline)
David Byers's avatar
 
David Byers committed
249 250 251
           (item kom-befriend)
           (item kom-moronify)
           (hline)
David Byers's avatar
David Byers committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
           (item kom-who-am-i)))

    (menu server
          ((item kom-status-server)
           (item kom-review-server-faq)
           (item kom-list-server-faqs)
           (hline)
           (menu server-admin
                 ((item kom-change-server-faq)
                  (item kom-add-server-faq)
                  (item kom-del-server-faq)
                  (hline)
                  (item kom-set-motd)
                  (item kom-remove-motd)
                  (hline)
                  (item kom-recommend-conference)
                  (hline)
                  (item kom-enable-adm-caps)
                  (item kom-disable-adm-caps)
                  (hline)
                  (item kom-shutdown-server)
                  (item kom-sync-database)))
           ))


David Byers's avatar
David Byers committed
277
    (menu other
David Byers's avatar
David Byers committed
278
          ((item kom-help)
279 280 281
           (menu language
                 ((item kom-change-global-language)
                  (item kom-change-local-language)))
David Byers's avatar
David Byers 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
           (item kom-where-is)
           (item kom-display-time)
           (item kom-calculate)
           (hline)
           (item kom-customize)
           (item kom-copy-options)
           (item kom-save-options)
           (item kom-show-user-area)
           (hline)
           (menu remote-control
                 ((item kom-remote-autoreply)
                  (item kom-remote-set-message)
                  (item kom-remote-list-messages)
                  (item kom-remote-erase-messages)
                  (item kom-remote-quit)))
           (menu autoreply
                 ((item kom-toggle-auto-reply)
                  (item kom-change-auto-reply)
                  (item kom-list-messages)
                  (item kom-erase-messages)))
           (hline)
           (item kom-keep-alive)
           (item kom-stop-keep-alive)
           (hline)
           (item kom-recover)
           (item kom-start-anew)
           (item kom-force-logout)
309
	   (item kom-list-sessions)
David Byers's avatar
David Byers committed
310 311
           (item kom-quit))))

312
  "The menus used in LysKOM.")
Niels Möller's avatar
Niels Möller committed
313

David Byers's avatar
X  
David Byers committed
314 315
(defvar lyskom-popup-menu-template
  (` (menu lyskom ((,@ lyskom-menu-template))))
316 317
  "Popup-menu in the backgrouond of the LysKOM window")

David Byers's avatar
X  
David Byers committed
318 319

(defvar lyskom-edit-menu-template
320
  '((menu lyskom
321 322
	  ((item kom-ispell-message)
           (item kom-edit-send)
Joel Rosdahl's avatar
Joel Rosdahl committed
323
	   (hline receiver-separator)
324 325
	   (item kom-edit-add-recipient)
	   (item kom-edit-add-copy)
326 327 328 329 330 331 332
           (item kom-edit-add-bcc)
           (item kom-edit-move-text)
           (item kom-edit-add-cross-reference)
           (hline special-separator)
           (item kom-edit-add-no-comments)
           (item kom-edit-add-personal-comments)
           (item kom-edit-add-read-confirm-request)
333 334 335 336
	   (hline comment-separator)
	   (item kom-edit-show-commented)
	   (hline send-separator)
	   (item kom-edit-quit))))
337
  "The menus for editing LysKOM messages.")
338

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
(defvar lyskom-prioritize-menu-template
  '((menu lyskom
          ((item lp--toggle-membership-selection)
           (hline select-separator-1)
           (item lp--select-region)
           (item lp--select-priority)
           (hline select-separator-2)
           (item lp--deselect-priority)
           (item lp--deselect-all)
           (hline select-separator-3)
           (menu lp--membership-priority
                 ((item lp--set-priority)
                  (item lp--move-up)
                  (item lp--move-down)
                  (item lp--increase-priority)
                  (item lp--decrease-priority)
                  (item lp--yank)))
           (menu lp--membership-type
                 ((item lp--toggle-invitation)
                  (item lp--toggle-passive)
                  (item lp--toggle-message-flag)
                  (item lp--toggle-secret)))
           (menu lp--filter
                 ((item lp--show-hide-memberships-read-before)
                  (item lp--show-hide-memberships-read-after)
                  (item lp--show-hide-read-memberships)
                  (item lp--show-hide-passive-memberships)
                  (hline filter-separator)
                  (item lp--show-all)))
           (menu lp--membership-expansion
                 ((item lp--toggle-entry-expansion)
                  (item lp--expand-entry)
                  (item lp--contract-entry))
                 (hline quit-separator)
                 (item lp--quit))))))



David Byers's avatar
X  
David Byers committed
377
(defvar lyskom-menu-list '((lyskom-mode . lyskom-menu)
378 379
                           (lyskom-edit-mode . lyskom-edit-menu)
                           (lp--mode . lyskom-prioritize-menu))
David Byers's avatar
X  
David Byers committed
380 381 382
  "List of menu sets in LysKOM")

(defvar lyskom-menu nil
383
  "A keymap describing the LysKOM top menu.")
384

David Byers's avatar
X  
David Byers committed
385
(defvar lyskom-edit-menu nil
386 387
  "A keymap the LysKOM menu in the edit buffer.")

388 389 390
(defvar lyskom-prioritize-menu nil
  "Menus for the prioritize mode.")

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

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
;;; ================================================================
;;; Hack for swedish bindings and shortcuts

(defvar lyskom-swedish-bindings 
  `(( . (aring Aring ,(elt (kbd "") 0) ,(elt (kbd "") 0)
                     229 197 2277 2245 3909 3941))
    ( . (adiaeresis Adiaeresis ,(elt (kbd "") 0) ,(elt (kbd "") 0)
                          228 196 2276 2244 3908 3940)))
  "Hack to deal with binding swedish characters")

(defvar lyskom-swedish-bindings-reverse
  (let ((tmp nil)
        (seq lyskom-swedish-bindings))
    (while seq
      (let ((el (car seq)))
        (setq tmp (nconc tmp (mapcar (lambda (x)
                                       (cons x (car el)))
                                     (cdr el)))))
      (setq seq (cdr seq)))
    tmp)
  "Hack to deal with binding swedish characters")

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
(defun lyskom-menu-guess-shortcuts (keymap &optional prefix result force)
  (lyskom-traverse-keymap
   (lambda (key binding)
     (when binding
       (let ((force (or force (assq key lyskom-swedish-bindings-reverse))))
         (if (keymapp binding)
             (setq result
                   (lyskom-menu-guess-shortcuts
                    (cond ((symbolp binding) (symbol-value binding))
                          (t binding))
                    (append prefix (list key))
                    result
                    force))
           (when force
             (setq key `(,@prefix ,key))
             (if (assq binding result)
                 (setcdr (assq binding result)
                         (cons (apply 'vector key)
                               (cdr (assq binding result))))
               (setq result (cons (cons binding 
                                        (list (apply 'vector key)))
                                  result))))))))
   keymap)
  result)

441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472

;;; ============================================================
;;; Creating menus

(defvar lyskom-menu-encoding-rules
  (lyskom-xemacs-or-gnu
   '((title . iso-8859-1)
     (item . iso-8859-1)
     (keys . iso8859-1))
   (cond ((< emacs-major-version 22) '((title . iso-8859-1)
				      (item . iso-8859-1)
				      (keys . iso8859-1)))
	 ((boundp 'gtk-version-string) '((title . utf-8)
					(item . utf-8)
					(keys . utf-8)))
	 ((memq window-system '(win32 mswindows w32)) '((title . utf-8)
				   (item . nil)
				   (keys . utf-8)))
	 (t '((title . iso-8859-1) (item . iso-8859-1) (keys . iso8859-1)))))
  "Rules for encoding menu strings")

(defun lyskom-menu-encode (string what)
  "Encode a string for use in menus.
STRING is the string to encode
WHAT is one of title, item or keys"
  (let ((coding (cdr (assq what lyskom-menu-encoding-rules))))
    (cond ((and coding (coding-system-p coding))
	   (lyskom-encode-coding-string string coding))
	  ((functionp coding)
	   (funcall coding string))
	  (t string))))

Niels Möller's avatar
Niels Möller committed
473
(defun lyskom-build-menus ()
David Byers's avatar
X  
David Byers committed
474 475 476 477 478 479
  "Create menus according to LYSKOM-MENUS"
  (lyskom-xemacs-or-gnu (lyskom-build-menus-xemacs)
                        (lyskom-build-menus-gnu)))


(defun lyskom-build-menus-xemacs ()
480
  (setq lyskom-prioritize-menu (lyskom-define-menu-xemacs lyskom-prioritize-menu-template))
David Byers's avatar
X  
David Byers committed
481 482 483 484 485 486 487 488 489 490 491
  (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))
492 493 494
  (setq lyskom-prioritize-menu (make-sparse-keymap))

  (lyskom-define-menu-gnu lyskom-prioritize-menu lyskom-prioritize-menu-template)
David Byers's avatar
X  
David Byers committed
495 496 497 498 499 500
  (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])))

501 502
(defun lyskom-define-menu-xemacs (menus &optional specials)
  (let ((specials (or specials
David Byers's avatar
David Byers committed
503 504
		      (when (current-local-map)
			(lyskom-menu-guess-shortcuts (current-local-map))))))
David Byers's avatar
X  
David Byers committed
505 506
    (cond ((null (car menus)))
          ((listp (car menus))          ; Menu bar
507
           (mapcar (lambda (x) (lyskom-define-menu-xemacs x specials)) menus))
David Byers's avatar
X  
David Byers committed
508 509 510
          ((eq (car menus) 'menu)       ; A menu
           (let ((menu-title (car (cdr menus)))
                 (menu-items (car (cdr (cdr menus)))))
511 512
             (cons (lyskom-menu-encode 
		    (lyskom-get-menu-string menu-title) 'title)
David Byers's avatar
X  
David Byers committed
513
                   (mapcar
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
		    (lambda (item)
		      (let ((type (car item))
			    (symbol (car (cdr item))))
			(cond ((eq type 'item)
			       (let ((shortcut nil))
				 (when (assq symbol specials)
				   (unless (lyskom-traverse key (cdr (assq symbol specials))
							    (unless (condition-case nil
									(eq (lookup-key (current-local-map) 
											key) symbol)
								      (error nil))
							      (lyskom-traverse-break t)))
				     (setq shortcut
					   (mapconcat 
					    (lambda (key)
					      (if (assq key lyskom-swedish-bindings-reverse)
						  (symbol-name 
						   (cdr (assq key lyskom-swedish-bindings-reverse)))
						(single-key-description key)))
					    (car (cdr (assq symbol specials)))
					    " "))))
				 (if shortcut
536 537 538
				     (vector (lyskom-menu-encode
					      (lyskom-get-menu-string symbol)
					      'item)
539 540
					     symbol
					     ':active t
541 542 543 544 545
					     ':keys (lyskom-menu-encode
						     shortcut 'keys))
				   (vector (lyskom-menu-encode 
					    (lyskom-get-menu-string symbol)
					    'item) symbol ':active t))))
546 547 548 549 550 551
			      ((eq type 'hline)
			       "--:shadowEtchedIn")
			      ((eq type 'menu)
			       (lyskom-define-menu-xemacs item specials))
			      (t (error "Bad menu item: %S" item)))))
		    menu-items))))
David Byers's avatar
X  
David Byers committed
552 553 554

          (t nil))))

555
(defvar lyskom-define-menu-gnu-title-encoding-type 'title)
556 557
(defun lyskom-define-menu-gnu (map menus &optional specials)
  (let ((specials (or specials
558 559
		      (when (current-local-map)
			(lyskom-menu-guess-shortcuts (current-local-map))))))
560 561 562 563 564 565 566
    (when menus
      (lyskom-define-menu-gnu map (cdr menus) specials)
      (let ((type (car (car menus)))
            (symbol (car (cdr (car menus)))))
        (cond ((eq 'hline type)
               (define-key map (vector (lyskom-gensym)) '("--")))
              ((eq 'menu type)
567 568 569 570 571
               (let* ((name (lyskom-menu-encode
			     (lyskom-get-menu-string symbol) 
			     lyskom-define-menu-gnu-title-encoding-type))
                      (submap (make-sparse-keymap name))
		      (lyskom-define-menu-gnu-title-encoding-type 'item))
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
                 (define-key map (vector symbol)
                   (cons name submap))
                 (lyskom-define-menu-gnu submap
                                         (car (cdr (cdr (car menus))))
                                         specials)))
              ((eq 'item type)
               (let ((shortcut nil))
                 (when (assq symbol specials)
                   (unless (lyskom-traverse key (cdr (assq symbol specials))
                             (unless (condition-case nil
                                         (eq (lookup-key (current-local-map) 
                                                         key) symbol)
                                       (error nil))
                               (lyskom-traverse-break t)))
                       (setq shortcut
                             (mapconcat 
                              (lambda (key)
                                (if (assq key lyskom-swedish-bindings-reverse)
                                    (symbol-name 
                                     (cdr (assq key lyskom-swedish-bindings-reverse)))
                                  (single-key-description key)))
                              (car (cdr (assq symbol specials)))
                              " "))))
                 (if shortcut
596 597 598 599 600
                     (define-key map (vector symbol)
                              `(menu-item ,(lyskom-menu-encode
					    (lyskom-get-menu-string symbol)
					    'item) ,symbol
                                          :keys ,(lyskom-menu-encode shortcut 'keys)))
601
                   (define-key map (vector symbol)
602
                     (cons (lyskom-menu-encode (lyskom-get-menu-string symbol) 'item) symbol)))))
603
              (t (error "Menu description invalid in lyskom-define-menu")))))))
Niels Möller's avatar
Niels Möller committed
604

David Byers's avatar
X  
David Byers committed
605 606 607 608 609 610 611 612

(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)
613 614
    (mapcar (lambda (mc)
	      (lyskom-set-menus mc (current-local-map)))
David Byers's avatar
X  
David Byers committed
615 616 617 618 619 620 621 622 623 624 625 626 627 628
            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
629 630
(eval-when-compile (defvar default-menubar nil))

David Byers's avatar
X  
David Byers committed
631 632 633 634 635 636 637 638 639 640 641
(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
642 643 644 645 646 647 648 649 650 651 652 653 654
;;;
;;; 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
655 656
     (cond ((null result))
           ((listp (car result)) 
David Byers's avatar
David Byers committed
657 658 659
            (apply (car (car result))
                   (cdr (car result))))
           ((commandp (car result))
660
            (call-interactively (car result)))
David Byers's avatar
David Byers committed
661 662 663 664
           ((functionp (car result))
            (funcall (car result)))
           (t nil)))))

David Byers's avatar
X  
David Byers committed
665

666 667
(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
668
  (let* ((menu lyskom-popup-menu)
David Byers's avatar
David Byers committed
669
	 (result (lyskom-do-popup-menu menu event)))))
670

Niels Möller's avatar
Niels Möller committed
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728



;;;;(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
729

730
(eval-and-compile (provide 'lyskom-menus))
David Kågedal's avatar
David Kågedal committed
731 732

;;; menus.el ends here