Also only show the startup prompt once.
// Notifies the delegate that the gutter was clicked at a certain line.
- (void)gutterClickedAtLine:(NSUInteger)line forFile:(NSString*)file;
+// An error occurrerd while attempting to read or highlight the file.
+- (void)error:(NSError*)error whileHighlightingFile:(NSString*)file;
+
@end
error:&error];
if (error) {
NSLog(@"Error reading file at %@: %@", filePath, error);
+ if ([delegate_ respondsToSelector:@selector(error:whileHighlightingFile:)]) {
+ [delegate_ error:error whileHighlightingFile:filePath];
+ }
return;
}
[textView_ setString:contents];
#import "DebuggerBackEnd.h"
#import "DebuggerModel.h"
#import "EvalController.h"
+#import "FileAccessController.h"
#import "PreferenceNames.h"
#import "NSXMLElementAdditions.h"
#import "StackFrame.h"
[_sourceViewer setMarkers:[manager breakpointsForFile:file]];
}
+- (void)error:(NSError*)error whileHighlightingFile:(NSString*)file
+{
+ if (error.code == NSFileReadNoPermissionError) {
+ [FileAccessController showFileAccessDialog];
+ }
+}
+
@end
@interface FileAccessController : NSWindowController <NSWindowDelegate>
+ (void)maybeShowFileAccessDialog;
++ (void)showFileAccessDialog;
- (IBAction)openFileAccess:(id)sender;
@end
+ (void)maybeShowFileAccessDialog
{
- NSDictionary* fileAccesses = [[NSUserDefaults standardUserDefaults] objectForKey:kPrefFileAccessBookmarks];
- if ([fileAccesses count] == 0) {
- FileAccessController* controller = [[FileAccessController alloc] init];
- [controller.window center];
- [controller showWindow:self];
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+ NSDictionary* fileAccesses = [defaults objectForKey:kPrefFileAccessBookmarks];
+ // TODO: Re-prompt after some amount of time.
+ if ([fileAccesses count] == 0 &&
+ ![defaults objectForKey:kPrefFileAccessStartupShowDate]) {
+ [defaults setObject:[NSDate date] forKey:kPrefFileAccessStartupShowDate];
+ [self showFileAccessDialog];
}
}
++ (void)showFileAccessDialog
+{
+ FileAccessController* controller = [[FileAccessController alloc] init];
+ [controller.window center];
+ [controller showWindow:self];
+}
+
- (instancetype)init
{
if ((self = [self initWithWindowNibName:@"FileAccess"])) {
// NSMutableDictionary of NSString paths to NSData file access bookmarks.
extern NSString* const kPrefFileAccessBookmarks;
+// NSDate of last showing the FileAccessController on startup.
+extern NSString* const kPrefFileAccessStartupShowDate;
+
// NSNumber bool for whether to stop the debugger on the first line of the
// program.
extern NSString* const kPrefBreakOnFirstLine;
NSString* const kPrefFileAccessBookmarks = @"FileAccessBookmarks";
+NSString* const kPrefFileAccessStartupShowDate = @"FileAccessStartupShowDate";
+
NSString* const kPrefBreakOnFirstLine = @"BreakOnFirstLine";
NSString* const kPrefDebuggerAttached = @"DebuggerAttached";