-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableViewDelegate.m
278 lines (226 loc) · 9.22 KB
/
TableViewDelegate.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//----------------------------------------------------------------------------------------
// TableViewDelegate.m
//
// Copyright © Chris, 2007 - 2010. All rights reserved.
//----------------------------------------------------------------------------------------
#import "TableViewDelegate.h"
#import "MyWorkingCopy.h"
#import "MyWorkingCopyController.h"
#import "NSString+MyAdditions.h"
#import "IconTextCell.h"
#import "CommonUtils.h"
#import "IconUtils.h"
enum { kFirstColumn = 1, kNumColumns = 8 };
static NSDictionary* helpTags[kNumColumns + 1] = { nil };
static ConstString colKeys[kNumColumns + 1] = {
nil, @"col1", @"col2", @"col3", @"col4", @"col5", @"col6", @"col7", @"col8"
};
//----------------------------------------------------------------------------------------
NSString*
HelpTagForWCItem (NSDictionary* wcFileInfo)
{
Assert(helpTags[1]);
NSMutableString* help = [NSMutableString string];
for (int i = kFirstColumn; i <= kNumColumns; ++i)
{
NSString* key = [wcFileInfo objectForKey: colKeys[i]];
if ([key isEqualToString: @" "])
continue;
NSString* str = [helpTags[i] objectForKey: key];
if (str)
{
if ([help length])
[help appendString: @"\n"];
[help appendString: str];
}
}
return help;
}
//----------------------------------------------------------------------------------------
@implementation TableViewDelegate
//----------------------------------------------------------------------------------------
- (id) init
{
if (helpTags[1] == nil)
{
// Item changes
helpTags[1] = [NSDictionary dictionaryWithObjectsAndKeys:
@"No modifications.", @" ",
@"Item is scheduled for Addition.", @"A",
@"Item is scheduled for Deletion.", @"D",
@"Item has been modified.", @"M",
@"Item has been replaced in your working copy. This means the file was scheduled for deletion,"
" and then a new file with the same name was scheduled for addition in its place.", @"R",
@"The contents (as opposed to the properties) of the item"
" conflict with updates received from the repository.", @"C",
@"Item is related to an externals definition.", @"X",
@"Item is being ignored (e.g. with the svn:ignore property).", @"I",
@"Item is not under version control.", @"?",
@"Item is missing (e.g. you moved or deleted it without using svn)."
" This also indicates that a directory is incomplete (a checkout or update was interrupted).", @"!",
@"Item is versioned as one kind of object (file, directory, link),"
" but has been replaced by different kind of object.", @"~",
@"Item has been modified and has received updates from the repository.", @"G",
nil];
// Properties
helpTags[2] = [NSDictionary dictionaryWithObjectsAndKeys:
@"No property modifications.", @" ",
@"Properties for this item have been modified.", @"M",
@"Properties for this item are in conflict with property updates received from the repository.", @"C",
nil];
// Working copy directory is locked
helpTags[3] = [NSDictionary dictionaryWithObjectsAndKeys:
@"Item is not locked.", @" ",
@"Item is locked. (You may want to run svn clean up!)", @"L",
nil];
// Scheduled for addition-with-history
helpTags[4] = [NSDictionary dictionaryWithObjectsAndKeys:
@"No history scheduled with commit.", @" ",
@"History scheduled with commit.", @"+",
nil];
// Switched
helpTags[5] = [NSDictionary dictionaryWithObjectsAndKeys:
@"Item is a child of its parent directory.", @" ",
@"Item is switched.", @"S",
nil];
// Lock
helpTags[6] = [NSDictionary dictionaryWithObjectsAndKeys:
@"Item is not locked in this working copy.", @" ",
@"Item is locked in this working copy.", @"K",
@"Item is locked either by another user or in another working copy.", @"O",
UTF_8_16("Item was locked in this working copy, but the lock has been \xE2\x80\x98"
"stolen\xE2\x80\x99 and is invalid. The file is currently locked in the repository.",
"Item was locked in this working copy, but the lock has been \u2018"
"stolen\u2019 and is invalid. The file is currently locked in the repository."), @"T",
UTF_8_16("Item was locked in this working copy, but the lock has been \xE2\x80\x98"
"broken\xE2\x80\x99 and is invalid. The file is no longer locked.",
"Item was locked in this working copy, but the lock has been \u2018"
"broken\u2019 and is invalid. The file is no longer locked."), @"B",
nil];
// Out-of-date information
helpTags[7] = [NSDictionary dictionaryWithObjectsAndKeys:
@"Item is up-to-date.", @" ",
@"A newer revision of the item exists in the repository.", @"*",
@"A newer revision of the item exists in the repository.", @"M",
nil];
helpTags[8] = [NSDictionary dictionaryWithObjectsAndKeys:
@"Item has properties", @"P",
UTF_8_16("Item doesn\xE2\x80\x99t have any properties.",
"Item doesn\u2019t have any properties."), @" ",
nil];
for (int i = kFirstColumn; i <= kNumColumns; ++i)
[helpTags[i] retain];
}
return [super init];
}
//----------------------------------------------------------------------------------------
- (int) numberOfRowsInTableView: (NSTableView*) tableView
{
#pragma unused(tableView)
return [[svnFilesAC arrangedObjects] count];
}
//----------------------------------------------------------------------------------------
- (BOOL) tableView: (NSTableView*) tableView
writeRowsWithIndexes: (NSIndexSet*) rowIndexes
toPasteboard: (NSPasteboard*) pboard
{
NSArray* filePaths;
id types[2];
int typesCount = 0;
#if 1
if ([document flatMode])
{
// Don't require items to be selected in order to drag them
filePaths = [[[svnFilesAC arrangedObjects] objectsAtIndexes: rowIndexes] valueForKey: @"fullPath"];
}
else
{
// Let's prevent the user from dragging non selected items
unsigned int index;
for (index = [rowIndexes firstIndex]; index != NSNotFound;
index = [rowIndexes indexGreaterThanIndex: index])
{
if (![tableView isRowSelected: index])
[tableView selectRowIndexes: rowIndexes byExtendingSelection: NO];
if (![tableView isRowSelected: index])
return NO;
}
filePaths = [[svnFilesAC selectedObjects] valueForKey: @"fullPath"];
types[typesCount++] = @"svnX";
}
#elif 1
// FIX_ME: In Tree Mode this does svn mv on the selected items (not the dragged items)
// Don't require items to be selected in order to drag them
filePaths = [[[svnFilesAC arrangedObjects] objectsAtIndexes: rowIndexes] valueForKey: @"fullPath"];
if (![document flatMode])
types[typesCount++] = @"svnX";
#endif
types[typesCount++] = NSFilenamesPboardType;
[pboard declareTypes: [NSArray arrayWithObjects: types count: typesCount] owner: nil];
[pboard setPropertyList: filePaths forType: NSFilenamesPboardType];
return YES;
}
//----------------------------------------------------------------------------------------
- (BOOL) control: (NSControl*) control
textShouldEndEditing: (NSText*) fieldEditor
{
#pragma unused(control)
[[document controller] requestSvnRenameSelectedItemTo:
[[[document workingCopyPath] stringByAppendingPathComponent: [document outlineSelectedPath]]
stringByAppendingPathComponent: [fieldEditor string]]];
return FALSE;
}
//----------------------------------------------------------------------------------------
- (NSString*) tableView: (NSTableView*) aTableView
toolTipForCell: (NSCell*) aCell
rect: (NSRectPointer) rect
tableColumn: (NSTableColumn*) aTableColumn
row: (int) row
mouseLocation: (NSPoint) mouseLocation
{
#pragma unused(aTableView, aCell, rect, mouseLocation)
const int colID = [[aTableColumn identifier] intValue];
if (colID >= kFirstColumn && colID <= kNumColumns)
{
// dprintf_("tableView %d: helpTags=%@ colKeys=%@", colID, helpTags[colID], colKeys[colID]);
NSDictionary* rowDict = [[svnFilesAC arrangedObjects] objectAtIndex: row];
return [helpTags[colID] objectForKey: [rowDict objectForKey: colKeys[colID]]];
}
else if (aTableColumn == fPathColumn)
{
return HelpTagForWCItem([[svnFilesAC arrangedObjects] objectAtIndex: row]);
}
return @"";
}
//----------------------------------------------------------------------------------------
- (void) tableView: (NSTableView*) tableView
willDisplayCell: (id) cell
forTableColumn: (NSTableColumn*) tableColumn
row: (int) row
{
#pragma unused(tableView)
// dprintf("col=%@ row=%d", [tableColumn identifier], row);
if (!fPathColumn)
fPathColumn = [tableView tableColumnWithIdentifier: @"path"];
if (tableColumn == fPathColumn)
{
NSDictionary* item = [[svnFilesAC arrangedObjects] objectAtIndex: row];
ConstString fullPath = [item objectForKey: @"fullPath"];
Boolean isDirectory = [[item objectForKey: @"isDir"] boolValue];
char path[2048];
if (ToUTF8(fullPath, path, sizeof(path)))
[cell setIconRef: GetFileOrTypeIcon(path, fullPath, &isDirectory)];
}
}
//----------------------------------------------------------------------------------------
- (void) tableViewSelectionDidChange: (NSNotification*) notification
{
#pragma unused(notification)
[[document controller] selectionChanged];
}
//----------------------------------------------------------------------------------------
- (id) document
{
return document;
}
@end // TableViewDelegate