Re: Finding CAPI elements by name
On Wed, 27 Feb 2008 23:49:31 -0500, Paul Tarvydas <tarvydas@visualframeworksinc.com> wrote:
> When I want to access a particular capi pane in an interface, I
> declare an :accessor initarg
Yes, thanks, I know about accessors. That's not what I need. In my
application there is one huge dialog with /lots/ of panes. The idea
is that when the user exits the dialog, it will remember the last
active (focused) pane as it is likely that the next time the dialog
will be opened again, the user wants to start with the focus in the
same pane. Now, I can't store the pane itself between invocations as
it is a CLOS object that will disappear. Instead, I store its (CAPI)
name and use that to set the focus the next time the dialog is
displayed. Something like this:
(defun find-pane-by-name (name interface)
(capi:map-pane-descendant-children interface
(lambda (child)
(when (eq name (capi:capi-object-name child))
(return-from find-pane-by-name child))))
nil)
(defun find-active-pane (interface)
(capi:map-pane-descendant-children interface
(lambda (child)
(when (capi:pane-has-focus-p child)
(return-from find-active-pane child))))
nil)
And the interface has callbacks like these:
:destroy-callback (lambda (interface)
(lw:when-let (active-pane (find-active-pane interface))
(setq *last-active-pane* (capi:capi-object-name active-pane))))
:create-callback (lambda (interface)
(when *last-active-name*
(lw:when-let (named-pane (find-pane-by-name *last-active-name* interface))
(when (capi:simple-pane-enabled named-pane)
(capi:activate-pane named-pane)))))
I was just checking if something like FIND-PANE-BY-NAME already
existed. It's only five lines, but I'm always eager to discover
things I've missed so far... :)
And, BTW, before someone complains - the above is only a sketch of the
idea. The actual implementation is a bit more difficult as in the
destroy callback above the pane with focus is probably the button that
closed the interface and that is not what I want. But the code
hopefully suffices to illustrate the idea.
> If we could all get into the same room for a week, we would probably
> learn all sorts of (very liberating) secrets from one another...
Hehe, yes. Maybe we should do that one day.