FROM : Fritz Anderson
DATE : Thu Apr 07 05:12:20 2005
On 6 Apr 2005, at 1:19 PM, daniel wrote:
> I am faced with this question in my attempt to add AppleScript
> support for a controller-managed window class in my application.
> Cocoa Scripting likes to instantiate objects directly by class
> name. In my case, it's an NSWindow subclass that I ultimately want
> to expose to AppleScript, but it's instantiated typically via an
> NSWindowController.
>
> Let's say FunWindowController manages a FunWindow whose interface
> is contained in FunWindow.nib.
>
> Ordinarily, to instantiate a FunWindow from code, I would allocate
> and initialize a FunWindowController, which would in turn
> "initWithWindowNibName" for FunWindow.nib.
>
> To get "easy AppleScript support," I can define a FunWindow class
> in my scripting definition and define it as a subclass of "window",
> with a class name of "FunWindow." The obvious problem here is that
> FunWindow is incapable of instantiating itself.
>
> So, I could add an "init" method to my FunWindow that releases self
> and in its place returns a freshly created FunWindowController's
> window. Yuck! I would probably also have to detect a cycle since
> init would probably re-enter as soon as FunWindowController created
> its window.
I think your problems begin when you think of windows as being a
primary part of the scriptable interface of your application.
AppleScript is not there for scripting the graphical interface; it's
there for scripting the underlying model. Window objects play an
incidental role, by way of identifying, for instance, the document of
window 1. There are also some convenience properties for moving and
sizing them.
But I don't know of any application whose scripting interface
includes "make new window." At the very least, it's "make new document."
If you want to make a new window, make a new thing that the window
displays, whether that's a document or a view on some model object,
and open it. Your graphical interface doesn't start its response to
the "New" command by creating a window; it creates something to fill
the window, then something to control it, and then the window. Your
scripting interface should do the same.
-- F
--
Fritz Anderson
Consulting Programmer
http://resume.manoverboard.org/
DATE : Thu Apr 07 05:12:20 2005
On 6 Apr 2005, at 1:19 PM, daniel wrote:
> I am faced with this question in my attempt to add AppleScript
> support for a controller-managed window class in my application.
> Cocoa Scripting likes to instantiate objects directly by class
> name. In my case, it's an NSWindow subclass that I ultimately want
> to expose to AppleScript, but it's instantiated typically via an
> NSWindowController.
>
> Let's say FunWindowController manages a FunWindow whose interface
> is contained in FunWindow.nib.
>
> Ordinarily, to instantiate a FunWindow from code, I would allocate
> and initialize a FunWindowController, which would in turn
> "initWithWindowNibName" for FunWindow.nib.
>
> To get "easy AppleScript support," I can define a FunWindow class
> in my scripting definition and define it as a subclass of "window",
> with a class name of "FunWindow." The obvious problem here is that
> FunWindow is incapable of instantiating itself.
>
> So, I could add an "init" method to my FunWindow that releases self
> and in its place returns a freshly created FunWindowController's
> window. Yuck! I would probably also have to detect a cycle since
> init would probably re-enter as soon as FunWindowController created
> its window.
I think your problems begin when you think of windows as being a
primary part of the scriptable interface of your application.
AppleScript is not there for scripting the graphical interface; it's
there for scripting the underlying model. Window objects play an
incidental role, by way of identifying, for instance, the document of
window 1. There are also some convenience properties for moving and
sizing them.
But I don't know of any application whose scripting interface
includes "make new window." At the very least, it's "make new document."
If you want to make a new window, make a new thing that the window
displays, whether that's a document or a view on some model object,
and open it. Your graphical interface doesn't start its response to
the "New" command by creating a window; it creates something to fill
the window, then something to control it, and then the window. Your
scripting interface should do the same.
-- F
--
Fritz Anderson
Consulting Programmer
http://resume.manoverboard.org/
| Related mails | Author | Date |
|---|---|---|
| daniel | Apr 6, 20:19 | |
| Fritz Anderson | Apr 7, 05:12 | |
| Matt Neuburg | Apr 7, 18:37 | |
| daniel | Apr 9, 02:53 |






Cocoa mail archive

