unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
Cc: Miguel Frasson <frasson@altair.math.leidenuniv.nl>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: RE: pop-up tool-bar
Date: Fri, 8 Oct 2004 10:20:04 -0700	[thread overview]
Message-ID: <MEEKKIABFKKDFJMPIOEBAELECGAA.drew.adams@oracle.com> (raw)
In-Reply-To: <FDELKNEBLPKKDCEBEJCBGEDCCIAA.drew.adams@oracle.com>

[-- Attachment #1: Type: text/plain, Size: 2546 bytes --]

Please try this version of the pop-up tool-bar, and see what you think about
including it in Emacs as an option. I've added it to `tool-bar.el'; patch
attached.

The added code adds two new minor modes:

 - tool-bar-here-mode
 - tool-bar-pop-up-mode

The former is not strictly related to the pop-up tool-bar. It is simply the
same thing as `tool-bar-mode', but local to the selected frame only. I'd
propose it independently, even if folks decided against including the pop-up
mode. The pop-up tool-bar uses the frame-local tool-bar
(`tool-bar-here-mode') to do its work, but `tool-bar-here-mode' does not
need `tool-bar-pop-up-mode'.

So, with this addition, we will have three modes:

 - tool-bar-mode:        global (all frames)
 - tool-bar-here-mode:   local to selected frame
 - tool-bar-pop-up-mode: local to selected frame; tool-bar pops up on demand

Command `tool-bar-pop-up-mode' functions as a toggle only if neither
`tool-bar-mode' nor `tool-bar-here-mode' is on. If either of those modes is
on, then command `tool-bar-pop-up-mode' turns them both off and turns
`tool-bar-pop-up-mode' on (regardless of whether or not variable
`tool-bar-pop-up-mode' considers the pop-up mode to already be on).

Conversely, turning on one of the other tool-bar modes effectively nullifies
`tool-bar-pop-up-mode'. In terms of user-visible effect, the two are thus
mutually exclusive: either pop-up or not. By default, `tool-bar-mode' is on
(and the other two are off).

This version of the tool-bar pop-up code solves an interesting pb that arose
with the previous version when you clicked the mouse while the tool-bar was
temporarily visible. Because the tool-bar disappearance caused the buffer
text (the window) to move relative to an unmoving mouse, the mouse click
caused a region selection. That is, even though the mouse didn't move (you
just clicked), the movement of the _window_ relative to the mouse caused a
selection.

The fix was to scroll the buffer (window) `tool-bar-lines' to compensate for
the window movement. This scrolling happens for mouse events only, since
other events do not cause the problem (and you don't want to scroll the
buffer each time you click a tool-bar button).

It's easier to experience all of this than to describe it, so please give it
a try. To use the pop-up tool-bar, patch the file tool-bar.el, then load it
and `M-x tool-bar-popup-mode'. Then click "Buttons" in the menu-bar to pop
up the tool-bar for a single command (button click). Pound on it a bit, and
let me know what you think.

Thanks,

  Drew

[-- Attachment #2: diff-tool-bar-pop-up.txt --]
[-- Type: text/plain, Size: 4268 bytes --]

diff -c "c:/emacs-21.3.50/lisp/toolbar/tool-bar.el" "c:/drews-lisp-20/tool-bar-w-popup.el"
*** c:/emacs-21.3.50/lisp/toolbar/tool-bar.el	Mon Jul 26 09:42:32 2004
--- c:/drews-lisp-20/tool-bar-w-popup.el	Fri Oct  8 09:46:22 2004
***************
*** 40,45 ****
--- 40,49 ----
  
  ;;; Code:
  
+ 
+ \f
+ ;;; Global Tool Bar Mode ------------------------
+ 
  ;;;###autoload
  (define-minor-mode tool-bar-mode
    "Toggle use of the tool bar.
***************
*** 266,271 ****
--- 270,366 ----
  		     :help "Pop up the Help menu")
    )
  
+ 
+ 
+ \f
+ ;;; Local Tool Bar Mode -------------------------
+ 
+ (define-minor-mode tool-bar-here-mode
+   "Toggle use of the tool bar on this frame only.
+ With numeric ARG, display the tool bar if and only if ARG is positive.
+ 
+ See `tool-bar-add-item' and `tool-bar-add-item-from-menu' for
+ conveniently adding tool bar items."
+   :init-value nil :global t :group 'mouse :group 'frames
+   (and (display-images-p)
+        (let ((lines (if tool-bar-here-mode 1 0)))
+ 	 ;; Alter existing frame...
+ 	 (modify-frame-parameters (selected-frame) (list (cons 'tool-bar-lines lines))))
+        (if (and tool-bar-here-mode
+ 		(display-graphic-p)
+ 		(= 1 (length (default-value 'tool-bar-map)))) ; not yet set up
+ 	   (tool-bar-setup))))
+ 
+ (make-variable-frame-local 'tool-bar-here-mode)
+ 
+ 
+ \f
+ ;;; Pop-Up Tool Bar Mode ------------------------
+ 
+ ;; If either of the normal tool-bar modes is turned on, then
+ ;; `tool-bar-popup-mode' is not available.
+ (define-key global-map [menu-bar pop-up-tool-bar]
+   '(menu-item
+     "Buttons" show-tool-bar-for-one-command
+     :visible (and tool-bar-pop-up-mode (not tool-bar-mode) (not tool-bar-here-mode))
+     :enable  (and tool-bar-pop-up-mode (not tool-bar-mode) (not tool-bar-here-mode))
+     :help "Use tool bar for one command"))
+ 
+ (setq menu-bar-final-items (append menu-bar-final-items (list 'pop-up-tool-bar)))
+ 
+ 
+ 
+ (define-minor-mode tool-bar-pop-up-mode
+   "Toggle tool-bar pop-up.
+ With numeric ARG, turn on tool-bar pop-up if and only if ARG is positive.
+ 
+ Note: Command `tool-bar-pop-up-mode' functions as a toggle only
+       if neither `tool-bar-mode' nor `tool-bar-here-mode' is on.
+ 
+       If either of those modes is on, then command
+       `tool-bar-pop-up-mode' turns them both off and turns
+       `tool-bar-pop-up-mode' on."
+   :init-value nil :global t :group 'mouse :group 'frames
+   (when (or tool-bar-mode tool-bar-here-mode)
+     (setq tool-bar-pop-up-mode t)
+     (tool-bar-mode -99)
+     (tool-bar-here-mode -99)))
+ 
+ 
+ ;; Note: This treats mouse events specially: it scrolls the buffer
+ ;; text (window) down to compensate for the disappearance of the
+ ;; tool-bar.  That is, it replaces the tool-bar with an equivalent
+ ;; number of lines of buffer text.
+ ;;
+ ;; The reason for this is so that where you click the mouse when the
+ ;; tool-bar is visible corresponds to where the mouse is after the
+ ;; tool-bar disappears. Otherwise, the buffer text moves up, relative
+ ;; to the mouse, and a region is selected (without ever physically
+ ;; moving the mouse).
+ ;;
+ (defun show-tool-bar-for-one-command ()
+   "Pop up the tool bar so you can click a button.
+ The tool bar stays visible until one command is executed
+ \(whether or not it was initiated by clicking a button)."
+   (interactive)
+   (unless tool-bar-pop-up-mode
+     (error "You must turn on `tool-bar-pop-up-mode' to use this command"))
+   (let (evnt tb-lines)
+     (unwind-protect
+         (progn
+           (tool-bar-here-mode 99)     ; Show tool-bar
+           (setq evnt (read-event))
+           (push evnt unread-command-events))
+       (when (and (consp evnt)
+                  (member (event-basic-type (car evnt)) '(mouse-1 mouse-2 mouse-3)))
+         (setq tb-lines (cdr (assq 'tool-bar-lines (frame-parameters (selected-frame)))))
+         (when tb-lines (scroll-down tb-lines)))
+       (tool-bar-here-mode -99))))     ; Hide tool-bar
+ 
+ 
+ 
+ ;;;;;;;;;;;;;;;;;;
+ 
  (provide 'tool-bar)
  
  ;;; arch-tag: 15f30f0a-d0d7-4d50-bbb7-f48fd0c8582f

Diff finished.  Fri Oct 08 09:46:52 2004

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  parent reply	other threads:[~2004-10-08 17:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-07  7:51 pop-up tool-bar Drew Adams
2004-10-07 11:33 ` Miguel Frasson
2004-10-07 19:01   ` Drew Adams
2004-10-07 20:07     ` Stefan Monnier
2004-10-07 21:04       ` Drew Adams
2004-10-07 21:44         ` Drew Adams
2004-10-09 15:44           ` Richard Stallman
2004-10-10 19:15             ` Drew Adams
2004-10-08 17:20         ` Drew Adams [this message]
2004-10-08 17:39           ` Stefan
2004-10-08 18:24             ` David Kastrup
2004-10-08 19:58               ` Drew Adams
2004-10-08 19:03             ` Drew Adams
2004-10-08 23:12               ` Stefan Monnier
2004-10-09  0:46                 ` Drew Adams
2004-10-11  4:45           ` Drew Adams
2004-10-07 20:08     ` David Kastrup
2004-10-07 20:20       ` Drew Adams
2004-10-07 20:54         ` Stefan Monnier
2004-10-07 20:56         ` David Kastrup
2004-10-08  6:12     ` Miguel Frasson
2004-10-09 15:45       ` Richard Stallman
2004-10-07 15:13 ` Stefan Monnier
2004-10-07 17:15   ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MEEKKIABFKKDFJMPIOEBAELECGAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=frasson@altair.math.leidenuniv.nl \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).