NSTableView dragging source image

2023-03-21 Thread Dragan Milić via Cocoa-dev
Hi all,

I have a simple problem, but I’m not able to solve it in an easy way, so I 
suspect I’m doing something wrong.

I have a simple view-based NSTableView, which is a dragging source. The data 
being dragged are provided to the pasteboard using the standard data source 
method - [NSObject tableView:writeRowsWithIndexes:toPasteboard:]. When rows of 
the table view are dragged, AppKit automatically creates a dragging image 
consisting of the visual copy for all dragged rows and all columns of the table 
view. If I want only particular columns, I can override -[NSTableView 
dragImageForRowsWithIndexes:tableColumns:event:offset:] and include only the 
columns I want in the dragged image.

Since [NSObject tableView:writeRowsWithIndexes:toPasteboard:] is rendered 
deprecated as of macOS 11, I want to use the alternative (which also supports 
multiple item dragging) -[NSObject tableView:pasteboardWriterForRow:]. However, 
when I use this method, AppKit creates a dragging image consisting of the 
visual copy for all dragged rows, BUT ONLY the column where the drag started. 
Overriding -[NSTableView 
dragImageForRowsWithIndexes:tableColumns:event:offset:] has no effect, as in 
this case that method isn’t being called at all.

So the question is, how do I influence the dragging image creation in the 
latter case? I haven’t found in docs anything related to that (except for the 
method mentioned above, but not being called in this case). Implementing data 
source method -[NSObject tableView:updateDraggingItemsForDrag:] doesn’t help, 
as it’s really intended to change the dragging image after the dragging has 
started and at the time it’s called for the first time, the AppKit created 
image is already there and visible.

Thanks a lot for any solution, hint or a suggestion.
-- Dragan
___

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: NSTableView

2019-04-21 Thread Arved von Brasch
Yeah, it was obvious that writeRowsWith: would soon be deprecated. After going 
through the documentation a bit, I did it via:

func tableView(_ tableView: NSTableView, draggingSession session: 
NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: 
IndexSet) {
session.enumerateDraggingItems(options: .concurrent,
   for: 
nil,
   
classes: [NSPasteboardItem.self],
   
searchOptions: [:],
   
using: { (draggingItem, index, stop) in


// Generate Image

let canvas = NSImage.init(size: canvasSize)


draggingItem.setDraggingFrame(NSMakeRect(session.draggingLocation.x, 
session.draggingLocation.y, canvas.size.width, canvas.size.height), contents: 
canvas)
})
}

> On 21 Apr 2019, at 19:03, Alex Zavatone  wrote:
> 
> What is the alternative, then?
> 
> If single image drags will not work because of this, is there a means to 
> impersonate another method?
> 
> Oh, and greets from the coast of Africa.  Cheers,
> Alex Zavatone
> 
> Sent from my iPhone
> 
>> On Apr 20, 2019, at 10:17 AM, Rob Petrovec  wrote:
>> 
>> Because dragImage is the old (and likely soon to be deprecated), single 
>> image style drag setup and the pasteboardWriter version is the modern 
>> multi-image drag set up.  Ever notice how when you drag a file around in the 
>> Finder the drag image will morph as the drag moves between windows with 
>> different view styles etc?  Or how the drag images change positions relative 
>> to the mouse as you drag multiple files around.  That is the multi-image 
>> drag setup.  Single image drags can’t do that.
>> 
>> —Rob
>> 
>> 
>>> On Apr 20, 2019, at 12:14 AM, Arved von Brasch  wrote:
>>> 
>>> Hello list,
>>> 
>>> Anyone know if it is intentionally the case that NSTableView doesn’t call
>>> 
>>> dragImageForRows(with dragRows: IndexSet, tableColumns: [NSTableColumn], 
>>> event dragEvent: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage
>>> 
>>> if you implement
>>> 
>>> func tableView(NSTableView, pasteboardWriterForRow: Int) -> 
>>> NSPasteboardWriting?
>>> 
>>> instead of
>>> 
>>> func tableView(NSTableView, writeRowsWith: IndexSet, to: NSPasteboard) -> 
>>> Bool
>>> 
>>> I can’t see a reason for it not to in the documentation, but it doesn’t in 
>>> my code.
>>> 
>>> Kind regards,
>>> Arved
>>> ___
>>> 
>>> 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/petrock%40mac.com
>>> 
>>> This email sent to petr...@mac.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/zav%40mac.com
>> 
>> This email sent to z...@mac.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: NSTableView

2019-04-21 Thread Alex Zavatone
What is the alternative, then?

If single image drags will not work because of this, is there a means to 
impersonate another method?

Oh, and greets from the coast of Africa.  Cheers,
Alex Zavatone

Sent from my iPhone

> On Apr 20, 2019, at 10:17 AM, Rob Petrovec  wrote:
> 
> Because dragImage is the old (and likely soon to be deprecated), single image 
> style drag setup and the pasteboardWriter version is the modern multi-image 
> drag set up.  Ever notice how when you drag a file around in the Finder the 
> drag image will morph as the drag moves between windows with different view 
> styles etc?  Or how the drag images change positions relative to the mouse as 
> you drag multiple files around.  That is the multi-image drag setup.  Single 
> image drags can’t do that.
> 
> —Rob
> 
> 
>> On Apr 20, 2019, at 12:14 AM, Arved von Brasch  wrote:
>> 
>> Hello list,
>> 
>> Anyone know if it is intentionally the case that NSTableView doesn’t call
>> 
>> dragImageForRows(with dragRows: IndexSet, tableColumns: [NSTableColumn], 
>> event dragEvent: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage
>> 
>> if you implement
>> 
>> func tableView(NSTableView, pasteboardWriterForRow: Int) -> 
>> NSPasteboardWriting?
>> 
>> instead of
>> 
>> func tableView(NSTableView, writeRowsWith: IndexSet, to: NSPasteboard) -> 
>> Bool
>> 
>> I can’t see a reason for it not to in the documentation, but it doesn’t in 
>> my code.
>> 
>> Kind regards,
>> Arved
>> ___
>> 
>> 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/petrock%40mac.com
>> 
>> This email sent to petr...@mac.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/zav%40mac.com
> 
> This email sent to z...@mac.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: NSTableView

2019-04-20 Thread Rob Petrovec
Because dragImage is the old (and likely soon to be deprecated), single image 
style drag setup and the pasteboardWriter version is the modern multi-image 
drag set up.  Ever notice how when you drag a file around in the Finder the 
drag image will morph as the drag moves between windows with different view 
styles etc?  Or how the drag images change positions relative to the mouse as 
you drag multiple files around.  That is the multi-image drag setup.  Single 
image drags can’t do that.

—Rob


> On Apr 20, 2019, at 12:14 AM, Arved von Brasch  wrote:
> 
> Hello list,
> 
> Anyone know if it is intentionally the case that NSTableView doesn’t call
> 
> dragImageForRows(with dragRows: IndexSet, tableColumns: [NSTableColumn], 
> event dragEvent: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage
> 
> if you implement
> 
> func tableView(NSTableView, pasteboardWriterForRow: Int) -> 
> NSPasteboardWriting?
> 
> instead of
> 
> func tableView(NSTableView, writeRowsWith: IndexSet, to: NSPasteboard) -> Bool
> 
> I can’t see a reason for it not to in the documentation, but it doesn’t in my 
> code.
> 
> Kind regards,
> Arved
> ___
> 
> 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/petrock%40mac.com
> 
> This email sent to petr...@mac.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


NSTableView

2019-04-20 Thread Arved von Brasch
Hello list,

Anyone know if it is intentionally the case that NSTableView doesn’t call

dragImageForRows(with dragRows: IndexSet, tableColumns: [NSTableColumn], event 
dragEvent: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage

if you implement

func tableView(NSTableView, pasteboardWriterForRow: Int) -> NSPasteboardWriting?

instead of

func tableView(NSTableView, writeRowsWith: IndexSet, to: NSPasteboard) -> Bool

I can’t see a reason for it not to in the documentation, but it doesn’t in my 
code.

Kind regards,
Arved
___

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


Tool tips for column headers of NSTableView not showing

2019-03-29 Thread James Walker
I have a view-based NSTableView with column headers, and I have assigned 
tool tips to all the columns in the nib.  The problem is that if I pause 
the mouse over column headers, the tool tips don't appear.  In contrast, 
tool tips for controls within table rows work fine.  However, if I click 
one of the columns headers, then the tool tips for all the column 
headers start working.  Or, if I just activate some other app and then 
go back to mine, the tool tips start working.  These clues made me 
suspect that it had something to do with window activation or first 
responder, but I checked that in the problematic case, the table is 
first responder and its window is main.


This is on High Sierra, if it matters.
___

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: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Saagar Jha
Yup, this declares ImportTool (a subclass of NSObject) with the lightweight 
generic parameters X, Y, and Z. Here 

 are some examples and how they map to Swift, which makes the exact declaration 
syntax a bit more clear.

Regards,
Saagar Jha

> On Mar 28, 2019, at 18:49, Andy Lee  wrote:
> 
> The compiler may accept it, but it doesn't interpret it the way you think.  
> You can confirm by checking whether your class formally conforms to the 
> protocols.  Try this with your old code and your new code, and compare:
> 
> NSLog(@"conforms to protocol? %d", [ImportTool 
> conformsToProtocol:@protocol(NSTableViewDataSource)]);
> 
> I think Quincey is right, what you really did is declare a generic type.  
> It's a subtle mistake.  Notice that this also compiles:
> 
> @interface  ImportTool  : NSObject
> @end
> 
> --Andy
> 
> On Mar 28, 2019, at 7:44 PM, Peter Hudson  > wrote:
>> 
>> Very strange - the compiler is quite happy with my waywardness. 
>> Peter
>> 
>>> On 28 Mar 2019, at 23:39, Quincey Morris 
>>>  wrote:
>>> 
 On Mar 28, 2019, at 15:58 , Peter Hudson  wrote:
 
 @interface  ImportTool >>> NSEncoding> : NSObject
>>> 
>>> You’re Doing It Wrong™. You mean:
>>> 
 @interface  ImportTool : NSObject >>> NSTableViewDelegate, NSEncoding>
>>> 
>>> 
>>> I don’t know what it means the way you wrote it. Something about 
>>> lightweight generic syntax, perhaps?
>> 
>> ___
>> 
>> 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/aglee%40mac.com 
>> 
>> 
>> This email sent to ag...@mac.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/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


Re: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Andy Lee
The compiler may accept it, but it doesn't interpret it the way you think.  You 
can confirm by checking whether your class formally conforms to the protocols.  
Try this with your old code and your new code, and compare:

NSLog(@"conforms to protocol? %d", [ImportTool 
conformsToProtocol:@protocol(NSTableViewDataSource)]);

I think Quincey is right, what you really did is declare a generic type.  It's 
a subtle mistake.  Notice that this also compiles:

@interface  ImportTool  : NSObject
@end

--Andy

On Mar 28, 2019, at 7:44 PM, Peter Hudson  wrote:
> 
> Very strange - the compiler is quite happy with my waywardness. 
> Peter
> 
>> On 28 Mar 2019, at 23:39, Quincey Morris 
>>  wrote:
>> 
>>> On Mar 28, 2019, at 15:58 , Peter Hudson  wrote:
>>> 
>>> @interface  ImportTool >> NSEncoding> : NSObject
>> 
>> You’re Doing It Wrong™. You mean:
>> 
>>> @interface  ImportTool : NSObject >> NSTableViewDelegate, NSEncoding>
>> 
>> 
>> I don’t know what it means the way you wrote it. Something about lightweight 
>> generic syntax, perhaps?
> 
> ___
> 
> 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/aglee%40mac.com
> 
> This email sent to ag...@mac.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: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Peter Hudson
Very strange - the compiler is quite happy with my waywardness. 
Peter

> On 28 Mar 2019, at 23:39, Quincey Morris 
>  wrote:
> 
>> On Mar 28, 2019, at 15:58 , Peter Hudson  wrote:
>> 
>> @interface  ImportTool > NSEncoding> : NSObject
> 
> You’re Doing It Wrong™. You mean:
> 
>> @interface  ImportTool : NSObject > NSTableViewDelegate, NSEncoding>
> 
> 
> I don’t know what it means the way you wrote it. Something about lightweight 
> generic syntax, perhaps?

___

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: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Rob Petrovec
Yes, this.

—Rob


> On Mar 28, 2019, at 5:39 PM, Quincey Morris 
>  wrote:
> 
> On Mar 28, 2019, at 15:58 , Peter Hudson  wrote:
>> 
>> @interface  ImportTool > NSEncoding> : NSObject
> 
> You’re Doing It Wrong™. You mean:
> 
>> @interface  ImportTool : NSObject > NSTableViewDelegate, NSEncoding>
> 
> 
> I don’t know what it means the way you wrote it. Something about lightweight 
> generic syntax, perhaps? 
> ___
> 
> 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/petrock%40mac.com
> 
> This email sent to petr...@mac.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: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Quincey Morris
On Mar 28, 2019, at 15:58 , Peter Hudson  wrote:
> 
> @interface  ImportTool  NSEncoding> : NSObject

You’re Doing It Wrong™. You mean:

> @interface  ImportTool : NSObject  NSTableViewDelegate, NSEncoding>


I don’t know what it means the way you wrote it. Something about lightweight 
generic syntax, perhaps?   
___

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: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Peter Hudson
Hi Alex

After some thought i cast the object in question to (id) and the compiler was 
happy, and the program runs. 

Guess i need to read up on this aspect of the language. 

Peter

> On 28 Mar 2019, at 23:29, Alex Zavatone  wrote:
> 
> Not sure if this is a right answer, but what happens if you weakify the 
> instance?
> 
> Also, I suspect this is for MacOS, not iOS?
> 
> What happens if you try to recreate this in a simple case in a fresh project?
> 
> Alex Zavatone
> 
> Sent from my iPhone
> 
>> On Mar 28, 2019, at 5:58 PM, Peter Hudson  wrote:
>> 
>> Hi there
>> 
>> The class I am trying to use as a datasource and delegate to an NSTableView 
>> adopts the required protocols and implements the required methods  :- 
>> 
>> @interface  ImportTool > NSEncoding> : NSObject
>> 
>> etc …
>> 
>> 
>> But when I try to assign an instance of ImportScript as datasource and 
>> delegate to the table view in question I get the following warning :-
>> 
>> Assigning to 'id _Nullable' from incompatible type 
>> 'ImportTool *__strong’
>> 
>> 
>> Any suggestions gratefully received !
>> 
>> Peter
>> ___
>> 
>> 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/zav%40mac.com
>> 
>> This email sent to z...@mac.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: Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Alex Zavatone
Not sure if this is a right answer, but what happens if you weakify the 
instance?

Also, I suspect this is for MacOS, not iOS?

What happens if you try to recreate this in a simple case in a fresh project?

Alex Zavatone

Sent from my iPhone

> On Mar 28, 2019, at 5:58 PM, Peter Hudson  wrote:
> 
> Hi there
> 
> The class I am trying to use as a datasource and delegate to an NSTableView 
> adopts the required protocols and implements the required methods  :- 
> 
> @interface  ImportTool  NSEncoding> : NSObject
> 
> etc …
> 
> 
> But when I try to assign an instance of ImportScript as datasource and 
> delegate to the table view in question I get the following warning :-
> 
> Assigning to 'id _Nullable' from incompatible type 
> 'ImportTool *__strong’
> 
> 
> Any suggestions gratefully received !
> 
> Peter
> ___
> 
> 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/zav%40mac.com
> 
> This email sent to z...@mac.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


Trouble assigning datasource and delegate to an instance of NSTableView

2019-03-28 Thread Peter Hudson
Hi there

The class I am trying to use as a datasource and delegate to an NSTableView 
adopts the required protocols and implements the required methods  :- 

@interface  ImportTool  
: NSObject

etc …


But when I try to assign an instance of ImportScript as datasource and delegate 
to the table view in question I get the following warning :-

Assigning to 'id _Nullable' from incompatible type 
'ImportTool *__strong’


Any suggestions gratefully received !

Peter
___

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: Popup-Menu Binding issue in Cell-based NSTableView

2018-01-04 Thread Keary Suska
> On Jan 4, 2018, at 12:27 AM, Motti Shneor  wrote:
> 
>>> If I last elect to add such out-of-table popup - can you think of a decent 
>>> way to disable opening those in-table popup button cells when more than one 
>>> line is selected?  
>> 
>> If you choose this route I think a better UI is to change the in-table popup 
>> bindings to apply to only the specific row. I wouldn’t disable the popup in 
>> this case as it will always behave as expected, and disabling would seem to 
>> be an odd UI to me.
> 
> But it is very confusing. You select 5 lines, then press the popup and it 
> opens. Then you select some new “Species” option. Mac UI rule is “Action is 
> always applied to current selection”.

It is just my little quibble, and worth the grain of salt that it is, but I 
would say that behavior is not typical in a table, where the controls in a row 
are expected to act on that row only. For instance, if the control was a 
checkbox or radio button, would you expect it to effect every selected row, or 
the row with the control? A popup menu is just a larger arbitrary set of 
options, but essentially serves the same purpose as those controls. Now, if it 
was a “command” type, i.e. that it didn’t show a value but allowed a user to 
select an action, by all means it should effect the selection. But being in 
every row would then seem odd ;-) Anyway,  I wouldn’t say it is necessarily a 
bad UI, and as long as you have also implemented robust undo it would be 
probably be OK for most people. 

> However - when I uncheck the same thing on the same binding on the 
> NSTableColumn / NSPopupButtonCell — nothing happens!!! this is mighty weird 
> for me. 

You mean it doesn’t disable on multiple selection? At any rate there are 
clearly some oddities with in-table bindings.

> I remember you wrote “Table editing mechanism is interfering” - but how? and 
> how can I affect it? 

I might be talking out of my hat but I think that what might be happening is 
that the table knows you clicked in a row but is letting the popup handle it 
(because the control need to to operate properly) but on mouse-up the table 
decides to handle the click by changing its selection to to clicked-in row. You 
can verify this by implementing -tableViewSelectionDidChange: (as delegate or 
just observe notification) and checking the model value to see whether it had 
changed. If it hadn’t, it means that the tableview is changing the selection 
before bindings can apply its change.

If this turns out to be the case, one possible workaround is to cache the 
selection and apply the change to all previously selected items and re-select. 
Since you only want to do this when changing the “species” value you can use 
KVO to detect a change. 


> Here I have some success — I was able to implement the NSMenuValidation 
> protocol, and Identify both popup button’s menu-items, using their TAG. When 
> binding the “Content” and “Content Values” of those popups, you can specify 
> “Content Placement Tag” (an integer)  and then you can tag a template 
> menu-item in the .xib with the same number, and it will be replaced by the 
> content.
> 
> Now when content binding replaces the single template menuItem with all those 
> entities - ALL OF THEM carry that tag!!! so here’s how I could do it last.
> 
> My validation is… well…. VERY complicated in this case, and I was able to 
> write only part of it now, to the point where 
> 1. Invalid items get disabled.
> 2. Invalid item titles are modified to include the REASON for invalidation 
> (hard to explain - scientific software)
> 2. Invalid items get HIDDEN — unless the “Option” key is pressed. 
> 
> This is beautiful - same validation applies to both Popup outside the table 
> and in the table. 
> 
> Still it maddens me - the popup OUTSIDE the table behaves very strangely on 
> the display. Sometimes it will “honor” the option key, sometimes not. Every 
> time I press that popup button the whole window resizes and the popup becomes 
> bigger and bigger, although it doesn’t display anything very long. Maybe some 
> auto layout issue, I don’t know - but still this is strange.

Can’t say, but if your assumption on autolayout is correct, it should only 
resize based on the content, so it shouldn’t always go up, it should also go 
down when the content is shorter.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

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: Popup-Menu Binding issue in Cell-based NSTableView

2018-01-02 Thread Keary Suska
ou are hitting an edge case of 
the bindings implementation or that they aren’t designed to work the way you 
want. I don’t think there is a way around that—I think the only solutions will 
likely be outside of the bindings system itself.

>>> When the content of a popup-button-cell is populated by binding - Can I 
>>> still apply NSMenu Validation protocol to that menu, and 
>>> Filter/Enable/Disable menu items as user clicks to open the menu?
>> 
>> I would say, generally, no, as you either have to set the delegate of the 
>> menu or action of each item. The former you might be able to do with a table 
>> delegate method, but you may not be able to do the latter depending on when 
>> bindings populates the popup.
> 
> Well - this I was able to do now - but with one strange behavior. I added the 
> -(BOOL) validateMenuItem:(NSMenuItem *)menuItem to my Window controller, and 
> it IS called for each and every item in the popup buttons - both in the 
> NSTableView and outside it. The problem is - how to identify these items in 
> the method. For other menus in my app - I use tags. but these popup-button 
> menus are populated by binding in runtime. I tried to identify them using 
> IBOutlet - pointers to the menus in the .xib, but strangely - the in-table 
> menu in runtime is not the same as the one in the IBOutlet. It looks like the 
> NSPopupButtonCell is duplicating the original menu, and populates the copy. 

Interesting on menu validation, though I would expect what you are seeing and I 
agree with your conclusions. Every popup cell in a table column must be a 
different object. Did you check to see whether the -representedObject of the 
NSMenuItem is being set? I don’t recall whether bindings does this, but if it 
does, you can use its unique ID (if you have a developer-specified ID) or have 
the tag be a property on the entity. If you can know that the menu title is 
always unique you can always test on that.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

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: Popup-Menu Binding issue in Cell-based NSTableView

2018-01-01 Thread Quincey Morris
On Jan 1, 2018, at 01:46 , Motti Shneor  wrote:
> 
> Selected Object  bound to Measurements Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: species, Allows Editing Multiple Values 
> Selection, Conditionally Sets Enabled, Creates Sort Descriptor

Your functional problem is here. You need to bind “Selected Object” to a 
*single* object, but you’ve bound it to the array of measurements. If you only 
have one row selected, it sort of works because bindings “deliberately” 
conflates an object with an array of one object or an array of the same object 
repeatedly, because … bindings. As soon as you have multiple rows selected, the 
functionality goes south.

Secondarily, your intention seems to be that choosing the popup in *one* of the 
selected rows should change the species in *all* of the selected rows. You 
can’t (or, probably can’t, though there might be a trick that does it) use a 
per-row control like this, and you’ll have to write code to transfer the 
per-row choice to all the other selected rows. The correct UI for this is to 
use a detail view — IOW, put the popup button outside the table, and have that 
single button reflect the species of the selected row, or of the selected rows. 
In that case, you might be able to get the desired functionality by binding 
“Selected Object” the Measurement Array Controller’s “selection” or 
“selectedObjects” controller key.

> When the content of a popup-button-cell is populated by binding - Can I still 
> apply NSMenu Validation protocol to that menu, and Filter/Enable/Disable menu 
> items as user clicks to open the menu?
> When the editing is done via the “Selected Object” binding - can I still 
> somehow intervene and “Catch” the change in code before it happens?

You can use KVC’s validation protocol (validate) with bindings, but you’re 
limited in what you can change.

But, how you proceed with this depends on whether you really want one menu 
choice to change all selected rows or just one row.

___

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: Popup-Menu Binding issue in Cell-based NSTableView

2018-01-01 Thread Keary Suska
> On Jan 1, 2018, at 2:46 AM, Motti Shneor <motti.shn...@me.com> wrote:
> 
> Hello everyone. Please excuse the anachronism, I am maintaining an old Mac 
> Application written early 2014 when Swift was not an option.  Pure Obj-C, 
> CoreData, and “No-custom-UI” approach.
> 
> I have an NSCell based NSTableView, whose columns are bound to an 
> NSArrayController, whose Content-Array in turn is bound to some CoreData 
> to-many relation - thus the table shows all the related entities.
> 
> Say we have a “WaterSample” entity, and the to-many relation is called 
> “measurements” and each Measurement has length, width, depth, colony-size and 
> species properties - each bound to one of the NSTableColumns. So far - the 
> very basic and stranded use of binding.
> 
> Of the Measurement properties - the species - is yet another to-one relation 
> to the  “Species” table. To allow the user to edit/change the species of a 
> Measurement (line in the table) I have placed a Popup Button Cell in the 
> “Species” column, and bound it like this:
> 
> Content  bound to Species Array Controller, Controller Key: arrangedObjects, 
> Content Placement Tag: 0
> Content Values  bound to Species Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: codeAndName, Content Placement Tag: 0,  
> Multiple Values Placeholder: Multiple Species
> Selected Object  bound to Measurements Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: species, Allows Editing Multiple Values 
> Selection, Conditionally Sets Enabled, Creates Sort Descriptor
> 
> Now it SEEMS to KIND-OF work, (I see the species codes and names, user can 
> click the popup button on each row to see and select from all our Species, 
> and even change the species to another one.
> 
> But I have these issues:
> 
> 1. When I select several Measurement rows of the table — All with the same 
> Species— and click the popup button on any row - it shows “Multiple Species” 
> as the selected value - although all rows have the same species selected.

My understanding (which could be wrong) is that this would be expected 
behavior. I.e., NSArrayController is agnostic about the actual values so either 
displays the single value or the placeholder if multiple values are selected, 
regardless of whether they are the same. I don’t think there is a non-hacky way 
to accomplish what you want, but you can play around with the 
contentArrayForMultipleSelection binding to see if you can get close.

> 2. Selecting a species only applies to the row where I clicked the popup 
> button - not to all selected rows. After releasing the mouse the selection 
> reduces to just one row - but it is terribly confusing.

I suspect that you are running afoul of trying to use bindings in a way that 
they are not intended. Editing multiple values is designed to be used in a 
master-detail type interface, and you are combining that with in-table editing. 
To verify this, have a single popup outside of the table with the same bindings 
except selected object to array controller->selection and see if you get the 
behavior you prefer.

I would say that the UI you are trying to create is rather confusing...

> 3. The editing is immediate, via binding, and I did not find any place to 
> interfere (Say I need to re-calculate things as species changed, or even 
> prevent the change if the newly-selected  species is not compatible with the 
> original.

You cannot intercept bindings, except to do validation, so whatever you do must 
be after-the-fact.

> I have set up a menu Action to the popup-button-cell - and it is called - but 
> the change is already done in the model.
> 
> My questions: 
> Is there anything wrong in my binding settings?

Probably, see my inline response above.

> When the content of a popup-button-cell is populated by binding - Can I still 
> apply NSMenu Validation protocol to that menu, and Filter/Enable/Disable menu 
> items as user clicks to open the menu?

I would say, generally, no, as you either have to set the delegate of the menu 
or action of each item. The former you might be able to do with a table 
delegate method, but you may not be able to do the latter depending on when 
bindings populates the popup.

> When the editing is done via the “Selected Object” binding - can I still 
> somehow intervene and “Catch” the change in code before it happens?

See above.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

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: Popup-Menu Binding issue in Cell-based NSTableView

2018-01-01 Thread Richard Charles
Your example is difficult to follow. You may need to post the actual project or 
a similar project online to get helpful feedback.

From the documentation: "NSArrayController is a bindings compatible class that 
manages a collection of objects. Typically the collection is an array, however, 
if the controller manages a relationship of a managed object the collection may 
be a set.” If what you are trying to do falls within the scope of this 
statement it should work correctly, if not it won’t.

NSArrayController will not manage a Core Data relationship. It manages a single 
collection of objects which may be an array or in the case of a Core Data 
relationship a set of objects. This single collection may be sorted, filtered 
and members of the collection may be selected. You can also set the class of 
objects that make up the content and then add and remove objects of that type 
to and from the collection.

So NSArrayController works within a very narrow range of capabilities.

--Richard Charles

> On Jan 1, 2018, at 2:46 AM, Motti Shneor <motti.shn...@me.com> wrote:
> 
> Hello everyone. Please excuse the anachronism, I am maintaining an old Mac 
> Application written early 2014 when Swift was not an option.  Pure Obj-C, 
> CoreData, and “No-custom-UI” approach.
> 
> I have an NSCell based NSTableView, whose columns are bound to an 
> NSArrayController, whose Content-Array in turn is bound to some CoreData 
> to-many relation - thus the table shows all the related entities.
> 
> Say we have a “WaterSample” entity, and the to-many relation is called 
> “measurements” and each Measurement has length, width, depth, colony-size and 
> species properties - each bound to one of the NSTableColumns. So far - the 
> very basic and stranded use of binding.
> 
> Of the Measurement properties - the species - is yet another to-one relation 
> to the  “Species” table. To allow the user to edit/change the species of a 
> Measurement (line in the table) I have placed a Popup Button Cell in the 
> “Species” column, and bound it like this:
> 
> Content  bound to Species Array Controller, Controller Key: arrangedObjects, 
> Content Placement Tag: 0
> Content Values  bound to Species Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: codeAndName, Content Placement Tag: 0,  
> Multiple Values Placeholder: Multiple Species
> Selected Object  bound to Measurements Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: species, Allows Editing Multiple Values 
> Selection, Conditionally Sets Enabled, Creates Sort Descriptor
> 
> Now it SEEMS to KIND-OF work, (I see the species codes and names, user can 
> click the popup button on each row to see and select from all our Species, 
> and even change the species to another one.
> 
> But I have these issues:
> 
> 1. When I select several Measurement rows of the table — All with the same 
> Species— and click the popup button on any row - it shows “Multiple Species” 
> as the selected value - although all rows have the same species selected.
> 
> 2. Selecting a species only applies to the row where I clicked the popup 
> button - not to all selected rows. After releasing the mouse the selection 
> reduces to just one row - but it is terribly confusing.
> 
> 3. The editing is immediate, via binding, and I did not find any place to 
> interfere (Say I need to re-calculate things as species changed, or even 
> prevent the change if the newly-selected  species is not compatible with the 
> original.
> 
> I have set up a menu Action to the popup-button-cell - and it is called - but 
> the change is already done in the model.
> 
> My questions: 
> Is there anything wrong in my binding settings?
> When the content of a popup-button-cell is populated by binding - Can I still 
> apply NSMenu Validation protocol to that menu, and Filter/Enable/Disable menu 
> items as user clicks to open the menu?
> When the editing is done via the “Selected Object” binding - can I still 
> somehow intervene and “Catch” the change in code before it happens?
> 
> Any hint will be appreciated - and - Happy new year everyone.
> 
> 
> Motti Shneor
> ---
> ceterum censeo microsoftiem delendam esse
> ---

___

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


Popup-Menu Binding issue in Cell-based NSTableView

2018-01-01 Thread Motti Shneor
Hello everyone. Please excuse the anachronism, I am maintaining an old Mac 
Application written early 2014 when Swift was not an option.  Pure Obj-C, 
CoreData, and “No-custom-UI” approach.

I have an NSCell based NSTableView, whose columns are bound to an 
NSArrayController, whose Content-Array in turn is bound to some CoreData 
to-many relation - thus the table shows all the related entities.

Say we have a “WaterSample” entity, and the to-many relation is called 
“measurements” and each Measurement has length, width, depth, colony-size and 
species properties - each bound to one of the NSTableColumns. So far - the very 
basic and stranded use of binding.

Of the Measurement properties - the species - is yet another to-one relation to 
the  “Species” table. To allow the user to edit/change the species of a 
Measurement (line in the table) I have placed a Popup Button Cell in the 
“Species” column, and bound it like this:

Content  bound to Species Array Controller, Controller Key: arrangedObjects, 
Content Placement Tag: 0
Content Values  bound to Species Array Controller, Controller Key: 
arrangedObjects, Model Key Path: codeAndName, Content Placement Tag: 0,  
Multiple Values Placeholder: Multiple Species
Selected Object  bound to Measurements Array Controller, Controller Key: 
arrangedObjects, Model Key Path: species, Allows Editing Multiple Values 
Selection, Conditionally Sets Enabled, Creates Sort Descriptor

Now it SEEMS to KIND-OF work, (I see the species codes and names, user can 
click the popup button on each row to see and select from all our Species, and 
even change the species to another one.

But I have these issues:

1. When I select several Measurement rows of the table — All with the same 
Species— and click the popup button on any row - it shows “Multiple Species” as 
the selected value - although all rows have the same species selected.

2. Selecting a species only applies to the row where I clicked the popup button 
- not to all selected rows. After releasing the mouse the selection reduces to 
just one row - but it is terribly confusing.

3. The editing is immediate, via binding, and I did not find any place to 
interfere (Say I need to re-calculate things as species changed, or even 
prevent the change if the newly-selected  species is not compatible with the 
original.

I have set up a menu Action to the popup-button-cell - and it is called - but 
the change is already done in the model.

My questions: 
Is there anything wrong in my binding settings?
When the content of a popup-button-cell is populated by binding - Can I still 
apply NSMenu Validation protocol to that menu, and Filter/Enable/Disable menu 
items as user clicks to open the menu?
When the editing is done via the “Selected Object” binding - can I still 
somehow intervene and “Catch” the change in code before it happens?

Any hint will be appreciated - and - Happy new year everyone.


Motti Shneor
---
ceterum censeo microsoftiem delendam esse
---


___

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: Creating NSTableView programmatically

2017-12-20 Thread Quincey Morris
On Dec 20, 2017, at 18:55 , Rob Petrovec  wrote:
> 
> Not for nothin', but I don’t think bindings have died.

So, let me respond jointly to all of the comments similar to this.

Of course bindings haven’t “died”, in the sense that no one *uses* them any 
more. My point was that bindings, as a conceptual software design paradigm or 
implementation framework for the general presentation or handling of data, 
don’t have much significance any more. We don’t sit down and *design* bindings 
for our apps, typically. We just bind things together when their values need to 
track each other. This should be understood as a simplification, not a denial 
that some people still get into them more deeply.

Consider also that there have been no functional improvements made to bindings 
since 10.5 (at least, I can’t think of even one), and that bindings were *not* 
taken over to iOS in 2008.

Of course, this is no rejection of KVO, which remains essential and creatively 
productive, despite being mechanically outdated.
___

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: Creating NSTableView programmatically

2017-12-20 Thread Rob Petrovec
Not for nothin', but I don’t think bindings have died. They are still supported 
and used all over the OS.  I use them all the time in my code too.  They are 
very useful.  Bindings are built onto of KVO, which is a fundamental technology.

—Rob


> On Dec 20, 2017, at 3:40 PM, Richard Charles  wrote:
> 
> 
>> On Dec 20, 2017, at 3:23 AM, Quincey Morris 
>>  wrote:
>> 
>> In effect, the whole thing with bindings died at 10.5, except for the part 
>> where they were used within IB to hook up specific controls to specific 
>> properties. That part is really all we use today.
> 
> It does seem like bindings died but I have found them very useful.
> 
> https://stackoverflow.com/questions/1169097/can-you-manually-implement-cocoa-bindings
> 
> https://www.tomdalling.com/blog/cocoa/implementing-your-own-cocoa-bindings/
> 
>> On Dec 20, 2017, at 3:07 PM, Charles Srstka  wrote:
>> 
>> I doubt I would have gone to the trouble of making it do that if I’d had to 
>> write the glue code manually.
> 
> For me it was a trade off. Do I invest time in learning bindings or become 
> really good at writing glue code. I suppose it would have worked either way 
> but for some reason I choose bindings.
> 
> --Richard Charles
> 
> ___
> 
> 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/petrock%40mac.com
> 
> This email sent to petr...@mac.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: Creating NSTableView programmatically

2017-12-20 Thread Richard Charles

> On Dec 20, 2017, at 3:23 AM, Quincey Morris 
>  wrote:
> 
> In effect, the whole thing with bindings died at 10.5, except for the part 
> where they were used within IB to hook up specific controls to specific 
> properties. That part is really all we use today.

It does seem like bindings died but I have found them very useful.

https://stackoverflow.com/questions/1169097/can-you-manually-implement-cocoa-bindings

https://www.tomdalling.com/blog/cocoa/implementing-your-own-cocoa-bindings/

> On Dec 20, 2017, at 3:07 PM, Charles Srstka  wrote:
> 
> I doubt I would have gone to the trouble of making it do that if I’d had to 
> write the glue code manually.

For me it was a trade off. Do I invest time in learning bindings or become 
really good at writing glue code. I suppose it would have worked either way but 
for some reason I choose bindings.

--Richard Charles

___

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: Creating NSTableView programmatically

2017-12-20 Thread Charles Srstka
> On Dec 20, 2017, at 4:23 AM, Quincey Morris 
>  wrote:
> 
>> The original code used all the same three array controllers, with the exact 
>> same subclassing of the target's one.
> 
> This is where I take the fifth. 
> 
> When bindings were introduced, back in 10.3 or 10.4, then refined in 10.5, it 
> looked very much like Apple was trying to sell a sort of data-manipulation 
> “language” constructed out of bindings and NS…Controller classes. While this 
> worked great for pushing glue code out of .m source files and into .nib files 
> (this predated .xib files), it’s was too general, too inscrutable and too 
> clumsy to have much wider appeal. In effect, the whole thing with bindings 
> died at 10.5, except for the part where they were used within IB to hook up 
> specific controls to specific properties. That part is really all we use 
> today.

That’s going a little far, isn’t it? I still find bindings/KVO useful for a lot 
of cases where I want to keep things synced. For example, in Pacifist I have a 
main outline view, and a search results table on the side (currently in a 
drawer, although that’s changing in the currently-under-development Swift 
rewrite). The selected item in the search results and in the main outline view 
should always be the same, and I do that by setting things up, via a system of 
computed properties and keyPathsForValuesAffecting methods, so that the 
table’s selectionIndexes and the outline’s selectionIndexPaths are both 
essentially backed by the same underlying property. The result is that not only 
does it update the selection in the outline view when you change the selection 
in the search results, as you’d expect, but it also manages to update the 
selection in the *search results* if you select an item in the main outline 
view that happens to also be a search result. A big deal? No, but it’s one of 
those little details that makes an old Mac geek like me smile. ;-) I doubt I 
would have gone to the trouble of making it do that if I’d had to write the 
glue code manually.

Charles
___

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: Creating NSTableView programmatically

2017-12-20 Thread Richard Charles

> On Dec 20, 2017, at 2:23 AM, Eric Matecki  wrote:
> 
> My project is based on what I believe is an official sample from Apple,
> which Richard Charles posted as an attachment to his msg from 12/12/2017.

It looks like you have taken your project from Malcolm Crawford's “Combatants” 
sample code. If I remember correctly Malcolm did work for Apple and was a one 
of the public experts on Cocoa bindings at the time. This sample code however 
is of his own making and did not come from Apple. In this sample code he does 
subclass NSArrayController and overrides the behavior of arrangeObjects: to 
exclude the selection (much to my surprise). This is very advanced stuff you 
are delving into.

Malcolm's sample code that really helped me was "Graphics Bindings” which was 
aligned with a major project I was working on. On this project I actually ended 
up subclassing NSArrayController because I could see no way around it but as 
Quincey Morris has indicated it was a very painful process.

But before delving into programmatic Cocoa bindings I must have spent a year 
with Aaron Hillegass in Cocoa Programming for Mac OS X. If you have a C++ 
background, Aaron will take you by the hand and lead you along a correct path. 
My current major project is for macOS and requires interoperability with C++ so 
I have yet to jump on the Swift or iOS bandwagon. Note that Cocoa Programming 
by Hillegass uses the Swift language starting with the 5th Edition and up.

I actually use OS X v10.9 documentation every day. It is old style, accurate, 
extremely usable, searchable, compact, and works well inside a web browser. I 
absolutely detest the new style documentation and find it almost unusable. 
Anyway that is what I do for documentation.

Good luck with your project.

--Richard Charles

___

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: Creating NSTableView programmatically

2017-12-20 Thread Quincey Morris
On Dec 20, 2017, at 01:23 , Eric Matecki  wrote:
> 
> The sole purpose of my project is to learn how bindings works, it has no 
> practical application per se.

Bindings exist to support the use of NIB-based UI behavior. All bindings work 
the same way, in the sense that they tie together the values of properties in 
each of two objects, so that a change in one appears as a change in the other, 
in either direction. This sort of equivalent to mutual KVO-observation with 
mutual updating, except that only the property in the target object (the one 
bound *to*) is actually a property in the KVC sense. The “property” in the 
source object (the one bound *from*) is a notional identifier that may or may 
not correspond to a true property of the object.

For example, when binding the content of a NSTextView, you bind the “value” 
binding to a NSString property of some other object. There is no “value” 
property, the binding name is meaningful only as a binding name. That means 
that all of the binding names have to be documented somewhere, and that happens 
to be the Cocoa Bindings Reference document, which is a long list of classes 
and the bindings that have been defined to exist in each.

That tells you what any given binding is for (provided you can understand what 
the documentation says, which is more of a problem than it ought to be), but it 
doesn’t tell you when you should use the binding. That you kinda figure out by 
trial and error. You can figure out when you need to use the NSTextView “value” 
binding, for example, and you can probably figure out the font and point size 
bindings, but go look at the bindings for NSPopUpButton and you’re gonna be 
scratching your head.

> I wonder how IB manages conflicts when merging your code back to the main 
> branch

Ever since version  of Xcode, IB manages this by using a XIB 
file as the source code of a compiled NIB file, and a XIB file is text in some 
kind of XML format. That means it can be diff’ed and merged, hence managed via 
source control. You can see this yourself by switching the assistant editor to 
show the version history, and the main view will switch from a graphic canvas 
to a long, long text description.

> The original code used all the same three array controllers, with the exact 
> same subclassing of the target's one.

This is where I take the fifth. 

When bindings were introduced, back in 10.3 or 10.4, then refined in 10.5, it 
looked very much like Apple was trying to sell a sort of data-manipulation 
“language” constructed out of bindings and NS…Controller classes. While this 
worked great for pushing glue code out of .m source files and into .nib files 
(this predated .xib files), it’s was too general, too inscrutable and too 
clumsy to have much wider appeal. In effect, the whole thing with bindings died 
at 10.5, except for the part where they were used within IB to hook up specific 
controls to specific properties. That part is really all we use today.

This particular sample app comes from about the 10.4 era, ideologically if not 
actually. It illustrates how to do things no one really wanted to do after 
about 2005. Your current project is archeology, not development.

> In the sample I have, I can't find any binding involving "selectionIndexes", 
> neither in the code nor in the NIB.
> It still works without them.
> Or, more precisely, without them being *explicitly* bound somewhere, and 
> that's the kind of magic I hate.


Well, it’s not quite magic, but nearly. This *isn’t* documented anywhere, or 
(if it was) it was documented in an old version of the Table View Programming 
Guide that no longer exists.

In a NSCell-based table view (the only kind at the time this sample app was 
written), when you bind table columns to a property of an array controller, 
something (the table view? the NIB-loading mechanism? IDK exactly) notices that 
the table view is missing its “content” binding and binds it to the array 
controller. Then it also binds the “selectionIndexes” binding. Most people 
don’t explicitly know that, because it just works and so they don’t have to 
think about it. It’s only when something is arranged differently (like using a 
table view without an array controller, or … what you’re doing) that anyone 
notices.

This is one reason why we generally use XIB/NIB files instead of code — it 
allows us to let IB to worry about the magic, so we don’t have to. (FWIW, stuff 
like this is one reason why IB is huge, slow and buggy. Every tiny detail of 
every old NIB behavior in every macOS version has to be religiously preserved 
in IB.)

>   @property(readonly, copy) NSIndexSet *selectionIndexes;

> So I can change a readonly property thru bindings ?

It’s … um … not readonly. But the setter method looks like this:

> - (BOOL)setSelectionIndexes:(NSIndexSet *)indexes;

which is to say, it’s not exactly a setter because it returns a value. If, 
however, you squint and ignore the return value, it 

Re: Creating NSTableView programmatically

2017-12-20 Thread Eric Matecki

Hi,

Richard, I also reply to your msg here to avoid too much redundancy.
Thanks for your efforts.

My project is based on what I believe is an official sample from Apple,
which Richard Charles posted as an attachment to his msg from 12/12/2017.
The sole purpose of my project is to learn how bindings works, it has no 
practical application per se.
I just converted it from NIB based to code generated UI, as I'll have to create 
GUIs procedurally in the near future.
NIBs are all well if your app is something very static, but I can't see how it 
can handle very dynamic stuff,
with data structures you don't event know at the time you write your code.
It may be possible, because...
yes, I'm a beginner with Cocoa/obj-c, that's why I want to learn the 
'best'/'modern' way to use it,
as a lot of the available documentation (the ones I found) is outdated...

But sooner or later you'll have to port your software to another OS, no more 
NIBs.
At least code, while cumbersome, states everything that happens. No magic 
happening behind the scene.
Also code is much easier to version/fix conflicts.
I wonder how IB manages conflicts when merging your code back to the main branch (I didn't try it, I'm not yet that advanced with 
my exploration of Cocoa app writing... may Apple came out with some clever trick...)



When I select a row in a NSTableView, that selection doesn't "make it" all the 
way to update the controller...


I masochistically downloaded your project, and I think it’s a perfect example 
of why not to do this. There is so much glue code
that it's impossible to tell whether your code is any more than locally correct 
(that is, beyond whether each line of code does
what it purports to do). But all that aside…

— I think it’s a tragic mistake to subclass a NSArrayController. The class is a 
largely inscrutable black box of glue code, and
any code that you add is thrown into the black hole. (I admit this is only an 
opinion. Others may love this kind of self-inflicted
pain.)

— I think it’s *probably* a mistake to use NSArrayControllers *at all* in this 
project, where you’re trying to implement a
specific UI. A NSArrayController is a generalized collection of behaviors 
intended to be used to support a large generality of UI
designs in a NIB file. That level of generality isn’t necessary when you’re 
writing UI code directly, without using NIBs. It’s the
equivalent of using a dictionary with string keys to represent properties, 
instead of declaring the actual properties you want.

The original code used all the same three array controllers, with the exact 
same subclassing of the target's one.


— Your actual problem is that selection doesn’t work because you didn’t connect 
up the right pieces to make it work. For example,
I fixed it for the first table by adding one line of code in the “buildGUI” 
method:


[combatantsTable bind: @"content"  toObject: self.combatantsController  withKeyPath: 
@"arrangedObjects"  options: 0]; //
existing code
[combatantsTable bind: @"selectionIndexes" toObject: self.combatantsController 
withKeyPath: @"selectionIndexes" options: 0]; //
added code

So, where is this documented ?
Finding documentation is the biggest problem I face.
Reference docs are easy to find, but
(https://developer.apple.com/documentation/appkit/nsarraycontroller/1529908-selectionindexes?language=objc)
""""
selectionIndexes
An index set containing the indexes of the receiver’s currently 
selected objects in the content array
Declaration
@property(readonly, copy) NSIndexSet *selectionIndexes;
Discussion
This property is observable using key-value observing.
"""
is of limited use... and it explicitly states KV-observable, not KV-coding 
compliant...

In the sample I have, I can't find any binding involving "selectionIndexes", 
neither in the code nor in the NIB.
It still works without them.
Or, more precisely, without them being *explicitly* bound somewhere, and that's 
the kind of magic I hate.
How should someone convert this to another API ?

So I can change a readonly property thru bindings ?
Whats the use of readonly if it's so easy to change ?
I guess this is just some more obj-c mystery that I'll eventually figure out...

Anyway, it works, so I'm somewhat happy...
Somewhat, because my goal was to understand how bindings work...
While it is logical to bind the selectionIndexes, I don't understand why it is 
readonly...
This readonly-ness is probably why I didn't even consider binding something to 
it,
it was just a 'source' of information in my mind, not a 'destination'.


IOW, the array controller doesn’t know what the current selection is unless you 
tell it. I didn’t try to fix any of the other
tables, but presumably they have the same problem.

Yes, they also work now.

>> printf("Targets::ArrangeObject()\n”);
> This smells like C++ which is okay but kind of lo

Re: Creating NSTableView programmatically

2017-12-19 Thread Richard Charles

> Eric Matecki - Combatants Project on GitHub
> 
> File Combatants.m
> 
> /*
>  Create and return an array of all the combatants that are not selected
>  */
> - (NSArray *) arrangeObjects: (NSArray*)iObjectsToArrange
> {
> printf("Targets::ArrangeObject()\n”);

This smells like C++ which is okay but kind of looks like you need more 
practice with Objective-C.

> unsigned int  scCount = (unsigned int)[selectedCombatants  count];
> 
> if( (scCount == 0)  ||  (selectedCombatants == nil) )
> // second test effectively redundant, but...
> {
> printf("no objects to arrange\n");
> return  [super  arrangeObjects: iObjectsToArrange];   
> }
> 
> /*
>  Create and return an array of all the combatants that are not selected
>  */

Oh dear, why are you doing this? The method arrangeObjects: returns an array 
containing objects filtered using the receiver's filter predicate and sorted 
according to the receiver’s sortDescriptors. This includes the selection. By 
excluding the selection you have changed the semantics of -[NSArrayController 
arrangeObjects:] for apparently no good reason.

> NSMutableArray*  arrangedObjects = [NSMutableArray  arrayWithCapacity: 
> [iObjectsToArrange  count] - scCount];
> 
> NSEnumerator*  objectEnumerator = [iObjectsToArrange  objectEnumerator];
> id  item;
> while( item = [objectEnumerator nextObject] )
> {
> if (![selectedCombatants  containsObject: item])
> {
> printf("%s\n", [[item  name]  UTF8String]);
> [arrangedObjects  addObject: item];
> }
> }
> return  [super  arrangeObjects: arrangedObjects];
> }

I agree with Quincey Morris, subclassing NSArrayController is generally a bad 
idea. It is apparent you need a lot more practice with Objective-C and the 
Cocoa frameworks before you should ever need to do something like this.

A great place to start is with Cocoa Programming for Mac OS X (4th Edition) by 
Aaron Hillegass if you are doing Objective-C. One of the things Aaron tells you 
right up front is “Beginning Cocoa programmers are often eager to create 
subclasses of NSString and NSMutableArray. Don’t. Stylish Objective-C 
programmers almost never do. Instead, they use NSString and NSMutableArray as 
parts of larger objects, a technique known as composition.”

I hope this helps.

--Richard Charles

___

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: Creating NSTableView programmatically

2017-12-19 Thread Quincey Morris
On Dec 19, 2017, at 02:24 , Eric Matecki <eml...@wanadoo.fr> wrote:
> 
> When I select a row in a NSTableView, that selection doesn't "make it" all 
> the way to update the controller...

I masochistically downloaded your project, and I think it’s a perfect example 
of why not to do this. There is so much glue code that it's impossible to tell 
whether your code is any more than locally correct (that is, beyond whether 
each line of code does what it purports to do). But all that aside…

— I think it’s a tragic mistake to subclass a NSArrayController. The class is a 
largely inscrutable black box of glue code, and any code that you add is thrown 
into the black hole. (I admit this is only an opinion. Others may love this 
kind of self-inflicted pain.)

— I think it’s *probably* a mistake to use NSArrayControllers *at all* in this 
project, where you’re trying to implement a specific UI. A NSArrayController is 
a generalized collection of behaviors intended to be used to support a large 
generality of UI designs in a NIB file. That level of generality isn’t 
necessary when you’re writing UI code directly, without using NIBs. It’s the 
equivalent of using a dictionary with string keys to represent properties, 
instead of declaring the actual properties you want.

— Your actual problem is that selection doesn’t work because you didn’t connect 
up the right pieces to make it work. For example, I fixed it for the first 
table by adding one line of code in the “buildGUI” method:

>   [combatantsTable bind: @"content"  toObject: self.combatantsController  
> withKeyPath: @"arrangedObjects"  options: 0]; // existing code
>   [combatantsTable bind: @"selectionIndexes" toObject: 
> self.combatantsController withKeyPath: @"selectionIndexes" options: 0]; // 
> added code


IOW, the array controller doesn’t know what the current selection is unless you 
tell it. I didn’t try to fix any of the other tables, but presumably they have 
the same problem.

___

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: Creating NSTableView programmatically

2017-12-19 Thread Eric Matecki

On 19/12/2017 11:24, Eric Matecki wrote:

Hello all,

No I didn't abandon all hope, I was just busy :)

Thanks to all the replies, I got a lot further, but still didn't reach my 
destination...

Now I have a nice window, looking almost exactly like the NIB created one.

Most things works, except the most fundamental one.
When I select a row in a NSTableView, that selection doesn't "make it" all the 
way to update the controller...

The code/project is now available here : 
https://gitlab.com/CocoaMusings/Combatants

Any suggestion(s) is appreciated.

Eric M.


I just noticed that the preview in gilab doubled-up some dashes in front of 
some methods.
I checked by cloning the repo in another folder, and they aren't there...
Just a display error from gitlab.

--
Keep intel OUTSIDE my Mac !
Hiii !!! I can see Intel chips creeping around my G5 !

Eric M.
___

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: Creating NSTableView programmatically

2017-12-19 Thread Eric Matecki

Hello all,

No I didn't abandon all hope, I was just busy :)

Thanks to all the replies, I got a lot further, but still didn't reach my 
destination...

Now I have a nice window, looking almost exactly like the NIB created one.

Most things works, except the most fundamental one.
When I select a row in a NSTableView, that selection doesn't "make it" all the 
way to update the controller...

The code/project is now available here : 
https://gitlab.com/CocoaMusings/Combatants

Any suggestion(s) is appreciated.

Eric M.

--
Keep intel OUTSIDE my Mac !
Hiii !!! I can see Intel chips creeping around my G5 !

Eric M.
___

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: NSTableView drag image - using the first column image

2017-12-18 Thread Marek Hrušovský
Override:

- (NSArray *)draggingImageComponents;


Apple uses it in its sample TableViewPlaygroud. I found it using br -n
"-[NSDraggingImageComponent initWithKey:]". lldb and breakpoints can help
you. Use hopper or class-dump to see method names (AppKit).


Marek.

On Fri, Dec 15, 2017 at 6:52 PM, David Catmull 
wrote:

> In my table view, when you drag an item, the drag image it uses comes from
> the column cell where the drag started, rather than using the cell from the
> first column where I have the icon and name. How do I make it use the first
> column?
>
> I'm looking at Apple's TableViewPlayground as an example, and the outline
> view there works like I want, and I can't see what the key difference is.
>
> I'm tempted to try to fix it in tableView:updateDraggingItemsForDrag: but
> the Apple sample only uses that to update the image for external drags. For
> local drags, that method is essentially not used. If I comment that method
> out, the first-column-image behavior I want still works in the sample.
>
> I have a simple example at https://github.com/Uncommon/TableTest - notice
> that dragging from different columns yields different drag images even
> though the data in the drag is the same.
> ___
>
> 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/xhruso00%40gmail.com
>
> This email sent to xhrus...@gmail.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: NSTableView drag image - using the first column image

2017-12-17 Thread Rob Petrovec
You probably want NSTableView 
-dragImageForRowsWithIndexes:tableColumns:event:offset:

—Rob


> On Dec 15, 2017, at 10:52 AM, David Catmull <davidcatm...@gmail.com> wrote:
> 
> In my table view, when you drag an item, the drag image it uses comes from
> the column cell where the drag started, rather than using the cell from the
> first column where I have the icon and name. How do I make it use the first
> column?
> 
> I'm looking at Apple's TableViewPlayground as an example, and the outline
> view there works like I want, and I can't see what the key difference is.
> 
> I'm tempted to try to fix it in tableView:updateDraggingItemsForDrag: but
> the Apple sample only uses that to update the image for external drags. For
> local drags, that method is essentially not used. If I comment that method
> out, the first-column-image behavior I want still works in the sample.
> 
> I have a simple example at https://github.com/Uncommon/TableTest - notice
> that dragging from different columns yields different drag images even
> though the data in the drag is the same.
> ___
> 
> 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/petrock%40mac.com
> 
> This email sent to petr...@mac.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


NSTableView drag image - using the first column image

2017-12-15 Thread David Catmull
In my table view, when you drag an item, the drag image it uses comes from
the column cell where the drag started, rather than using the cell from the
first column where I have the icon and name. How do I make it use the first
column?

I'm looking at Apple's TableViewPlayground as an example, and the outline
view there works like I want, and I can't see what the key difference is.

I'm tempted to try to fix it in tableView:updateDraggingItemsForDrag: but
the Apple sample only uses that to update the image for external drags. For
local drags, that method is essentially not used. If I comment that method
out, the first-column-image behavior I want still works in the sample.

I have a simple example at https://github.com/Uncommon/TableTest - notice
that dragging from different columns yields different drag images even
though the data in the drag is the same.
___

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: Creating NSTableView programmatically

2017-12-14 Thread corbin dunn


> On Dec 12, 2017, at 2:12 AM, Eric Matecki <eml...@wanadoo.fr> wrote:
> 
> Hi,
> 
> On 11/12/2017 20:10, Quincey Morris wrote:
>>> I made my own text field class according to this (in NSTableCellView's doc) 
>>> :
>> 
>> I think you’re still kinda Doing It Wrong™. The standard (and, I believe, 
>> recommended) way to do this is to create an instance of
>> NSTableCellView, which has the “objectValue” property, along with other 
>> potentially useful behaviors for cell views (such as
>> identifiers that allow the NSTableView to cache and manage cell views).
> 
> I know it's wrong, or at least bad, but NSTextView and NSButton are the 
> controls I kind of master right now...
> I really don't need a textview, as I'm just trying to reproduce the 
> "Combattant" example.
> I still can't get the names to display with NSTableCellView.
> 
> Here (at the bottom of the page) :
> https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
> it says :
> """
> When you make the connection to the table view’s Content binding, the 
> objectValue property of the NSTableViewCell used as the cell for the table 
> column is configured such that for each item in the model array, the table 
> updates the objectValue property to the current row’s Person object
> 1) Select the text field in the table column cell and create the binding.
> All bindings of subviews in the cell are made to the objectValue.
> Configure the textField instance’s value binding.
> 
> Binding field | Value
> ---
> Bind to:  | Table Cell View
> Model key path| objectValue.name
> """
> 
> So I have this in my NSTableView's delegate, which is my interpretation of 
> the above :
> 
> - (NSView *)tableView:(NSTableView *)tableView
>   viewForTableColumn:(NSTableColumn *)tableColumn
>  row:(NSInteger)row
> {
> #if 0  // this shows the names
> 
>cTextView*  view = [[cTextView  alloc]  init]; // cTextView is my custom 
> NSTextView with just an added objectValue property
>[view  bind: @"value"  toObject: tableView  withKeyPath: 
> @"objectValue.name"  options: 0];  // wrong, but works
>//[view  bind: @"value"  toObject: view  withKeyPath: @"objectValue.name"  
> options: 0]; // right, works
> 
> #else // this doesn't show the names
> 
>NSTableCellView*  view = [[NSTableCellView  alloc]  init];
>//[[view  textField]  setBackgroundColor: [NSColor  redColor]]; // just to 
> be sure to see it when empty... nada
>//[[view  textField]  bind: @"value"  toObject: tableView  withKeyPath: 
> @"objectValue.name"  options: 0]; // wrong, doesn't work
>[[view  textField]  bind: @"value"  toObject: view  withKeyPath: 
> @"objectValue.name"  options: 0]; // right?, but doesn't work

^ This is correct, but the piece you are missing is somehow providing the 
objectValue for the resulting tableCellView. 

NSTableView sets the objectValue to the result from the table’s content 
binding. It does this on the result you return from the above method. However, 
I recommend just implementing tableView:objectValueForTableColumn:row: in your 
delegate and returning something. The “something” you are turning has to be an 
object that has a “name” property (based on your binding). You could just bind 
it to “objectValue” and return a (cached) string.

corbin

> 
> #endif
>return  view;
> }
> 
> Note that I bind the NSTextView to tableView, while the doc says "the 
> objectValue property of the NSTableViewCell", not of the tableview... but it 
> works, and I don't understand why... I don't like it when I don't understand 
> what's happening.
> It also works when binding to the view, which is expected (I first bound it 
> to tableView by mistake...).
> It's still weird (to me) to bind an object's binding to one of it's own 
> properties.
> I guess it's more or less by chance that it displays the names, and that some 
> changes in my model won't get correctly propagated...
> 
> In the case of NSTableCellView, neither binding works... I don't get any 
> exception or crash, but nothing is displayed inside my table view (although 
> it's size suggests the four rows are there).
> But setting the backgroud of the textfield to red doesn't show any red on the 
> screen...
> (Trying to the set the cell's background gives me a "may not respond to 
> message" warning, and obviously nothing gets red on the screen).
> 
> Something in the "big scheme of things" escapes me,

Re: Creating NSTableView programmatically

2017-12-12 Thread Richard Charles

> On Dec 12, 2017, at 2:40 PM, Jonathan Mitchell  wrote:
> 
>> On 12 Dec 2017, at 19:56, Richard Charles  wrote:
>> 
>> I always assumed the reason bindings never came over to iOS was they 
>> consumed too much cpu power and were too difficult to understand. It seems 
>> evident that 10 or 20 years from now Apple anticipates the bulk of it 
>> programmers coming out of school will use iPads with the new style 
>> documentation. Cocoa bindings do not fit very well into this picture.
> I am not sure if stringent power concerns were the overriding factor for 
> excluding bindings from iOS. 
> Bindings are driven by observations, which do exist on iOS.

I stand somewhat corrected, I did not know KVO was available on iOS.

> Bindings are actually a fairly essential technology for medium to large scale 
> data driven macOS applications.
> Trying to manually glue hundreds of controls and data paths together quickly 
> becomes a major development obstacle.

Amen to that!

--Richard Charles

___

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: Creating NSTableView programmatically

2017-12-12 Thread Jonathan Mitchell

> On 12 Dec 2017, at 19:56, Richard Charles  wrote:
> 
> I always assumed the reason bindings never came over to iOS was they consumed 
> too much cpu power and were too difficult to understand. It seems evident 
> that 10 or 20 years from now Apple anticipates the bulk of it programmers 
> coming out of school will use iPads with the new style documentation. Cocoa 
> bindings do not fit very well into this picture.
I am not sure if stringent power concerns were the overriding factor for 
excluding bindings from iOS. 
Bindings are driven by observations, which do exist on iOS. 
I think that some developers use reactive frameworks such as ReactiveCocoa to 
achieve UI binding on IOS - but I am not sure that would count as a 
simplification.

Cocoa bindings are okay though they lack flexibility and features when compared 
to the likes of WPF bindings.
WPF bindings are just about as tricky to get right - though the use of a GC 
makes life generally easier in a managed world.

Bindings are actually a fairly essential technology for medium to large scale 
data driven macOS applications.
Trying to manually glue hundreds of controls and data paths together quickly 
becomes a major development obstacle.

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: Creating NSTableView programmatically

2017-12-12 Thread Richard Charles

> On Dec 12, 2017, at 12:08 PM, Quincey Morris 
>  wrote:
> 
> I don’t think bindings are fading away. They can’t, while they’re the only 
> way to connect UI elements without custom glue code. However, the design is 
> ancient (IIRC, bindings were introduced in macOS 10.3, and refined in 10.4, 
> and really nothing has changed since then).

It is the documentation of bindings that is fading away and if you are an iOS 
programmer then bindings are irrelevant. Malcolm Crawford had an excellent 
resource on the web for understanding bindings (Cocoa Bindings Examples and 
Hints) but it has disappeared. Malcolm Crawford made his last post to cocoa-dev 
in 2012 and so time marches on.

> What has fallen away (because it never really got off the ground) was the use 
> of *custom* bindings, in part because no one could understand what to do, and 
> because they really needed the IB customization features introduced in Xcode 
> 3.0 (or was it earlier?) and killed off in Xcode 3.1 (or thereabouts).

Custom programmatic bindings (not integrated with IB) work great but it is 
daunting to figure this out. So I agree.

> In modern terms, bindings are a horrible hack, and that’s why (I assume) they 
> were never taken over to iOS.

I always assumed the reason bindings never came over to iOS was they consumed 
too much cpu power and were too difficult to understand. It seems evident that 
10 or 20 years from now Apple anticipates the bulk of it programmers coming out 
of school will use iPads with the new style documentation. Cocoa bindings do 
not fit very well into this picture.

--Richard Charles

___

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: Creating NSTableView programmatically

2017-12-12 Thread Quincey Morris
On Dec 12, 2017, at 02:12 , Eric Matecki  wrote:
> 
> In the case of NSTableCellView, neither binding works... I don't get any 
> exception or crash, but nothing is displayed inside my table view (although 
> it's size suggests the four rows are there).

This was a conceptual failure on my part, since I’ve never actually created a 
NSTableCellView manually. The cell view has “imageView" and “textField” 
outlets, but they’re not connected to anything by default, and the cell view 
has no subviews by default. (One or both subviews is present and connected when 
you do this in IB, because IB uses a preconfigured cell view hierarchy.)

If you want to use a text view, you will have to subclass NSTableCellView to 
add a “textView” outlet. or you can use a text field with the existing 
“textField” outlet. Either way, you’ll need to create the text-displaying 
subview, and set the corresponding outlet.

>[view  bind: @"value"  toObject: tableView  withKeyPath: 
> @"objectValue.name"  options: 0];  // wrong, but works

I have no idea why that works, it makes no sense whatever.

You’re still missing some stuff, BTW:

— For proper table view behavior, you really should create the cells by 
invoking "makeView(withIdentifier:owner:)”, so that the table view can manage 
the lifetimes and reusability of the cell views. However, this mechanism is 
intended to work with a NIB for the table cell view. This can either come from 
the table view’s own NIB file (via a private mechanism that IB sets up for you) 
or a freestanding NIB file (which you must register with the table view 
manually). Since you have neither, you will (I guess) need to let the cell 
creation portion of the "makeView(withIdentifier:owner:)” API fail, when a cell 
view isn’t being reused, then create your cell view manually.

Technically, you don’t have to do this, I suppose, but you said you were trying 
to learn what normally goes on, and cell view caching is what normally happens.

— You didn’t embed your table view in a scroll view. 

If it can’t scroll, the table view isn’t much use.

> How do you "ignore" what you don't need in an NSTableCellView ?

As I said, I was confusing two things. Most standard cells created in IB are 
just text, and have no image view.

> And when I add a subview to one, how do I arrange (layout) it's content

The usual ways, which is to say: add layout constraints, or set the frame 
manually if you’re not using autolayout.

> It's still weird (to me) to bind an object's binding to one of it's own 
> properties.

It’s just a special case of a “derived” property. It’s not so unusual for an 
object to observe one of its own properties in order to provide a KVO compliant 
value for another property. Anyway, in this case, it’s conceptually binding to 
a different object (the one referenced by “objectValue”) to get its “name” 
property. The indirection falls out of the division between standard behavior 
and custom behavior that’s built into the table view design.

> Too bad that bindings are fading away

I don’t think bindings are fading away. They can’t, while they’re the only way 
to connect UI elements without custom glue code. However, the design is ancient 
(IIRC, bindings were introduced in macOS 10.3, and refined in 10.4, and really 
nothing has changed since then).

What has fallen away (because it never really got off the ground) was the use 
of *custom* bindings, in part because no one could understand what to do, and 
because they really needed the IB customization features introduced in Xcode 
3.0 (or was it earlier?) and killed off in Xcode 3.1 (or thereabouts).

In modern terms, bindings are a horrible hack, and that’s why (I assume) they 
were never taken over to iOS.

___

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: Creating NSTableView programmatically

2017-12-12 Thread Eric Matecki

Hi Richard,

thanks for all this reading !
I'll need a day or two to understand everything therein. Even if they aren't 
that long, there are a lot of subtle details :)

Too bad that bindings are fading away, the concept is great, the implementation 
is not so great from skimming thru these pages

Eric M.

On 12/12/2017 14:02, Richard Charles wrote:



On Dec 12, 2017, at 3:12 AM, Eric Matecki  wrote:

It's still weird (to me) to bind an object's binding to one of it's own 
properties.


I have an applicaiton that extensively uses programmatic and custom bindings. 
The following have helped me understanding bindings.


...


==

Bindings are a bit of a mystery especially programmatic bindings. Perhaps 
because iOS does not have bindings, interest in bindings and information about 
bindings appears to be diminishing.

--Richard Charles


--
Keep intel OUTSIDE my Mac !
Hiii !!! I can see Intel chips creeping around my G5 !

Eric M.
___

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: Creating NSTableView programmatically

2017-12-12 Thread Eric Matecki

Hi,

On 11/12/2017 20:10, Quincey Morris wrote:

I made my own text field class according to this (in NSTableCellView's doc) :


I think you’re still kinda Doing It Wrong™. The standard (and, I believe, 
recommended) way to do this is to create an instance of
NSTableCellView, which has the “objectValue” property, along with other 
potentially useful behaviors for cell views (such as
identifiers that allow the NSTableView to cache and manage cell views).


I know it's wrong, or at least bad, but NSTextView and NSButton are the 
controls I kind of master right now...
I really don't need a textview, as I'm just trying to reproduce the 
"Combattant" example.
I still can't get the names to display with NSTableCellView.

Here (at the bottom of the page) :
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
it says :
"""
When you make the connection to the table view’s Content binding, the objectValue property of the NSTableViewCell used as the cell 
for the table column is configured such that for each item in the model array, the table updates the objectValue property to the 
current row’s Person object

1) Select the text field in the table column cell and create the binding.
All bindings of subviews in the cell are made to the objectValue.
Configure the textField instance’s value binding.

Binding field   | Value
---
Bind to:| Table Cell View
Model key path  | objectValue.name
"""

So I have this in my NSTableView's delegate, which is my interpretation of the 
above :

- (NSView *)tableView:(NSTableView *)tableView
   viewForTableColumn:(NSTableColumn *)tableColumn
  row:(NSInteger)row
{
#if 0  // this shows the names

cTextView*  view = [[cTextView  alloc]  init]; // cTextView is my custom 
NSTextView with just an added objectValue property
[view  bind: @"value"  toObject: tableView  withKeyPath: 
@"objectValue.name"  options: 0];  // wrong, but works
//[view  bind: @"value"  toObject: view  withKeyPath: @"objectValue.name"  
options: 0]; // right, works

#else // this doesn't show the names

NSTableCellView*  view = [[NSTableCellView  alloc]  init];
//[[view  textField]  setBackgroundColor: [NSColor  redColor]]; // just to 
be sure to see it when empty... nada
//[[view  textField]  bind: @"value"  toObject: tableView  withKeyPath: 
@"objectValue.name"  options: 0]; // wrong, doesn't work
[[view  textField]  bind: @"value"  toObject: view  withKeyPath: 
@"objectValue.name"  options: 0]; // right?, but doesn't work

#endif
return  view;
}

Note that I bind the NSTextView to tableView, while the doc says "the objectValue property of the NSTableViewCell", not of the 
tableview... but it works, and I don't understand why... I don't like it when I don't understand what's happening.

It also works when binding to the view, which is expected (I first bound it to 
tableView by mistake...).
It's still weird (to me) to bind an object's binding to one of it's own 
properties.
I guess it's more or less by chance that it displays the names, and that some 
changes in my model won't get correctly propagated...

In the case of NSTableCellView, neither binding works... I don't get any exception or crash, but nothing is displayed inside my 
table view (although it's size suggests the four rows are there).

But setting the backgroud of the textfield to red doesn't show any red on the 
screen...
(Trying to the set the cell's background gives me a "may not respond to message" warning, and obviously nothing gets red on the 
screen).


Something in the "big scheme of things" escapes me, and Apple's doc was not 
very helpful until now.


In a very unusual or complex case, you might subclass NSTableCellView to add 
properties or behaviors to it, but it’s normally not
necessary. Custom properties, for example, can be carried around by the object 
referred to by “objectValue”, and custom behaviors
can sometimes be implemented as part of the delegate.

Instead of using a cell view other than a NSTableCellView or subclass, it’s 
usual to *add subviews* for things like text fields
and buttons. That separates the behavior of the cell *as a cell* (such as being 
cached for the table view) from the view hierarchy
represented by the cell. However, if your cell just needs to contain a text 
field, you don’t need to add one yourself,
because NSTableCellView already contains a NSTextField subview that you can 
just *use*. It also contains NSImageView subview that
you can use or ignore.


How do you "ignore" what you don't need in an NSTableCellView ?
And when I add a subview to one, how do I arrange (layout) it's content, so it works with the way the 'free' NSTextField and 
NSImageView are arra

Re: Creating NSTableView programmatically

2017-12-11 Thread Charles Srstka
> On Dec 11, 2017, at 4:59 AM, Eric Matecki <eml...@wanadoo.fr> wrote:
> 
> 
> Hello,
> 
> I'm trying to implement in Objective-C on macOS *programmatically* the "Real 
> World Example" at the bottom of this page :
> https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html
>  
> <https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html>
> 
> …
> 
> -- 
> Keep intel OUTSIDE my Mac !
> Hiii !!! I can see Intel chips creeping around my G5 !

I dunno, to me it seems that trying to get NSTableView to work right without 
just using a nib is as much of a losing battle as still trying to fight the 
PPC->Intel transition in 2017… ;-)

Charles

___

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: Creating NSTableView programmatically

2017-12-11 Thread Quincey Morris
On Dec 11, 2017, at 10:19 , Alastair Houghton <alast...@alastairs-place.net> 
wrote:
> 
> NSTableViewCell is the old way to do it, before view-based tables were the 
> norm

In this case, I think “NSTableViewCell” is a typo in the documentation. In the 
following tables, it refers to the binding target as “Table Cell View”, not 
“Table View Cell”. NSCell-based tables did use cell class names with the 
pattern “NS…Cell”, but NSTableViewCell wasn’t one of them AFAIK. (In iOS, of 
course, the equivalent cell view is UITableViewCell, just to keep us on our 
toes.)


On Dec 11, 2017, at 05:53 , Eric Matecki <eml...@wanadoo.fr> wrote:
> 
> I made my own text field class according to this (in NSTableCellView's doc) :

I think you’re still kinda Doing It Wrong™. The standard (and, I believe, 
recommended) way to do this is to create an instance of NSTableCellView, which 
has the “objectValue” property, along with other potentially useful behaviors 
for cell views (such as identifiers that allow the NSTableView to cache and 
manage cell views). 

In a very unusual or complex case, you might subclass NSTableCellView to add 
properties or behaviors to it, but it’s normally not necessary. Custom 
properties, for example, can be carried around by the object referred to by 
“objectValue”, and custom behaviors can sometimes be implemented as part of the 
delegate.

Instead of using a cell view other than a NSTableCellView or subclass, it’s 
usual to *add subviews* for things like text fields and buttons. That separates 
the behavior of the cell *as a cell* (such as being cached for the table view) 
from the view hierarchy represented by the cell. However, if your cell just 
needs to contain a text field, you don’t need to add one yourself, because 
NSTableCellView already contains a NSTextField subview that you can just *use*. 
It also contains NSImageView subview that you can use or ignore.

> Now I can see all the names :)

One reason to use a NSTableCellView instead of a control sum as a text field is 
that the cell view’s size is *forced* to the dimensions required by the table 
view row. That means you have no control of the placement of the contents 
relative to the row. For a text field, for example, you have no direct way of 
controlling the margins surrounding the text. This approach also limits the use 
of autolayout, which may or may not be an issue in your project.

> - (NSView *)tableView:(NSTableView *)tableView  
> viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
>NSTextView*  view = [[NSTextView  alloc]  init];
> …

You say “text field” everywhere, but you actually create a text view. I don’t 
get a sense of which one you really want to use, but using a separate 
NSTextView for each row of the table could end badly, and subclassing 
NSTextView is probably a code smell.

___

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: Creating NSTableView programmatically

2017-12-11 Thread Alastair Houghton
On 11 Dec 2017, at 13:53, Eric Matecki  wrote:
> 
> Thanks Jonathan,
> 
> I got a lot further now.
> So it is NSTableCellView, not NSTableViewCell as stated in the doc !

FWIW, NSTableViewCell is the old way to do it, before view-based tables were 
the norm, which probably explains your confusion here as the documentation most 
likely still covers both techniques.

Kind regards,

Alastair.

--
http://alastairs-place.net

___

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: Creating NSTableView programmatically

2017-12-11 Thread Eric Matecki

Thanks Jonathan,

I got a lot further now.
So it is NSTableCellView, not NSTableViewCell as stated in the doc !
I could have searched a long time before finding this out

I made my own text field class according to this (in NSTableCellView's doc) :
"""
The objectValue is used when setting the value of the view cell by the tableView:objectValueForTableColumn:row: method in the 
NSTableViewDataSource. If you use your own custom view cells that are not based on NSTableCellView you should implement this 
property in order to be able to receive changes to cell values.

"""
I added an "objectValue" property, with custom setter and getter, and updated 
the textfield's string in the setter.
Now I can see all the names :)

I'm on the saddle again for the rest of my journey...

Eric M.

On 11/12/2017 12:46, Jonathan Mitchell wrote:

For NSTableCellView see
https://developer.apple.com/documentation/appkit/nstablecellview

objectValue is a property on NSTableCellView not on NStableView.

The NSTableViewDelegate method
- (NSView *)tableView:(NSTableView *)tableView 
viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
provides the required NSTableView instances on demand.

You also need to bind the NSTableView's content object to the 
NSArrayController’s arrangedObjects.

The nib makes all this easier  though its still fiddly.
I would get it working in a nib first and then work backwards from there.



On 11 Dec 2017, at 10:59, Eric Matecki <eml...@wanadoo.fr> wrote:


Hello,

I'm trying to implement in Objective-C on macOS *programmatically* the "Real World 
Example" at the bottom of this page :
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html

I want to do it programmatically instead of using IB to really understand what 
happens.

Just creating the "Attacker" NSTableView causes me already a lot of trouble.
My code is at the bottom of this message.

I can't just bind "value" of the attacker tableview to the array controller's 
"arrangedObjects.name",
I get a "this class is not key value coding-compliant for the key value" 
exception.

So I create a column (I think this is mandatory anyway...).
In my delegates tableView:viewForTableColumn:row: I create a text field 
(NSTextView).
(I create a textfield for now, will probably be a NSButton in the final 
version).

I now see a table with four rows (the number of entries in my array), each with 
a text field I can edit.
But they start empty and don't change my array of combattants.

How do I bind this text field to the right "thing" ?

According to the last paragraph of this page:
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
I have to :
"""
When you make the connection to the table view’s Content binding, the 
objectValue property of the NSTableViewCell used as the cell for the table 
column is configured such that for each item in the model array, the table 
updates the objectValue property to the current row’s Person object.
"""
But NSTableViewCell doesn't seem to exists (a search on Apple's dev doc gives 
27 results... all about *UI*TableViewCell)

So I need to bind "value" from the text field to "objectValue.name" from... 
something...
Whatever I try I get either an exception for not KV compliance, or it doesn't 
seem to do anything.

Please shed some light on this...
Thanks.

CODE:

#include "Cocoa/Cocoa.h"

//===
 cCombattant

@interface  cCombattant : NSObject

@property (copy) NSString*  weapon1;
@property (copy) NSString*  weapon2;
@property (copy) NSString*  weapon3;
@property (copy,readwrite) NSString*  name;
@propertyNSString**  selectedWeapon;

- (cCombattant*)initWithName: (NSString*)  iName;

//DEBUG
- (void)addObserver: (NSObject *)observer
forKeyPath: (NSString *)keyPath
   options: (NSKeyValueObservingOptions)options
   context: (void *)context;

//DEBUG
- (void)removeObserver: (NSObject *)observer
   forKeyPath: (NSString *)keyPath;
@end


@implementation  cCombattant

- (cCombattant*)initWithName: (NSString*)  iName
{
   self = [super  init];

   [self  setWeapon1: @"Dagger"];
   [self  setWeapon2: @"Sword"];
   [self  setWeapon3: @"Pike"];
   [self  setSelectedWeapon: &_weapon1];
   [self  setName: iName];

   return  self;
}

//DEBUG
- (void)addObserver: (NSObject *)observer
forKeyPath: (NSString *)keyPath
   options: (NSKeyValueObservingOptions)options
   context: (void *)context
{
   printf( "[%p addObserver: %p forKeyPath: %s options: XXX context: %p]\n", 
self, observer, [k

Re: Creating NSTableView programmatically

2017-12-11 Thread Jonathan Mitchell
For NSTableCellView see
https://developer.apple.com/documentation/appkit/nstablecellview

objectValue is a property on NSTableCellView not on NStableView.

The NSTableViewDelegate method 
- (NSView *)tableView:(NSTableView *)tableView 
viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
provides the required NSTableView instances on demand.

You also need to bind the NSTableView's content object to the 
NSArrayController’s arrangedObjects.

The nib makes all this easier  though its still fiddly.
I would get it working in a nib first and then work backwards from there.


> On 11 Dec 2017, at 10:59, Eric Matecki <eml...@wanadoo.fr> wrote:
> 
> 
> Hello,
> 
> I'm trying to implement in Objective-C on macOS *programmatically* the "Real 
> World Example" at the bottom of this page :
> https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html
> 
> I want to do it programmatically instead of using IB to really understand 
> what happens.
> 
> Just creating the "Attacker" NSTableView causes me already a lot of trouble.
> My code is at the bottom of this message.
> 
> I can't just bind "value" of the attacker tableview to the array controller's 
> "arrangedObjects.name",
> I get a "this class is not key value coding-compliant for the key value" 
> exception.
> 
> So I create a column (I think this is mandatory anyway...).
> In my delegates tableView:viewForTableColumn:row: I create a text field 
> (NSTextView).
> (I create a textfield for now, will probably be a NSButton in the final 
> version).
> 
> I now see a table with four rows (the number of entries in my array), each 
> with a text field I can edit.
> But they start empty and don't change my array of combattants.
> 
> How do I bind this text field to the right "thing" ?
> 
> According to the last paragraph of this page:
> https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
> I have to :
> """
> When you make the connection to the table view’s Content binding, the 
> objectValue property of the NSTableViewCell used as the cell for the table 
> column is configured such that for each item in the model array, the table 
> updates the objectValue property to the current row’s Person object.
> """
> But NSTableViewCell doesn't seem to exists (a search on Apple's dev doc gives 
> 27 results... all about *UI*TableViewCell)
> 
> So I need to bind "value" from the text field to "objectValue.name" from... 
> something...
> Whatever I try I get either an exception for not KV compliance, or it doesn't 
> seem to do anything.
> 
> Please shed some light on this...
> Thanks.
> 
> CODE:
> 
> #include "Cocoa/Cocoa.h"
> 
> //===
>  cCombattant
> 
> @interface  cCombattant : NSObject
> 
> @property (copy) NSString*  weapon1;
> @property (copy) NSString*  weapon2;
> @property (copy) NSString*  weapon3;
> @property (copy,readwrite) NSString*  name;
> @propertyNSString**  selectedWeapon;
> 
> - (cCombattant*)initWithName: (NSString*)  iName;
> 
> //DEBUG
> - (void)addObserver: (NSObject *)observer
> forKeyPath: (NSString *)keyPath
>options: (NSKeyValueObservingOptions)options
>context: (void *)context;
> 
> //DEBUG
> - (void)removeObserver: (NSObject *)observer
>forKeyPath: (NSString *)keyPath;
> @end
> 
> 
> @implementation  cCombattant
> 
> - (cCombattant*)initWithName: (NSString*)  iName
> {
>self = [super  init];
> 
>[self  setWeapon1: @"Dagger"];
>[self  setWeapon2: @"Sword"];
>[self  setWeapon3: @"Pike"];
>[self  setSelectedWeapon: &_weapon1];
>[self  setName: iName];
> 
>return  self;
> }
> 
> //DEBUG
> - (void)addObserver: (NSObject *)observer
> forKeyPath: (NSString *)keyPath
>options: (NSKeyValueObservingOptions)options
>context: (void *)context
> {
>printf( "[%p addObserver: %p forKeyPath: %s options: XXX context: %p]\n", 
> self, observer, [keyPath UTF8String], /*options,*/ context );
>int bkpt=bkpt;
>[super  addObserver: observer  forKeyPath: keyPath  options: options  
> context: context];
> }
> 
> //DEBUG
> - (void)removeObserver: (NSObject *)observer
>forKeyPath: (NSString *)keyPath
> {
>printf( "[%p removeObserver: %p forKeyPath: 

Creating NSTableView programmatically

2017-12-11 Thread Eric Matecki


Hello,

I'm trying to implement in Objective-C on macOS *programmatically* the "Real World 
Example" at the bottom of this page :
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html

I want to do it programmatically instead of using IB to really understand what 
happens.

Just creating the "Attacker" NSTableView causes me already a lot of trouble.
My code is at the bottom of this message.

I can't just bind "value" of the attacker tableview to the array controller's 
"arrangedObjects.name",
I get a "this class is not key value coding-compliant for the key value" 
exception.

So I create a column (I think this is mandatory anyway...).
In my delegates tableView:viewForTableColumn:row: I create a text field 
(NSTextView).
(I create a textfield for now, will probably be a NSButton in the final 
version).

I now see a table with four rows (the number of entries in my array), each with 
a text field I can edit.
But they start empty and don't change my array of combattants.

How do I bind this text field to the right "thing" ?

According to the last paragraph of this page:
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
I have to :
"""
When you make the connection to the table view’s Content binding, the objectValue property of the NSTableViewCell used as the cell 
for the table column is configured such that for each item in the model array, the table updates the objectValue property to the 
current row’s Person object.

"""
But NSTableViewCell doesn't seem to exists (a search on Apple's dev doc gives 
27 results... all about *UI*TableViewCell)

So I need to bind "value" from the text field to "objectValue.name" from... 
something...
Whatever I try I get either an exception for not KV compliance, or it doesn't 
seem to do anything.

Please shed some light on this...
Thanks.

CODE:

#include "Cocoa/Cocoa.h"

//===
 cCombattant

@interface  cCombattant : NSObject

@property (copy) NSString*  weapon1;
@property (copy) NSString*  weapon2;
@property (copy) NSString*  weapon3;
@property (copy,readwrite) NSString*  name;
@propertyNSString**  selectedWeapon;

- (cCombattant*)initWithName: (NSString*)  iName;

//DEBUG
- (void)addObserver: (NSObject *)observer
 forKeyPath: (NSString *)keyPath
options: (NSKeyValueObservingOptions)options
context: (void *)context;

//DEBUG
- (void)removeObserver: (NSObject *)observer
forKeyPath: (NSString *)keyPath;
@end


@implementation  cCombattant

- (cCombattant*)initWithName: (NSString*)  iName
{
self = [super  init];

[self  setWeapon1: @"Dagger"];
[self  setWeapon2: @"Sword"];
[self  setWeapon3: @"Pike"];
[self  setSelectedWeapon: &_weapon1];
[self  setName: iName];

return  self;
}

//DEBUG
- (void)addObserver: (NSObject *)observer
 forKeyPath: (NSString *)keyPath
options: (NSKeyValueObservingOptions)options
context: (void *)context
{
printf( "[%p addObserver: %p forKeyPath: %s options: XXX context: %p]\n", self, observer, [keyPath UTF8String], /*options,*/ 
context );

int bkpt=bkpt;
[super  addObserver: observer  forKeyPath: keyPath  options: options  
context: context];
}

//DEBUG
- (void)removeObserver: (NSObject *)observer
forKeyPath: (NSString *)keyPath
{
printf( "[%p removeObserver: %p forKeyPath: %s]\n", self, observer, 
[keyPath UTF8String] );
int bkpt=bkpt;
[super  removeObserver: observer  forKeyPath: keyPath];
}

@end

//===
 cDelegate

@interface  cDelegate : NSObject < NSTableViewDelegate >

- (cDelegate*)init;

@end


@implementation  cDelegate


- (cDelegate*)init
{
self = [super  init];
return  self;
}

- (NSView *)tableView:(NSTableView *)tableView
   viewForTableColumn:(NSTableColumn *)tableColumn
  row:(NSInteger)row
{
NSTextView*  view = [[NSTextView  alloc]  init];
[view  setRichText: NO];
[view  setFieldEditor: YES];
[view  bind: @"value"  toObject: tableView  withKeyPath: 
@"objectValue.name"  options: 0];
return  view;
}

@end

//===
 JustDoIt2()

void
JustDoIt2()
{
@try{
NSArray*  combattants =
[[NSArray  alloc]  initWithObjects:
[[cCombattant  alloc]  initWithName: @"Atilla"],
[[cCombattant  alloc]  initWithName: @"Vlad"],

Re: cell-based NSTableView, NSArrayController and first responder

2017-07-12 Thread Martin Hewitson

> On 12 Jul 2017, at 14:32, Ken Thomases <k...@codeweavers.com> wrote:
> 
> On Jul 12, 2017, at 4:52 AM, Martin Hewitson <martin.hewit...@aei.mpg.de> 
> wrote:
>> 
>> I have a new bug in an application which I believe has only appeared in 
>> 10.12.
>> 
>> I have a cell-based NSTableView backed by an NSArrayController, and the 
>> (new) problem I have is that the editing of a cell ends after the first 
>> keystroke. It looks as if first responder is resigned, but I can’t figure 
>> out why, and as I say, this seems to be new behaviour.
> 
> If you focus the cell again and type, does editing end after _every_ 
> keystroke?  Or can you continue editing properly after that?

Yes, it ends after every keystroke. One has to double click to enable editing 
again, but a single keystroke ends editing.

> 
> Where does focus go?  Is the table view focused?  Or is nothing in the window 
> focused?  For example, if you type an up- or down-arrow key, does it select 
> rows in the table view?

I tried to determine that, but I couldn’t find where it goes. It seems to go 
away from the window.


> 
>> Has anyone else hit this issue and solved it? Or does anyone have any 
>> pointers where to start digging? I reviewed all the bindings and tableview 
>> setup, but I haven’t changed anything here in years.
> 
> Is the array controller set to rearrange its contents automatically based on 
> sort descriptors?  

No.

> Does the table column's value binding have Continuously Updates Value enabled?

Yes.

>  If so and you change that, does the problem go away?

Yes!

> 
> The table view will be the text cell's delegate and will be called for the 
> delegate methods described in the NSControlTextEditingDelegate protocol as 
> well as those described in NSControl.  Try using a custom subclass of 
> NSTableView (if you're not already) and overriding -controlTextDidEndEditing: 
> and -control:textShouldEndEditing: to log [NSThread callStackSymbols] and 
> call through to super (if the static superclass's instances respond to those 
> methods, i.e. [NSTableView instancesRespondToSelector:_cmd]).  The stack 
> trace should give you some idea of what's responsible for removing focus from 
> the cell.
> 
> If the whole table view is losing focus, you could do the same with 
> -resignFirstResponder.

I tried most (if not all) of this, and didn’t have any joy. 

Anyway, the ‘Continuously Updates Value’ setting seems to have done the trick. 
Has something changed in the underlying implementation? As I said, this was 
working fine until recently.

Thanks a lot for the detailed answer! I’m happy it’s fixed, but unhappy that I 
don’t really understand why.

Cheers,

Martin


> 
> Try to reproduce the problem in a new project, adding/changing as little as 
> possible to get it to reproduce.  If you can, try sharing that with us.
> 
> Regards,
> Ken
> 


Dr. Martin Hewitson, Staff Scientist
Institut für Gravitationsphysik der Leibniz Universität Hannover
Callinstraße 38
D-30167 Hannover, Germany
Tel: +49 511 762 17121
Fax: +49 511 762 5861
Email: hewit...@aei.mpg.de


___

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: cell-based NSTableView, NSArrayController and first responder

2017-07-12 Thread Ken Thomases
On Jul 12, 2017, at 4:52 AM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:
> 
> I have a new bug in an application which I believe has only appeared in 10.12.
> 
> I have a cell-based NSTableView backed by an NSArrayController, and the (new) 
> problem I have is that the editing of a cell ends after the first keystroke. 
> It looks as if first responder is resigned, but I can’t figure out why, and 
> as I say, this seems to be new behaviour.

If you focus the cell again and type, does editing end after _every_ keystroke? 
 Or can you continue editing properly after that?

Where does focus go?  Is the table view focused?  Or is nothing in the window 
focused?  For example, if you type an up- or down-arrow key, does it select 
rows in the table view?

> Has anyone else hit this issue and solved it? Or does anyone have any 
> pointers where to start digging? I reviewed all the bindings and tableview 
> setup, but I haven’t changed anything here in years.

Is the array controller set to rearrange its contents automatically based on 
sort descriptors?  Does the table column's value binding have Continuously 
Updates Value enabled?  If so and you change that, does the problem go away?

The table view will be the text cell's delegate and will be called for the 
delegate methods described in the NSControlTextEditingDelegate protocol as well 
as those described in NSControl.  Try using a custom subclass of NSTableView 
(if you're not already) and overriding -controlTextDidEndEditing: and 
-control:textShouldEndEditing: to log [NSThread callStackSymbols] and call 
through to super (if the static superclass's instances respond to those 
methods, i.e. [NSTableView instancesRespondToSelector:_cmd]).  The stack trace 
should give you some idea of what's responsible for removing focus from the 
cell.

If the whole table view is losing focus, you could do the same with 
-resignFirstResponder.

Try to reproduce the problem in a new project, adding/changing as little as 
possible to get it to reproduce.  If you can, try sharing that with us.

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


cell-based NSTableView, NSArrayController and first responder

2017-07-12 Thread Martin Hewitson
Dear list,

I have a new bug in an application which I believe has only appeared in 10.12.

I have a cell-based NSTableView backed by an NSArrayController, and the (new) 
problem I have is that the editing of a cell ends after the first keystroke. It 
looks as if first responder is resigned, but I can’t figure out why, and as I 
say, this seems to be new behaviour.

Has anyone else hit this issue and solved it? Or does anyone have any pointers 
where to start digging? I reviewed all the bindings and tableview setup, but I 
haven’t changed anything here in years.

Many thanks,

Martin

___

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: Very slow NSTableView

2017-07-05 Thread Graham Cox

> On 5 Jul 2017, at 7:25 pm, Georg Seifert  wrote:
> 
> Any reason you set the tableview to be "Source List". Set it to regular and 
> it will work perfectly. It seems that the NSPopUpButtonCell don’t like to be 
> in a source list. Maybe you can subclass it and draw yourself?


Interesting… I don’t know why it was set to ‘source list’, in fact the regular 
style doesn’t do transparency/vibrancy so it’s win-win.

However, I’m converting it all to view-based anyway, which also does not seem 
to be hampered by such issues, even when using a pop-up button within a cell 
view.

—Graham


___

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: Very slow NSTableView

2017-07-05 Thread Georg Seifert
Any reason you set the tableview to be "Source List". Set it to regular and it 
will work perfectly. It seems that the NSPopUpButtonCell don’t like to be in a 
source list. Maybe you can subclass it and draw yourself?

Georg

> On 05.07.2017, at 03:36, Graham Cox  wrote:
> 
> 
>> On 5 Jul 2017, at 11:23 am, Graham Cox  wrote:
>> 
>> If anyone can offer a place to host the project, I’d be happy to share it, 
>> and see whether the problem is seen by others. (I no longer have file 
>> hosting services).
> 
> 
> Never mind - I remembered I had an Amazon S3 account.
> 
> http://s3.amazonaws.com/Mapdiva/Source/Test%20Projects/TestTableViewPopups.zip
> 
> 
> —Graham
> ___
> 
> 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/georg.seifert%40gmx.de
> 
> This email sent to georg.seif...@gmx.de

___

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: Very slow NSTableView

2017-07-04 Thread Quincey Morris
On Jul 4, 2017, at 18:23 , Graham Cox  wrote:
> 
> However, as of the latest documentation I can find, cell-based tables are not 
> exactly deprecated. They’re just treated as the embarrassing brother no-one 
> talks about, which is not quite the same thing:

I was basing it on this pages like this:


https://developer.apple.com/documentation/appkit/nstablecolumn/1534251-datacell 


which is the new Xcode 9/macOS 10.13 documentation.

___

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: Very slow NSTableView

2017-07-04 Thread Graham Cox

> On 5 Jul 2017, at 11:23 am, Graham Cox  wrote:
> 
> If anyone can offer a place to host the project, I’d be happy to share it, 
> and see whether the problem is seen by others. (I no longer have file hosting 
> services).


Never mind - I remembered I had an Amazon S3 account.

http://s3.amazonaws.com/Mapdiva/Source/Test%20Projects/TestTableViewPopups.zip


—Graham
___

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: Very slow NSTableView

2017-07-04 Thread Graham Cox

> On 5 Jul 2017, at 5:21 am, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> OTOH, before you go to too much more trouble with this, it seems to me that 
> your next step is to convert to a view-based table view. It’s really not that 
> much work, and cell-based table views were deprecated in 10.10, which is 
> basically 3 years ago.
> 
> If you have to submit a bug report, I think you’ll get a better outcome if 
> you’re not complaining about a long-deprecated feature.


I do take your point, and I’m considering this.

However, as of the latest documentation I can find, cell-based tables are not 
exactly deprecated. They’re just treated as the embarrassing brother no-one 
talks about, which is not quite the same thing:

"NSCell-based tables continue to be supported in OS X v10.7 and later, but 
they’re typically used only to support legacy code. In general, you should use 
NSView-based tables.”

This is legacy code, and a standard no-frills cell-based table is perfectly 
adequate to display it. Until they are officially deprecated, they should still 
perform adequately. I can certainly imagine they get no love inside Apple, but 
that’s all the more reason to suspect that there’s been an oversight in testing 
cell-based drawing with the new transparency effects.

> Again, does the problem disappear if you don’t have any popups in your UI. 
> (The answer was no, not completely, before.) If there’s something going on 
> *besides* the way popups are drawn, you shouldn’t get too fixated on those.
> 

Replacing the pop-ups with a text cell, the problem does disappear, pretty much 
entirely. Previously, without layer backing there was still some sluggishness 
(maybe 10 frames per second when scrolling, versus 1 frame every 2 seconds), 
but with layer backing there are no obvious delays at all. Instruments does not 
show any significant time spent rendering the table view (I can’t even find an 
entry for that, it’s swamped by the main content redraw of my app, which is 
what I would expect).


In any case, I am able to reproduce the problem in a test app that does nothing 
except draw a long cell-based table with pop-ups. If I use text cells, it’s 
fine. Add pop-up cells, it tanks. The stack trace is the same as my app.

7.02 s   86.4%  0 s -[NSTableView 
drawRect:]
7.00 s   86.1%  0 s  -[NSTableView 
drawRowIndexes:clipRect:]
6.99 s   86.0%  0 s   -[NSTableView 
drawRow:clipRect:]
6.94 s   85.3%  0 s    
-[NSTableView _drawContentsAtRow:column:withCellFrame:]
6.68 s   82.2%  1.00 ms 
-[NSPopUpButtonCell drawWithFrame:inView:]


If anyone can offer a place to host the project, I’d be happy to share it, and 
see whether the problem is seen by others. (I no longer have file hosting 
services).


—Graham


___

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: Very slow NSTableView

2017-07-04 Thread Jens Alfke

> On Jul 4, 2017, at 12:00 AM, Graham Cox  wrote:
> 
> Heh, well, I wish I knew.
> Instruments isn’t working. It’s a new machine which I set up from my older 
> machine. XCode works fine, but Instruments doesn’t. I guess that just copying 
> stuff over isn’t enough to install it.

FYI, you don’t need Instruments to do quick and dirty CPU sampling. Just use 
the “sample” tool, or the View>Sample Process command in Activity Monitor.
Activity Monitor produces prettier output, but I find the CLI tool more 
convenient to use — if I need to trigger the behavior by e.g. scrolling, I’ll 
enter “sleep 5; sample MyApp 2” in Terminal, then switch to my app and start 
scrolling until the sampling finishes.

—Jens
___

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: Very slow NSTableView

2017-07-04 Thread Quincey Morris
On Jul 4, 2017, at 05:02 , Graham Cox  wrote:
> 
> But it’s still spending an excruciating amount of time rendering the title of 
> the pop-up button, but most of it is in the mysterious rgba64_DAplusdDA 
> function. This is called twice for each pop-up button rendered, and the time 
> divides fairly evenly between them.

Again, does the problem disappear if you don’t have any popups in your UI. (The 
answer was no, not completely, before.) If there’s something going on *besides* 
the way popups are drawn, you shouldn’t get too fixated on those.

OTOH, before you go to too much more trouble with this, it seems to me that 
your next step is to convert to a view-based table view. It’s really not that 
much work, and cell-based table views were deprecated in 10.10, which is 
basically 3 years ago.

If you have to submit a bug report, I think you’ll get a better outcome if 
you’re not complaining about a long-deprecated feature.

___

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: Very slow NSTableView

2017-07-04 Thread Graham Cox

> On 4 Jul 2017, at 6:02 pm, Graham Cox <graham@bigpond.com> wrote:
> 
> I can live with layer-backing as a solution, it doesn’t appear to have any 
> downsides.


I spoke too soon.

Layer backing disguises the performance issue by capturing the first render 
pass which is then used for scrolling. So scrolling is fast.

But the render pass itself is still really slow. It’s not quite as bad, because 
it only does it once for each new reload of the table view, rather than on 
every scroll change. But it’s still spending an excruciating amount of time 
rendering the title of the pop-up button, but most of it is in the mysterious 
rgba64_DAplusdDA function. This is called twice for each pop-up button 
rendered, and the time divides fairly evenly between them.

It’s a bit hard to post the full stack trace as it’s so deep, but here are the 
two main branches, with much in between them collapsed (every line is meant to 
be indented from the one above, but mail isn’t preserving the formatting at 
all).

24.72 s   78.7% 0 s      -[NSTableView 
drawRect:]
24.55 s   78.1% 0 s       -[NSTableView 
drawRowIndexes:clipRect:]
24.54 s   78.1% 1.00 ms    -[NSTableView 
drawRow:clipRect:]
24.16 s   76.9% 0 s     -[NSTableView 
_drawContentsAtRow:column:withCellFrame:]
22.30 s   70.9% 0 s  
-[NSPopUpButtonCell drawWithFrame:inView:]
10.63 s   33.8% 0 s   
-[NSMenuItemCell drawWithFrame:inView:]
10.45 s   33.2% 1.00 ms
-[NSMenuItemCell drawInteriorWithFrame:inView:]
10.44 s   33.2% 0 s 
-[NSMenuItemCell drawTitleWithFrame:inView:]
10.44 s   33.2% 1.00 ms  
-[NSButtonCell _configureAndDrawTitleWithRect:cellFrame:controlView:]
10.36 s   32.9% 0 s   
drawTitle_withFrame_inView_
10.36 s   32.9% 1.00 ms
-[NSPopUpButtonCell drawTitle:withFrame:inView:]
10.29 s   32.7% 0 s 
_NSStringDrawingCore
10.29 s   32.7% 2.00 ms  
__NSStringDrawingEngine
10.20 s   32.4% 1.00 ms   
-[NSLineFragmentRenderingContext drawAtPoint:inContext:]
10.19 s   32.4% 1.00 ms
-[CUICatalog 
drawGlyphs:atPositions:inContext:withFont:count:stylePresetName:styleConfiguration:foregroundColor:]
10.16 s   32.3% 1.00 ms 
-[CUITextEffectStack 
drawGlyphs:inContext:usingFont:atPositions:count:lineHeight:inBounds:atScale:]
9.71 s   30.9%  0 s  
CGContextEndTransparencyLayer
9.71 s   30.9%  0 s   
ripc_EndLayer
9.70 s   30.8%  0 s
ripc_RenderImage
9.70 s   30.8%  0 s 
RIPLayerBltImage
9.70 s   30.8%  0 s 
 ripl_Mark
9.70 s   30.8%  1.00 ms 
  rgba64_image
9.61 s   30.5%  2.15 s  
   rgba64_mark
7.46 s   23.7%  7.46 s  
rgba64_DAplusdDA



24.72 s   78.7% 0 s      -[NSTableView 
drawRect:]
24.55 s   78.1% 0 s       -[NSTableView 
drawRowIndexes:clipRect:]
24.54 s   78.1% 1.00 ms    -[NSTableView 
drawRow:clipRect:]
24.16 s   76.9% 0 s     -[NSTableView 
_drawContentsAtRow:column:withCellFrame:]
22.30 s   70.9% 0 s  
-[NSPopUpButtonCell drawWithFrame:inView:]
10.63 s   33.8% 0 s   
-[NSMenuItemCell drawWithFrame:inView:]
10.38 s   33.0% 0 s   -[NSCell 
_endVibrantBlendGroup]
10.38 s   33.0% 0 s
CGContextEndTransparencyLayer
10.38 s   33.0% 0 s 
ripc_EndLayer
9.66 s   30.7%  0 s  
ripc_RenderImage
9.66 s   30.7%  1.00 ms   
RIPLayerBltImage
9.66 s   30.7%  0 sripl_Mark
9.66 s   30.7%  0 s 
rgba64_image
9.58

Re: Very slow NSTableView

2017-07-04 Thread Quincey Morris
On Jul 4, 2017, at 01:02 , Graham Cox <graham@bigpond.com> wrote:
> 
>  Is NSTableView documented anywhere to require layer backing?

Not that I know of. A couple of things to keep in mind:

— This thing about the dramatic effect *might* be specific to NSCell-based 
table views (i.e. in a sense they no longer care about the performance of older 
NSTableView drawing configurations). It may be that view-based table views are 
more or less the same regardless of whether the views are layer-backed or not.

— Be careful with layer backing. I ran into a couple of cases (in Xcode 9 beta, 
which may or may not be a relevant factor) where a sort of preferences window 
(with lots of controls in it) had half of its contents simply disappear when to 
top level view was layer backed.

___

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: Very slow NSTableView

2017-07-04 Thread Graham Cox

> On 4 Jul 2017, at 5:39 pm, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jul 4, 2017, at 00:18 , Graham Cox <graham@bigpond.com> wrote:
>> 
>> Is there a way to opt-out of vibrancy for an entire table view?
> 
> There’s no clear indication that the performance problem has anything to do 
> with vibrancy.

True, but the -[NSCell _endVibrantBlendGroup] might suggest it - though it 
seems to just call through to CGContextEndTransparencyLayer, which is where the 
time is spent (my understanding is that CGLayers buffer drawing using a 
temporary bitmap).

So, turning vibrancy on/off in system prefs has no effect.

Next, I subclassed the NSTableView to return NO from -allowsVibrancy. It works 
- no more nasty desktop bleedthrough, but it still scrolls very slowly.


> In both cases, the “expensive” call was about transparency, which could just 
> be about compositing view with transparent backgrounds. I’m wondering if 
> there are views that you can make opaque by specifying solid background 
> colors.

The views this is part of are all opaque - in many cases returning YES from 
-isOpaque on purpose, as well as painting their backgrounds with solid colours.

> Also check whether the table or cell views is marked as “layer backed” (in 
> the last tab of the inspector). I’ve noticed that in recent Xcodes, the top 
> level view of new projects seems to have this checked by default. It may be 
> that your older project *doesn’t* have this set, and it’s important to set it 
> for recent macOS versions, or (conversely) you do have this set and it’s not 
> a good idea.

Aha… that certainly made a difference.

It was not layer-backed, but turning on layer backing for just the top-level 
view that is hosting the scroller+table view does seem to allow it to work 
smoothly.

> 
> OTOH, if the problem is related to vibrancy, compositing or transparency, 
> it’s hard to believe that this could/should slow things down so dramatically. 
> Can you try running the app with the popup menus removed temporarily, and see 
> what difference that makes?  There might be some justification for a bug 
> report.
> 

Removing the pop-up buttons temporarily also speeds things up quite a bit, 
though not as dramatically as the layer backing.

I can live with layer-backing as a solution, it doesn’t appear to have any 
downsides. Obviously code internal to these views is now assuming it’s there. 
Is NSTableView documented anywhere to require layer backing?





___

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: Very slow NSTableView

2017-07-04 Thread Quincey Morris
On Jul 4, 2017, at 00:18 , Graham Cox  wrote:
> 
> Is there a way to opt-out of vibrancy for an entire table view?

There’s no clear indication that the performance problem has anything to do 
with vibrancy. In both cases, the “expensive” call was about transparency, 
which could just be about compositing view with transparent backgrounds. I’m 
wondering if there are views that you can make opaque by specifying solid 
background colors.

Also check whether the table or cell views is marked as “layer backed” (in the 
last tab of the inspector). I’ve noticed that in recent Xcodes, the top level 
view of new projects seems to have this checked by default. It may be that your 
older project *doesn’t* have this set, and it’s important to set it for recent 
macOS versions, or (conversely) you do have this set and it’s not a good idea.

OTOH, if the problem is related to vibrancy, compositing or transparency, it’s 
hard to believe that this could/should slow things down so dramatically. Can 
you try running the app with the popup menus removed temporarily, and see what 
difference that makes?  There might be some justification for a bug report.

___

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: Very slow NSTableView

2017-07-04 Thread Graham Cox

> On 4 Jul 2017, at 5:00 pm, Graham Cox <graham@bigpond.com> wrote:
> 
> 
>> On 4 Jul 2017, at 12:29 pm, Quincey Morris 
>> <quinceymor...@rivergatesoftware.com> wrote:
>> 
>> On Jul 3, 2017, at 18:19 , Graham Cox <graham@bigpond.com> wrote:
>>> 
>>> slow. as. molasses.
>> 
>> What does Instruments say it’s doing?
>> 
> 
> 
> Heh, well, I wish I knew.
> 
> Instruments isn’t working. It’s a new machine which I set up from my older 
> machine. XCode works fine, but Instruments doesn’t. I guess that just copying 
> stuff over isn’t enough to install it.
> 
> I’ll try downloading a new copy of Xcode and see if I can get Instruments 
> working - seems it’s the only way to find out. I just wondered if anyone had 
> seen this and had a quick answer.




OK, I have reinstalled Instruments using XCode 8. Fixed all the new warnings 
and compilation glitches that going from XCode 7 to 8 inevitably causes, and my 
app is running again.

Here’s what instruments says it’s spending all its time doing:

18.47 s   94.0% 0 s   
-[NSTableView drawRowIndexes:clipRect:]
18.47 s   93.9% 0 s    
-[NSTableView drawRow:clipRect:]
18.28 s   93.0% 0 s 
-[NSTableView _drawContentsAtRow:column:withCellFrame:]
17.21 s   87.6% 0 s  
-[NSPopUpButtonCell drawWithFrame:inView:]
7.69 s   39.1%  0 s   
-[NSMenuItemCell drawWithFrame:inView:]
7.51 s   38.2%  1.00 ms
-[NSMenuItemCell drawInteriorWithFrame:inView:]
7.51 s   38.2%  0 s 
-[NSMenuItemCell drawTitleWithFrame:inView:]
7.51 s   38.2%  0 s  
-[NSButtonCell _configureAndDrawTitleWithRect:cellFrame:controlView:]
7.43 s   37.8%  0 s   
drawTitle_withFrame_inView_
7.43 s   37.8%  0 s
-[NSPopUpButtonCell drawTitle:withFrame:inView:]
7.38 s   37.5%  0 s 
_NSStringDrawingCore
7.38 s   37.5%  1.00 ms 
 __NSStringDrawingEngine
7.31 s   37.1%  2.00 ms 
  -[NSLineFragmentRenderingContext drawAtPoint:inContext:]
7.29 s   37.1%  0 s 
   -[CUICatalog 
drawGlyphs:atPositions:inContext:withFont:count:stylePresetName:styleConfiguration:foregroundColor:]
7.26 s   36.9%  0 s 
-[CUITextEffectStack 
drawGlyphs:inContext:usingFont:atPositions:count:lineHeight:inBounds:atScale:]
6.86 s   34.9%  0 s 
 CGContextEndTransparencyLayer


The other 37% of the 87.6% is in:

7.36 s   37.4%  0 s   
-[NSCell _endVibrantBlendGroup]
7.36 s   37.4%  0 s
CGContextEndTransparencyLayer

Every row of my table includes a pop-up button cell, so it seems to be this 
that’s dragging it down, trying to render vibrancy effects. I should mention 
that I have vibrancy turned off in my own System Prefs, but that won’t be the 
case for every user. In any case, it doesn’t seem to stop the renderer trying 
to composite vibrancy effects.

Is there a way to opt-out of vibrancy for an entire table view? There is no way 
this table would benefit from being transparent - it’s just data, and that’s 
what our customers need to work with. It doesn’t need no stinkin’ CPU-sapping 
stupid special effect.

I should also mention this on the very latest i7/RX580 iMac. If this can’t 
render it quickly, what chance has an older machine or laptop got?
___

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: Very slow NSTableView

2017-07-04 Thread Graham Cox

> On 4 Jul 2017, at 12:29 pm, Quincey Morris 
>  wrote:
> 
> On Jul 3, 2017, at 18:19 , Graham Cox  wrote:
>> 
>> slow. as. molasses.
> 
> What does Instruments say it’s doing?
> 


Heh, well, I wish I knew.

Instruments isn’t working. It’s a new machine which I set up from my older 
machine. XCode works fine, but Instruments doesn’t. I guess that just copying 
stuff over isn’t enough to install it.

I’ll try downloading a new copy of Xcode and see if I can get Instruments 
working - seems it’s the only way to find out. I just wondered if anyone had 
seen this and had a quick answer.


___

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: Very slow NSTableView

2017-07-03 Thread Roland King

isn't this what Instruments is supposed to be good at telling you?


On 04/07/2017 11:07, Alex Zavatone wrote:

Stab in the dark, but what is your cell identifier value?

I have seen WAY TOO MUCH CODE where people have created a different cell 
identifier for each cell.

Also, on iOS, there is a method called prepareCellForReuse that might apply 
here.

You can also log when the cell is displayed at the start and the end and see 
where the time suck is happening in an attempt to narrow this down.

GL.

- Alex Zavatone


On Jul 3, 2017, at 8:19 PM, Graham Cox <graham@bigpond.com> wrote:

I have a NSTableView, cell-based (partially because it’s a very long-standing 
piece of code, partially because it is just a table of values which a 
cell-based table is ideally suited to - view-based would not do anything for me 
here).

This table has always worked fine, but in Sierra, it is slow. as. molasses.

It is particularly noticeable when scrolling, which is needed when it has more 
than about 20 items. I get a ‘framerate’ of about 1 every 2 seconds.

I assumed my data source methods were slow, so I tried stubbing them out to see 
if that was indeed the cause, but no - even returning placeholder strings 
doesn’t make any difference.

Has anyone else noticed this in Sierra? What has changed that could make table 
views slow, and how can I restore its normal performance? I’ve turned off 
elasticity and ‘auto content inset’ for the scrollview, which I have noticed to 
cause some performance issues in other views, but it hasn’t helped.

—Graham


___

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/zav%40mac.com

This email sent to z...@mac.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/rols%40rols.org

This email sent to r...@rols.org


___

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: Very slow NSTableView

2017-07-03 Thread Alex Zavatone
Stab in the dark, but what is your cell identifier value?

I have seen WAY TOO MUCH CODE where people have created a different cell 
identifier for each cell.

Also, on iOS, there is a method called prepareCellForReuse that might apply 
here.

You can also log when the cell is displayed at the start and the end and see 
where the time suck is happening in an attempt to narrow this down.

GL.

- Alex Zavatone

> On Jul 3, 2017, at 8:19 PM, Graham Cox <graham@bigpond.com> wrote:
> 
> I have a NSTableView, cell-based (partially because it’s a very long-standing 
> piece of code, partially because it is just a table of values which a 
> cell-based table is ideally suited to - view-based would not do anything for 
> me here).
> 
> This table has always worked fine, but in Sierra, it is slow. as. molasses.
> 
> It is particularly noticeable when scrolling, which is needed when it has 
> more than about 20 items. I get a ‘framerate’ of about 1 every 2 seconds.
> 
> I assumed my data source methods were slow, so I tried stubbing them out to 
> see if that was indeed the cause, but no - even returning placeholder strings 
> doesn’t make any difference.
> 
> Has anyone else noticed this in Sierra? What has changed that could make 
> table views slow, and how can I restore its normal performance? I’ve turned 
> off elasticity and ‘auto content inset’ for the scrollview, which I have 
> noticed to cause some performance issues in other views, but it hasn’t helped.
> 
> —Graham
> 
> 
> ___
> 
> 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/zav%40mac.com
> 
> This email sent to z...@mac.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: Very slow NSTableView

2017-07-03 Thread Quincey Morris
On Jul 3, 2017, at 18:19 , Graham Cox  wrote:
> 
> slow. as. molasses.

What does Instruments say it’s doing?

___

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


Very slow NSTableView

2017-07-03 Thread Graham Cox
I have a NSTableView, cell-based (partially because it’s a very long-standing 
piece of code, partially because it is just a table of values which a 
cell-based table is ideally suited to - view-based would not do anything for me 
here).

This table has always worked fine, but in Sierra, it is slow. as. molasses.

It is particularly noticeable when scrolling, which is needed when it has more 
than about 20 items. I get a ‘framerate’ of about 1 every 2 seconds.

I assumed my data source methods were slow, so I tried stubbing them out to see 
if that was indeed the cause, but no - even returning placeholder strings 
doesn’t make any difference.

Has anyone else noticed this in Sierra? What has changed that could make table 
views slow, and how can I restore its normal performance? I’ve turned off 
elasticity and ‘auto content inset’ for the scrollview, which I have noticed to 
cause some performance issues in other views, but it hasn’t helped.

—Graham


___

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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-07 Thread Quincey Morris
On Apr 7, 2017, at 16:24 , Daryle Walker  wrote:
> 
> I first tried overriding “prepareForReuse” in my text-field subclass, but it 
> never stuck.

It’s never going to be called for that view, because the table view doesn’t 
know anything about it. You have to override it in a NSTextCellView subclass, 
because that what your table cells are.

___

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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-07 Thread Daryle Walker

> On Apr 7, 2017, at 4:43 PM, Quincey Morris 
>  wrote:
> 
> On Apr 7, 2017, at 07:24 , Daryle Walker  > wrote:
>> 
>> Does anyone have any ideas how to do this a runtime? I need to intercept 
>> when a table cell is created so I can either change its font property or set 
>> a font binding.
> 
> Do you implement tableView:viewFor:row: in your delegate? That’s the (well, 
> a) place to configure table cells.

This is what I did, although I was initially nervous because I didn’t want to 
handle cell-view creation. There is another delegate method that notifies you 
of when a view is about to be used for a cell; I overrode that first, but it 
never got called (or at least the “guard” checking if the view was a 
“NSTableCellView” never passed). I also had to change the font in the delegate 
call I already had for row-height calculation.

> Note that if you want to reference subviews of the cell view via outlets, 
> you’ll need to subclass NSTableCellView to add the outlets. Then you can 
> connect them from the cell view prototype in IB to individual UI elements. 
> (The standard outlets “text” and “image” work the same way, but you get them 
> for free on NSTableCellView. )
> 
> Alternatively, if you subclass NSTableCellView, you can override 
> “prepareForReuse”, which would allow you to configure subviews without having 
> to put the code in the delegate method.

I first tried overriding “prepareForReuse” in my text-field subclass, but it 
never stuck.

— 
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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-07 Thread Quincey Morris
On Apr 7, 2017, at 07:24 , Daryle Walker  wrote:
> 
> Does anyone have any ideas how to do this a runtime? I need to intercept when 
> a table cell is created so I can either change its font property or set a 
> font binding.

Do you implement tableView:viewFor:row: in your delegate? That’s the (well, a) 
place to configure table cells.

Note that if you want to reference subviews of the cell view via outlets, 
you’ll need to subclass NSTableCellView to add the outlets. Then you can 
connect them from the cell view prototype in IB to individual UI elements. (The 
standard outlets “text” and “image” work the same way, but you get them for 
free on NSTableCellView. )

Alternatively, if you subclass NSTableCellView, you can override 
“prepareForReuse”, which would allow you to configure subviews without having 
to put the code in the delegate method.

___

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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-07 Thread Daryle Walker

> On Apr 5, 2017, at 5:19 PM, Daryle Walker  wrote:
> 
>> On Apr 5, 2017, at 5:08 PM, Daryle Walker  wrote:
>> 
>>> On Apr 5, 2017, at 12:19 PM, Charles Srstka  
>>> wrote:
>>> 
>>> Actually, while NSTableCellView won’t bind to *most* things outside of the 
>>> table view, there is an exception for the table’s delegate. So, if you set 
>>> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
>>> ‘font’ binding to File’s Owner, it should work.*
>>> 
>>> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck 
>>> in an infinite loop which will continue even after you click the “Stop” 
>>> button, grabbing more and more RAM surreptitiously in the background until 
>>> your Mac runs out of swap space and you’re forced to do a hard reboot. 
>>> Hooray for Xcode!
>> 
>> I am using a storyboard. And this hang upon XIB-compilation is what happens 
>> whenever I try font-binding.
> 
> Hmm, I wonder if I can do this binding at run-time, within the view 
> controller’s “viewDidLoad” or whatever. But I need to get references to each 
> columns’ prototype cell. Can I control-drag from the cell to create an outlet 
> for those?!

You can control-drag from a prototype cell to the source file to create an 
outlet, but IB flags an error soon afterwards, proclaiming the connection to be 
invalid. Makes sense, since I’m connecting a prototype and not actual table 
cells, and the actual cells are too transient for an outlet connection. Does 
anyone have any ideas how to do this a runtime? I need to intercept when a 
table cell is created so I can either change its font property or set a font 
binding. (If we do the latter, we also need to intercept the cell’s destruction 
so I can unbind.)

— 
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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Charles Srstka
> On Apr 5, 2017, at 4:08 PM, Daryle Walker  wrote:
> 
>> 
>> On Apr 5, 2017, at 12:19 PM, Charles Srstka > > wrote:
>> 
>> 
>> Actually, while NSTableCellView won’t bind to *most* things outside of the 
>> table view, there is an exception for the table’s delegate. So, if you set 
>> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
>> ‘font’ binding to File’s Owner, it should work.*
>> 
>> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck in 
>> an infinite loop which will continue even after you click the “Stop” button, 
>> grabbing more and more RAM surreptitiously in the background until your Mac 
>> runs out of swap space and you’re forced to do a hard reboot. Hooray for 
>> Xcode!
> 
> I am using a storyboard. And this hang upon XIB-compilation is what happens 
> whenever I try font-binding.

I filed a radar (rdar://31468797 ), so hopefully this will 
eventually be fixed.

Charles

___

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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Daryle Walker

> On Apr 5, 2017, at 5:08 PM, Daryle Walker  wrote:
> 
> 
>> On Apr 5, 2017, at 12:19 PM, Charles Srstka  wrote:
>> 
>> 
>> Actually, while NSTableCellView won’t bind to *most* things outside of the 
>> table view, there is an exception for the table’s delegate. So, if you set 
>> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
>> ‘font’ binding to File’s Owner, it should work.*
>> 
>> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck in 
>> an infinite loop which will continue even after you click the “Stop” button, 
>> grabbing more and more RAM surreptitiously in the background until your Mac 
>> runs out of swap space and you’re forced to do a hard reboot. Hooray for 
>> Xcode!
> 
> I am using a storyboard. And this hang upon XIB-compilation is what happens 
> whenever I try font-binding.

Hmm, I wonder if I can do this binding at run-time, within the view 
controller’s “viewDidLoad” or whatever. But I need to get references to each 
columns’ prototype cell. Can I control-drag from the cell to create an outlet 
for those?!

— 
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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Daryle Walker

> On Apr 5, 2017, at 12:19 PM, Charles Srstka  wrote:
> 
> 
> Actually, while NSTableCellView won’t bind to *most* things outside of the 
> table view, there is an exception for the table’s delegate. So, if you set 
> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
> ‘font’ binding to File’s Owner, it should work.*
> 
> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck in 
> an infinite loop which will continue even after you click the “Stop” button, 
> grabbing more and more RAM surreptitiously in the background until your Mac 
> runs out of swap space and you’re forced to do a hard reboot. Hooray for 
> Xcode!

I am using a storyboard. And this hang upon XIB-compilation is what happens 
whenever I try font-binding.

— 
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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Charles Srstka
> On Apr 5, 2017, at 8:38 AM, Keary Suska  wrote:
> 
>> 
>> On Apr 4, 2017, at 4:34 PM, Daryle Walker > > wrote:
>> 
>> 
>>> On Apr 4, 2017, at 9:57 AM, Keary Suska >> > wrote:
>>> 
>>> 
 On Apr 3, 2017, at 5:40 PM, Daryle Walker > wrote:
 
 Is there a way to affect the font of a table cell via Bindings? The few 
 times I tried, at the NSTextField level (NSTableCellView does not have any 
 font-related Bindings), resulted in Xcode’s XIB compiler jamming. (I 
 always cancel and take out the change.)
>>> 
>>> Remember that NSTableCellView subviews cannot bind outside of the 
>>> NSTableCellView. The easiest approach is to have the font a property on the 
>>> model object set as NSTableCellView’s objectValue, and bind to that.
>> 
>> My model just stores strings.
> 
> So? Do you have a religious belief against mixing class properties? (Sorry, 
> couldn’t resist ;-) If the issue is persistence, the value would be transient 
> and not stored (as it is stored elsewhere).
> 
>> So, I would have to make a value-transformer that reads the font preference 
>> from the user-defaults and create a attributed-string with the model string 
>> in the desired font?
> 
> You could, but you wouldn’t be able to easily update the UI when the font is 
> changed.

Actually, while NSTableCellView won’t bind to *most* things outside of the 
table view, there is an exception for the table’s delegate. So, if you set the 
table’s delegate to File’s Owner, and then bind the NSTableCellView’s ‘font’ 
binding to File’s Owner, it should work.*

*But only in a XIB file. In a storyboard, the XIB compiler will get stuck in an 
infinite loop which will continue even after you click the “Stop” button, 
grabbing more and more RAM surreptitiously in the background until your Mac 
runs out of swap space and you’re forced to do a hard reboot. Hooray for Xcode!

Charles

___

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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Keary Suska

> On Apr 4, 2017, at 4:34 PM, Daryle Walker  wrote:
> 
> 
>> On Apr 4, 2017, at 9:57 AM, Keary Suska  wrote:
>> 
>> 
>>> On Apr 3, 2017, at 5:40 PM, Daryle Walker  wrote:
>>> 
>>> Is there a way to affect the font of a table cell via Bindings? The few 
>>> times I tried, at the NSTextField level (NSTableCellView does not have any 
>>> font-related Bindings), resulted in Xcode’s XIB compiler jamming. (I always 
>>> cancel and take out the change.)
>> 
>> Remember that NSTableCellView subviews cannot bind outside of the 
>> NSTableCellView. The easiest approach is to have the font a property on the 
>> model object set as NSTableCellView’s objectValue, and bind to that.
> 
> My model just stores strings.

So? Do you have a religious belief against mixing class properties? (Sorry, 
couldn’t resist ;-) If the issue is persistence, the value would be transient 
and not stored (as it is stored elsewhere).

> So, I would have to make a value-transformer that reads the font preference 
> from the user-defaults and create a attributed-string with the model string 
> in the desired font?

You could, but you wouldn’t be able to easily update the UI when the font is 
changed.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

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

What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-04 Thread Daryle Walker
Neither class (directly?) has font controls, so would any related binding 
affect, if anything?

Is there a way to affect the font of a table cell via Bindings? The few times I 
tried, at the NSTextField level (NSTableCellView does not have any font-related 
Bindings), resulted in Xcode’s XIB compiler jamming. (I always cancel and take 
out the change.)

— 
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: NSTableView column sizes

2017-03-17 Thread Daryle Walker
The effect I don’t like about the default code is that when the last column’s 
width is set to fill out the table, it’s only set for the current set of 
widths. As soon as you narrow an earlier column, the last column’s right border 
becomes visible. I want the last column to always max out, no matter how 
earlier columns are resized.

> On Mar 15, 2017, at 4:38 PM, Quincey Morris 
>  wrote:
> 
> On Mar 15, 2017, at 06:51 , Stephane Sudre  > wrote:
>> 
>> the Column Sizing option
> 
> Remember too that each column has its own sizing options that operate in 
> conjunction with the table view’s options. For each column, you can decide 
> whether the column participates in autoresizing (separately from whether it 
> is user resizable), and you can set minimum and maximum widths.
> 
> You can do most reasonable things with these combinations of options, without 
> having to resort to programmatic adjustment.

— 
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: NSTableView column sizes

2017-03-15 Thread Quincey Morris
On Mar 15, 2017, at 06:51 , Stephane Sudre  wrote:
> 
> the Column Sizing option

Remember too that each column has its own sizing options that operate in 
conjunction with the table view’s options. For each column, you can decide 
whether the column participates in autoresizing (separately from whether it is 
user resizable), and you can set minimum and maximum widths.

You can do most reasonable things with these combinations of options, without 
having to resort to programmatic adjustment.

___

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: NSTableView column sizes

2017-03-15 Thread Stephane Sudre
On Wed, Mar 15, 2017 at 9:59 AM, Daryle Walker  wrote:
> 1. Is there a way to make the last (right in the U.S. localization) column to 
> always be at the end of the table-view, instead of a gap after a resize?

Yes, there is.

> 2. My table has two columns. Is there a way to keep their sizes in proportion 
> after a window resize? (If the divider is moved, resizes will follow the new 
> proportions.)

Yes, there is.

In both cases, if you are not happy with the Column Sizing option
(respectively Last Column Only and Uniform), you can always enumerate
the columns of the table view and set their width as you like (by
registering for the NSViewFrameDidChangeNotification notification of
the appropriate view). You need to take into account the
intercellSpacing.
___

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: NSTableView column sizes

2017-03-15 Thread Steve Mills
On Mar 15, 2017, at 03:59:43, Daryle Walker  wrote:
> 
> 1. Is there a way to make the last (right in the U.S. localization) column to 
> always be at the end of the table-view, instead of a gap after a resize?
> 
> 2. My table has two columns. Is there a way to keep their sizes in proportion 
> after a window resize? (If the divider is moved, resizes will follow the new 
> proportions.)

Setting the Column Sizing to Uniform doesn't help with both of those? If not, 
use a delegate and see what you can do in tableViewColumnDidResize:. You'll 
probably need to prevent infinite recursion with a simple flag in case that 
notification is sent when columns are resized programmatically as well as by 
the user.

--
Steve Mills
Drummer, Mac geek


___

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


NSTableView column sizes

2017-03-15 Thread Daryle Walker
1. Is there a way to make the last (right in the U.S. localization) column to 
always be at the end of the table-view, instead of a gap after a resize?

2. My table has two columns. Is there a way to keep their sizes in proportion 
after a window resize? (If the divider is moved, resizes will follow the new 
proportions.)

— 
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: Is it possible to set an NSTableView cell background color?

2017-02-23 Thread David Delmonte
I worked the problem. I’m rather rusty these days.

This is what I came up with:

1. Moved to view-based table view.

2. In viewForRow, I added this line:

 cell.memoryName.drawsBackground = true

3. And then:

 cell.memoryName.backgroundColor = mintGreen

Thanks to all for the pointers.


> On Feb 23, 2017, at 5:11 PM, corbin dunn  wrote:
> 
> 
>> On Feb 22, 2017, at 6:27 PM, David Delmonte  wrote:
>> 
>> I tried you solution but it doesn’t color the cell. Scratching my head some 
>> more.. I’ll probably ask on Stack Overflow.
> 
> How did you get it to compile?  It requires a view based tableview. Your 
> first step is to convert to a view based tableview.
> 
> corbin
> 
>> 
>> 
>>> On Feb 22, 2017, at 8:37 PM, Saagar Jha  wrote:
>>> 
>>> Well, assuming you have a NSTableCellView, you can set its background color 
>>> using its layer. For example:
>>> 
>>> cell.layer.backgroundColor = NSColor.black.cgColor
>>> 
>>> Saagar Jha
>>> 
 On Feb 22, 2017, at 16:14, David Delmonte > wrote:
 
 Hi all, I have a table that has records by date. I want to color those 
 entries based on the decade.
 
 I cannot seem to find a way to do this.
 
 Any help would be appreciated.
 
 David
 ___
> 

___

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: Is it possible to set an NSTableView cell background color?

2017-02-23 Thread corbin dunn

> On Feb 22, 2017, at 6:27 PM, David Delmonte  wrote:
> 
> I tried you solution but it doesn’t color the cell. Scratching my head some 
> more.. I’ll probably ask on Stack Overflow.

How did you get it to compile?  It requires a view based tableview. Your first 
step is to convert to a view based tableview.

corbin

> 
> 
>> On Feb 22, 2017, at 8:37 PM, Saagar Jha  wrote:
>> 
>> Well, assuming you have a NSTableCellView, you can set its background color 
>> using its layer. For example:
>> 
>> cell.layer.backgroundColor = NSColor.black.cgColor
>> 
>> Saagar Jha
>> 
>>> On Feb 22, 2017, at 16:14, David Delmonte >> > wrote:
>>> 
>>> Hi all, I have a table that has records by date. I want to color those 
>>> entries based on the decade.
>>> 
>>> I cannot seem to find a way to do this.
>>> 
>>> Any help would be appreciated.
>>> 
>>> David
>>> ___


___

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: Is it possible to set an NSTableView cell background color?

2017-02-22 Thread Quincey Morris
On Feb 22, 2017, at 17:45 , David Delmonte  wrote:
> 
> It's cell based!

In that case, you need to implement the delegate method 
"tableView(_:willDisplayCell:for:row:)”, which is called once for each cell 
that’s redrawn.

In your method, you need to verify that the cell is of the type you expect (a 
NSTextFieldCell, I’m guessing), cast it to the correct type, and then set its 
backgroundColor property. Note that NSCell does not itself have such a 
property, it’s only implemented by specific subclasses.

Alternatively, it is possible to prepare one cell per color at initialization, 
then supply the correctly colored cell at each row/column. This is slightly 
more efficient, because it doesn’t involve re-configuring the cell each time 
it’s used, but it’s a bit more code (also in the delegate).




___

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: Is it possible to set an NSTableView cell background color?

2017-02-22 Thread David Delmonte
I tried you solution but it doesn’t color the cell. Scratching my head some 
more.. I’ll probably ask on Stack Overflow.


> On Feb 22, 2017, at 8:37 PM, Saagar Jha  wrote:
> 
> Well, assuming you have a NSTableCellView, you can set its background color 
> using its layer. For example:
> 
> cell.layer.backgroundColor = NSColor.black.cgColor
> 
> Saagar Jha
> 
>> On Feb 22, 2017, at 16:14, David Delmonte > > wrote:
>> 
>> Hi all, I have a table that has records by date. I want to color those 
>> entries based on the decade.
>> 
>> I cannot seem to find a way to do this.
>> 
>> Any help would be appreciated.
>> 
>> David
>> ___
>> 
>> 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

Re: Is it possible to set an NSTableView cell background color?

2017-02-22 Thread David Delmonte
It's cell based!

> On Feb 22, 2017, at 20:38, Quincey Morris 
>  wrote:
> 
>> On Feb 22, 2017, at 16:14 , David Delmonte  wrote:
>> 
>> I have a table that has records by date. I want to color those entries based 
>> on the decade.
> 
> NSCell-based or NSView-based?
> 
___

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: Is it possible to set an NSTableView cell background color?

2017-02-22 Thread Quincey Morris
On Feb 22, 2017, at 16:14 , David Delmonte  wrote:
> 
> I have a table that has records by date. I want to color those entries based 
> on the decade.

NSCell-based or NSView-based?

___

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: Is it possible to set an NSTableView cell background color?

2017-02-22 Thread Saagar Jha
Well, assuming you have a NSTableCellView, you can set its background color 
using its layer. For example:

cell.layer.backgroundColor = NSColor.black.cgColor

Saagar Jha

> On Feb 22, 2017, at 16:14, David Delmonte  wrote:
> 
> Hi all, I have a table that has records by date. I want to color those 
> entries based on the decade.
> 
> I cannot seem to find a way to do this.
> 
> Any help would be appreciated.
> 
> David
> ___
> 
> 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


Is it possible to set an NSTableView cell background color?

2017-02-22 Thread David Delmonte
Hi all, I have a table that has records by date. I want to color those entries 
based on the decade.

I cannot seem to find a way to do this.

Any help would be appreciated.

David
___

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: View based NSTableView bounds to NSArrayController bounds to NSUserDefaultsController

2017-02-06 Thread Steve Mills

On Feb 06, 2017, at 02:37 PM, Ken Thomases  wrote:

What is your cell view? An NSTableCellView with an NSTextField as a descendant 
view? An NSTextField directly?

The default you get when you create a new table, NSTableCellView containing an 
NSTextField, which contains an NSTextFieldCell (and the default NSTextFieldCell 
as a sibling to the NSTextField).
 
Are you also using bindings for the text field's value? How is that binding 
configured?

Yes, the NSTextField's Value is bound to Table Cell View using Model Key Path 
objectValue.EmailAddress. These are on:
Allows Editing Multiple Values Selection
Conditionally Sets Editable
Raises for Not Applicable Keys

Going up the chain, the column has no bindings set. The table's Content is 
bound to an Array Controller, Controller Key arrangedObjects.

That Array Controller's Content Array is bound to Shared User Defaults 
Controller, Controller Key values, Model Key Path EUGEmailAddresses (an array 
of dicts), Mode Class, Class Name NSMutableDictionary, Prepares Content, 
Editable, a single Key named EmailAddress.

Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
___

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: View based NSTableView bounds to NSArrayController bounds to NSUserDefaultsController

2017-02-06 Thread Ken Thomases
On Feb 6, 2017, at 8:43 AM, Steve Mills  wrote:
> 
> The problem is that when I edit values in the table, they only seem to get 
> written to the defaults if I add a new item after editing an existing item.
> 
> 1. Run app.
> 2. Edit existing row value.
> 3. Add new row and edit it.
> Result: Edited row is changed, new row has only default value instead of 
> edited value.
> 
> Any ideas?

What is your cell view?  An NSTableCellView with an NSTextField as a descendant 
view?  An NSTextField directly?

Are you also using bindings for the text field's value?  How is that binding 
configured?

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: View based NSTableView bounds to NSArrayController bounds to NSUserDefaultsController

2017-02-06 Thread Steve Mills

On Feb 06, 2017, at 10:30 AM, Keary Suska  wrote:

Warning: the following explanation assumes a scenario that you don’t explicitly 
describe, namely that you are editing an array-type defaults value.

This is a known “issue”, if you want to call it that. As I understand it, the 
problem is that NSUserDefaultsController cannot "deep-observe” array-type 
defaults. I.e., it can watch the array itself for changes but not individual array 
elements because there is no clear key path to a specific array element. That is why 
you see changes when you alter the array itself (by adding/removing array elements), 
but not changes to the values of individual array elements. So, this is a limitation 
to the implementation of KVC/KVO, rather than any specific issue with 
NSUserDefaultsController.

The only way to handle this situation, IMHO, is to have some intermediary or 
user-driven event (like a “commit” button) that “tricks” the defaults 
controller into thinking the entire array has changed when you need to it see 
changes to individual elements.

I don't think that's the issue. We have other tables that are able to change 
existing values within arrays in prefs, although they are cell based instead of 
view based.

To aid debugging, I've connected an action method to the NSTextField used in 
the NSTableCellView to be called when editing is ended. If I log the pref at 
that time, it's still the old value. So the field editor is not even writing 
the new value to the prefs.

The only way I've been able to make this work is by handling 
controlTextDidEndEditing: in the table's delegate and manually setting the 
value in prefs, even though the value is coming from the 
arrayController.content, which is what's bound to the pref in the first place.

Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
___

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: View based NSTableView bounds to NSArrayController bounds to NSUserDefaultsController

2017-02-06 Thread Keary Suska

> On Feb 6, 2017, at 7:43 AM, Steve Mills  wrote:
> 
> (Has cocoa-dev been down for days or what?)
> 
> Why is it that most times when I implement a table, it can waste hours of my 
> time?
> 
> So I think I have everything set up like it should be. I'll just jump right 
> to the bug and then we can work back. The problem is that when I edit values 
> in the table, they only seem to get written to the defaults if I add a new 
> item after editing an existing item.
> 
> 1. Run app.
> 2. Edit existing row value.
> 3. Add new row and edit it.
> Result: Edited row is changed, new row has only default value instead of 
> edited value.
> 
> Any ideas?

Warning: the following explanation assumes a scenario that you don’t explicitly 
describe, namely that you are editing an array-type defaults value.

This is a known “issue”, if you want to call it that. As I understand it, the 
problem is that NSUserDefaultsController cannot "deep-observe” array-type 
defaults. I.e., it can watch the array itself for changes but not individual 
array elements because there is no clear key path to a specific array element. 
That is why you see changes when you alter the array itself (by adding/removing 
array elements), but not changes to the values of individual array elements. 
So, this is a limitation to the implementation of KVC/KVO, rather than any 
specific issue with NSUserDefaultsController.

The only way to handle this situation, IMHO, is to have some intermediary or 
user-driven event (like a “commit” button) that “tricks” the defaults 
controller into thinking the entire array has changed when you need to it see 
changes to individual elements.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

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

View based NSTableView bounds to NSArrayController bounds to NSUserDefaultsController

2017-02-06 Thread Steve Mills
(Has cocoa-dev been down for days or what?)

Why is it that most times when I implement a table, it can waste hours of my 
time?

So I think I have everything set up like it should be. I'll just jump right to 
the bug and then we can work back. The problem is that when I edit values in 
the table, they only seem to get written to the defaults if I add a new item 
after editing an existing item.

1. Run app.
2. Edit existing row value.
3. Add new row and edit it.
Result: Edited row is changed, new row has only default value instead of edited 
value.

Any ideas?

Sent from iCloud's ridiculous UI, so, sorry about the formatting
___

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: Success with NSTableView weak delegates?

2016-09-20 Thread Sean McBride
On Tue, 20 Sep 2016 16:41:07 -0700, Greg Parker said:

>Those crashes are expected. 
>
>NSTableView's delegate is zeroing-weak when both of the following are true:
>* Your app was built with the 10.11 SDK or newer.
>* Your app is running on 10.12 or newer.
>
>The delegate is unsafe-unretained when running on 10.11 and earlier, no
>matter what SDK you built with.

Ah ha, thanks!  That WWDC video is quite misleading then.  I was about to 
lament the lack of any better docs, but now realize that it's actually nicely 
documented here in the 10.12 release notes:


So sorry for the noise!

Thanks David & Greg!

Cheers,

-- 

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com 
Mac Software Developer  Montréal, Québec, Canada



___

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: Success with NSTableView weak delegates?

2016-09-20 Thread Greg Parker

> On Sep 20, 2016, at 2:47 PM, Sean McBride  wrote:
> 
> On Tue, 20 Sep 2016 14:26:27 -0700, David Duncan said:
> 
>>> On Sep 20, 2016, at 1:21 PM, Sean McBride  wrote:
>>> 
>>> Hi all,
>>> 
>>> WWDC 2016 Session 203 "What's New in Cocoa" at around 43:37 in the
>>> video, says that if you link against the 10.11 SDK that NSTableView's
>>> delegate is weak.  So I went and wrapped my delegate nil-ing in:
>>> 
>>> #if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
>>> [tableView setDelegate:nil];
>>> [tableView setDataSource:nil];
>>> #endif
>>> 
>>> yet (with NSZombie especially), I easily reproduce message-to-zombie
>>> crashes with builds that are made against the Xcode 7.3.1 10.11 SDK.
>> 
>> On which OS version?
> 
> At runtime: 10.9.5, 10.10.5, and 10.11.6.
> 
>> The macro above only says “do this if I link against an SDK prior to
>> 10.11” – that doesn’t handle what happens at runtime when you are on
>> 10.10 or below. In particular, if you plan to deploy back to prior to
>> 10.11, then you would want to either do a runtime check, or for trivial
>> code like this always run the code until your MIN_ALLOWED (deployment
>> target) is >= 10.11.
> 
> Yes, I'm aware of these differences.  I'm also aware, as you surely are, that 
> sometimes behaviour depends (only) on what SDK you link against.
> 
> If you scrub to around 43:37 here:
> 
> 
> you'll see they specifically refer to "linked on 10.11".
> 
> Besides, I both build and run on 10.11.6 and yet I see these 
> message-to-zombie crashes after removing the setDelegate:nil code.

Those crashes are expected. 

NSTableView's delegate is zeroing-weak when both of the following are true:
* Your app was built with the 10.11 SDK or newer.
* Your app is running on 10.12 or newer.

The delegate is unsafe-unretained when running on 10.11 and earlier, no matter 
what SDK you built with.


-- 
Greg Parker gpar...@apple.com  Runtime 
Wrangler


___

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: Success with NSTableView weak delegates?

2016-09-20 Thread David Duncan

> On Sep 20, 2016, at 2:47 PM, Sean McBride  wrote:
> 
> On Tue, 20 Sep 2016 14:26:27 -0700, David Duncan said:
> 
>>> On Sep 20, 2016, at 1:21 PM, Sean McBride  wrote:
>>> 
>>> Hi all,
>>> 
>>> WWDC 2016 Session 203 "What's New in Cocoa" at around 43:37 in the
>> video, says that if you link against the 10.11 SDK that NSTableView's
>> delegate is weak.  So I went and wrapped my delegate nil-ing in:
>>> 
>>> #if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
>>> [tableView setDelegate:nil];
>>> [tableView setDataSource:nil];
>>> #endif
>>> 
>>> yet (with NSZombie especially), I easily reproduce message-to-zombie
>> crashes with builds that are made against the Xcode 7.3.1 10.11 SDK.
>> 
>> On which OS version?
> 
> At runtime: 10.9.5, 10.10.5, and 10.11.6.
> 
>> The macro above only says “do this if I link against an SDK prior to
>> 10.11” – that doesn’t handle what happens at runtime when you are on
>> 10.10 or below. In particular, if you plan to deploy back to prior to
>> 10.11, then you would want to either do a runtime check, or for trivial
>> code like this always run the code until your MIN_ALLOWED (deployment
>> target) is >= 10.11.
> 
> Yes, I'm aware of these differences.  I'm also aware, as you surely are, that 
> sometimes behaviour depends (only) on what SDK you link against.

Sure, but that generally only applies to that OS or later, as we cannot 
generally change the behavior of older OSes (there are specific recent 
exceptions to that, but they are typically fairly low level and targeted). I 
don’t think the speaker here was trying to imply that this feature was 
available prior to 10.11.

> Besides, I both build and run on 10.11.6 and yet I see these 
> message-to-zombie crashes after removing the setDelegate:nil code.

Thats pretty much what I was trying to verify, and so this sounds like this is 
a bug somewhere. I would highly recommend filing it.
--
David Duncan

___

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: Success with NSTableView weak delegates?

2016-09-20 Thread Sean McBride
On Tue, 20 Sep 2016 14:26:27 -0700, David Duncan said:

>> On Sep 20, 2016, at 1:21 PM, Sean McBride  wrote:
>> 
>> Hi all,
>> 
>> WWDC 2016 Session 203 "What's New in Cocoa" at around 43:37 in the
>video, says that if you link against the 10.11 SDK that NSTableView's
>delegate is weak.  So I went and wrapped my delegate nil-ing in:
>> 
>> #if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
>>  [tableView setDelegate:nil];
>>  [tableView setDataSource:nil];
>> #endif
>> 
>> yet (with NSZombie especially), I easily reproduce message-to-zombie
>crashes with builds that are made against the Xcode 7.3.1 10.11 SDK.
>
>On which OS version?

At runtime: 10.9.5, 10.10.5, and 10.11.6.

>The macro above only says “do this if I link against an SDK prior to
>10.11” – that doesn’t handle what happens at runtime when you are on
>10.10 or below. In particular, if you plan to deploy back to prior to
>10.11, then you would want to either do a runtime check, or for trivial
>code like this always run the code until your MIN_ALLOWED (deployment
>target) is >= 10.11.

Yes, I'm aware of these differences.  I'm also aware, as you surely are, that 
sometimes behaviour depends (only) on what SDK you link against.

If you scrub to around 43:37 here:


you'll see they specifically refer to "linked on 10.11".

Besides, I both build and run on 10.11.6 and yet I see these message-to-zombie 
crashes after removing the setDelegate:nil code.

Cheers,

-- 

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com 
Mac Software Developer  Montréal, Québec, Canada

___

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: Success with NSTableView weak delegates?

2016-09-20 Thread David Duncan

> On Sep 20, 2016, at 1:21 PM, Sean McBride  wrote:
> 
> Hi all,
> 
> WWDC 2016 Session 203 "What's New in Cocoa" at around 43:37 in the video, 
> says that if you link against the 10.11 SDK that NSTableView's delegate is 
> weak.  So I went and wrapped my delegate nil-ing in:
> 
> #if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
>   [tableView setDelegate:nil];
>   [tableView setDataSource:nil];
> #endif
> 
> yet (with NSZombie especially), I easily reproduce message-to-zombie crashes 
> with builds that are made against the Xcode 7.3.1 10.11 SDK.

On which OS version?

The macro above only says “do this if I link against an SDK prior to 10.11” – 
that doesn’t handle what happens at runtime when you are on 10.10 or below. In 
particular, if you plan to deploy back to prior to 10.11, then you would want 
to either do a runtime check, or for trivial code like this always run the code 
until your MIN_ALLOWED (deployment target) is >= 10.11.

> 
> Anyone have success with these supposedly weak tableview delegates?
> 
> Thanks,
> 
> -- 
> 
> Sean McBride, B. Eng s...@rogue-research.com
> Rogue Researchwww.rogue-research.com 
> Mac Software Developer  Montréal, Québec, Canada
> 
> 
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

  1   2   3   4   5   6   7   8   9   10   >