3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import "AppDelegate.h"
19 #import <Sparkle/Sparkle.h>
21 #import "FileAccessController.h"
22 #import "PreferenceNames.h"
24 @implementation AppDelegate
{
25 PreferencesController
* _prefsController
;
29 @synthesize breakpoint
;
30 @synthesize loggingController
= loggingController_
;
33 * Initialize method that is called before all other messages. This will set the default
39 NSDictionary
* defaults
= @
{
41 kPrefInspectorWindowVisible
: @YES,
42 kPrefPathReplacements
: [NSMutableArray array
],
44 kPrefFileAccessBookmarks
: [NSMutableDictionary dictionary
],
46 kPrefBreakOnFirstLine
: @YES,
47 kPrefDebuggerAttached
: @YES,
48 kPrefSelectedDebuggerSegment
: @1,
50 [[NSUserDefaults standardUserDefaults
] registerDefaults
:defaults
];
54 + (AppDelegate
*)instance
56 return (AppDelegate
*)[NSApp delegate
];
59 - (PreferencesController
*)prefsController
61 if (!_prefsController
)
62 _prefsController
= [[PreferencesController alloc
] init
];
63 return _prefsController
;
66 - (void)applicationDidFinishLaunching
:(NSNotification
*)notification
68 // Record whether this user ever used the beta VersionCast feed. In the
69 // future, we will use this bit to query for unstable releases after the user
70 // has upgraded to a stable version.
71 NSUserDefaults
* defaults
= [NSUserDefaults standardUserDefaults
];
73 BOOL usesUnstable
= [defaults boolForKey
:kPrefUnstableVersionCast
];
74 NSURL
* feedURL
= [[SUUpdater sharedUpdater
] feedURL
];
75 usesUnstable
= usesUnstable ||
76 [[feedURL absoluteString
] rangeOfString
:@
"?unstable"].location
!= NSNotFound
;
77 [defaults setBool
:usesUnstable forKey
:kPrefUnstableVersionCast
];
80 [FileAccessController maybeShowFileAccessDialog
];
82 [self _activateSecureFileAccess
];
83 #endif // USE_APP_SANDBOX
86 - (void)applicationWillTerminate
:(NSNotification
*)notification
88 [[NSUserDefaults standardUserDefaults
] setBool
:self.debugger.connection.autoAttach
89 forKey
:kPrefDebuggerAttached
];
93 * Shows the debugger window
95 - (IBAction
)showDebuggerWindow
:(id)sender
97 [[debugger window
] makeKeyAndOrderFront
:self];
98 [debugger.segmentControl setSelectedSegment
:1];
102 * Shows the breakpoints window
104 - (IBAction
)showBreakpointWindow
:(id)sender
106 [[debugger window
] makeKeyAndOrderFront
:sender
];
107 [debugger.segmentControl setSelectedSegment
:2];
111 * Shows the preferences window. Lazily loads the PreferencesController.
113 - (IBAction
)showPreferences
:(id)sender
115 [self.prefsController showPreferencesWindow
];
119 * Opens the URL to the help page
121 - (IBAction
)openHelpPage
:(id)sender
123 [[NSWorkspace sharedWorkspace
] openURL
:[NSURL URLWithString
:@
"https://www.bluestatic.org/software/macgdbp/help/"]];
128 * Activates any secure file access bookmarks stored in preferences.
130 - (void)_activateSecureFileAccess
132 NSDictionary
* prefs
= [NSUserDefaults.standardUserDefaults objectForKey
:kPrefFileAccessBookmarks
];
133 NSMutableDictionary
<NSString
*, NSData
*>* bookmarks
= [NSMutableDictionary dictionaryWithDictionary
:prefs
];
134 for (NSString
* path
in bookmarks
) {
135 NSURL
* url
= [NSURL URLWithString
:path
];
139 url
= [NSURL URLByResolvingBookmarkData
:bookmarks
[path
]
140 options
:NSURLBookmarkResolutionWithSecurityScope
142 bookmarkDataIsStale
:&isStale
145 NSLog(@
"Failed to resolve secure bookmark for path %@: %@", path
, error
);
149 NSData
* newBookmark
= [PreferencesController secureBookmarkDataForURL
:url
];
150 bookmarks
[url.absoluteString
] = newBookmark
;
151 [bookmarks removeObjectForKey
:path
];
154 if (![url startAccessingSecurityScopedResource
]) {
155 NSLog(@
"Failed to start accessing resource %@", path
);
160 [NSUserDefaults.standardUserDefaults setObject
:bookmarks forKey
:kPrefFileAccessBookmarks
];
162 #endif // USE_APP_SANDBOX