Re: Open a panel in secondary thread?

2020-03-24 Thread Dave via Cocoa-dev
Hi,

You may want to call performSelectorOnMainThread and pass YES as the wait until 
done flag.

Cheer
Dave



> On 21 Mar 2020, at 20:05, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Is it possible to open an NSOpenPanel in a secondary thread?
> 
> I create the thread like this:
> 
>directoryScanThread_ = [[NSThread alloc] initWithTarget: self
>   selector: 
> @selector(scanDirectory:)
> object: nil];
>[directoryScanThread_ start];
> 
> 
> But when I do:
> 
>NSOpenPanel *oPanel = [NSOpenPanel openPanel];
> 
> it crashes at this point.
> 
> In the docs, I found a hint that one should use
> 
>lockFocusIfCanDraw
> 
> but that is deprecated now.
> 
> Any ideas will be highly appreciated.
> 
> 
> Best regards, Gabriel
> 
> 
> ___
> 
> 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/dave%40looktowindward.com
> 
> This email sent to d...@looktowindward.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: Open a panel in secondary thread?

2020-03-23 Thread Glenn L. Austin via Cocoa-dev
Correct.

main_queue will *always* be on the main thread, but the main thread may be 
running a different queue at any specific point in time.

So, if you're *not* on the main thread, throwing code over to the main queue to 
execute will guarantee that it's on the main thread - but not vice-versa.

> On Mar 23, 2020, at 8:25 AM, Alex Zavatone via Cocoa-dev 
>  wrote:
> 
> Main queue is analogous to the main thread, but not exactly the same - 
> according to Apple’s docs.
> 
> Sent from my iPhone
> 
>> On Mar 23, 2020, at 12:53 PM, Gabriel Zachmann via Cocoa-dev 
>>  wrote:
>> 
>> Thanks a lot for your response.
>> 
>>> I would not do this.  It is widely documented that AppKit API that produce 
>>> UI elements, like NSOpenPanel, are _not_ thread safe.  
>> 
>> Right, and that is why I have to execute any UI code in the main thread,
>> or so I thought.
>> As far as I understand, the dispatch_get_main_queue is executed by the main 
>> thread, isn't it?
>> 
>> 
>>> So you may find your app hitting some memory stomping issues or strange 
>>> crashes/exceptions due to this.  Specifically what problems you will hit 
>>> are anyones guess, but its just a matter of time.  There is a reason Xcode 
>>> has the Main Thread Checker to catch UI elements being used on secondary 
>>> threads.
>>> 
>>> Lets come at  this from a different direction: What are you trying to do? 
>>> Why do you think you need to use the open panel on a secondary thread?
>> 
>> When the user selects a directory, I collect all files in that sub-tree (aka 
>> "scan").
>> That might involve aliases. which means I need to ask the user to open the 
>> directory that alias points to.
>> Because that scan can take several seconds (10-20),
>> I wanted to do that scan in a secondary thread so that it can update 
>> progress info in the UI.
>> 
>> Best regards, Gabriel
>> 
>> ___
>> 
>> 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/glenn%40austinsoft.com
> 
> This email sent to gl...@austinsoft.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: Open a panel in secondary thread?

2020-03-23 Thread Alex Zavatone via Cocoa-dev
Main queue is analogous to the main thread, but not exactly the same - 
according to Apple’s docs.

Sent from my iPhone

> On Mar 23, 2020, at 12:53 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Thanks a lot for your response.
> 
>> I would not do this.  It is widely documented that AppKit API that produce 
>> UI elements, like NSOpenPanel, are _not_ thread safe.  
> 
> Right, and that is why I have to execute any UI code in the main thread,
> or so I thought.
> As far as I understand, the dispatch_get_main_queue is executed by the main 
> thread, isn't it?
> 
> 
>> So you may find your app hitting some memory stomping issues or strange 
>> crashes/exceptions due to this.  Specifically what problems you will hit are 
>> anyones guess, but its just a matter of time.  There is a reason Xcode has 
>> the Main Thread Checker to catch UI elements being used on secondary threads.
>> 
>> Lets come at  this from a different direction: What are you trying to do? 
>> Why do you think you need to use the open panel on a secondary thread?
> 
> When the user selects a directory, I collect all files in that sub-tree (aka 
> "scan").
> That might involve aliases. which means I need to ask the user to open the 
> directory that alias points to.
> Because that scan can take several seconds (10-20),
> I wanted to do that scan in a secondary thread so that it can update progress 
> info in the UI.
> 
> Best regards, Gabriel
> 
> ___
> 
> 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: Open a panel in secondary thread?

2020-03-23 Thread Gabriel Zachmann via Cocoa-dev
> 
> Yes, understood.  Does the user have to ask for this process to begin, or 
> does it start automatically?

The user starts the process by opening a directory.
Then, when the process hits an alias pointing to some other directory, the 
process will ask the user again to open that directory.
So, it is fine if the process stops while asking.

> Is the user allowed to interact with the app while this is going on,

No.



Best regards, Gabriel


___

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: Open a panel in secondary thread?

2020-03-23 Thread Sandor Szatmari via Cocoa-dev

> On Mar 23, 2020, at 10:01 AM, Gabriel Zachmann  wrote:
> 
> 
 I would not do this.  It is widely documented that AppKit API that produce 
 UI elements, like NSOpenPanel, are _not_ thread safe.  
>>> 
>>> Right, and that is why I have to execute any UI code in the main thread,
>>> or so I thought.
>>> As far as I understand, the dispatch_get_main_queue is executed by the main 
>>> thread, isn't it?
>> Yes
> 
> So, why is 
>dispatch_sync( dispatch_get_main_queue(),  block opening a NSOpenPanel )
> a bad idea?
I think it’s fine if the following is true… you are ok with blocking your 
secondary thread while the user interacts with the panel.
> 
>>> 
>>> When the user selects a directory, I collect all files in that sub-tree 
>>> (aka "scan").
>>> That might involve aliases. which means I need to ask the user to open the 
>>> directory that alias points to.
>>> Because that scan can take several seconds (10-20),
>>> I wanted to do that scan in a secondary thread so that it can update 
>>> progress info in the UI.
>> 
>> This is all reasonable…  I guess there may be two options, ask the user on 
>> the main thread, before you are on your background thread,
> 
> Would be doable, but would complicate the code, because
>  
> I would first need to scan the whole directory tree for aliases,
I haven’t had much experience with needing to request permission to access 
files, but I thought you’d have to ask permission before scanning.  Are you 
allowed to scan before you ask for permission?

> get user permission ,
> then pass the array of directories to a secondary thread.
> 
> Also, I would like to give the user progress info while the secondary thread 
> is collecting.
Yes, understood.  Does the user have to ask for this process to begin, or does 
it start automatically?  Is the user allowed to interact with the app while 
this is going on, or does the UI just update with progress?

Sandor
> 
>> and only start the background thread after the user answers, or dispatch the 
>> UI work to the main thread from your background thread as your code sample 
>> showed.
> 
> So my solution is viable ?
> 
> 
> Best regards, Gabriel
> 
> 
> 
___

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: Open a panel in secondary thread?

2020-03-23 Thread Rob Petrovec via Cocoa-dev


> On Mar 23, 2020, at 8:01 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
 I would not do this.  It is widely documented that AppKit API that produce 
 UI elements, like NSOpenPanel, are _not_ thread safe.  
>>> 
>>> Right, and that is why I have to execute any UI code in the main thread,
>>> or so I thought.
>>> As far as I understand, the dispatch_get_main_queue is executed by the main 
>>> thread, isn't it?
>> Yes
> 
> So, why is 
>   dispatch_sync( dispatch_get_main_queue(),  block opening a NSOpenPanel )
> a bad idea?
It’s not a bad idea.  I misread the code.   I didn’t see 
dispatch_get_main_queue.  Sorry about that.  This will invoke the open panel on 
the main thread and not return until the panel is dismissed.


>>> When the user selects a directory, I collect all files in that sub-tree 
>>> (aka "scan").
>>> That might involve aliases. which means I need to ask the user to open the 
>>> directory that alias points to.
>>> Because that scan can take several seconds (10-20),
>>> I wanted to do that scan in a secondary thread so that it can update 
>>> progress info in the UI.
>> 
>> This is all reasonable…  I guess there may be two options, ask the user on 
>> the main thread, before you are on your background thread,
> 
> Would be doable, but would complicate the code, because I would first need to 
> scan
> the whole directory tree for aliases, get user permission , then pass the 
> array of directories to a secondary thread.
> 
> Also, I would like to give the user progress info while the secondary thread 
> is collecting.
> 
>> and only start the background thread after the user answers, or dispatch the 
>> UI work to the main thread from your background thread as your code sample 
>> showed.
> 
> So my solution is viable ?
Yes.

—Rob


___

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: Open a panel in secondary thread?

2020-03-23 Thread Gabriel Zachmann via Cocoa-dev
>>> I would not do this.  It is widely documented that AppKit API that produce 
>>> UI elements, like NSOpenPanel, are _not_ thread safe.  
>> 
>> Right, and that is why I have to execute any UI code in the main thread,
>> or so I thought.
>> As far as I understand, the dispatch_get_main_queue is executed by the main 
>> thread, isn't it?
> Yes

So, why is 
   dispatch_sync( dispatch_get_main_queue(),  block opening a NSOpenPanel )
a bad idea?

>> 
>> When the user selects a directory, I collect all files in that sub-tree (aka 
>> "scan").
>> That might involve aliases. which means I need to ask the user to open the 
>> directory that alias points to.
>> Because that scan can take several seconds (10-20),
>> I wanted to do that scan in a secondary thread so that it can update 
>> progress info in the UI.
> 
> This is all reasonable…  I guess there may be two options, ask the user on 
> the main thread, before you are on your background thread,

Would be doable, but would complicate the code, because I would first need to 
scan
the whole directory tree for aliases, get user permission , then pass the array 
of directories to a secondary thread.

Also, I would like to give the user progress info while the secondary thread is 
collecting.

> and only start the background thread after the user answers, or dispatch the 
> UI work to the main thread from your background thread as your code sample 
> showed.

So my solution is viable ?


Best regards, Gabriel



___

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: Open a panel in secondary thread?

2020-03-23 Thread Sandor Szatmari via Cocoa-dev
Gabriel,

> On Mar 23, 2020, at 8:54 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Thanks a lot for your response.
> 
>> I would not do this.  It is widely documented that AppKit API that produce 
>> UI elements, like NSOpenPanel, are _not_ thread safe.  
> 
> Right, and that is why I have to execute any UI code in the main thread,
> or so I thought.
> As far as I understand, the dispatch_get_main_queue is executed by the main 
> thread, isn't it?
Yes
> 
> 
>> So you may find your app hitting some memory stomping issues or strange 
>> crashes/exceptions due to this.  Specifically what problems you will hit are 
>> anyones guess, but its just a matter of time.  There is a reason Xcode has 
>> the Main Thread Checker to catch UI elements being used on secondary threads.
>> 
>> Lets come at  this from a different direction: What are you trying to do? 
>> Why do you think you need to use the open panel on a secondary thread?
> 
> When the user selects a directory, I collect all files in that sub-tree (aka 
> "scan").
> That might involve aliases. which means I need to ask the user to open the 
> directory that alias points to.
> Because that scan can take several seconds (10-20),
> I wanted to do that scan in a secondary thread so that it can update progress 
> info in the UI.

This is all reasonable…  I guess there may be two options, ask the user on the 
main thread, before you are on your background thread, and only start the 
background thread after the user answers, or dispatch the UI work to the main 
thread from your background thread as your code sample showed.

The fact you have to block (dispatch_sync) your background thread sort of leads 
me to think you could be avoiding the extra care needed to run things on the 
main thread by calling in before you start your background thread.

Sandor

> 
> Best regards, Gabriel
> 
> ___
> 
> 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/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@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: Open a panel in secondary thread?

2020-03-23 Thread Gabriel Zachmann via Cocoa-dev
Thanks a lot for your response.

> I would not do this.  It is widely documented that AppKit API that produce UI 
> elements, like NSOpenPanel, are _not_ thread safe.  

Right, and that is why I have to execute any UI code in the main thread,
or so I thought.
As far as I understand, the dispatch_get_main_queue is executed by the main 
thread, isn't it?


> So you may find your app hitting some memory stomping issues or strange 
> crashes/exceptions due to this.  Specifically what problems you will hit are 
> anyones guess, but its just a matter of time.  There is a reason Xcode has 
> the Main Thread Checker to catch UI elements being used on secondary threads.
> 
> Lets come at  this from a different direction: What are you trying to do? Why 
> do you think you need to use the open panel on a secondary thread?

When the user selects a directory, I collect all files in that sub-tree (aka 
"scan").
That might involve aliases. which means I need to ask the user to open the 
directory that alias points to.
Because that scan can take several seconds (10-20),
I wanted to do that scan in a secondary thread so that it can update progress 
info in the UI.

Best regards, Gabriel

___

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: Open a panel in secondary thread?

2020-03-22 Thread Steve Mills via Cocoa-dev
On Mar 22, 2020, at 19:32:25, Sandor Szatmari  
wrote:
> 
> 
> The only issue I see is that if this code were ever called on the main 
> thread.  I don’t know if this is likely because we don’t know enough about 
> the OP’s code.  But if there is a chance a simple test would suffice.
> 
> if ( [NSThread isMainThread] )
>   // call code directly
> else
>   // call dispatch_sync(…)

Right. That's standard practice.

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


Re: Open a panel in secondary thread?

2020-03-22 Thread Sandor Szatmari via Cocoa-dev

> On Mar 22, 2020, at 6:20 PM, Steve Mills via Cocoa-dev 
>  wrote:
> 
> 
>> 
>> On Mar 22, 2020, at 15:38, Rob Petrovec via Cocoa-dev 
>>  wrote:
>> 
>> I would not do this.  It is widely documented that AppKit API that produce 
>> UI elements, like NSOpenPanel, are _not_ thread safe.
> 
> The code shown *is* threadsafe. It’s calling it on the main thread.
The only issue I see is that if this code were ever called on the main thread.  
I don’t know if this is likely because we don’t know enough about the OP’s 
code.  But if there is a chance a simple test would suffice.

if ( [NSThread isMainThread] )
   // call code directly
else
   // call dispatch_sync(…)

Sandor

> 
> Steve via iPad
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@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: Open a panel in secondary thread?

2020-03-22 Thread Steve Mills via Cocoa-dev
> On Mar 22, 2020, at 15:38, Rob Petrovec via Cocoa-dev 
>  wrote:
> 
> I would not do this.  It is widely documented that AppKit API that produce 
> UI elements, like NSOpenPanel, are _not_ thread safe.

The code shown *is* threadsafe. It’s calling it on the main thread.

Steve via iPad


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Open a panel in secondary thread?

2020-03-22 Thread Rob Petrovec via Cocoa-dev
I would not do this.  It is widely documented that AppKit API that produce UI 
elements, like NSOpenPanel, are _not_ thread safe.  So you may find your app 
hitting some memory stomping issues or strange crashes/exceptions due to this.  
Specifically what problems you will hit are anyones guess, but its just a 
matter of time.  There is a reason Xcode has the Main Thread Checker to catch 
UI elements being used on secondary threads.

Lets come at  this from a different direction: What are you trying to do? Why 
do you think you need to use the open panel on a secondary thread?

—Rob
 

> On Mar 22, 2020, at 1:11 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
>> 
>> Don't know if this helps you but you can look into dispatch_sync
>> and  dispatch_async.
>> 
> 
> Thanks a lot!
> That made things very easy.
> 
> I am opening the panel now with this piece of code:
> 
>__block NSURL * user_permitted_url;
>__block long int result;
>// UI stuff must be executed in the main thread
>dispatch_sync( dispatch_get_main_queue(), ^(void)
>{
>result = [self askUserToOpenDirectory: resolvedurl 
> newURL: & user_permitted_url];
>}
>);
> 
> (where my method askUserToOpenDirectory opens the NSOpenPanel and gets the 
> URL.)
> 
> BTW:
> just in case others stumble over this:
> in my case, I am opening the NSOpenPanel with the directory set to 
> resolvedurl, for which I am asking permission. So the user is just supposed 
> to click "OK".
> So, I thought, I don't need to do anything else;
> but it turns out I get permission from the OS really only if I actually get 
> the URL using 
>oPanel.URL 
> , even if it is the same as resolvedurl!
> 
> 
> Best regards, Gabriel
> 
> 
> ___
> 
> 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: Open a panel in secondary thread?

2020-03-22 Thread Gabriel Zachmann via Cocoa-dev
> 
> Don't know if this helps you but you can look into dispatch_sync
> and  dispatch_async.
> 

Thanks a lot!
That made things very easy.

I am opening the panel now with this piece of code:

__block NSURL * user_permitted_url;
__block long int result;
// UI stuff must be executed in the main thread
dispatch_sync( dispatch_get_main_queue(), ^(void)
{
result = [self askUserToOpenDirectory: resolvedurl 
newURL: & user_permitted_url];
}
);

(where my method askUserToOpenDirectory opens the NSOpenPanel and gets the URL.)

BTW:
just in case others stumble over this:
in my case, I am opening the NSOpenPanel with the directory set to resolvedurl, 
for which I am asking permission. So the user is just supposed to click "OK".
So, I thought, I don't need to do anything else;
but it turns out I get permission from the OS really only if I actually get the 
URL using 
oPanel.URL 
, even if it is the same as resolvedurl!


Best regards, Gabriel


___

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: Open a panel in secondary thread?

2020-03-21 Thread Vassilis via Cocoa-dev
Don't know if this helps you but you can look into dispatch_sync
and  dispatch_async.

Cheers

On Sat, Mar 21, 2020 at 9:16 PM Sandor Szatmari via Cocoa-dev <
cocoa-dev@lists.apple.com> wrote:

> You must run the panel on the main thread.
>
> Sandor
>
> > On Mar 21, 2020, at 3:05 PM, Gabriel Zachmann via Cocoa-dev <
> cocoa-dev@lists.apple.com> wrote:
> >
> > Is it possible to open an NSOpenPanel in a secondary thread?
> >
> > I create the thread like this:
> >
> >directoryScanThread_ = [[NSThread alloc] initWithTarget: self
> >   selector:
> @selector(scanDirectory:)
> > object: nil];
> >[directoryScanThread_ start];
> >
> >
> > But when I do:
> >
> >NSOpenPanel *oPanel = [NSOpenPanel openPanel];
> >
> > it crashes at this point.
> >
> > In the docs, I found a hint that one should use
> >
> >lockFocusIfCanDraw
> >
> > but that is deprecated now.
> >
> > Any ideas will be highly appreciated.
> >
> >
> > Best regards, Gabriel
> >
> >
> > ___
> >
> > 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/admin.szatmari.net%40gmail.com
> >
> > This email sent to admin.szatmari@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/bpantazhs%40gmail.com
>
> This email sent to bpanta...@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: Open a panel in secondary thread?

2020-03-21 Thread Sandor Szatmari via Cocoa-dev
You must run the panel on the main thread.

Sandor

> On Mar 21, 2020, at 3:05 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Is it possible to open an NSOpenPanel in a secondary thread?
> 
> I create the thread like this:
> 
>directoryScanThread_ = [[NSThread alloc] initWithTarget: self
>   selector: 
> @selector(scanDirectory:)
> object: nil];
>[directoryScanThread_ start];
> 
> 
> But when I do:
> 
>NSOpenPanel *oPanel = [NSOpenPanel openPanel];
> 
> it crashes at this point.
> 
> In the docs, I found a hint that one should use
> 
>lockFocusIfCanDraw
> 
> but that is deprecated now.
> 
> Any ideas will be highly appreciated.
> 
> 
> Best regards, Gabriel
> 
> 
> ___
> 
> 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/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@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: Open a panel in secondary thread?

2020-03-21 Thread Rob Petrovec via Cocoa-dev
No you can’t one an NSOpenPanel on a secondary thread.  UI elements must be on 
the main thread.

—Rob


> On Mar 21, 2020, at 1:05 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Is it possible to open an NSOpenPanel in a secondary thread?
> 
> I create the thread like this:
> 
>directoryScanThread_ = [[NSThread alloc] initWithTarget: self
>   selector: 
> @selector(scanDirectory:)
> object: nil];
>[directoryScanThread_ start];
> 
> 
> But when I do:
> 
>NSOpenPanel *oPanel = [NSOpenPanel openPanel];
> 
> it crashes at this point.
> 
> In the docs, I found a hint that one should use
> 
>lockFocusIfCanDraw
> 
> but that is deprecated now.
> 
> Any ideas will be highly appreciated.
> 
> 
> Best regards, Gabriel
> 
> 
> ___
> 
> 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: Open a panel in secondary thread?

2020-03-21 Thread Alex Zavatone via Cocoa-dev
Isn’t the main thread meant for updating the UI?

> On Mar 21, 2020, at 7:05 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Is it possible to open an NSOpenPanel in a secondary thread?
> 
> I create the thread like this:
> 
>directoryScanThread_ = [[NSThread alloc] initWithTarget: self
>   selector: 
> @selector(scanDirectory:)
> object: nil];
>[directoryScanThread_ start];
> 
> 
> But when I do:
> 
>NSOpenPanel *oPanel = [NSOpenPanel openPanel];
> 
> it crashes at this point.
> 
> In the docs, I found a hint that one should use
> 
>lockFocusIfCanDraw
> 
> but that is deprecated now.
> 
> Any ideas will be highly appreciated.
> 
> 
> Best regards, Gabriel
> 
> 
> ___
> 
> 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