[R-SIG-Mac] R GUI copy/save PDF drawing bug

thatsanicehatyouhave at mac.com thatsanicehatyouhave at mac.com
Fri Feb 16 18:28:07 CET 2007


Hello,

I have been going through the R GUI code trying to fix a specific  
bug. I reported this a while ago and tried to fix it then but with no  
luck:

https://stat.ethz.ch/pipermail/r-sig-mac/2006-March/002723.html

I've had another stab at it, and this is what I think is going on.  
There is an NSTimer that fires every 0.5 s that calls showWorkingDir:  
in RController.m. My guess is that when copy: is called in RQuartz.m  
and the operation takes more than 0.5 s that the working directory  
text field (WDirView) is being drawn on that view since the focus is  
locked onto it. This depends on the relative positions and sizes of  
the windows as well, which makes sense with the relative coordinate  
systems.

You'll much more likely to see this on plots with a large amount of  
data since they take more time to draw (relatively). This is very  
typical for me so I see the problem all the time.

Here's my solution:

R.Controller.h

add instance:
NSMutableString *currentWorkingDirectory;

RController.m

in init add:
currentWorkingDirectory = [[NSMutableString string] retain];

Replace showWorkingDir with:

- (IBAction) showWorkingDir:(id)sender
{
	NSString *wd = [[NSFileManager defaultManager] currentDirectoryPath];
	if (!wd) wd = NLS(@"<deleted>");
	if (![currentWorkingDirectory isEqualToString:wd]) {
		[WDirView setStringValue: [wd stringByAbbreviatingWithTildeInPath]];
		[currentWorkingDirectory	 setString:wd];
	}
}

...and then to clean up, in dealloc add:
[currentWorkingDirectory release];

Note that it is unnecessary to call setEditable:. This is only used  
to make the text field editable by the user which is never the case.

This function only attempts to update the view if the current  
directory has actually changed which will never happen in the middle  
of a copy/paste/save operation. Well, I suppose it will if the  
working directory is somehow deleted while someone copies or saves,  
but I'm willing to live with that.

Finally, is the timer in place only to see if the folder has been  
removed from underneath R? If so, it might be cleaner to set  
something up to notify us when a particular directory (e.g. the  
current working directory) has been removed. There is a class called  
DRFileNotificationSubscription described here that does exactly that.

http://www.cocoadev.com/index.pl?FileSystemNotifications

If you'd like, I can code it up and test it, but I wanted to ask if  
there was another purpose for the timer before spending the time on it.

Cheers,

Demitri



More information about the R-SIG-Mac mailing list