Mercurial > emacs
comparison lisp/mouse.el @ 30328:7ce202715b72
(popup-menu): Allow a list of keymaps for menu arg.
(mouse-popup-menubar, mouse-popup-menubar-stuff): New functions.
(global-map): Bind c-down-mouse-3 to mouse-popup-menubar-stuff.
author | Dave Love <fx@gnu.org> |
---|---|
date | Wed, 19 Jul 2000 15:52:02 +0000 |
parents | a97801b43475 |
children | 544a9b8ebb8d |
comparison
equal
deleted
inserted
replaced
30327:09b01c9914a6 | 30328:7ce202715b72 |
---|---|
1 ;;; mouse.el --- window system-independent mouse support | 1 ;;; mouse.el --- window system-independent mouse support |
2 | 2 |
3 ;; Copyright (C) 1993, 1994, 1995, 1999 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1993, 1994, 1995, 1999, 2000 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Maintainer: FSF | 5 ;; Maintainer: FSF |
6 ;; Keywords: hardware | 6 ;; Keywords: hardware, mouse |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
9 | 9 |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | 10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
11 ;; it under the terms of the GNU General Public License as published by | 11 ;; it under the terms of the GNU General Public License as published by |
44 | 44 |
45 ;; Provide a mode-specific menu on a mouse button. | 45 ;; Provide a mode-specific menu on a mouse button. |
46 | 46 |
47 (defun popup-menu (menu &optional position prefix) | 47 (defun popup-menu (menu &optional position prefix) |
48 "Popup the given menu and call the selected option. | 48 "Popup the given menu and call the selected option. |
49 MENU can be a keymap or an easymenu-style menu. | 49 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for |
50 `x-popup-menu'. | |
50 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to | 51 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to |
51 the current mouse position. | 52 the current mouse position. |
52 PREFIX is the prefix argument (if any) to pass to the command." | 53 PREFIX is the prefix argument (if any) to pass to the command." |
53 (let* ((map (if (keymapp menu) menu | 54 (let* ((map (cond |
54 (let* ((map (easy-menu-create-menu (car menu) (cdr menu))) | 55 ((keymapp menu) menu) |
56 ((and (listp menu) (keymapp (car menu))) menu) | |
57 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu))) | |
55 (filter (when (symbolp map) | 58 (filter (when (symbolp map) |
56 (plist-get (get map 'menu-pro) :filter)))) | 59 (plist-get (get map 'menu-pro) :filter)))) |
57 (if filter (funcall filter (symbol-function map)) map)))) | 60 (if filter (funcall filter (symbol-function map)) map))))) |
58 event) | 61 event) |
59 ;; The looping behavior was taken from lmenu's popup-menu-popup | 62 ;; The looping behavior was taken from lmenu's popup-menu-popup |
60 (while (and map (setq event (x-popup-menu position map))) | 63 (while (and map (setq event (x-popup-menu position map))) |
61 ;; Strangely x-popup-menu returns a list. | 64 ;; Strangely x-popup-menu returns a list. |
62 ;; mouse-major-mode-menu was using a weird: | 65 ;; mouse-major-mode-menu was using a weird: |
133 (setq tail (cdr tail))) | 136 (setq tail (cdr tail))) |
134 (if (eq submap t) | 137 (if (eq submap t) |
135 menubar | 138 menubar |
136 (setq mouse-major-mode-menu-prefix (list (car submap))) | 139 (setq mouse-major-mode-menu-prefix (list (car submap))) |
137 (lookup-key menubar (vector (car submap))))))) | 140 (lookup-key menubar (vector (car submap))))))) |
141 | |
142 (defun mouse-popup-menubar (event prefix) | |
143 "Pops up a menu equiavlent to the menu bar a keyboard EVENT with PREFIX. | |
144 The contents are the items that would be in the menu bar whether or | |
145 not it is actually displayed." | |
146 (interactive "@e \nP") | |
147 (run-hooks 'activate-menubar-hook) | |
148 (let* ((local-menu (lookup-key (current-local-map) [menu-bar])) | |
149 (global-menu (lookup-key global-map [menu-bar]))) | |
150 ;; Supplying the list is faster than making a new map. | |
151 (popup-menu (list global-menu local-menu) event prefix))) | |
152 | |
153 (defun mouse-popup-menubar-stuff (event prefix) | |
154 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'. | |
155 Use the former if the menu bar is showing, otherwise the latter." | |
156 (interactive "@e \nP") | |
157 (if (zerop (assoc-default 'menu-bar-lines (frame-parameters) 'eq 0)) | |
158 (mouse-popup-menubar event prefix) | |
159 (mouse-major-mode-menu event prefix))) | |
138 | 160 |
139 ;; Commands that operate on windows. | 161 ;; Commands that operate on windows. |
140 | 162 |
141 (defun mouse-minibuffer-check (event) | 163 (defun mouse-minibuffer-check (event) |
142 (let ((w (posn-window (event-start event)))) | 164 (let ((w (posn-window (event-start event)))) |
2045 ;; event to make the selection, saving a click. | 2067 ;; event to make the selection, saving a click. |
2046 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) | 2068 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) |
2047 (if (not (eq system-type 'ms-dos)) | 2069 (if (not (eq system-type 'ms-dos)) |
2048 (global-set-key [S-down-mouse-1] 'mouse-set-font)) | 2070 (global-set-key [S-down-mouse-1] 'mouse-set-font)) |
2049 ;; C-down-mouse-2 is bound in facemenu.el. | 2071 ;; C-down-mouse-2 is bound in facemenu.el. |
2050 (global-set-key [C-down-mouse-3] 'mouse-major-mode-menu) | 2072 (global-set-key [C-down-mouse-3] 'mouse-popup-menubar-stuff) |
2051 | 2073 |
2052 | 2074 |
2053 ;; Replaced with dragging mouse-1 | 2075 ;; Replaced with dragging mouse-1 |
2054 ;; (global-set-key [S-mouse-1] 'mouse-set-mark) | 2076 ;; (global-set-key [S-mouse-1] 'mouse-set-mark) |
2055 | 2077 |