Re: Copy and Paste of rows in a NSTableView
Re: Copy and Paste of rows in a NSTableView
- Subject: Re: Copy and Paste of rows in a NSTableView
- From: Luke Adamson <email@hidden>
- Date: Mon, 11 Jun 2001 23:46:33 -0700
On Monday, June 11, 2001, at 06:55 AM, Stiphane Sudre wrote:
I have a NSTableView and want to be able to copy/paste data relating
the lines selected.
You do this by implementing copy:/paste: in your controller and then
using the result of [[self window] firstResponder] (or similar) to
determine which view to copy from/paste into (assuming the
firstResponder doesn't implement copy:/paste: directly, as NSTextView
does).
Rough pseudocode:
- (void)copy:(id)sender;
{
NSResponder *firstResponder;
firstResponder = [[self window] firstResponder];
if (firstResponder == myTableViewOfSongs) {
[songs addObjectsFromArray:[MySongClass
songsFromPasteboard:[NSPasteboard generalPasteboard]];
[songsTableView reloadData];
} else if (firstResponder == myTableViewOfArtists) {
[artists addObjectsFromArray:[MySongClass
songsFromPasteboard:[NSPasteboard generalPasteboard]];
[artistsTableView reloadData];
} else {
// Validation should probably prevent this case, but if it
happens...
NSBeep();
}
}
I've finally found a solution using the First Responder but is there
not a solution using the delegate of the NSTableView ?
Using the firstResponder is the "correct" mechanism for doing this. The
object which will respond to the copy:/paste: method will very likely be
the delegate (and data source) of the NSTableView (unless you're working
with a contrived, or complex case). But, it will be in the responder
chain because it will also be the delegate of the window which
"contains" the table view (the main window's delegate is in the
responder chain by definition).
Have fun!
---
Luke
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev