emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pop-up tool-bar


From: Stefan Monnier
Subject: Re: pop-up tool-bar
Date: Thu, 07 Oct 2004 16:07:59 -0400
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux)

> The mouse-up event is two events removed from the event that triggers
> command show-tool-bar-for-one-command: 1) click Tool Bar, 2) mouse-down, 3)
> mouse-up. The Tool Bar click shows, then hides, the tool-bar, but the hiding
> doesn't take place until the mouse-down.

It looks like the problem is that the event you get from read-event is not
"valid" any more after you remove the toolbar (becaue the position is
changed).

Using read-event is generally a source a trouble.  But the alternatives
aren't great either.  Maybe you can try something like the appended code.

Note: you should pay attention to the case where the frame has been deleted
by the next command.

Also, you declare your minor mode to be ":global t" but it is frame-local,
so you should add (make-variable-frame-local 'tool-bar-here-mode) somewhere
at the toplevel.


        Stefan


(defun add-hook-once (hook function append local)
  "Same as `add-hook', but FUN is only run once.
Also contrary to `add-hook', this is not idempotent."
  (let ((code (list 'lambda)))
    (setcdr code `(() (,function) (remove-hook ',hook ',code ',local)))
    (add-hook hook code append local)))

...

(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)
  (tool-bar-here-mode 1)
  (add-hook-once 'post-command-hook
                 `(lambda ()
                    ;; We're just now done with show-tool-bar-for-one-command.
                    (add-hook-once 'post-command-hook
                                   (lambda ()
                                     ;; We're done with the next command.
                                     (select-frame ',(selected-frame))
                                     (tool--bar-here-mode -1))))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]