git-gui: Teach class system to support [$this cmd] syntax
commit6233ab17297684c0049923cb8492393276672b01
authorShawn O. Pearce <spearce@spearce.org>
Sat, 30 Jun 2007 08:34:59 +0000 (30 04:34 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 9 Jul 2007 01:12:45 +0000 (8 21:12 -0400)
treef8e6a52efe57c2cb448c403d51963ec09fec4c6e
parent4ca131250c9e56efec638831d6157aaf4f130be9
git-gui: Teach class system to support [$this cmd] syntax

Its handy to be able to ask an object to do something for you by
handing it a subcommand.  For example if we want to get the value
of an object's private field the object could expose a method that
would return that value.  Application level code can then invoke
"$inst get" to perform the method call.

Tk uses this pattern for all of its widgets, so we'd certainly
like to use it for our own mega-widgets that we might develop.
Up until now we haven't needed such functionality, but I'm working
on a new revision picker mega-widget that would benefit from it.

To make this work we have to change the definition of $this to
actually be a procedure within the namespace.  By making $this a
procedure any caller that has $this can call subcommands by passing
them as the first argument to $this.  That subcommand then needs
to call the proper subroutine.

Placing the dispatch procedure into the object's variable namespace
ensures that it will always be deleted when the object is deleted.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
lib/class.tcl