From 47f99758ccea4e39938e81ca8e1b3417a1045ae7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 8 Dec 2019 13:40:54 -0500 Subject: [PATCH] Add startup dialog for when no file access has been granted. --- MacGDBp.xcodeproj/project.pbxproj | 18 +++++++ Source/AppDelegate.h | 2 +- Source/AppDelegate.m | 19 ++++++-- Source/FileAccessController.h | 23 +++++++++ Source/FileAccessController.m | 59 ++++++++++++++++++++++ en.lproj/FileAccess.xib | 81 +++++++++++++++++++++++++++++++ 6 files changed, 196 insertions(+), 6 deletions(-) create mode 100644 Source/FileAccessController.h create mode 100644 Source/FileAccessController.m create mode 100644 en.lproj/FileAccess.xib diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index 8bf4c27..287e2bb 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ 1E9582670E2524AD001A3D89 /* PreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E9582660E2524AD001A3D89 /* PreferencesController.m */; }; 1E9583200E2531BD001A3D89 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E95831F0E2531BD001A3D89 /* Sparkle.framework */; }; 1E95834C0E2531D5001A3D89 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1E95831F0E2531BD001A3D89 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; + 1E9C305B239D6DC600EFE30E /* FileAccess.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E9C3059239D6DC600EFE30E /* FileAccess.xib */; }; + 1E9C305F239D6E4200EFE30E /* FileAccessController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E9C305E239D6E4200EFE30E /* FileAccessController.m */; }; 1EB7BED50ECF3CA90033283A /* StackFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EB7BED40ECF3CA90033283A /* StackFrame.m */; }; 1EC1337E127DBB00007946FC /* VariableNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EC1337D127DBB00007946FC /* VariableNode.m */; }; 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */; }; @@ -132,6 +134,9 @@ 1E9C3056239C3BED00EFE30E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/Log.xib; sourceTree = ""; }; 1E9C3057239C3BED00EFE30E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; 1E9C3058239C3BEE00EFE30E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/Preferences.xib; sourceTree = ""; }; + 1E9C305A239D6DC600EFE30E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/FileAccess.xib; sourceTree = ""; }; + 1E9C305D239D6E4200EFE30E /* FileAccessController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FileAccessController.h; path = Source/FileAccessController.h; sourceTree = ""; }; + 1E9C305E239D6E4200EFE30E /* FileAccessController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FileAccessController.m; path = Source/FileAccessController.m; sourceTree = ""; }; 1EB7BED30ECF3CA90033283A /* StackFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StackFrame.h; path = Source/StackFrame.h; sourceTree = ""; }; 1EB7BED40ECF3CA90033283A /* StackFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StackFrame.m; path = Source/StackFrame.m; sourceTree = ""; }; 1EC1337C127DBB00007946FC /* VariableNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VariableNode.h; path = Source/VariableNode.h; sourceTree = ""; }; @@ -272,6 +277,7 @@ 1E1E53010DF9B89800D334F9 /* Breakpoints.xib */, 1E9582600E252474001A3D89 /* Preferences.xib */, 1E6B594A11610993001189D2 /* Log.xib */, + 1E9C3059239D6DC600EFE30E /* FileAccess.xib */, ); name = Interfaces; sourceTree = ""; @@ -298,6 +304,8 @@ 1E9582660E2524AD001A3D89 /* PreferencesController.m */, 1E67E6FB0F3C052000E68F1B /* PreferencesPathsArrayController.h */, 1E67E6FC0F3C052000E68F1B /* PreferencesPathsArrayController.m */, + 1E9C305D239D6E4200EFE30E /* FileAccessController.h */, + 1E9C305E239D6E4200EFE30E /* FileAccessController.m */, ); name = Preferences; sourceTree = ""; @@ -474,6 +482,7 @@ buildActionMask = 2147483647; files = ( 1E42F1D70F53317B008412DB /* dsa_pub.pem in Resources */, + 1E9C305B239D6DC600EFE30E /* FileAccess.xib in Resources */, 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 1EEBFBE50D34C793008F835B /* Debugger.xib in Resources */, 1EEBFC2B0D358EBD008F835B /* StepIn.png in Resources */, @@ -530,6 +539,7 @@ 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.mm in Sources */, 1E11814A1319805E003BFEF1 /* BSSourceViewTextView.m in Sources */, 1EE97E55232B11CB000FA8E6 /* ValidatingNSToolbarItem.m in Sources */, + 1E9C305F239D6E4200EFE30E /* FileAccessController.m in Sources */, 1E108E40136CC8B9002E34E0 /* EvalController.m in Sources */, 1E109019136DD92D002E34E0 /* StripLineBreaksValueTransformer.m in Sources */, 1EEBE842176FEA80003622C3 /* MessageQueue.m in Sources */, @@ -597,6 +607,14 @@ name = Preferences.xib; sourceTree = ""; }; + 1E9C3059239D6DC600EFE30E /* FileAccess.xib */ = { + isa = PBXVariantGroup; + children = ( + 1E9C305A239D6DC600EFE30E /* en */, + ); + name = FileAccess.xib; + sourceTree = ""; + }; 1EEBFBE30D34C793008F835B /* Debugger.xib */ = { isa = PBXVariantGroup; children = ( diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index 1350a98..990107b 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -25,12 +25,12 @@ { IBOutlet DebuggerController* debugger; IBOutlet LoggingController* loggingController_; - PreferencesController* prefs; } @property (readonly) DebuggerController* debugger; @property (readonly) BreakpointController* breakpoint; @property (readonly) LoggingController* loggingController; +@property (readonly) PreferencesController* prefsController; // Returns the instance of this class that is acting as the application's // delegate. diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index cab45e7..0ce51bb 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -18,9 +18,12 @@ #import +#import "FileAccessController.h" #import "PreferenceNames.h" -@implementation AppDelegate +@implementation AppDelegate { + PreferencesController* _prefsController; +} @synthesize debugger; @synthesize breakpoint; @@ -51,6 +54,13 @@ return (AppDelegate*)[NSApp delegate]; } +- (PreferencesController*)prefsController +{ + if (!_prefsController) + _prefsController = [[PreferencesController alloc] init]; + return _prefsController; +} + - (void)applicationDidFinishLaunching:(NSNotification*)notification { // Record whether this user ever used the beta VersionCast feed. In the @@ -64,6 +74,8 @@ [[feedURL absoluteString] rangeOfString:@"?unstable"].location != NSNotFound; [defaults setBool:usesUnstable forKey:kPrefUnstableVersionCast]; + [FileAccessController maybeShowFileAccessDialog]; + [self _activateSecureFileAccess]; } @@ -96,10 +108,7 @@ */ - (IBAction)showPreferences:(id)sender { - if (!prefs) - prefs = [[PreferencesController alloc] init]; - - [prefs showPreferencesWindow]; + [self.prefsController showPreferencesWindow]; } /** diff --git a/Source/FileAccessController.h b/Source/FileAccessController.h new file mode 100644 index 0000000..67cceab --- /dev/null +++ b/Source/FileAccessController.h @@ -0,0 +1,23 @@ +/* +* MacGDBp +* Copyright (c) 2019, Blue Static +* +* This program is free software; you can redistribute it and/or modify it under the terms of the GNU +* General Public License as published by the Free Software Foundation; either version 2 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along with this program; if not, +* write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +#import + +@interface FileAccessController : NSWindowController ++ (void)maybeShowFileAccessDialog; + +- (IBAction)openFileAccess:(id)sender; +@end diff --git a/Source/FileAccessController.m b/Source/FileAccessController.m new file mode 100644 index 0000000..871cfdd --- /dev/null +++ b/Source/FileAccessController.m @@ -0,0 +1,59 @@ +/* +* MacGDBp +* Copyright (c) 2019, Blue Static +* +* This program is free software; you can redistribute it and/or modify it under the terms of the GNU +* General Public License as published by the Free Software Foundation; either version 2 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along with this program; if not, +* write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +#import "FileAccessController.h" + +#import "AppDelegate.h" +#import "PreferenceNames.h" +#import "PreferencesController.h" + +@implementation FileAccessController { + // Self-owned window controller reference. Cleared when |-windowWillClose:|. + FileAccessController* __strong _selfRef; +} + ++ (void)maybeShowFileAccessDialog +{ + NSDictionary* fileAccesses = [[NSUserDefaults standardUserDefaults] objectForKey:kPrefFileAccessBookmarks]; + if ([fileAccesses count] == 0) { + FileAccessController* controller = [[FileAccessController alloc] init]; + [controller.window center]; + [controller showWindow:self]; + } +} + +- (instancetype)init +{ + if ((self = [self initWithWindowNibName:@"FileAccess"])) { + _selfRef = self; + } + return self; +} + +- (IBAction)openFileAccess:(id)sender +{ + [self close]; + PreferencesController* prefs = [[AppDelegate instance] prefsController]; + [prefs showPreferencesWindow]; + [prefs showFileAccess:sender]; +} + +- (void)windowWillClose:(NSNotification*)notification +{ + _selfRef = nil; +} + +@end diff --git a/en.lproj/FileAccess.xib b/en.lproj/FileAccess.xib new file mode 100644 index 0000000..c3e53e9 --- /dev/null +++ b/en.lproj/FileAccess.xib @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + In order to show the source code for file breakpoints, MacGDBp needs to be granted permission to read the files. + +This is necessary because MacGDBp is sandboxed. + +Granting access to the root of your PHP projects folder is the simplest approach. But you always have complete control in Preferences over the files MacGDBp can read. + + + + + + + + + + + + + + + + + + + + + + + + -- 2.43.5