Re: NSWindow class that allocs its own controller?
Re: NSWindow class that allocs its own controller?
- Subject: Re: NSWindow class that allocs its own controller?
- From: Fritz Anderson <email@hidden>
- Date: Wed, 6 Apr 2005 22:12:20 -0500
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/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden