]> src.bluestatic.org Git - macgdbp.git/blob - Source/FileAccessController.m
Add a README.md.
[macgdbp.git] / Source / FileAccessController.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2019, Blue Static <https://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #if USE_APP_SANDBOX
18
19 #import "FileAccessController.h"
20
21 #import "AppDelegate.h"
22 #import "PreferenceNames.h"
23 #import "PreferencesController.h"
24
25 @implementation FileAccessController {
26 // Self-owned window controller reference. Cleared when |-windowWillClose:|.
27 FileAccessController* __strong _selfRef;
28 }
29
30 + (void)maybeShowFileAccessDialog
31 {
32 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
33 NSDictionary* fileAccesses = [defaults objectForKey:kPrefFileAccessBookmarks];
34 // TODO: Re-prompt after some amount of time.
35 if ([fileAccesses count] == 0 &&
36 ![defaults objectForKey:kPrefFileAccessStartupShowDate]) {
37 [defaults setObject:[NSDate date] forKey:kPrefFileAccessStartupShowDate];
38 [self showFileAccessDialog];
39 }
40 }
41
42 + (void)showFileAccessDialog
43 {
44 FileAccessController* controller = [[FileAccessController alloc] init];
45 [controller.window center];
46 [controller showWindow:self];
47 }
48
49 - (instancetype)init
50 {
51 if ((self = [self initWithWindowNibName:@"FileAccess"])) {
52 _selfRef = self;
53 }
54 return self;
55 }
56
57 - (IBAction)openFileAccess:(id)sender
58 {
59 [self close];
60 PreferencesController* prefs = [[AppDelegate instance] prefsController];
61 [prefs showPreferencesWindow];
62 [prefs showFileAccess:sender];
63 }
64
65 - (void)windowWillClose:(NSNotification*)notification
66 {
67 _selfRef = nil;
68 }
69
70 @end
71
72 #endif // USE_APP_SANDBOX