Create string constants for all preference names.
[macgdbp.git] / Source / AppDelegate.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, Blue Static <http://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 #import "AppDelegate.h"
18
19 #import <Sparkle/Sparkle.h>
20
21 #import "PreferenceNames.h"
22
23 @implementation AppDelegate
24
25 @synthesize debugger;
26 @synthesize breakpoint;
27 @synthesize loggingController = loggingController_;
28
29 /**
30 * Initialize method that is called before all other messages. This will set the default
31 * preference values.
32 */
33 + (void)load
34 {
35 @autoreleasepool {
36 NSDictionary* defaults = @{
37 kPrefPort : @9000,
38 kPrefBreakpointsWindowVisible : @YES,
39 kPrefInspectorWindowVisible : @YES,
40 kPrefPathReplacements : [NSMutableArray array],
41 kPrefBreakOnFirstLine : @YES,
42 kPrefDebuggerAttached : @YES
43 };
44 [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
45 }
46 }
47
48 + (AppDelegate*)instance
49 {
50 return (AppDelegate*)[NSApp delegate];
51 }
52
53 - (void)applicationDidFinishLaunching:(NSNotification*)notification
54 {
55 // Record whether this user ever used the beta VersionCast feed. In the
56 // future, we will use this bit to query for unstable releases after the user
57 // has upgraded to a stable version.
58 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
59
60 BOOL usesUnstable = [defaults boolForKey:kPrefUnstableVersionCast];
61 NSURL* feedURL = [[SUUpdater sharedUpdater] feedURL];
62 usesUnstable = usesUnstable ||
63 [[feedURL absoluteString] rangeOfString:@"?unstable"].location != NSNotFound;
64 [defaults setBool:usesUnstable forKey:kPrefUnstableVersionCast];
65 }
66
67 - (void)applicationWillTerminate:(NSNotification*)notification
68 {
69 [[NSUserDefaults standardUserDefaults] setBool:self.debugger.connection.autoAttach
70 forKey:kPrefDebuggerAttached];
71 }
72
73 /**
74 * Shows the debugger window
75 */
76 - (IBAction)showDebuggerWindow:(id)sender
77 {
78 [[debugger window] makeKeyAndOrderFront:self];
79 }
80
81 /**
82 * Shows the breakpoints window
83 */
84 - (IBAction)showBreakpointWindow:(id)sender
85 {
86 if (![[breakpoint window] isVisible] || ![[breakpoint window] isKeyWindow])
87 [[breakpoint window] makeKeyAndOrderFront:sender];
88 else
89 [[breakpoint window] orderOut:sender];
90 }
91
92 /**
93 * Shows the preferences window. Lazily loads the PreferencesController.
94 */
95 - (IBAction)showPreferences:(id)sender
96 {
97 if (!prefs)
98 prefs = [[PreferencesController alloc] init];
99
100 [prefs showPreferencesWindow];
101 }
102
103 /**
104 * Opens the URL to the help page
105 */
106 - (IBAction)openHelpPage:(id)sender
107 {
108 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.bluestatic.org/software/macgdbp/help.php"]];
109 }
110
111 @end