-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyFileMergeController.m
197 lines (153 loc) · 5.71 KB
/
MyFileMergeController.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
//
// MyFileMergeController.m - Controller for UI sheet for Subversion diff using selection(s) from log
//
#import "MyFileMergeController.h"
#import "MySvn.h"
#import "MySvnLogView.h"
#import "MyWorkingCopy.h"
#import "NSString+MyAdditions.h"
#import "RepoItem.h"
#import "Tasks.h"
#import "CommonUtils.h"
@implementation MyFileMergeController
//----------------------------------------------------------------------------------------
// Private:
- (void) setupWithOptions: (NSInvocation*) options
sourceItem: (NSDictionary*) sourceItem
descPath: (id) descPath
descRev: (NSString*) descRev
{
if (svnOptionsInvocation != options)
{
[svnOptionsInvocation release];
svnOptionsInvocation = [options retain];
}
[objectController setValue: sourceItem forKeyPath: @"content.sourceItem"];
[objectController setValue: PathWithRevision(descPath, descRev) forKeyPath: @"content.desc"];
[svnLogView setRevision: descRev];
[svnLogView setSvnOptionsInvocation: options];
[svnLogView fetchSvn];
}
//----------------------------------------------------------------------------------------
- (void) setupUrl: (NSURL*) url
options: (NSInvocation*) options
revision: (NSString*) revision
{
// dprintf("(url=<%@> revision=%@)", url, revision);
[svnLogView setPath: [url absoluteString]];
[objectController setValue: url forKeyPath: @"content.itemUrl"];
[self setupWithOptions: options
sourceItem: [NSDictionary dictionaryWithObject: url forKey: @"url"] // content.sourceItem.url
descPath: url
descRev: revision];
}
//----------------------------------------------------------------------------------------
// Private:
- (id) initDiffSheet: (MyWorkingCopy*) workingCopy
path: (NSString*) path
sourceItem: (NSDictionary*) sourceItem
{
if (self = [super init])
{
svnOperation = kSvnDiff; // kSvnWCDiff?
if ([NSBundle loadNibNamed: @"svnFileMerge" owner: self])
{
[svnLogView setPath: path];
[objectController setValue: path forKeyPath: @"content.itemPath"];
[self setupWithOptions: [workingCopy svnOptionsInvocation] sourceItem: sourceItem
descPath: path descRev: [sourceItem objectForKey: @"revisionCurrent"]];
[NSApp beginSheet: svnSheet
modalForWindow: [workingCopy windowForSheet]
modalDelegate: [workingCopy controller]
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: self];
}
else
dprintf("loadNibNamed FAILED");
}
return self;
}
//----------------------------------------------------------------------------------------
+ (void) runSheet: (MyRepository*) repository
url: (NSURL*) url
revision: (NSString*) revision
{
[self runSheet: kSvnDiff repository: repository url: url revision: revision];
}
//----------------------------------------------------------------------------------------
+ (void) runSheet: (MyWorkingCopy*) workingCopy
path: (NSString*) path
sourceItem: (NSDictionary*) sourceItem
{
[[self alloc] initDiffSheet: workingCopy path: path sourceItem: sourceItem];
}
//----------------------------------------------------------------------------------------
- (void) finished
{
[svnLogView unload];
// the owner has to release its top level nib objects
[svnSheet release];
[objectController release];
[self release];
}
//----------------------------------------------------------------------------------------
- (IBAction) validate: (id) sender
{
id callback = [objectController valueForKeyPath: @"content.sourceItem.callback"];
if (callback) // see singleFileInspector
{
// [callback closeCallback];
}
[NSApp endSheet: svnSheet returnCode: [sender tag]];
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark FileMerge
//----------------------------------------------------------------------------------------
// Private:
- (void) comparePath: (NSString*) path
toWorkingCopy: (BOOL) toWorkingCopy
{
// Block the button's action if the list is currently unpopulated.
if ([svnLogView selectedRevision] == nil || [svnLogView currentRevision] == nil)
{
NSBeep();
return;
}
id revOption = [NSString stringWithFormat:
toWorkingCopy ? @"-r%@" // Compare selected to working copy
: @"-r%@:%@", // Compare selected to marked
[svnLogView selectedRevision], [svnLogView currentRevision]];
[MySvn diffItems: [NSArray arrayWithObject: path]
generalOptions: svnOptionsInvocation
options: [NSArray arrayWithObject: revOption]
callback: MakeCallbackInvocation(self, @selector(fileMergeCallback:))
callbackInfo: nil
taskInfo: [NSDictionary dictionaryWithObject: @"svnDiff" forKey: @"documentName"]];
}
//----------------------------------------------------------------------------------------
// used by fileHistoryOpenSheetForItem from MyWorkingCopyController
- (IBAction) compare: (id) sender
{
[self comparePath: [objectController valueForKeyPath: @"content.sourceItem.fullPath"]
toWorkingCopy: ([sender tag] == 0)];
}
//----------------------------------------------------------------------------------------
// used by svnFileMerge from MyRepository
- (IBAction) compareUrl: (id) sender
{
#pragma unused(sender)
NSString* path = [[objectController valueForKeyPath: @"content.sourceItem.url"] absoluteString];
[self comparePath: PathPegRevision(path, [svnLogView revision]) toWorkingCopy: NO];
}
//----------------------------------------------------------------------------------------
- (void) fileMergeCallback: (id) taskObj
{
if (!isCompleted(taskObj))
{
NSString* errorString = stdErr(taskObj);
if (errorString)
[svnLogView svnError: taskObj];
}
}
@end