-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMySvnView.m
257 lines (191 loc) · 5.04 KB
/
MySvnView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// MySvnView.m - Superclass of MySvnLogView & MySvnRepositoryBrowserView
//
#import "MySvnView.h"
#import "MyRepository.h"
#import "Tasks.h"
#import "CommonUtils.h"
@implementation MySvnView
- (id) initWithFrame: (NSRect) frameRect
{
if (self = [super initWithFrame: frameRect])
{
}
return self;
}
- (void) dealloc
{
// dprintf("0x%X", self);
[self setPendingTask: nil];
[self setUrl: nil];
[self setRevision: nil];
[fOptionsInvocation release];
[super dealloc];
}
- (void) unload
{
// dprintf("%@ 0x%X->refs=%d", [self className], self, [self retainCount]);
// tell the task center to cancel pending callbacks to prevent crash
[Tasks cancelCallbacksOnTarget: self];
[self setPendingTask: nil];
[fView release]; // the nib is responsible for releasing its top-level objects
fView = nil;
// Unbind objects that are bound to the NIB file's owner
[progress unbind: NSAnimateBinding];
[refetch unbind: NSValueBinding];
}
- (IBAction) refetch: (id) sender
{
// An object that sends this message with a tag of the form 10### is an alias for
// the fetch command only (not the stop command).
const int tag = [sender tag];
if ((tag / 1000) == 10) // => Maps cmd-key to fetch only
{
if (!isFetching)
[[self viewWithTag: (tag % 1000)] performClick: self];
else
NSBeep();
}
else if ([sender state] == NSOnState) // => Fetch
{
[self fetchSvn];
}
else // => Stop
{
[self setIsFetching: FALSE];
if ( [self pendingTask] != nil )
{
NSTask *task = [[self pendingTask] valueForKey: @"task"];
if ( [task isRunning] )
{
[task terminate];
}
}
[self setPendingTask: nil];
}
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark svn related methods
- (void) fetchSvn
{
[self setIsFetching: TRUE];
}
- (void) svnCommandComplete: (id) taskObj
{
// NSLog(@"hom %@", stdOut(taskObj));
if (isCompleted(taskObj))
{
[self performSelectorOnMainThread: @selector(fetchSvnReceiveDataFinished:)
withObject: taskObj
waitUntilDone: YES];
// [self fetchSvnReceiveDataFinished: taskObj];
}
else if (taskObj = stdErr(taskObj))
[self svnError: taskObj];
}
- (void) svnError: (NSString*) errorString
{
if (fRepository)
{
[fRepository svnError: errorString];
return;
}
NSAlert *alert = [NSAlert alertWithMessageText: @"svn Error"
defaultButton: @"OK"
alternateButton: nil
otherButton: nil
informativeTextWithFormat: @"%@", errorString];
[alert setAlertStyle: NSCriticalAlertStyle];
[self setIsFetching: NO];
if ([self window] != nil)
{
[alert beginSheetModalForWindow: [self window]
modalDelegate: self
didEndSelector: nil
contextInfo: nil];
}
else
{
[alert runModal];
}
}
- (void) fetchSvnReceiveDataFinished: (id) taskObj
{
#pragma unused(taskObj)
[self setIsFetching: FALSE];
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark Helpers
- (NSInvocation*) makeCallbackInvocationOfKind: (int) callbackKind
{
#pragma unused(callbackKind)
// only one kind of invocation for now, but more complex callbacks will be possible in the future
return MakeCallbackInvocation(self, @selector(svnCommandComplete:));
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark Accessors
- (NSInvocation*) svnOptionsInvocation { return fOptionsInvocation; }
- (void) setSvnOptionsInvocation: (NSInvocation*) aSvnOptionsInvocation
{
id old = fOptionsInvocation;
fOptionsInvocation = [aSvnOptionsInvocation retain];
[old release];
}
// - url:
- (NSURL*) url { return fURL; }
- (void) setUrl: (NSURL*) anUrl
{
id old = fURL;
fURL = [anUrl retain];
[old release];
}
// - revision:
- (NSString*) revision { return fRevision; }
- (void) setRevision: (NSString*) aRevision
{
id old = fRevision;
fRevision = [aRevision retain];
[old release];
}
// - isFetching:
- (BOOL) isFetching { return isFetching; }
- (void) setIsFetching: (BOOL) flag
{
isFetching = flag;
}
// - pendingTask:
- (id) pendingTask { return pendingTask; }
- (void) setPendingTask: (id) aPendingTask
{
id old = pendingTask;
pendingTask = [aPendingTask retain];
[old release];
}
//----------------------------------------------------------------------------------------
// Returns the displayed repository or nil.
- (MyRepository*) repository
{
return fRepository;
}
//----------------------------------------------------------------------------------------
- (void) setRepository: (MyRepository*) repository
{
Assert(fRepository == nil);
fRepository = repository;
}
//----------------------------------------------------------------------------------------
- (NSDictionary*) documentNameDict
{
id itsTitle = nil;
if (fRepository)
itsTitle = [fRepository windowTitle];
if (itsTitle == nil)
itsTitle = [[self window] title];
if (itsTitle == nil)
itsTitle = @"";
return [NSDictionary dictionaryWithObject: itsTitle forKey: @"documentName"];
}
@end