Re: Deconstructing Text Tables

2014-11-20 Thread Charles Jenkins
Thank you, Ken. It took some research and experimentation before I could 
understand your explanation, but it looks like that’s exactly what I needed.  

—

Charles Jenkins


On Tuesday, November 18, 2014 at 3:43 PM, Ken Thomases wrote:

 On Nov 18, 2014, at 6:38 AM, Charles Jenkins cejw...@gmail.com 
 (mailto:cejw...@gmail.com) wrote:
  
  It’s very easy to create an NSAttributedString that represents a text 
  table, then show the table in a TextView so the user can edit information 
  in the cells. The documentation on how to create a text table 
  (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextLayout/Articles/TextTables.html)
   is fairly clear.  
   
  What I don’t see—and maybe it’s there but I just don’t understand it—is how 
  to pull the table apart again. Suppose I want to grab all text from the 
  first cell after the user has edited it. How do I do that?
  
 You would presumably enumerate the attributed string's ranges for the 
 NSParagraphStyleAttributeName attribute, using 
 -enumerateAttribute:inRange:options:usingBlock:. For each paragraph style 
 object, you would check its textBlocks property to determine which cell the 
 range is part of.
  
 You're presumably either dealing with just a one-level table or the top-level 
 table, so you would be interested in the firstObject of the textBlocks array. 
 After verifying that it's an NSTextTableBlock, you'd check its table, 
 startingRow, rowSpan, startingColumn, and columnSpan to determine which cell 
 it's a part of. If you're interested in the entire contents of the first 
 cell, you'll need to accumulate the ranges that are part of it, since they 
 won't necessarily all be part of a single range as enumerated.
  
 Regards,
 Ken
  
  


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Deconstructing Text Tables

2014-11-18 Thread Keary Suska
On Nov 18, 2014, at 2:38 AM, Charles Jenkins cejw...@gmail.com wrote:

 It’s very easy to create an NSAttributedString that represents a text table, 
 then show the table in a TextView so the user can edit information in the 
 cells. The documentation on how to create a text table 
 (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextLayout/Articles/TextTables.html)
  is fairly clear.  
 
 What I don’t see—and maybe it’s there but I just don’t understand it—is how 
 to pull the table apart again. Suppose I want to grab all text from the first 
 cell after the user has edited it. How do I do that?

-rangeOfTextBlock:atIndex: might be your best bet. The hard part is finding 
exactly where you are interested in. If you are only interested in where a 
user has edited, a delegate method may get you there, otherwise, I don't know. 
You may need to keep meta-data about constructed tables.

HTH,

Keary Suska
Esoteritech, Inc.



___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Deconstructing Text Tables

2014-11-18 Thread Charles Jenkins
Keary,

Thanks for responding. :-)

Your answer is what I was afraid of…

If “index” only applies to characters, and therefore index 0 is the position of 
the first visible character in the TextView’s NSAttributedString, I could 
iterate through, finding the range of each cell’s characters, then jumping to 
the next index after that and asking again.

That should work, but what the heck would I pass as the textBlock pointer? 
Since a text block is exactly what I’m trying to find, I don’t have a good 
pointer to start with, do I?

—  

Charles Jenkins


On Tuesday, November 18, 2014 at 12:50, Keary Suska wrote:

 On Nov 18, 2014, at 2:38 AM, Charles Jenkins cejw...@gmail.com 
 (mailto:cejw...@gmail.com) wrote:
  
  It’s very easy to create an NSAttributedString that represents a text 
  table, then show the table in a TextView so the user can edit information 
  in the cells. The documentation on how to create a text table 
  (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextLayout/Articles/TextTables.html)
   is fairly clear.  
   
  What I don’t see—and maybe it’s there but I just don’t understand it—is how 
  to pull the table apart again. Suppose I want to grab all text from the 
  first cell after the user has edited it. How do I do that?
  
 -rangeOfTextBlock:atIndex: might be your best bet. The hard part is finding 
 exactly where you are interested in. If you are only interested in where a 
 user has edited, a delegate method may get you there, otherwise, I don't 
 know. You may need to keep meta-data about constructed tables.
  
 HTH,
  
 Keary Suska
 Esoteritech, Inc.
  
  


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Deconstructing Text Tables

2014-11-18 Thread Ken Thomases
On Nov 18, 2014, at 6:38 AM, Charles Jenkins cejw...@gmail.com wrote:

 It’s very easy to create an NSAttributedString that represents a text table, 
 then show the table in a TextView so the user can edit information in the 
 cells. The documentation on how to create a text table 
 (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextLayout/Articles/TextTables.html)
  is fairly clear.  
 
 What I don’t see—and maybe it’s there but I just don’t understand it—is how 
 to pull the table apart again. Suppose I want to grab all text from the first 
 cell after the user has edited it. How do I do that?

You would presumably enumerate the attributed string's ranges for the 
NSParagraphStyleAttributeName attribute, using 
-enumerateAttribute:inRange:options:usingBlock:.  For each paragraph style 
object, you would check its textBlocks property to determine which cell the 
range is part of.

You're presumably either dealing with just a one-level table or the top-level 
table, so you would be interested in the firstObject of the textBlocks array.  
After verifying that it's an NSTextTableBlock, you'd check its table, 
startingRow, rowSpan, startingColumn, and columnSpan to determine which cell 
it's a part of.  If you're interested in the entire contents of the first cell, 
you'll need to accumulate the ranges that are part of it, since they won't 
necessarily all be part of a single range as enumerated.

Regards,
Ken


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com