Which way should my document class handle an older format?

2017-03-04 Thread Daryle Walker
My document class reads in UTF-8 data for its internal format. The format has 
an older version that is ASCII-based. Since the latter is a subset of the 
former, my parser can handle both formats. Right now, I can’t write out in the 
older format. (The new format is just a text dump upon save. The old format 
would need to handle any post-ASCII values.)

I’m wondering how I should be the old format in the Info.plist. I could put it 
in as a second document type. This lets me set it as “Viewer” independently of 
the first format being set to “Editor.” Altering the message and trying to save 
gives a system error about the file not being able to be saved. However, the 
“isInViewMode” flag doesn’t get set, so the document is editable! (But the 
edits can’t be saved.)

The other way is to have one document type entry in the Info.plist, but put the 
old format as a second content type. Of course, it’ll always be in “Editor.” 
And the save sheet gets a pop-up menu for the format to be saved. I haven’t 
added an entry for exported-types in the p-list, so the menu is just the first 
type. The second type isn’t in the menu and if I try to duplicate the file (the 
new-world-order substitute for “Save As” since Lion), I get a can’t-be-saved 
error.

I guess the second scenario seems to be what I want, but it still seems ugly. 
Are there any better solutions?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

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: Attributed strings - and bounding rects

2017-03-04 Thread Jonathan Mitchell
> I’m still not out of the wood yet though.


Sorry. I should have provided more details.

What I do to support table cell view wrapping is this. However, I have to 
support back to 10.9 so it may be possible to use some of the newer auto 
NSTextField line wrapping stuff.

1. Create a nib containing a wrapping cell view and associate it with a column 
that we want to wrap the content of. View based tableviews use Auto Layout for 
interior layout but in IB it doesn’t generally add and constrains to the 
default table cell views. So make a BPWrappingTableCellView nib that contains 
an NSTextField configured to wrap and constrained to the width and height of 
the cell.

columnCellNib = [[NSNib alloc] initWithNibNamed:@"BPWrappingTableCellView" 
bundle:nil];
[self.tableView registerNib:columnCellNib forIdentifier:@"action”];

2. Now the height of a row in the tableview must equal the height of the 
tallest cell in the row. There is a NSTableViewDelegate call for this. IN this 
example I have only one column that I need to wrap. If you have more you will 
need to find out which column has the tallest content.

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
// calculate height of row based on height of cell view in variable height 
column
id obj = self.arrayController.arrangedObjects[row];
CGFloat height = [tableView bp_heightOfRowForString:obj.description 
variableHeightColumnIdentifier:@"action"];
return height;
}

3. Calculate height of cell using a worker cell. This is an NSTableView 
category method.

#pragma mark -
#pragma mark Row height support

- (CGFloat)bp_heightOfRowForString:(NSString *)text 
variableHeightColumnIdentifier:(NSString *)identifier
{
/*
 
 Calculate height of row to accomodate wrapping text field in the 
description column.
 On 10.11 it might be possible to just use the fields Automatic setting.
 
 
http://stackoverflow.com/questions/7504546/view-based-nstableview-with-rows-that-have-dynamic-heights
 
 */
// we use a layout worker cell for height calcs.
if (!self.layoutCellView) {
self.layoutCellView = [self makeViewWithIdentifier:identifier 
owner:nil];
}

// reset size
CGFloat width = [self tableColumnWithIdentifier:identifier].width;
[self.layoutCellView setFrameSize:NSMakeSize(width, 10)];

// set the cell text
self.layoutCellView.textField.stringValue = text;

// layout to calculate size
self.layoutCellView.textField.preferredMaxLayoutWidth = width - 
self.layoutCellView.textField.frame.origin.x - 10;
[self.layoutCellView layoutSubtreeIfNeeded];
CGFloat height = self.layoutCellView.frame.size.height;

if (height < 30) height = 30;
if (height > 150) height = 150;

return height;
}

4. Deal with column resizing:

- (void)tableViewColumnDidResize:(NSNotification *)aNotification
{
// notify table view of row height change if variable height column width 
changes
NSTableColumn *tableColumn = aNotification.userInfo[@"NSTableColumn"];
NSTableView *tableView = tableColumn.tableView;
[tableView bp_columnDidResize:tableColumn 
variableHeightColumnIdentifiers:@[@"action"]];
}

Another NSTableView category method.
- (void)bp_columnDidResize:(NSTableColumn *)tableColumn 
variableHeightColumnIdentifiers:(NSArray *)columnIds
{
/*
 
 Trigger row height recalculation when change table column width
 
 */
if (self.numberOfRows > 0 && [columnIds 
containsObject:tableColumn.identifier]) {
 NSIndexSet *rowIndexSet = [NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(0, self.numberOfRows)];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0];
[self noteHeightOfRowsWithIndexesChanged:rowIndexSet];
[NSAnimationContext endGrouping];
}
}

HTH

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

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

Re: Attributed strings - and bounding rects

2017-03-04 Thread Peter Hudson
Many thanks for this detailed help Jonathan.  
I’ll work my way through it !

Peter



> On 4 Mar 2017, at 09:54, Jonathan Mitchell  wrote:
> 
>> I’m still not out of the wood yet though.
> 
> 
> Sorry. I should have provided more details.
> 
> What I do to support table cell view wrapping is this. However, I have to 
> support back to 10.9 so it may be possible to use some of the newer auto 
> NSTextField line wrapping stuff.
> 
> 1. Create a nib containing a wrapping cell view and associate it with a 
> column that we want to wrap the content of. View based tableviews use Auto 
> Layout for interior layout but in IB it doesn’t generally add and constrains 
> to the default table cell views. So make a BPWrappingTableCellView nib that 
> contains an NSTextField configured to wrap and constrained to the width and 
> height of the cell.
> 
>columnCellNib = [[NSNib alloc] initWithNibNamed:@"BPWrappingTableCellView" 
> bundle:nil];
>[self.tableView registerNib:columnCellNib forIdentifier:@"action”];
> 
> 2. Now the height of a row in the tableview must equal the height of the 
> tallest cell in the row. There is a NSTableViewDelegate call for this. IN 
> this example I have only one column that I need to wrap. If you have more you 
> will need to find out which column has the tallest content.
> 
> - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
> {
>// calculate height of row based on height of cell view in variable height 
> column
>id obj = self.arrayController.arrangedObjects[row];
>CGFloat height = [tableView bp_heightOfRowForString:obj.description 
> variableHeightColumnIdentifier:@"action"];
>return height;
> }
> 
> 3. Calculate height of cell using a worker cell. This is an NSTableView 
> category method.
> 
> #pragma mark -
> #pragma mark Row height support
> 
> - (CGFloat)bp_heightOfRowForString:(NSString *)text 
> variableHeightColumnIdentifier:(NSString *)identifier
> {
>/*
> 
> Calculate height of row to accomodate wrapping text field in the 
> description column.
> On 10.11 it might be possible to just use the fields Automatic setting.
> 
> 
> http://stackoverflow.com/questions/7504546/view-based-nstableview-with-rows-that-have-dynamic-heights
> 
> */
>// we use a layout worker cell for height calcs.
>if (!self.layoutCellView) {
>self.layoutCellView = [self makeViewWithIdentifier:identifier 
> owner:nil];
>}
> 
>// reset size
>CGFloat width = [self tableColumnWithIdentifier:identifier].width;
>[self.layoutCellView setFrameSize:NSMakeSize(width, 10)];
> 
>// set the cell text
>self.layoutCellView.textField.stringValue = text;
> 
>// layout to calculate size
>self.layoutCellView.textField.preferredMaxLayoutWidth = width - 
> self.layoutCellView.textField.frame.origin.x - 10;
>[self.layoutCellView layoutSubtreeIfNeeded];
>CGFloat height = self.layoutCellView.frame.size.height;
> 
>if (height < 30) height = 30;
>if (height > 150) height = 150;
> 
>return height;
> }
> 
> 4. Deal with column resizing:
> 
> - (void)tableViewColumnDidResize:(NSNotification *)aNotification
> {
>// notify table view of row height change if variable height column width 
> changes
>NSTableColumn *tableColumn = aNotification.userInfo[@"NSTableColumn"];
>NSTableView *tableView = tableColumn.tableView;
>[tableView bp_columnDidResize:tableColumn 
> variableHeightColumnIdentifiers:@[@"action"]];
> }
> 
> Another NSTableView category method.
> - (void)bp_columnDidResize:(NSTableColumn *)tableColumn 
> variableHeightColumnIdentifiers:(NSArray *)columnIds
> {
>/*
> 
> Trigger row height recalculation when change table column width
> 
> */
>if (self.numberOfRows > 0 && [columnIds 
> containsObject:tableColumn.identifier]) {
> NSIndexSet *rowIndexSet = [NSIndexSet 
> indexSetWithIndexesInRange:NSMakeRange(0, self.numberOfRows)];
>[NSAnimationContext beginGrouping];
>[[NSAnimationContext currentContext] setDuration:0];
>[self noteHeightOfRowsWithIndexesChanged:rowIndexSet];
>[NSAnimationContext endGrouping];
>}
> }
> 
> HTH
> 
> 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Attributed strings - and bounding rects

2017-03-04 Thread Steve Mills
> On Mar 4, 2017, at 04:20, Peter Hudson  wrote:
> 
> Many thanks for this detailed help Jonathan.  
> I’ll work my way through it !

Don't forget to cache the row heights and reset when the table says to. That 
makes a huge difference as the number of cells grows.

Steve via iPad


___

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: Adding a watchOS complication to an existing project?

2017-03-04 Thread Saagar Jha
I remember doing this around a year ago, but IIRC there wasn’t an easy way to 
do this. I think I created a new extension with a complication and copy/pasted 
stuff from the new target.

Saagar Jha

> On Mar 3, 2017, at 07:08, Eric E. Dolecki  wrote:
> 
> Everything I've seen shows adding the complication on project creation. How
> does one go about adding it to a project later on? I have my watch app
> right where I want it, but I didn't think I would need a complication.
> Until today.
> 
> Thanks!
> ___
> 
> 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/saagar%40saagarjha.com
> 
> This email sent to saa...@saagarjha.com

___

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