Re: NSTask is intermittently failing to return results.

2011-03-19 Thread Anders Norlander
If it is a read call that is interrupted, you might get around the problem by 
making the signal restartable (SIGCHLD probably).
Assuming availableData doesn't mess around with the signals (which it 
shouldn't).
If the implementation of availableData is using select, or one of its brethren, 
the system
call will be interrupted anyway. My guess is that it uses select if the type of 
the file descriptor
supports it (like pipes).

If you use the "solution" at the link you mention, you should at least check if 
the reason string
contains strerror(EINTR) instead of an exact comparison to a string constant.
Does the exception have an info dictionary?

/Anders


On 2011-03-17, at 10:01 , Jason Harris wrote:

> General Problem:
> 
> NSTask is most of the time working for me, but intermittently it's failing to 
> return results. Either the result is silently dropped, or more infrequently I 
> am getting exceptions in:
> 
> [NSConcreteData initWithBytes:length:copy:freeWhenDone:bytesAreVM:] or
> [NSConcreteFileHandle availableData] or
> [NSConcreteFileHandle readDataOfLength:]
> 
> depending on the tweaks / experiments I am attempting to play with.
> 
> If MacHg issues the *exact* same command a little later it will work.
> 
> 
> 
> Background:
> 
> I write MacHg an open source OSX multithreaded GUI client for Mercurial. I 
> have wanted to move to showing progress bars in MacHg as Mercurial progresses 
> in doing its long running operations.
> 
> In all my released versions of MacHg so far I have used only the 
> readDataToEndOfFileIgnoringErrors approach to NSTask (since once I launch a 
> task I am only ever reading data from it, and not actually ever sending data 
> to its stdin). Ie something like:
> 
>   NSData* outData = [[outPipe fileHandleForReading] 
> readDataToEndOfFileIgnoringErrors]
>   NSData* errData = [[errPipe fileHandleForReading] 
> readDataToEndOfFileIgnoringErrors];
> 
> However, I have previously had problems with intermittent exceptions of 
> [NSConcreteFileHandle readDataOfLength:] which bugged me. I spent some time 
> trying to fix these but in the end couldn't figure out what was going wrong / 
> how to fix them properly. In the end I used the bandaided approach of: 
> http://www.cocoabuilder.com/archive/cocoa/173348-nstask-stealth-bug-in-readdataoflength.html#173647
> 
> (Of note I have Garbage collection turned on in the MacHg project.)
> 
> 
> 
> Moving to Notification based NSTask:
> 
> But it has nagged me as to why this was occurring using 
> readDataToEndOfFileIgnoringErrors.  In any case I had thought moving to a 
> "Moriarity" style NSTask usage was going to solve my problems. I have now 
> coded a "Moriarity" style NSTask usage up in MacHg. Ie using 
> NSFileHandleReadCompletionNotification and NSTaskDidTerminateNotification. 
> However, I discovered that the frequency of odd behavior has actually 
> increased not decreased in moving to this approach.
> 
> I have looked at (in fact studied in detail) the source code for Moriarity, 
> AMShellWrapper, MyTask, and OpenFileKiller. 
> (http://cocoadev.com/index.pl?NSTask ) (I have not really covered looking at 
> MFTask, or trying to use Pseudo-TTYs or fork(), exec(), popen(), pipe() sorts 
> of low level unix / posix things.)
> 
> The hart of the code is the following (Note there are currently things in the 
> code which won't be in the production code since they are used for debugging. 
> Eg, the member theShellTask_ of ExecutionResult will be ripped out for 
> production.)
> 
> 
> 
> The Relevant Code:
> 
> 
> - (void) setPendingTermination
> {
>pendingTermination_ = YES;
>[NSObject cancelPreviousPerformRequestsWithTarget:self  
> selector:@selector(finishUp)  object:nil];
>[self performSelector:@selector(finishUp)  withObject:nil  
> afterDelay:10.0];
> }
> 
> - (void) resetPendingTermination
> {
>[NSObject cancelPreviousPerformRequestsWithTarget:self  
> selector:@selector(finishUp)  object:nil];
>pendingTermination_ = NO;
> }
> 
> - (id) initWithCommand:(NSString*)cmd andArgs:(NSArray*)args 
> onTask:(NSTask*)task
> {
>generatingCmd_ = cmd;
>generatingArgs_ = args;
>task_ = task ? task : [[NSTask alloc] init];
> 
>outPipe_= [[NSPipe alloc] init]; // Create the pipe to write 
> standard out to
>errPipe_= [[NSPipe alloc] init]; // Create the pipe to write 
> standard error to
>outHandle_  = [outPipe_ fileHandleForReading];
>errHandle_  = [errPipe_ fileHandleForReading];
>outputData_ = [[NSMutableData alloc] init];
>errorData_  = [[NSMutableData alloc] init];
> 
>[task_ setLaunchPath:cmd];
>[task_ setArguments:args];
>[task_ setStandardInput:[NSPipe pipe]];
>[task_ setStandardOutput:outPipe_];
>[task_ setStandardError:errPipe_];
> 
>[self observe:NSFileHandleReadCompletionNotification from:ou

Re: Is a file open in another application?

2011-03-19 Thread Brad Stone
I do need it to work for any app, not just Word or XL.

I guess a poor workaround would be since it's not possible to reliably check if 
the file is open I can force the user to quit the file's default app before 
allowing them to encrypt.  It's just kind of heavy-handed.

On Mar 19, 2011, at 6:20 PM, Charles Srstka wrote:

> On Mar 19, 2011, at 1:40 PM, Conrad Shultz wrote:
> 
>> On 3/19/11 11:10 AM, Kyle Sluder wrote:
>>> On Sat, Mar 19, 2011 at 9:13 AM, Conrad Shultz
>>>  wrote:
 Note that this will only capture files that are properly opened (i.e.
 fopen()'d), so you won't catch every apparently open file.  For example,
 if you open a file in vi(m), it creates a hidden scratch file in the
 same directory and closes the original file.  You then edit the scratch
 file, which is only written out to the original file on save.  In this
 way, the original file is protected from damage due to a crash, but lsof
 will almost never show it as being open.
>>> 
>>> This is also how Cocoa apps work. They only keep the file open to read
>>> its contents.
>>> 
>>> I'm afraid that what Brad wants to do is not possible yet.
>> 
>> Are you certain that is a general behavior?
> 
> Just looking at NSDocument’s default hooks for opening/saving files will show 
> you the answer to that. The ones the user is encouraged to use in the general 
> case read the file into an NSData object on open, and write an NSData out to 
> the file on save.
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev%40softraph.com
> 
> This email sent to cocoa-...@softraph.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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSTask is intermittently failing to return results.

2011-03-19 Thread Jason Harris
Answer part III

On Mar 19, 2011, at 8:43 PM, Bill Monk wrote:

> * Except, when it finally does call finishUp (if it ever does; here it seems 
> to get into an infinite loop), it's just too complicated. All you do here is 
> unregister observers, read any remaining data, and dispose of file handles 
> etc. 
> 
> Some comment on -finishUp are below.
> 
> 
> - (void) finishUp
> {
>   if (isFinished_) 
>   return;
>   
>   DebugLog(@"...Finishing up for %@ ...", [self commandLineString]);
>   
>   [NSObject cancelPreviousPerformRequestsWithTarget:self  
> selector:@selector(finishUp)  object:nil];
>   [self stopObserving:NSFileHandleReadCompletionNotification from:nil];
>   [self stopObserving:NSTaskDidTerminateNotification from:nil];
>   
>   [task_ terminate];
>   
>   // Clear standard out and standard error
>   NSData* data;
>   while ((data = [outHandle_ availableDataIgnoringErrors]) && [data 
> length])
>   [outputData_ appendData:data];  
>   while ((data = [errHandle_ availableDataIgnoringErrors]) && [data 
> length])
>   [errorData_ appendData:data];
>   
>   outHandle_ = nil;
>   errHandle_ = nil;
>   result_ = [task_ terminationStatus];
>   isFinished_ = YES;  
> }
> 
> 
> ---
>   if (isFinished_) 
>   return;
> 
> You don't need to check (or maintain) an isFinished ivar - the task is 
> finished. It just told you so.

isFinished was recording if the finalizer had been called.

Ie if the run loop had been working and the exit notification fired and was 
correctly caught and control returned to the runloop like I had intended then 
reading the code its pretty clear that finishUp could be called more than once. 
When things fire asynchronously you sometimes need to have guards. This 
condition was such a guard.


> ---
>   cancelPreviousPerformRequestsWithTarget 
> 
> Lose all this stuff - it only serves to hide problems.You think it's helping 
> and then the code gets on a different machine and instead of crashing, it 
> does other weird stuff that never happened on your machine, like the 
> never-ending tasks I'm seeing here. 

Again, other people had this...


> 
>   [task_ terminate];  
> 
> Why? This accomplishes nothing - the task has terminated. If you -did- need 
> to terminate it, say because the app is quitting, you'd do that elsewhere, 
> not in the method that gets called in response to a task termination.
> 

Apples Moriarty sample had this code. (Amongst other projects out there.)


> 
>   while ((data = [outHandle_ availableDataIgnoringErrors]) && [data 
> length])
>   [outputData_ appendData:data];  
>   while ((data = [errHandle_ availableDataIgnoringErrors]) && [data 
> length])
>   [errorData_ appendData:data];
> 
> 
> If it were my code, I would remove this wholly bogus 
> availableDataIgnoringErrors method. At best, it's a band-aid covering up 
> serious problems.

AMTask had this block of code without the error handling. Others do it as well 
when I googled around... As far as the error handling, again I very much wanted 
to remove this handling and solve the main problem... hence... *I posted to 
this news group* in order to find a way not to use this exception handling, and 
basically fix the problems I was having. 


> Also, it is NOT ignoring "errors", it ignores NSFileHandleOperationException, 
> which should not be happening. (And, a -regex- in the @catch block to check 
> [error reason]??? Simplify...)
> 
> Docs say: "Raised by NSFileHandle if attempts to determine file-handle type 
> fail or if attempts to read from a file or channel fail." 
> 
> That exception is valuable info that your code has, somewhere, hosed things 
> up. Stop trying to suppress useful crashes - embrace them and fix their 
> causes.

U... Thats the exact reason why I was posting here...

In summary please read the code in eg Moriarty, AMTask, OpenFileKiller, or 
MYTask code in order to follow up...

And again. I wasn't saying the code was perfect... In fact far from it. Hence 
my posting and request for help to this list...  I was trying to use basically 
the other code out there that I had seen. In addition since I was having 
problems and couldn't find the solution I was trying the next best thing of 
course of trying to at least catch the errors. (Nowhere near as good as solving 
the original problem which I really very badly wanted to fix.)

Happily with Jonathan pointing out apples sample code of 
CommandLineToolPlugin.m, my code here is now much much simpler:

Cheers,
  Jas___

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:
http://lists.apple.com/mailman/options/cocoa

Re: NSTask is intermittently failing to return results.

2011-03-19 Thread Jason Harris
Answer part II

On Mar 19, 2011, at 8:43 PM, Bill Monk wrote:


> Please, you must stop now, you're going to make yourself nuts. :)
> 
> - (void) gotError:(NSNotification*)notification
> {
> 
> (@"...got NULL Error Output for %@ ...", [self commandLineString]);
> errHandle_ = nil;
> if ([self shouldFinishUp])
> [self finishUp];
> 
> Why do you care if the error output is null? Getting a single zero-length 
> NSData from the stdErr pipe is normal if the task completed without error. 
> Why? Because when you call readInBackgroundAndNotify, it calls availableData 
> on the file handle. Docs say availableData "Returns an empty data object if 
> the end of file is reached", so you might get a notification with a 
> zero-length NSData. That is not an indication that the task is finished, or 
> that you should set its stdErr filehandle to nil, or that you should start 
> guessing whether the task it done. It will notify you when it is done.
> 
> When you receive your gotError method, just do whatever you want to do with 
> the actual error data. Thats's all. If there's not any data, fine. That does 
> not indicate an error. 
> 
> 
> * When you receive NSTaskDidTerminateNotification, simply believe it. Close 
> up shop. If you want the tasks's status, call terminationStatus. But don't 
> try to guess if it's "really" finished, or "really and truly finished", or 
> "really, truly, for sure, for certain, finished". It is finished. 

Uhh no... you are *quite* wrong in that last paragraph. Again look at Moriarty, 
AMShell, OpenFileKiller, and MyTask. In fact others in this very thread 
commented on this. Reread some of the others comments about this. The exit 
notification is *not* enough to exit. It just means that the task finished, it 
doesn't mean that you have got all the output and or errors yet. You are 
receiving them asynchronously, and they could, and very often are, out of order.

Please see the other sample codes for examples...


> What you've got here, no:
> 
> - (void) gotExit:(NSNotification*)notification
> {
>   if (notification)
>   DebugLog(@"...got Exit for %@ ...", [self commandLineString]);
>   if ([self shouldFinishUp])
>   [self finishUp];
> else
> [self setPendingTermination];
> }
> 
> If something is happening that makes you think it's not REALLY finished, find 
> and fix THAT bug. All this method needs to do is 
> 
> Also, why is this doing this?
> 
> if (notification)
> 
> The method wouldn't be called if there weren't a notification. And all it 
> needs to do is call your finishUp method.

That was in there since eg MyTask calls the finishing method both as a 
notification and as a way to finish things up. At one stage I did the same. I 
have been through lots of variants in order to find the right way to do things.


Cheers,
  Jas___

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

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


Re: NSTask is intermittently failing to return results.

2011-03-19 Thread Jason Harris
Sorry I have to break this into several replies to get around the automatic 
size limits of post to this group. So here is the reply in a couple of bites:

On Mar 19, 2011, at 8:43 PM, Bill Monk wrote:

>> I have looked at (in fact studied in detail) the source code for Moriarity, 
>> AMShellWrapper, MyTask, and OpenFileKiller
> 
> I don't mean this to be as harsh, the way it will look in print but...Really? 
> Those projects show how simple it should be. You are making it complicated. 
> And weird.

Uhmmm... My code was based on those projects, and its very very similar to 
those projects. Probably most similar to OpenFileKiller and MyTask since they 
both use the run loop approach ie they wanted to synchronously call NSTask 
using the asynchronous notification mechanisms. One interesting thing I found 
about MyTask is that the exit notification is never caught in the run loop (at 
least in my experimentation) since the run loop was working in a different mode 
yet the notification was delivered in the NSDefaultRunLoopMode...) But anyway 
my code was strongly based on theirs so it really shouldn't be all that 
different or shocking to you.


>> NSTask is most of the time working for me, but intermittently it's failing 
>> to return results. Either the result is silently dropped, or more 
>> infrequently I am getting exceptions in:
>> 
>> [NSConcreteData initWithBytes:length:copy:freeWhenDone:bytesAreVM:] or
>> [NSConcreteFileHandle availableData] or
>> [NSConcreteFileHandle readDataOfLength:]
>> 
>> depending on the tweaks / experiments I am attempting to play with.
> 
> I've never seen anything like that with NSTask.

Other people have and its documented. Just google for it, or even look at the 
links I included in my original post. Likely there are / were making the same 
small subtle mistakes that I am / was.


> I do not find it flaky or intermittent. But when I run your app, following 
> your instructions, I don't get crashes, I just get an ever-increasing number 
> of unfinished tasks (with indeterminate progress indicators) in the 
> Information pane at lower left. Looks like just another manifestation of the 
> same problem.

Were you breaking on exceptions? Also it didn't crash since the exceptions were 
caught... Also if you are building from source then the tip revision as of now 
is of course not a good version to actually *do things* with. It was the 
example code which I was having problems with which I posted to this list...


> Some big differences between your code and how NSTask is supposed to work are:
> 
> * What's all this polling in -waitTillFinished after calling -launch on the 
> task? Forget running your own runloop here. Why?

This is exactly what OpenFileKiller and MyTask do. How can you say those other 
projects "show how simple it should be" if you haven't even read their 
code?!?... That was their way to get synchronous reading from the asynchronous 
notifications. It seemed like the standard way to do it from what I saw 
googling around. In fact if you look at the documentation on NSTask you see:

waitUntilExit
Block until the receiver is finished.

- (void)waitUntilExit
Discussion
This method first checks to see if the receiver is still running using 
isRunning.
Then it polls the current run loop using NSDefaultRunLoopMode until the task
completes.

Ie apple is internally messing with runLoops to make this work. The other 
sample codes written by others were just making this a bit more explicit I 
guess... Or working around bugs, or something... (Note there are lots of 
questions on NSTask if you google for it...)


> Either just exit and let the notifications tell you when the task is done, or 
> you call -waitUntilExit on the task, and block right there. 

Well yes. The waitUntilExit does seem to be working.  Which was pointed out by 
Jonathan Mitchell. It appears strange to me that one can simply use this, and 
that someone as knowledgeable as Matt Gallagher was using the more complicated 
runLoop approach that I initially tried to use. Maybe the explicit runLoop 
approach solved some bugs at one time or another for him?

Note that the only piece of sample code which I have seen while googling around 
on NSTaskk that uses the [task waitUntilExit] approach is now the code Jonathan 
Mitchell pointed out to us.


> * Why are you trying to *infer* when the task is done? You've got the ivars 
> isFinished_ and pendingTermination_, and methods -shouldFinishUp, -finishUp  
> and -waitTillFinished (that runs the unnecessary runloop), a 
> -setPendingTermination to call -finishUp after a 10 second delay after you 
> guess that the task might be finished, and a -resetPendingTermination method 
> to try again if the previous guess was wrong.
> 
> This is madness - this is all unnecessary. You've got a crash, and you have 
> to find and fix it. Adding all these layers just masks the problem, and makes 
> it harder to find. None of the sample code you referenced go through any of 

Re: iPhone animation puzzle

2011-03-19 Thread Roland King
UIViewAnimationOptionAllowUserInteraction ?



On Mar 20, 2011, at 5:42, David Rowland  wrote:

> This works. It fades the label to invisibility.
> 
>  label.alpha = 1.0;
>  [UIView beginAnimations:nil context:nil];
>  [UIView setAnimationDuration:2.5];
>  label.alpha = 0;
>  [UIView commitAnimations];
> 
> 
> and so does this,
> 
>  label.alpha = 1.0;
>  [UIView animateWithDuration:2.5 animations:^{label.alpha = 0.0;} ];
> 
> 
> The documentation says the latter is now preferred and does the same thing as 
> the former. In particular, both will
> start a separate thread for the animation.
> 
> My problem is that the second method seems to block the main thread. While it 
> is acting I cannot use any of the controls on the screen. The first method 
> lets me do what I wish as it proceeds.
> 
> 
> Anyone have advice?
> 
> thanks,
> 
> 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:
> http://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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


TableView / ArrayController sorting not updating the tableview

2011-03-19 Thread Darren Wheatley
Hi,

I have an NSTableView bound to a core-data-backed NSArrayController by
binding individual columns to arraycontroller.arrangedObjects.

I have the default out-of-the-box sorting working, but when I click one of
the column headers to sort the table I have problems.

Basically the display of the table gets messed up: rows get duplicated,
and the sort order is all over the place.

However, when I click on a row the TableView redraws and everything looks
fine.

So, it looks like the sorting is working properly, but it is not being
reflected in the display of the tableview until I click on a row.

Can anyone tell me why my tableview isn't updating properly when I sort?

I have Googled this extensively, looked in the docs, and tried everything
I can think of in the code but can't work out what is happening.

Thanks

Darren.



___

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

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


Re: Visual feedback of invalid cell data from Core Data - how to?

2011-03-19 Thread Jerry Krinock

On 2011 Mar 19, at 14:55, Quincey Morris wrote:

> Note that Core Data doesn't give a damn if you pollute your data model with 
> invalid attribute values, even violations of entity-declared constraints, 
> until it gets to a save. At that point it will refuse to save if there are 
> any errors it can detect, and return an entire array of error objects.

… and it will display a modal dialog to the user announcing "Cocoa Error 
134100", or something like that, in bold font.  And as Quincey noted this 
happens after your user has been working on a document for 30 minutes and now 
wants to save.  Not a pretty picture.  Core Data's built-in validation is 
useable for in-house projects only.

___

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

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


Re: Is a file open in another application?

2011-03-19 Thread Charles Srstka
On Mar 19, 2011, at 1:40 PM, Conrad Shultz wrote:

> On 3/19/11 11:10 AM, Kyle Sluder wrote:
>> On Sat, Mar 19, 2011 at 9:13 AM, Conrad Shultz
>>  wrote:
>>> Note that this will only capture files that are properly opened (i.e.
>>> fopen()'d), so you won't catch every apparently open file.  For example,
>>> if you open a file in vi(m), it creates a hidden scratch file in the
>>> same directory and closes the original file.  You then edit the scratch
>>> file, which is only written out to the original file on save.  In this
>>> way, the original file is protected from damage due to a crash, but lsof
>>> will almost never show it as being open.
>> 
>> This is also how Cocoa apps work. They only keep the file open to read
>> its contents.
>> 
>> I'm afraid that what Brad wants to do is not possible yet.
> 
> Are you certain that is a general behavior?

Just looking at NSDocument’s default hooks for opening/saving files will show 
you the answer to that. The ones the user is encouraged to use in the general 
case read the file into an NSData object on open, and write an NSData out to 
the file on save.

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

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


Re: Icon not bouncing in Dock when App started

2011-03-19 Thread Markus Spoettl
On Mar 19, 2011, at 7:46 PM, Nick Zitzmann wrote:
>> Is that a hardware issue then? Can someone recreate this on their hardware?
> 
> No, it's a software thing. If you turn on CoreAnimation on one of the 
> dual-GPU Macs, and graphics switching is turned on, and the Mac isn't plugged 
> into a monitor, then the Mac will always auto-switch to the discrete GPU 
> because CoreAnimation always uses the discrete GPU. The same is true for 
> initializing an NSOpenGLView. This is normal and not an issue, unless your 
> app turns on CoreAnimation but doesn't actually use it.


Yes, right. I'm using layers so that's legitimate, thanks!

The issue appears to be in the Dock application then which doesn't take the 
switch to discrete graphics very well if the app that just started happens to 
be the reason for that switch.

Regards
Markus
--
__
Markus Spoettl

___

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

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


Re: Visual feedback of invalid cell data from Core Data - how to?

2011-03-19 Thread Quincey Morris
On Mar 19, 2011, at 13:44, Luke Evans wrote:

> I definitely want the regular Core Data validation process to propagate and
> drive this, rather than having to set formatters on all my cell (or
> something) and manually figure out validation by some means.

I think your want might be internally self-inconsistent, but it depends what 
you mean by "regular" Core Data validation. It's not clear if you're trying to 
rely on entity value constraints in the Core Data model, or validate 
methods in managed object subclasses, or something else.

I think you have to ask yourself:

Can I tolerate having invalid values stored in my data model, even temporarily?

If the answer is YES, then I'd suggest you don't handle this as property-level 
validation in the usual sense. Instead, create some derived 'isXXXValid' 
properties in your managed object subclass, which uses 
'keyPathsForValuesAffectingIsXXXValid' to get KVO compliance. Bind something in 
your UI to these properties to decide what background color to use.

In this case, you'd add code at (say) save time to re-check for validation 
errors and put up an alert. I believe this kind of deferred validation is 
discussed in the Core Data documentation.

If the answer is NO, then you're going to have to create intermediate or shadow 
properties, say in the window controller, which *are* allowed to be invalid, 
and then figure everything out from there, using the above technique or 
something different.

In this case, you'd have to transfer the values into the model at (say) save 
time, provided they're valid at that point.

Note that Core Data doesn't give a damn if you pollute your data model with 
invalid attribute values, even violations of entity-declared constraints, until 
it gets to a save. At that point it will refuse to save if there are any errors 
it can detect, and return an entire array of error objects.


___

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

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


iPhone animation puzzle

2011-03-19 Thread David Rowland
This works. It fades the label to invisibility.

  label.alpha = 1.0;
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:2.5];
  label.alpha = 0;
  [UIView commitAnimations];


and so does this,

  label.alpha = 1.0;
  [UIView animateWithDuration:2.5 animations:^{label.alpha = 0.0;} ];


The documentation says the latter is now preferred and does the same thing as 
the former. In particular, both will
start a separate thread for the animation.

My problem is that the second method seems to block the main thread. While it 
is acting I cannot use any of the controls on the screen. The first method lets 
me do what I wish as it proceeds.


Anyone have advice?

thanks,

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

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


Re: Is a file open in another application?

2011-03-19 Thread Dave Keck
> Is there a way for me to tell if a particular file is open in another 
> application?

The following thread offers one solution:


http://www.cocoabuilder.com/archive/cocoa/288040-notification-of-file-system-modification-arrives-too-early.html

which might be worth using if proc_listpidspath() is due to become
official API in 10.7. (I believe the Finder has used this interface
since 10.6 to determine whether a disk can be ejected, and if not, it
tells you what app is using it.)
___

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

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


Visual feedback of invalid cell data from Core Data - how to?

2011-03-19 Thread Luke Evans
I'm curious as to the best (or a) way to achieve the following:

- I have a Core Data model set up with validation of various kinds
(non-optional values, ranges, regexs etc.) on attributes.
- I have a table based UI showing these entities for viewing and editing.

I would like to make the background colour of my table cells change colour
(maybe to yellow or red) if the value therein does not validate, according
to the Core Data constraints of course.

Now, it's easy enough to set up the basic validation protocol, but this
seems to assume you want to put up an error of some kind (i.e. a sheet) when
validation fails.
What I _think_ I'd like is for the regular binding validation process,
perhaps even with "Validates immediately", to somehow get state into my
(presumably custom) cell telling it the value is invalid so I can set a
visual cue.

I definitely want the regular Core Data validation process to propagate and
drive this, rather than having to set formatters on all my cell (or
something) and manually figure out validation by some means.

Is there a slick way to do this, or is does this sort of thing require a lot
of work to introduce custom stringy bits to get per-cell validation?

Thanks!

-- Luke
___

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

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


Re: Is a file open in another application?

2011-03-19 Thread Scott Ribe
On Mar 19, 2011, at 1:58 PM, Frédéric Testuz wrote:

> I can't think of a general solution, but IIRC Brad is only interested about 
> Word and Excel. These applications have AppleScript support.
> 
> I'm sure he can ask Word by AppleScript for the open documents. He had to 
> check if Word can also return the path of the file for these documents.

Yes, for Word this works. You can get the path of any open document. And unlike 
some things in Word, this bit seems to work reliably.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

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

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


Re: Is a file open in another application?

2011-03-19 Thread Frédéric Testuz
Le 19 mars 2011 à 20:03, Kyle Sluder a écrit :

> On Sat, Mar 19, 2011 at 11:40 AM, Conrad Shultz
>  wrote:
>> Are you certain that is a general behavior?
> 
> 1. Open TextEdit.
> 2. Type some stuff.
> 3. Save As > /tmp/somefile.rtf
> 4. `lsof |grep somefile` prints nothing.
> 
>> For example, I have Preview open right now, and it very much lists all
>> its open files:
> 
> Preview probably mmaps the file contents. And that could even be done
> by PDFKit or NSImage, not explicitly by the application.
> 
>> But it does seem from the above that this can be handled in an
>> implementation-specific manner, no?  (Please forgive my ignorance, I
>> develop mostly with iOS.)
> 
> I don't think a general solution exists for Brad's problem.

I can't think of a general solution, but IIRC Brad is only interested about 
Word and Excel. These applications have AppleScript support.

I'm sure he can ask Word by AppleScript for the open documents. He had to check 
if Word can also return the path of the file for these documents.

-- 
Frédéric Testuz___

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

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


Re: Is a file open in another application?

2011-03-19 Thread Scott Ribe
On Mar 19, 2011, at 12:40 PM, Conrad Shultz wrote:

> For example, I have Preview open right now, and it very much lists all
> its open files:

And I have Preview open right now, and it does not have any of its files open. 
This is on 10.6.6, Preview 5.0.3. Further, I can tell you that some older 
versions of Preview did not always properly close the file when you closed the 
window. So, no, what Brad wants to do is most definitely not possible.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

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

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


Re: Is a file open in another application?

2011-03-19 Thread jonat...@mugginsoft.com

On 19 Mar 2011, at 13:34, Brad Stone wrote:

> Is there a way for me to tell if a particular file is open in another 
> application?
> 
> I have a feature I'd like to provide to my users that involves encrypting 
> files that belong to other apps (i.e. my application can encrypt/decrypt a 
> Word or Excel file).  I want to prevent the user from encrypting or 
> decrypting the file if it's open (i.e. the file is open in Word).  I would 
> like to display a dialog box that says something like "myWord Doc.docx is 
> open.  Please close it and continue."  I've found the ability to find running 
> applications and I've found commentary that says what I'm asking for is not 
> possible.  I couldn't find anything in NSWorkspace or NSFileManager to help 
> unless there's a file attribute I don't know about that can tell me.  Any 
> ideas?
> 

If the feature is only required to target a limited number of applications and 
they are scriptable you could use AppleEvents (or AppleScript or the 
ScriptingBridge framework) to query the application document list. This would 
give access to files open at the application level rather than files open at 
the system library level.

If the feature is to be wholly generic however this is a non starter.

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Is a file open in another application?

2011-03-19 Thread Kyle Sluder
On Sat, Mar 19, 2011 at 11:40 AM, Conrad Shultz
 wrote:
> Are you certain that is a general behavior?

1. Open TextEdit.
2. Type some stuff.
3. Save As > /tmp/somefile.rtf
4. `lsof |grep somefile` prints nothing.

> For example, I have Preview open right now, and it very much lists all
> its open files:

Preview probably mmaps the file contents. And that could even be done
by PDFKit or NSImage, not explicitly by the application.

> But it does seem from the above that this can be handled in an
> implementation-specific manner, no?  (Please forgive my ignorance, I
> develop mostly with iOS.)

I don't think a general solution exists for Brad's problem.

--Kyle Sluder
___

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

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


Re: Icon not bouncing in Dock when App started

2011-03-19 Thread Nick Zitzmann

On Mar 19, 2011, at 5:41 AM, Markus Spoettl wrote:

> On Mar 19, 2011, at 11:29 AM, Markus Spoettl wrote:
>> In my document based application, when started (by clicking on the dock icon 
>> or otherwise), the icon's startup bounce motion interrupts near the top of 
>> the animation, stays there for around 0.3 - 0.5 seconds and then the icon 
>> drops to the base position instantly.
> 
> OK, shortly after clicking send I had an idea how to figure out what it might 
> be caused by, and now I got closer: I have a layer hosting view in my 
> document window, the view is layer hosting is switched on in -awakeFromNib
> 
> - (void)awakeFromNib
> {
>   [self setLayer:scopeLayer];
>   [self setWantsLayer:YES];
> }
> 
> scopeLayer is created and set up in the view's -initWithFrame:. This is 
> causing the bounce-pause. When I remove these lines, bouncing works. Of 
> course my view doesn't. 
> 
> Now it gets really interesting: I've found that switching off "Automatic 
> graphics switching" in the Energy Saver Preferences gets rid of the issue. So 
> making the view layer hosting switches the graphics mode to the dedicated 
> hardware. Why I don't know, it happens regardless of what the layer really is 
> setup with, even if it never gets any content. 
> 
> Is that a hardware issue then? Can someone recreate this on their hardware?

No, it's a software thing. If you turn on CoreAnimation on one of the dual-GPU 
Macs, and graphics switching is turned on, and the Mac isn't plugged into a 
monitor, then the Mac will always auto-switch to the discrete GPU because 
CoreAnimation always uses the discrete GPU. The same is true for initializing 
an NSOpenGLView. This is normal and not an issue, unless your app turns on 
CoreAnimation but doesn't actually use it.

Nick Zitzmann




___

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

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


Re: Is a file open in another application?

2011-03-19 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 3/19/11 11:10 AM, Kyle Sluder wrote:
> On Sat, Mar 19, 2011 at 9:13 AM, Conrad Shultz
>  wrote:
>> Note that this will only capture files that are properly opened (i.e.
>> fopen()'d), so you won't catch every apparently open file.  For example,
>> if you open a file in vi(m), it creates a hidden scratch file in the
>> same directory and closes the original file.  You then edit the scratch
>> file, which is only written out to the original file on save.  In this
>> way, the original file is protected from damage due to a crash, but lsof
>> will almost never show it as being open.
> 
> This is also how Cocoa apps work. They only keep the file open to read
> its contents.
> 
> I'm afraid that what Brad wants to do is not possible yet.

Are you certain that is a general behavior?

For example, I have Preview open right now, and it very much lists all
its open files:

iodine:~ shultzc$ lsof -p 1379 | grep pdf
Preview 1379 shultzc  txt  REG   14,2189325 9688581
/Users/shultzc/Downloads/758206463.pdf
Preview 1379 shultzc  txt  REG   14,2 91087 9682563
/Users/shultzc/Downloads/jo001518o.pdf
Preview 1379 shultzc  txt  REG   14,2492849 9684998
/Users/shultzc/Downloads/pat5925487.pdf
Preview 1379 shultzc  txt  REG   14,2818740 9682461
/Users/shultzc/Downloads/103_34.pdf

Ditto for Pages:

iodine:~ shultzc$ lsof -p 13384 | grep pages
Pages   13384 shultzc   13r REG   14,2 93930 7814760
/Users/shultzc/develop/Synthetiq/forms/2010-09-14_Apple_fax.pages

I _do_ see that OmniFocus uses a cache instead of the underlying
database (kudos!), but unfortunately I don't actually have Office, so I
can't test the OP's scenario.

But it does seem from the above that this can be handled in an
implementation-specific manner, no?  (Please forgive my ignorance, I
develop mostly with iOS.)


- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFNhPi7aOlrz5+0JdURAv9MAJ4td5dC1YGAsfX8CQaKWObWWAUNNQCcCHnT
r1e4FtZkwiC923cmmDcnxCE=
=amxm
-END PGP SIGNATURE-
___

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

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


Re: Is a file open in another application?

2011-03-19 Thread Kyle Sluder
On Sat, Mar 19, 2011 at 9:13 AM, Conrad Shultz
 wrote:
> Note that this will only capture files that are properly opened (i.e.
> fopen()'d), so you won't catch every apparently open file.  For example,
> if you open a file in vi(m), it creates a hidden scratch file in the
> same directory and closes the original file.  You then edit the scratch
> file, which is only written out to the original file on save.  In this
> way, the original file is protected from damage due to a crash, but lsof
> will almost never show it as being open.

This is also how Cocoa apps work. They only keep the file open to read
its contents.

I'm afraid that what Brad wants to do is not possible yet.

--Kyle Sluder
___

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

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


Re: NSTask is intermittently failing to return results.

2011-03-19 Thread Jason Harris

On Mar 19, 2011, at 1:27 PM, Ken Thomases wrote:

> On Mar 18, 2011, at 5:32 PM, Jason Harris wrote:
> 
>> On Mar 18, 2011, at 11:07 PM, Ken Thomases wrote:
>> 
>>> The exception is saying that the file descriptor backing the 
>>> NSPipe/NSFileHandle has been closed.  Retrying after some time can only 
>>> result in the frameworks co-opting a new, unrelated file object that 
>>> happened to get the same file descriptor.  That would explain why your 
>>> reads sometimes never get any data -- you're reading from a completely 
>>> different file object.
>> 
>> I am sorry, but can you explain the paragraph in more detail?
> 
> Well, are you familiar with file descriptors?  When you open a file, pipe, 
> socket, or whatever, you get a file descriptor by which to refer to it.  A 
> file descriptor is just a number, like 5.  When you use Cocoa's NSPipe or 
> NSFileHandle, these details are hidden behind the scenes.
> 
> Anyway, something may be closing the file descriptor.  When that happens, 
> _for a while_ any code which tries to use that file descriptor (in this case, 
> 5) with the system calls for reading from the file will get an error, EBADF, 
> indicating that the file descriptor doesn't refer to an open file.  However, 
> and this is very important, it is very likely that future requests to open 
> files, pipes, sockets, etc. will reuse the file descriptor.  That is, some 
> other part of the code will open a file and receive the file descriptor 5 for 
> its open file.  Once that happens, the original code which had been use file 
> descriptor 5 can't tell that this new file descriptor 5 is not the one it 
> used to own.  It will keep trying to use it, and that may seem to succeed, 
> but it's accessing a completely different file than it should be.  It may be 
> trying to read from a file which will never receive any data, which would 
> explain why you don't receive the output from your task.

I was sort of aware of this but its very nice to have it explained in the 
context of my problem. Thank you!


>> (Just to be clear sometimes I never get the exception and yet it still drops 
>> data... So the ugly bit of the @catch is never hit but it still was dropping 
>> the data...)
> 
> Note that there's no guarantee that your attempt to read from the file 
> descriptor will happen during the window when the file descriptor is invalid. 
>  The file descriptor may be closed and then nearly-immediately reused for a 
> different file, and your first attempt to read from it will access a 
> different, unrelated file.  That would be bad and wrong, but would not cause 
> the exception resulting from an EBADF error.
> 
> 
>>> I'm not sure why the file descriptor is being closed.  It may be a 
>>> framework bug having to do with garbage collection.
>>> 
>>> I'd try creating the file descriptors manually with the pipe(2) system 
>>> call.  Then, construct NSFileHandles from them with 
>>> -initWithFileDescriptor:theReadFD closeOnDealloc:NO.
>> 
>> Sorry just so I don't stuff this up can I ask you to give me the exact code 
>> here... or point me to an example of this?
> 
> Well, this is sketched in mail.  By the way, I reviewed the docs and the 
> closeOnDealloc:NO part is not necessary since that's the default:
> 
>   int out_pipe_fds[2];
>   // Creates a pipe consisting of two file descriptors.  The [0] element 
> gets the read end of the
>   // pipe; the [1] element gets the write end.
>   if (pipe(out_pipe_fds) != 0)
>   /* handle error */;
>   NSFileHandle* outReadHandle = [[NSFileHandle alloc] 
> initWithFileDescriptor:out_pipe_fds[0]];
>   NSFileHandle* outWriteHandle = [[NSFileHandle alloc] 
> initWithFileDescriptor:out_pipe_fds[1]];
>   [task setStandardOutput:outWriteHandle];
> 
>   // Initiate reading on the read handle, including observing the 
> appropriate notification
> 
>   // Repeat for stderr
> 
>   [task launch];
>   [outWriteHandle release];
>   close(out_pipe_fds[1]);
>   // Repeat for stderr
> 
>   // ...
> 
>   // After you've received the end-of-file indication:
>   [outReadHandle release];
>   close(out_pipe_fds[0]);

Thanks!

> 
>>> I see no evidence that it has "vanished".  It seems to me that 
>>> -waitTillFinished is still executing, presumably blocked in the run loop.  
>>> Note that, not only is the DebugLog at the end of -waitTillFinished not 
>>> hit, but neither is the one immediately after the call to it in 
>>> +execute:withArgs:onTask:.  In other words, it just hasn't returned.
>> 
>> Ahh so you are saying that the loop is still executing? Well if I put a 
>> break point in the loop in waitTillFinished then it doesn't break on this 
>> breakpoint...
> 
> The run loop is still executing in the sense of flow of execution has not 
> returned back to your code.  You are still blocked in the -runMode:untilDate: 
> call.  So, your breakpoint won't be hit because your breakpoint is outside of 
> that metho

Re: Is a file open in another application?

2011-03-19 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

(Copying the list this time...)

On 3/19/11 6:34 AM, Brad Stone wrote:
> Is there a way for me to tell if a particular file is open in another
> application?
> 
> I have a feature I'd like to provide to my users that involves
> encrypting files that belong to other apps (i.e. my application can
> encrypt/decrypt a Word or Excel file).  I want to prevent the user
> from encrypting or decrypting the file if it's open (i.e. the file is
> open in Word).  I would like to display a dialog box that says
> something like "myWord Doc.docx is open.  Please close it and
> continue."  I've found the ability to find running applications and
> I've found commentary that says what I'm asking for is not possible.
> I couldn't find anything in NSWorkspace or NSFileManager to help
> unless there's a file attribute I don't know about that can tell me.
> Any ideas?
> 
> Thanks in advance___

Use NSTask and lsof.

(In the terminal):

man lsof

will tell you every gory detail you (don't) want to know, but a short
synopsis is that:

lsof /path/to/file

will tell you which processes have a certain file open.  You will need
to run with escalated privileges (e.g. sudo) to see certain files and/or
processes belonging to other users.

Note that this will only capture files that are properly opened (i.e.
fopen()'d), so you won't catch every apparently open file.  For example,
if you open a file in vi(m), it creates a hidden scratch file in the
same directory and closes the original file.  You then edit the scratch
file, which is only written out to the original file on save.  In this
way, the original file is protected from damage due to a crash, but lsof
will almost never show it as being open.

This might be what the "commentary" you reference was talking about.


- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2E1gwACgkQaOlrz5+0JdV5oACePw5xtZm4BrFClOD2sqbly29Y
BV8AnRY5wkmU/zwz0nhc4s8AKSGsnYCK
=v1Hz
-END PGP SIGNATURE-
___

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

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


Is a file open in another application?

2011-03-19 Thread Brad Stone
Is there a way for me to tell if a particular file is open in another 
application?

I have a feature I'd like to provide to my users that involves encrypting files 
that belong to other apps (i.e. my application can encrypt/decrypt a Word or 
Excel file).  I want to prevent the user from encrypting or decrypting the file 
if it's open (i.e. the file is open in Word).  I would like to display a dialog 
box that says something like "myWord Doc.docx is open.  Please close it and 
continue."  I've found the ability to find running applications and I've found 
commentary that says what I'm asking for is not possible.  I couldn't find 
anything in NSWorkspace or NSFileManager to help unless there's a file 
attribute I don't know about that can tell me.  Any ideas?

Thanks in advance___

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

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


Re: NSMatrix bindings

2011-03-19 Thread Christian Ziegler

On Mar 18, 2011, at 10:14 PM, Ken Thomases wrote:

> On Mar 18, 2011, at 3:45 AM, Christian Ziegler wrote:
> 
>> I'm having hard times figuring out how to bind an NSMatrix properly. I got 
>> an NSMatrix with NSButtonCells (checkboxes) and I want to somehow bind to my 
>> model which of these checkboxes are selected. What should work is binding 
>> the content objects of the NSMatrix to an ArrayController and fill the 
>> arrayController's content with NSButtonCells programmatically.
> 
> Huh?  An NSMatrix is a view (in the Model-View-Controller design pattern), an 
> array controller is a controller, and it provides access to model data.  
> NSButtonCells are not model data, they are elements of the view.  You don't 
> "fill the arrayController's content with NSButtonCells".

Hehe shame on me!

> 
> You should have a model property somewhere which is an array of objects to be 
> presented in the matrix.  This might be as simple as strings for the names of 
> the checkboxes, or it might be objects each of which has a property which 
> will be the name of a checkbox.  You bind the array controller's contentArray 
> to this model property (the array of objects).
> 
> You then bind the matrix's content to the array controller's arrangedObjects. 
>  If the objects are not themselves the values for the checkboxes, you also 
> bind the matrix's contentValues to the array controller's arrangedObjects 
> with a model key path which obtains the values for the checkboxes.
> 
> You can bind the matrix's selectedObjects or selectedValues to another 
> controller's property, which is a to-many property with the appropriate 
> mutation accessors.  You bind selectedObjects if you want to track the 
> objects which correspond to each checkbox.  You bind selectedValues if you 
> want to track the values, if there's a distinction (see previous paragraph).
> 
> It should also work to bind the matrix's selectedObjects to the array 
> controller's selection.  Then you can bind the array controller's 
> selectionIndexes to a property of your coordinating controller (e.g. File's 
> Owner).  That way, your property which tracks the selection can be related 
> back to the property which provided the array controller's content, instead 
> of merely being another array which shares some elements.
> 
> I hope that helps.
> 
> Regards,
> Ken
> 

Thanks Ken. I was assuming that it works that way, however I figured there must 
be an easier way. I will write a nice little model object then :)

Cheers,
Chris

___

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

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


Re: NSTask is intermittently failing to return results.

2011-03-19 Thread Ken Thomases
On Mar 18, 2011, at 5:32 PM, Jason Harris wrote:

> On Mar 18, 2011, at 11:07 PM, Ken Thomases wrote:
> 
>> The exception is saying that the file descriptor backing the 
>> NSPipe/NSFileHandle has been closed.  Retrying after some time can only 
>> result in the frameworks co-opting a new, unrelated file object that 
>> happened to get the same file descriptor.  That would explain why your reads 
>> sometimes never get any data -- you're reading from a completely different 
>> file object.
> 
> I am sorry, but can you explain the paragraph in more detail?

Well, are you familiar with file descriptors?  When you open a file, pipe, 
socket, or whatever, you get a file descriptor by which to refer to it.  A file 
descriptor is just a number, like 5.  When you use Cocoa's NSPipe or 
NSFileHandle, these details are hidden behind the scenes.

Anyway, something may be closing the file descriptor.  When that happens, _for 
a while_ any code which tries to use that file descriptor (in this case, 5) 
with the system calls for reading from the file will get an error, EBADF, 
indicating that the file descriptor doesn't refer to an open file.  However, 
and this is very important, it is very likely that future requests to open 
files, pipes, sockets, etc. will reuse the file descriptor.  That is, some 
other part of the code will open a file and receive the file descriptor 5 for 
its open file.  Once that happens, the original code which had been use file 
descriptor 5 can't tell that this new file descriptor 5 is not the one it used 
to own.  It will keep trying to use it, and that may seem to succeed, but it's 
accessing a completely different file than it should be.  It may be trying to 
read from a file which will never receive any data, which would explain why you 
don't receive the output from your task.

> (Just to be clear sometimes I never get the exception and yet it still drops 
> data... So the ugly bit of the @catch is never hit but it still was dropping 
> the data...)

Note that there's no guarantee that your attempt to read from the file 
descriptor will happen during the window when the file descriptor is invalid.  
The file descriptor may be closed and then nearly-immediately reused for a 
different file, and your first attempt to read from it will access a different, 
unrelated file.  That would be bad and wrong, but would not cause the exception 
resulting from an EBADF error.


>> I'm not sure why the file descriptor is being closed.  It may be a framework 
>> bug having to do with garbage collection.
>> 
>> I'd try creating the file descriptors manually with the pipe(2) system call. 
>>  Then, construct NSFileHandles from them with 
>> -initWithFileDescriptor:theReadFD closeOnDealloc:NO.
> 
> Sorry just so I don't stuff this up can I ask you to give me the exact code 
> here... or point me to an example of this?

Well, this is sketched in mail.  By the way, I reviewed the docs and the 
closeOnDealloc:NO part is not necessary since that's the default:

int out_pipe_fds[2];
// Creates a pipe consisting of two file descriptors.  The [0] element 
gets the read end of the
// pipe; the [1] element gets the write end.
if (pipe(out_pipe_fds) != 0)
/* handle error */;
NSFileHandle* outReadHandle = [[NSFileHandle alloc] 
initWithFileDescriptor:out_pipe_fds[0]];
NSFileHandle* outWriteHandle = [[NSFileHandle alloc] 
initWithFileDescriptor:out_pipe_fds[1]];
[task setStandardOutput:outWriteHandle];

// Initiate reading on the read handle, including observing the 
appropriate notification

// Repeat for stderr

[task launch];
[outWriteHandle release];
close(out_pipe_fds[1]);
// Repeat for stderr

// ...

// After you've received the end-of-file indication:
[outReadHandle release];
close(out_pipe_fds[0]);


>> I see no evidence that it has "vanished".  It seems to me that 
>> -waitTillFinished is still executing, presumably blocked in the run loop.  
>> Note that, not only is the DebugLog at the end of -waitTillFinished not hit, 
>> but neither is the one immediately after the call to it in 
>> +execute:withArgs:onTask:.  In other words, it just hasn't returned.
> 
> Ahh so you are saying that the loop is still executing? Well if I put a break 
> point in the loop in waitTillFinished then it doesn't break on this 
> breakpoint...

The run loop is still executing in the sense of flow of execution has not 
returned back to your code.  You are still blocked in the -runMode:untilDate: 
call.  So, your breakpoint won't be hit because your breakpoint is outside of 
that method in the caller, but that's never reached.

Keep in mind that -runMode:untilDate: won't necessarily return for _everything_ 
that happens within it.  In particular, see this note in the documentation:

> Note: A timer is not considered an input source and may fire multiple times 
> while waiting for

Re: Icon not bouncing in Dock when App started

2011-03-19 Thread Markus Spoettl
On Mar 19, 2011, at 11:29 AM, Markus Spoettl wrote:
> In my document based application, when started (by clicking on the dock icon 
> or otherwise), the icon's startup bounce motion interrupts near the top of 
> the animation, stays there for around 0.3 - 0.5 seconds and then the icon 
> drops to the base position instantly.

OK, shortly after clicking send I had an idea how to figure out what it might 
be caused by, and now I got closer: I have a layer hosting view in my document 
window, the view is layer hosting is switched on in -awakeFromNib

- (void)awakeFromNib
{
   [self setLayer:scopeLayer];
   [self setWantsLayer:YES];
}

scopeLayer is created and set up in the view's -initWithFrame:. This is causing 
the bounce-pause. When I remove these lines, bouncing works. Of course my view 
doesn't. 

Now it gets really interesting: I've found that switching off "Automatic 
graphics switching" in the Energy Saver Preferences gets rid of the issue. So 
making the view layer hosting switches the graphics mode to the dedicated 
hardware. Why I don't know, it happens regardless of what the layer really is 
setup with, even if it never gets any content. 

Is that a hardware issue then? Can someone recreate this on their hardware?

Regards
Markus
--
__
Markus Spoettl

___

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

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


Icon not bouncing in Dock when App started

2011-03-19 Thread Markus Spoettl
Hi,

  I have a strange problem, and I have no idea what causes it: 

In my document based application, when started (by clicking on the dock icon or 
otherwise), the icon's startup bounce motion interrupts near the top of the 
animation, stays there for around 0.3 - 0.5 seconds and then the icon drops to 
the base position instantly.

The only way that I can make the icon bounce correctly is if I don't create an 
empty document on app startup (by implementing 
-applicationShouldOpenUntitledFile: in the app delegate, returning NO). That 
means that something in my document setup code is causing this, but I have no 
idea what it might be. 

I tried bypassing -awakeFromNib in the NSWindowController subclass for the 
document window, the only place were anything that could possibly need CPU 
power at that time happens. That doesn't change anything. The documents window 
XIB is really very small, containing only a window with 3 views on it, no 
binding, nothing.

I thought that the dock icon animation was independent of the application, it's 
Dock.app that does that after all. So what in my application could cause an 
animation glitch like that?

I'm using Xcode 4, on a new 17'' MacBook Pro quad-core i7 with 8GB. That should 
be sufficient to bounce the icon, I guess. Other apps don't exhibit this issue. 
The app is compiled with LLVM 2.0. Interestingly the bounce-pause is much 
shorter when the app is started through the debugger, still noticeable, though.

Any ideas what that could be caused by?

Regards
Markus
--
__
Markus Spoettl

___

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

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