Re: Best way to implement a modal window
Re: Best way to implement a modal window
- Subject: Re: Best way to implement a modal window
- From: Public Look <email@hidden>
- Date: Sun, 4 Apr 2004 19:33:45 -0400
On Apr 4, 2004, at 10:41 AM, Christoffer Lerno wrote:
>
For my editor, I'm planning on using NSDocument to structure things.
>
Now, being new to cocoa, I quickly ran into a small design problem.
>
It's not that I can't make it work, it's just that I want it to be a
>
good design too.
>
>
This is what is supposed to happen:
>
>
1. User clicks New in the menu
>
2. A modal window appears, asking for the width and height of the map
>
3. If width and height is correct, pressing the button labeled
>
"create" will close the modal window and open a new window laid out
>
with the requested width and height.
>
>
How do I design this best? For example, what class should be handling
>
the modal window's stopModal request?
>
>
My original design (before adding the modal window) looked like this:
>
>
ScenarioWindow (NSWindow)
>
ScenarioDocument (NSDocument subclass)
>
ScenarioWindowController (NSWindowController subclass)
>
>
Sure, I could put an action in ScenarioWindowController for my
>
NewDocumentPanel's "create" button to connect to when it wants to
>
close, but that doesn't seem like it's responsibility. Another way
>
could be to simply add that functionality to NSPanel, and yet another
>
to make a Controller for the panel (but that seems like overkill).
>
>
What's the best design?
>
I would say that upon new document creation, a sheet should open to
enable the user to enter map dimensions. If nothing is entered or the
wrong values are entered, a "cancel" button is enabled but the
"continue" button is disabled. IMHO "create" is not the right label
because although a map is being created, the document is already
created, but that is just IMHO. When correct values are entered, the
continue button becomes enabled and the default button. There is
probably no reason to keep a user from working in other document
windows while in the process of creating a new one. Perhaps the user
would like to check a detail in an existing document before deciding
what the dimensions of the new map should be. I consider it MS
Windows like to have any application modal windows at all if they are
not strictly necessary.
There is probably no reason to have ScenarioWindow at all. NSWindow is
almost never subclassed (except of course NSPanel). I wonder what your
subclass does ? Have I misunderstood ?
Your ScenarioDocument is probably a good place to handle the sheet for
selecting map size. If the user presses cancel, the NSDocument can
conveniently close itself without saving. If the user presses
continue, the document can close the sheet, instruct model objects to
create the appropriate map, and then get on with the business of
enabling editing of the map.
I am also curious ScenarioWindowController does ? NSWindowController
is often subclassed but usually only to override a default behavior
such as custom title or to perform some setup tasks before the window
is loaded. You haven't mentioned a need for any of those things that
your NSDocument subclass or its delegate can't do for you more easily.
Is it possible you are making things too complex ?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.