Re: Unique copy/paste behavior based on tableview

Christiaan Hofman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Jan 1, 2010, at 8:35, earl.deshazer wrote:

> I'm trying to get an elegant/standard solution to a scenario that I suspect is common. I could easily cobble a solution together, but I hate re-inventing the wheel.
> 
> Overall, I am developing CoreData document-based application. In the copy/paste CoreData examples that I have seen:
> 
> http://developer.apple.com/mac/library/documentation/cocoa/conceptual/NSPersistentDocumentTutorial/05_CopyAndPaste/copyAndPaste.html#//apple_ref/doc/uid/TP40002833-SW1
> http://themikeswan.wordpress.com/2009/05/30/a-core-data-tutorial-part-2-polishing-the-basics/
> 
> the examples assume that a copy is only possible from the employeeTableController. The capability of duplicating a manager MO and/or an employe MO is ignored. I have a scenario, however, which would require the copy action to discern which tableView/MO was selected to determine which MO (and its associated data) to copy. The paste action would similarly need to be aware of what tableView was selected to determine the appropriate coarse of action.
> 
> My hammer approach would utilize the mousedown: for each tableView to populate variables that I would define inside of MyDocument that would then be used in the copy/paste methods. This would make the copy/paste methods generic. Is there another way to get the behavior I am looking for? Have I overlooked some basic NSWindow/NSView/NSResponder behavior/information.
> 
> Thanks in advance,
> 
> Will DeShazer

I think you have two options, I'm not sure which one would be more "standard", it also depends on your situation. Either inspect the window's first responder to see which table is selected. Or implement the -copy: action in an tableView subclass rather than your windowController/document. I am often doing the latter in a generic way using either tableView:writeRowsWithIndexes:toPasteboard: or a custom delegate method (depending on the requirements, because often drag and copy should do the same thing, but not always).

Christiaan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.