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
],
43 kPrefFileAccessBookmarks
: [NSMutableDictionary dictionary
],
44 kPrefBreakOnFirstLine
: @YES,
45 kPrefDebuggerAttached
: @YES,
46 kPrefSelectedDebuggerSegment
: @1,
48 [[NSUserDefaults standardUserDefaults
] registerDefaults
:defaults
];
52 + (AppDelegate
*)instance
54 return (AppDelegate
*)[NSApp delegate
];
57 - (PreferencesController
*)prefsController
59 if (!_prefsController
)
60 _prefsController
= [[PreferencesController alloc
] init
];
61 return _prefsController
;
64 - (void)applicationDidFinishLaunching
:(NSNotification
*)notification
66 // Record whether this user ever used the beta VersionCast feed. In the
67 // future, we will use this bit to query for unstable releases after the user
68 // has upgraded to a stable version.
69 NSUserDefaults
* defaults
= [NSUserDefaults standardUserDefaults
];
71 BOOL usesUnstable
= [defaults boolForKey
:kPrefUnstableVersionCast
];
72 NSURL
* feedURL
= [[SUUpdater sharedUpdater
] feedURL
];
73 usesUnstable
= usesUnstable ||
74 [[feedURL absoluteString
] rangeOfString
:@
"?unstable"].location
!= NSNotFound
;
75 [defaults setBool
:usesUnstable forKey
:kPrefUnstableVersionCast
];
77 [FileAccessController maybeShowFileAccessDialog
];
79 [self _activateSecureFileAccess
];
82 - (void)applicationWillTerminate
:(NSNotification
*)notification
84 [[NSUserDefaults standardUserDefaults
] setBool
:self.debugger.connection.autoAttach
85 forKey
:kPrefDebuggerAttached
];
89 * Shows the debugger window
91 - (IBAction
)showDebuggerWindow
:(id)sender
93 [[debugger window
] makeKeyAndOrderFront
:self];
94 [debugger.segmentControl setSelectedSegment
:1];
98 * Shows the breakpoints window
100 - (IBAction
)showBreakpointWindow
:(id)sender
102 [[debugger window
] makeKeyAndOrderFront
:sender
];
103 [debugger.segmentControl setSelectedSegment
:2];
107 * Shows the preferences window. Lazily loads the PreferencesController.
109 - (IBAction
)showPreferences
:(id)sender
111 [self.prefsController showPreferencesWindow
];
115 * Opens the URL to the help page
117 - (IBAction
)openHelpPage
:(id)sender
119 [[NSWorkspace sharedWorkspace
] openURL
:[NSURL URLWithString
:@
"https://www.bluestatic.org/software/macgdbp/help/"]];
123 * Activates any secure file access bookmarks stored in preferences.
125 - (void)_activateSecureFileAccess
127 NSDictionary
* prefs
= [NSUserDefaults.standardUserDefaults objectForKey
:kPrefFileAccessBookmarks
];
128 NSMutableDictionary
<NSString
*, NSData
*>* bookmarks
= [NSMutableDictionary dictionaryWithDictionary
:prefs
];
129 for (NSString
* path
in bookmarks
) {
130 NSURL
* url
= [NSURL URLWithString
:path
];
134 url
= [NSURL URLByResolvingBookmarkData
:bookmarks
[path
]
135 options
:NSURLBookmarkResolutionWithSecurityScope
137 bookmarkDataIsStale
:&isStale
140 NSLog(@
"Failed to resolve secure bookmark for path %@: %@", path
, error
);
144 NSData
* newBookmark
= [PreferencesController secureBookmarkDataForURL
:url
];
145 bookmarks
[url.absoluteString
] = newBookmark
;
146 [bookmarks removeObjectForKey
:path
];
149 if (![url startAccessingSecurityScopedResource
]) {
150 NSLog(@
"Failed to start accessing resource %@", path
);
155 [NSUserDefaults.standardUserDefaults setObject
:bookmarks forKey
:kPrefFileAccessBookmarks
];