Move the status into the toolbar, and remove it from the bottom of the window.
[macgdbp.git] / Source / Breakpoint.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 "Breakpoint.h"
18
19 #import "PreferenceNames.h"
20
21 NSString* const kBreakpointTypeFile = @"line";
22 NSString* const kBreakpointTypeFunctionEntry = @"call";
23
24 @implementation Breakpoint {
25 NSString* _type; // weak
26 unsigned long _debuggerId;
27
28 NSString* _file;
29
30 NSString* _functionName;
31 }
32
33 - (instancetype)initWithLine:(NSUInteger)l inFile:(NSString*)f
34 {
35 if ((self = [super init])) {
36 _type = kBreakpointTypeFile;
37 _file = [f copy];
38 _line = l;
39 }
40 return self;
41 }
42
43 - (instancetype)initWithFunctionNamed:(NSString *)function {
44 if ((self = [super init])) {
45 _type = kBreakpointTypeFunctionEntry;
46 _functionName = [function copy];
47 }
48 return self;
49 }
50
51 - (id)initWithDictionary:(NSDictionary*)dict
52 {
53 if ((self = [super init])) {
54 NSString* type = [dict valueForKey:@"type"];
55 if (!type || [type isEqualToString:kBreakpointTypeFile]) {
56 _type = kBreakpointTypeFile;
57 _file = [[dict valueForKey:@"file"] copy];
58 _line = [[dict valueForKey:@"line"] intValue];
59 } else if ([type isEqualToString:kBreakpointTypeFunctionEntry]) {
60 _type = kBreakpointTypeFunctionEntry;
61 _functionName = [[dict valueForKey:@"function"] copy];
62 } else {
63 [NSException raise:NSInvalidArgumentException
64 format:@"Unknown Breakpoint type: %@", type];
65 }
66 }
67 return self;
68 }
69
70 - (void)dealloc
71 {
72 [_file release];
73 [_functionName release];
74 [super dealloc];
75 }
76
77 /**
78 * Returns the transformed path for the breakpoint, as Xdebug needs it
79 */
80 - (NSString*)transformedPath
81 {
82 NSString* path = self.file;
83
84 NSMutableArray* transforms = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:kPrefPathReplacements];
85 if (!transforms || [transforms count] < 1)
86 return path;
87
88 for (NSDictionary* replacement in transforms)
89 {
90 path = [path
91 stringByReplacingOccurrencesOfString:[replacement valueForKey:@"local"]
92 withString:[replacement valueForKey:@"remote"]
93 ];
94 }
95
96 return path;
97 }
98
99 - (BOOL)isEqual:(id)obj
100 {
101 if (![obj isKindOfClass:[self class]]) {
102 return NO;
103 }
104
105 Breakpoint* other = obj;
106 if (self.type != other.type) {
107 return NO;
108 }
109
110 if (self.type == kBreakpointTypeFile) {
111 return [self.file isEqualToString:other.file] && self.line == other.line;
112 } else if (self.type == kBreakpointTypeFunctionEntry) {
113 return [self.functionName isEqualToString:other.functionName];
114 }
115
116 return NO;
117 }
118
119 - (NSDictionary*)dictionary
120 {
121 if (self.type == kBreakpointTypeFile) {
122 return @{
123 @"type" : self.type,
124 @"file" : self.file,
125 @"line" : @(self.line)
126 };
127 } else if (self.type == kBreakpointTypeFunctionEntry) {
128 return @{
129 @"type" : self.type,
130 @"function" : self.functionName
131 };
132 }
133 return nil;
134 }
135
136 - (NSString*)description
137 {
138 return [NSString stringWithFormat:@"Breakpoint %@", [[self dictionary] description]];
139 }
140
141 @end