From e64b3e14034b4dc74ad2596a3bdec86a0fb4a76f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 10 Apr 2016 12:37:48 -0400 Subject: [PATCH] Create string constants for all preference names. --- MacGDBp.xcodeproj/project.pbxproj | 6 +++++ Source/AppDelegate.m | 21 ++++++++------- Source/Breakpoint.m | 3 ++- Source/BreakpointController.m | 3 ++- Source/BreakpointManager.m | 8 +++--- Source/DebuggerController.m | 9 ++++--- Source/PreferenceNames.h | 43 +++++++++++++++++++++++++++++++ Source/PreferenceNames.m | 33 ++++++++++++++++++++++++ 8 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 Source/PreferenceNames.h create mode 100644 Source/PreferenceNames.m diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index 595735f..075aefe 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 1E1E53030DF9B89800D334F9 /* Breakpoints.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E1E53010DF9B89800D334F9 /* Breakpoints.xib */; }; 1E2F0A6912D5371C00EBF675 /* Stop.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E2F0A6812D5371B00EBF675 /* Stop.png */; }; 1E35FC760C6579CA0030F527 /* NSXMLElementAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E35FC750C6579CA0030F527 /* NSXMLElementAdditions.m */; }; + 1E3F9D941CBAB57B005D896B /* PreferenceNames.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E3F9D931CBAB57B005D896B /* PreferenceNames.m */; }; 1E416FF90D36F821009A53A2 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E416FF60D36F821009A53A2 /* MainMenu.xib */; }; 1E42F1D70F53317B008412DB /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 1E42F1D60F53317B008412DB /* dsa_pub.pem */; }; 1E4C7AF90DA401C7000A9DC7 /* BreakpointManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E4C7AF80DA401C7000A9DC7 /* BreakpointManager.m */; }; @@ -101,6 +102,8 @@ 1E2F0A6812D5371B00EBF675 /* Stop.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Stop.png; path = Icons/Stop.png; sourceTree = ""; }; 1E35FC750C6579CA0030F527 /* NSXMLElementAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = NSXMLElementAdditions.m; path = Source/NSXMLElementAdditions.m; sourceTree = ""; }; 1E35FFB00C65A74C0030F527 /* NSXMLElementAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSXMLElementAdditions.h; path = Source/NSXMLElementAdditions.h; sourceTree = ""; }; + 1E3F9D931CBAB57B005D896B /* PreferenceNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PreferenceNames.m; path = Source/PreferenceNames.m; sourceTree = ""; }; + 1E3F9D951CBAB589005D896B /* PreferenceNames.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PreferenceNames.h; path = Source/PreferenceNames.h; sourceTree = ""; }; 1E416FF70D36F821009A53A2 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; }; 1E42F1D60F53317B008412DB /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = ""; }; 1E4C7AF70DA401C7000A9DC7 /* BreakpointManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BreakpointManager.h; path = Source/BreakpointManager.h; sourceTree = ""; }; @@ -281,6 +284,8 @@ 1E9582640E252480001A3D89 /* Preferences */ = { isa = PBXGroup; children = ( + 1E3F9D951CBAB589005D896B /* PreferenceNames.h */, + 1E3F9D931CBAB57B005D896B /* PreferenceNames.m */, 1E9582650E2524AD001A3D89 /* PreferencesController.h */, 1E9582660E2524AD001A3D89 /* PreferencesController.m */, 1E67E6FB0F3C052000E68F1B /* PreferencesPathsArrayController.h */, @@ -509,6 +514,7 @@ 1E02C5710C610158006F1752 /* DebuggerBackEnd.m in Sources */, 1E02C5F60C610724006F1752 /* DebuggerController.m in Sources */, 1E35FC760C6579CA0030F527 /* NSXMLElementAdditions.m in Sources */, + 1E3F9D941CBAB57B005D896B /* PreferenceNames.m in Sources */, 1E7188690D839F6300969277 /* BSSourceView.mm in Sources */, 1E822CDD0DA28AC30027A23F /* Breakpoint.m in Sources */, 1E4C7AF90DA401C7000A9DC7 /* BreakpointManager.m in Sources */, diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index d3ab27b..7e39838 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -18,6 +18,8 @@ #import +#import "PreferenceNames.h" + @implementation AppDelegate @synthesize debugger; @@ -32,12 +34,12 @@ { @autoreleasepool { NSDictionary* defaults = @{ - @"Port" : @9000, - @"BreakpointsWindowVisible" : @YES, - @"InspectorWindowVisible" : @YES, - @"PathReplacements" : [NSMutableArray array], - @"BreakOnFirstLine" : @YES, - @"DebuggerAttached" : @YES + kPrefPort : @9000, + kPrefBreakpointsWindowVisible : @YES, + kPrefInspectorWindowVisible : @YES, + kPrefPathReplacements : [NSMutableArray array], + kPrefBreakOnFirstLine : @YES, + kPrefDebuggerAttached : @YES }; [[NSUserDefaults standardUserDefaults] registerDefaults:defaults]; } @@ -53,20 +55,19 @@ // Record whether this user ever used the beta VersionCast feed. In the // future, we will use this bit to query for unstable releases after the user // has upgraded to a stable version. - NSString* const kUsesUnstableVersionCast = @"UnstableVersionCast"; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - BOOL usesUnstable = [defaults boolForKey:kUsesUnstableVersionCast]; + BOOL usesUnstable = [defaults boolForKey:kPrefUnstableVersionCast]; NSURL* feedURL = [[SUUpdater sharedUpdater] feedURL]; usesUnstable = usesUnstable || [[feedURL absoluteString] rangeOfString:@"?unstable"].location != NSNotFound; - [defaults setBool:usesUnstable forKey:kUsesUnstableVersionCast]; + [defaults setBool:usesUnstable forKey:kPrefUnstableVersionCast]; } - (void)applicationWillTerminate:(NSNotification*)notification { [[NSUserDefaults standardUserDefaults] setBool:self.debugger.connection.autoAttach - forKey:@"DebuggerAttached"]; + forKey:kPrefDebuggerAttached]; } /** diff --git a/Source/Breakpoint.m b/Source/Breakpoint.m index 7f70153..1629a65 100644 --- a/Source/Breakpoint.m +++ b/Source/Breakpoint.m @@ -16,6 +16,7 @@ #import "Breakpoint.h" +#import "PreferenceNames.h" @implementation Breakpoint @@ -65,7 +66,7 @@ { NSString* path = self.file; - NSMutableArray* transforms = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"PathReplacements"]; + NSMutableArray* transforms = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:kPrefPathReplacements]; if (!transforms || [transforms count] < 1) return path; diff --git a/Source/BreakpointController.m b/Source/BreakpointController.m index 382d7ec..34a52a1 100644 --- a/Source/BreakpointController.m +++ b/Source/BreakpointController.m @@ -17,6 +17,7 @@ #import "BreakpointController.h" #import "AppDelegate.h" +#import "PreferenceNames.h" @implementation BreakpointController @@ -30,7 +31,7 @@ if (self = [super initWithWindowNibName:@"Breakpoints"]) { manager = [BreakpointManager sharedManager]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BreakpointsWindowVisible"]) + if ([[NSUserDefaults standardUserDefaults] boolForKey:kPrefBreakpointsWindowVisible]) [[self window] orderBack:nil]; } return self; diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m index 76a540c..1301ae5 100644 --- a/Source/BreakpointManager.m +++ b/Source/BreakpointManager.m @@ -15,7 +15,9 @@ */ #import "BreakpointManager.h" + #import "AppDelegate.h" +#import "PreferenceNames.h" @interface BreakpointManager (Private) - (void)updateDisplaysForFile:(NSString*)file; @@ -37,7 +39,7 @@ breakpoints = [[NSMutableArray alloc] init]; } - savedBreakpoints = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"Breakpoints"] mutableCopy]; + savedBreakpoints = [[[NSUserDefaults standardUserDefaults] arrayForKey:kPrefBreakpoints] mutableCopy]; if (savedBreakpoints) { for (NSDictionary* d in savedBreakpoints) @@ -77,7 +79,7 @@ [connection addBreakpoint:bp]; [savedBreakpoints addObject:[bp dictionary]]; - [[NSUserDefaults standardUserDefaults] setObject:savedBreakpoints forKey:@"Breakpoints"]; + [[NSUserDefaults standardUserDefaults] setObject:savedBreakpoints forKey:kPrefBreakpoints]; [self updateDisplaysForFile:[bp file]]; } @@ -96,7 +98,7 @@ [connection removeBreakpoint:b]; [savedBreakpoints removeObject:[b dictionary]]; - [[NSUserDefaults standardUserDefaults] setObject:savedBreakpoints forKey:@"Breakpoints"]; + [[NSUserDefaults standardUserDefaults] setObject:savedBreakpoints forKey:kPrefBreakpoints]; [self updateDisplaysForFile:file]; return b; diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 3037ae4..9bba07e 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -22,6 +22,7 @@ #import "DebuggerBackEnd.h" #import "DebuggerModel.h" #import "EvalController.h" +#import "PreferenceNames.h" #import "NSXMLElementAdditions.h" #import "StackFrame.h" @@ -50,14 +51,14 @@ options:NSKeyValueObservingOptionNew context:nil]; - connection = [[DebuggerBackEnd alloc] initWithPort:[defaults integerForKey:@"Port"] - autoAttach:[defaults boolForKey:@"DebuggerAttached"]]; + connection = [[DebuggerBackEnd alloc] initWithPort:[defaults integerForKey:kPrefPort] + autoAttach:[defaults boolForKey:kPrefDebuggerAttached]]; connection.model = _model; expandedVariables = [[NSMutableSet alloc] init]; [[self window] makeKeyAndOrderFront:nil]; [[self window] setDelegate:self]; - if ([defaults boolForKey:@"InspectorWindowVisible"]) + if ([defaults boolForKey:kPrefInspectorWindowVisible]) [inspector orderFront:self]; } return self; @@ -184,7 +185,7 @@ [errormsg setHidden:YES]; if (!self.connection.autoAttach) return; - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BreakOnFirstLine"]) + if ([[NSUserDefaults standardUserDefaults] boolForKey:kPrefBreakOnFirstLine]) [self stepIn:self]; // Do not cache the file between debugger executions. sourceViewer.file = nil; diff --git a/Source/PreferenceNames.h b/Source/PreferenceNames.h new file mode 100644 index 0000000..0a1b5ef --- /dev/null +++ b/Source/PreferenceNames.h @@ -0,0 +1,43 @@ +/* + * MacGDBp + * Copyright (c) 2016, 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 + */ + +@class NSString; + +// NSNumber integer for the port to listen on. +extern NSString* const kPrefPort; + +// NSNumber bool for whether the breakpoints window is visible. +extern NSString* const kPrefBreakpointsWindowVisible; + +// NSNumber bool for whether the inspector window is visible. +extern NSString* const kPrefInspectorWindowVisible; + +// NSMutableArray of path replacements. +extern NSString* const kPrefPathReplacements; + +// NSNumber bool for whether to stop the debugger on the first line of the +// program. +extern NSString* const kPrefBreakOnFirstLine; + +// NSNumber bool for whether the debugger is currently listening/attached. +extern NSString* const kPrefDebuggerAttached; + +// NSNumber bool for whether the app ever reported as an unstable version in +// update checks. This will let the user download future unstable versions. +extern NSString* const kPrefUnstableVersionCast; + +// NSMutableArray of breakpoints. +extern NSString* const kPrefBreakpoints; diff --git a/Source/PreferenceNames.m b/Source/PreferenceNames.m new file mode 100644 index 0000000..1c398ef --- /dev/null +++ b/Source/PreferenceNames.m @@ -0,0 +1,33 @@ +/* + * MacGDBp + * Copyright (c) 2016, 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 + +NSString* const kPrefPort = @"Port"; + +NSString* const kPrefBreakpointsWindowVisible = @"BreakpointsWindowVisible"; + +NSString* const kPrefInspectorWindowVisible = @"InspectorWindowVisible"; + +NSString* const kPrefPathReplacements = @"PathReplacements"; + +NSString* const kPrefBreakOnFirstLine = @"BreakOnFirstLine"; + +NSString* const kPrefDebuggerAttached = @"DebuggerAttached"; + +NSString* const kPrefUnstableVersionCast = @"UnstableVersionCast"; + +NSString* const kPrefBreakpoints = @"Breakpoints"; -- 2.22.5