Show the FileAccessController when reading a source file fails.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 14 Dec 2019 20:24:44 +0000 (15:24 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 15 Dec 2019 17:08:04 +0000 (12:08 -0500)
Also only show the startup prompt once.

Source/BSSourceView.h
Source/BSSourceView.mm
Source/DebuggerController.m
Source/FileAccessController.h
Source/FileAccessController.m
Source/PreferenceNames.h
Source/PreferenceNames.m

index a9359da7f00d53fb4cbaae67096db550f248b5dc..2bfb18de5b5820a98f6709dc15bb541a1775feeb 100644 (file)
@@ -64,4 +64,7 @@
 // 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
index e7bf17bfe00b441cdeccc7396c1eecb3d1ff3d3c..591480369316b3afa6e0109673724f080ded18d7 100644 (file)
                                                     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];
index f7d85b43d6d7cc8cbc498d14d4526dfa59c5dc05..0a2cedb7cb87e59725994582b822fee1192e57a8 100644 (file)
@@ -23,6 +23,7 @@
 #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
index 67cceabdfe1d6c990bea1f65c6d16a9f29a0fda8..744795a57711a32f12324305a2f09cf365231b01 100644 (file)
@@ -18,6 +18,7 @@
 
 @interface FileAccessController : NSWindowController <NSWindowDelegate>
 + (void)maybeShowFileAccessDialog;
++ (void)showFileAccessDialog;
 
 - (IBAction)openFileAccess:(id)sender;
 @end
index 871cfdd6beb8379518e60b686185b5cd2bb01877..9ec95c61ca2f9479a3469614a39484c77dc1eeb0 100644 (file)
 
 + (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"])) {
index fa6b7775255709651875389a61fde0cdd04489a6..c2361817a5dd012984307aee4bdfc8cbfea0e126 100644 (file)
@@ -28,6 +28,9 @@ extern NSString* const kPrefPathReplacements;
 // 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;
index 49da56b514db2d185226fde1b9e07812bf94527d..e2958b54a8fdb1696cd6c597f232f2fd051890a1 100644 (file)
@@ -24,6 +24,8 @@ NSString* const kPrefPathReplacements = @"PathReplacements";
 
 NSString* const kPrefFileAccessBookmarks = @"FileAccessBookmarks";
 
+NSString* const kPrefFileAccessStartupShowDate = @"FileAccessStartupShowDate";
+
 NSString* const kPrefBreakOnFirstLine = @"BreakOnFirstLine";
 
 NSString* const kPrefDebuggerAttached = @"DebuggerAttached";