Re: Challenge 18 in Hillegass Book
On Aug 10, 2008, at 10:03 AM, Kyle Sluder wrote: On Sat, Aug 9, 2008 at 8:54 PM, James Gorham [EMAIL PROTECTED] wrote: I think that's where I'm unclear. Making the Document class aware of the view is easy enough with an IBOutlet. But how to properly make the view aware of the document I'm unsure of. You're missing the point. You don't connect your NSDocument (model) to your views, you have a controller in between. This controller is responsible for noticing/being notified when the document changes so it can update the view, and it is also responsible for noticing/being notified when the view changes so it can update the document. Understood. For such an example, it seemed like creating a dedicated controller was a bit overkill, while not adhering strictly to MVC. I ended up making the custom view an outlet in the document, and setting a pointer to the document as an ivar in the view. During redraw, the view requests the list of objects from the NSDocument. When new objects are added, the view messages the document to add them to the collection. It looks like the line of code from Dave Carrigan could have solved it pretty easily as well, without requiring the NSDocument ivar. id doc = [[[self window] windowController] document] So yes, the document does end up acting as both the controller and model, but it works well enough for this simple application. Thanks to all for their input, it was helpful in both achieving the solution and increasing my understanding. -James ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Challenge 18 in Hillegass Book
On Sat, Aug 9, 2008 at 8:54 PM, James Gorham [EMAIL PROTECTED] wrote: I think that's where I'm unclear. Making the Document class aware of the view is easy enough with an IBOutlet. But how to properly make the view aware of the document I'm unsure of. You're missing the point. You don't connect your NSDocument (model) to your views, you have a controller in between. This controller is responsible for noticing/being notified when the document changes so it can update the view, and it is also responsible for noticing/being notified when the view changes so it can update the document. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Challenge 18 in Hillegass Book
On Aug 10, 2008, at 5:22 PM, Ashley Perrien wrote: But the question I think is still valid and one I'm I'm trying to figure out myself. How, for instance, would you have the view request data from the document (or any other object for that matter). id doc = [[[self window] windowController] document] -- Dave Carrigan [EMAIL PROTECTED] Seattle, WA, USA PGP.sig Description: This is a digitally signed message part ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Challenge 18 in Hillegass Book
But the question I think is still valid and one I'm I'm trying to figure out myself. How, for instance, would you have the view request data from the document (or any other object for that matter). I understand that it may not always be the best design choices but how is it done? Posting notifications is about the only way I can think of and perhaps sending self as the context info. Ashley Perrien How would you have a view request data from the documet ? - You could use a Data Source like NSTableView and let the document instance be the Data Source (connected via File's Owner). - You could use NSViewController instances like NSCollectionView and give each NSViewController a pointer to a document. - You could send a message up the responder chain on the usually valid assumption that the right document instance will be in the responder chain. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Challenge 18 in Hillegass Book
On Aug 8, 2008, at 6:40 PM, Graham Cox wrote: So there needs to be a connection between model, controller and view that allows you to communicate freely back and forth. For now you could just use the view as the model, unless you are really keen to explore MVC at this point rather than just complete the exercise. I think that's where I'm unclear. Making the Document class aware of the view is easy enough with an IBOutlet. But how to properly make the view aware of the document I'm unsure of. Thanks to all for the responses, they've been helpful! -J ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Challenge 18 in Hillegass Book
I stepped away from the book for a bit, and I'm now trying to work through the Challenge 18 of Hillegass's Cocoa book (3rd edition). The gist of the challenge is to create a document-based application allowing the user to draw ovals in arbitrary locations and size using NSBezierPath, as well as adding save and undo. My question is along the lines of the proper way to design the classes. I'll have a custom view class that will do the drawing, and the collection of ovals will be an iVar of the MyDocument class, so that I can support de/coding and undo. What's the best way to make the oval collection available for drawing from the document class to the custom view (and the reverse, to pass new ovals drawn by the user from the view to the document for storage). Thanks for the help. -James ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Challenge 18 in Hillegass Book
Hi James, I'd recommend looking at the AppKit Sketch example for architecture and Scott Stevenson's tutorial for using NSBezierPath: http://cocoadevcentral.com/d/intro_to_quartz_two/ HTH, Joel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Challenge 18 in Hillegass Book
On 9 Aug 2008, at 8:55 am, James G. wrote: My question is along the lines of the proper way to design the classes. I'll have a custom view class that will do the drawing, and the collection of ovals will be an iVar of the MyDocument class, so that I can support de/coding and undo. What's the best way to make the oval collection available for drawing from the document class to the custom view (and the reverse, to pass new ovals drawn by the user from the view to the document for storage). A couple of pointers that might be of help: [NSArray makeObjectsPerformSelector:]; If your objects are NSBezierPaths, you could do this to draw the lot: [myListOfPaths makeObjectsPerformSelector:@selector(fill)]; However bezier paths do not have information about colour or whether to stroke, fill or both, so you might wrap your paths in another object that adds those properties. That object might implement a method such as -draw which you can supply as the argument above. For undo, implement two methods - one to add an object to the list and one to remove it. Then in the add method you'd do something like: (typed into mail) - (void)addMyObject:(id) object { [[[self undoManager] prepareWithInvocationTarget:self] removeMyObject:object]; [myListOfPaths addObject:object]; [self setNeedsDisplay]; } and the remove method: - (void)removeMyObject:(id) object { [[[self undoManager] prepareWithInvocationTarget:self] addMyObject:object]; [myListOfPaths removeObject:object]; [self setNeedsDisplay]; } For simplicity these could be methods of your custom view class, but equally they could live in a controller or model class elsewhere - you'd then arrange to get the list from the model and draw it, or else have a draw method in the model that you call from the view. So there needs to be a connection between model, controller and view that allows you to communicate freely back and forth. For now you could just use the view as the model, unless you are really keen to explore MVC at this point rather than just complete the exercise. hth, Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]