• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Copy/paste multiple table rows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy/paste multiple table rows


  • Subject: Re: Copy/paste multiple table rows
  • From: Greg Titus <email@hidden>
  • Date: Fri, 13 Sep 2002 09:11:35 -0700

On Friday, September 13, 2002, at 08:16 AM, Matthew Roberts wrote:
I have a document-based app; each doc's window chiefly consists of a table
of items. So far I can drag rows out of the table into other apps--no
problem. I also have it so that I can copy/paste rows into the table itself
(for duplicating items, moving them between documents, etc).

However, I can't figure out the way to copy and paste (or I guess drag)
multiple rows within the document. The table datasource is a mutablearray
of dictionaries (keyed by field name which translates into column
titles)--pretty standard.

When dragging stuff out of the table, I can drag multiple rows and the end
result is just what I want (the rows get passed through a format parser and
end up just as a single string of text on the drag pasteboard). Only one
thing gets put onto the pasteboard.

What's the best way to approach copy/paste/drag of items within the document
when I want to preserve the dictionary structure of the items? Is there
some way to "compress" the dictionaries (e.g. Via description accessor or by
coder) and then add the compressed info to the pasteboard just as one data
object? Or is there someway to queue up multiple objects (e.g.
Dictionaries) onto a pasteboard, determine how many there are, and then add
them back to the document?

Hi Matthew,

Pasteboards (for both copy/pasting and dragging) can accept any property list type (NSStrings, NSNumbers, NSArrays, NSDictionaries), which means that you can directly place an array onto the pasteboard if you want.

The usual way of doing this kind of thing is to declare 2 different types on the pasteboard when you drag or copy. One should be the formatted string that you are already using (so that you can still drag into other apps), but the second should be your own custom type. The types on NSPasteboard are just strings, so you can declare a "MyApp Custom Dictionaries" type, or whatever.

For the second type, use -setPropertyList:forType: on the NSPasteboard, and always use an array of dictionaries for that type (even if there is only a single row selected). When you paste or drop, look for that type first (make sure it is first in the list you pass to -availableTypeFromArray:), and if that type is available, call -propertyListForType:, and you'll get back the array of dictionaries.

This is a pretty standard pattern to use even if your original data objects aren't made up of dictionaries directly - in that case you just add an extra step to convert your data objects into dictionaries and then back again.

Hope this helps,
- Greg
_______________________________________________
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.

References: 
 >Copy/paste multiple table rows (From: Matthew Roberts <email@hidden>)

  • Prev by Date: Copy/paste multiple table rows
  • Next by Date: Re: [splitView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
  • Previous by thread: Copy/paste multiple table rows
  • Next by thread: Re: Copy/paste multiple table rows
  • Index(es):
    • Date
    • Thread