Re: NSPathControl (popup) - programatically show Choose dialog
Re: NSPathControl (popup) - programatically show Choose dialog
- Subject: Re: NSPathControl (popup) - programatically show Choose dialog
- From: Jonathan Taylor <email@hidden>
- Date: Tue, 17 Mar 2015 10:16:36 +0000
OK, I've got part of the way to a solution, but haven't got it fully working yet. Perhaps the weekday crowd here can advise?
I've realised that I can get my path control to performClick:
// When adding a new sequence we immediately prompt the user to select a folder to use for image files
simulatingPathControlClick = true;
[folderSelectPopup performClick:self];
simulatingPathControlClick = false;
This is a good start, because I see my delegate function being called:
-(void)pathControl:(NSPathControl*)pathControl willPopUpMenu:(NSMenu*)menu
{
if (simulatingPathControlClick)
{
[menu performActionForItemAtIndex:0];
}
}
This seems to be the only way of getting access to the menu (folderSelectPopup.menu always seems to return nil...). Now that I have access to the menu I can get it to performActionForItemAtIndex. That is basically what I'm trying to do here. However it doesn't quite work as it should. The code as written here brings up the Open dialog, which works as intended, but I am calling it sooner than I should (in willPopUpMenu; the menu has not yet popped up!). As a result, after the user dismisses the Open dialog, THEN the "choose" menu on the path control pops up, which is annoying and illogical for the user.
If alternatively I wrap the performClick in a dispatch_async on the main thread (i.e. it should execute after the menu pops up) then something weird happens - the menu appears and then the Open dialog pops up (as I had hoped), but no file system items appear in there. I have a suspicion this has something to do with funny run-loop states when tracking menus, but I don't know what to do about it!
I don't know if what I am trying to do is an appropriate way of going about things, but hopefully it gives a clearer idea of what I am trying to achieve here (bring up the Open dialog, just as if the user had selected "Choose..." themselves). And hopefully somebody can suggest how I should tweak what I am doing so it behaves correctly?
Thanks again
Jonny
On 15 Mar 2015, at 13:18, Jonathan Taylor <email@hidden> wrote:
> I have a dialog which allows the user to select a folder containing data to be processed, set various parameters that affect the processing, and displays the result of the analysis. There is an NSPathControl (popup) to select the folder. Inevitably the first thing the user does is choose a folder (and of course they have the option of changing this later). I would like to simplify the workflow by automatically popping up the "open" dialog when the main dialog is first opened, as if the user has clicked on the path popup and selected "choose". However, I can't work out an obvious way of triggering the path control to behave as if the user has manually selected "choose" from the popup.
>
> Is there a way I can do that? I could of course throw up my own "open" dialog and programatically set the URL associated with the path control, but that seems like unnecessary duplication of code when I could just call something like [myPathControl displayChooseDialog] (if such a method existed!).
>
> Can anyone suggest a way of doing what I want here?
>
> Thanks for any suggestions
> Jonny
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden