NSPathControl ClickedPathItem Doesn't Work

MacOS, 10.15, Objective C.

I'm trying to update a functioning linear NSPathControl to not using deprecated cells. Simply replacing NSPathComponentCell by NSPathControlItem displays properly, but clickedPathItem doesn't work, aparantly because of the copy property. I need the index in the path array, so I tried indexOfObject using the clickedPathItem object and the pathItems array. No go. You can see why by looking at the following:

- (IBAction)pathControlSingleClick:(id)sender {

NSPathControlItem *pcc = [self.pathControl clickedPathItem];

if(pcc == nil)

return; // Path Control clicked, but nobody is home.

NSArray *items = self.pathControl.pathItems;

if(items == nil || [items count] == 0)

return; // Double CYA.

NSUInteger clickedIndex = [items indexOfObject:pcc];


[self.sftpManager.pathArray shortenToLength:clickedIndex];

[self updataPathComponentArray];

[self updateListing];

}


selfRTPServerUploadWindowController *0x1006100b00x00000001006100b0
pccNSPathControlItem *0x6000000268400x0000600000026840
NSObjectNSObject
_secretCellNSPathComponentCell *0x600003303de00x0000600003303de0
cells__NSArrayM *@"3 elements"0x0000600000cf0810
[0]NSPathControlItem *0x6000000269d00x00006000000269d0
NSObjectNSObject
_secretCellNSPathComponentCell *0x6000033020800x0000600003302080
[1]NSPathControlItem *0x600000026f300x0000600000026f30
NSObjectNSObject
_secretCellNSPathComponentCell *0x600003303de00x0000600003303de0
[2]NSPathControlItem *0x600000025ca00x0000600000025ca0
NSObjectNSObject
_secretCellNSPathComponentCell *0x600003303b600x0000600003303b60
clickedIndexNSUInteger9223372036854775807


The secretCells in the array do contain a matching item, but the NSPathControlIem objects do not. Any suggestions for a workaround? Bug report time?


Addendun: I tried asking for the URL of clickedPathItem, but got nil;

Bug Report: FB7484074


Went back to cells for now. Work fine again.

Sorry, but I have problem understanding exactly the question.


What do you mean 'deprecated' cells ? And secretCells.


Could you explain the logic behing and what you try ?

Documentation and compiler warnings flag cells as deprecated for NSPathControl and say to use the "item" methods instead.


Putting a breakpoint near the end of the above code allows expanding local variables to display the contained "_secretCell" for each "item" as shown in the table. My theory is that the "copy" attribute on the item properties gives you items that are useless in determining the array index of the item that was clicked, because none of them match the "clickedPathItem" returned. However, if you look at the "_secretCell" for clickedPathItem, it does match the clicked _secretCell" in the pathItems array. But you don't have programatic access to the secretCells.


A. better solution might be to just return the index of the clicked item.


"Someone might say "just match the titles". That doesn't work, because paths can contain duplicates. Maybe instead of "indexOfObject" in the array, we might be able to write a routine to match a binary equivalent.

This is how I do it and I'm not having any issues, but I'm using double action, not a single action:


-(IBAction)pathControlDoubleClickAction:(NSPathControl*)sender
{
    NSPathControlItem *clickedItem = sender.clickedPathItem;
    NSArray <NSPathControlItem*>*pathItems = sender.pathItems;
    NSURL *clickedURL = clickedItem.URL.filePathURL.URLWithTrailingSlash; //<--Assumes directory, but that may not be the case for your app.
    if (clickedURL == nil)
    {
        return;
   }
      NSURL *lastPathItemURL = pathItems.lastObject.URL.filePathURL.URLWithTrailingSlash;

if ([clickedURL isEqual:lastPathItemURL])
    {
         //Ignore double action if last path item is clicked (may not be what you want in your app).
         return;
     }


    [self _doUpdateUIWithURL:clickedURL];
}

Well I'm back, and this bug has never been fixed in Objective C, and I'm pretty sure it also persists in Swift. The problem is that clickedPathItem is readonly and returns a reference to the clicked item, but pathItems is "copy" and does not contain the clicked item. Copies likely also copy the enclosed secretCells. Both indexOfObject: and indexOfObjectIdenticalTo: return NSNotFound and are therefore useless. While I could try to find the index by comparing titles, that is also useless because URL paths can contain multiple titles that are identical. So far, I have not come up with a workaround. I'm trying to get rid of compiler complaints about using deprecated cells.

NSPathControl ClickedPathItem Doesn't Work
 
 
Q