-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySvnFilesArrayController.m
136 lines (102 loc) · 2.96 KB
/
MySvnFilesArrayController.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
//
// MySvnFilesArrayController.m
//
#import "MySvnFilesArrayController.h"
#import "MyWorkingCopy.h"
#import "CommonUtils.h"
//----------------------------------------------------------------------------------------
@implementation MySvnFilesArrayController
- (void) search: (id) sender
{
[self setSearchString: [sender stringValue]];
[self rearrangeObjects];
}
- (NSArray*) arrangeObjects: (NSArray*) objects
{
NSMutableArray* matchedObjects = [NSMutableArray arrayWithCapacity: [objects count]];
const int filter = [document filterMode];
const BOOL treeMode = ![document flatMode];
NSString* const selectedPath = [document outlineSelectedPath];
NSString* const lowerSearch = (searchString != nil && [searchString length] > 0) ? [searchString lowercaseString] : nil;
BOOL isCommittable = NO;
for_each_obj(en, item, objects)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
BOOL test = TRUE;
if (filter != kFilterAll)
{
const unichar c1 = [[item objectForKey: @"col1"] characterAtIndex: 0],
c2 = [[item objectForKey: @"col2"] characterAtIndex: 0];
switch (filter)
{
case kFilterModified:
test = (c1 == 'M' || c2 == 'M');
break;
case kFilterNew:
test = (c1 == '?');
break;
case kFilterMissing:
test = (c1 == '!');
break;
case kFilterConflict:
test = (c1 == 'C' || c2 == 'C');
break;
case kFilterChanged: // Modified, added, deleted, replaced, conflict, missing, wrong kind
test = (c1 == 'M' || c1 == 'A' || c1 == 'D' || c1 == 'R' || c1 == 'C' || c1 == '!' || c1 == '~');
if (!test)
test = (c2 == 'M' || c2 == 'C'); // Modified or conflict property
break;
}
}
NSString* path = nil;
if (test && treeMode)
{
test = [[item objectForKey: @"dirPath"] isEqualToString: selectedPath] &&
![(path = [item objectForKey: @"path"]) isEqualToString: selectedPath];
}
if (test && lowerSearch)
{
if (path == nil)
path = [item objectForKey: @"path"];
test = ([[path lowercaseString] rangeOfString: lowerSearch].location != NSNotFound);
}
if (test)
[matchedObjects addObject: item];
if (!isCommittable)
isCommittable = [[item objectForKey: @"committable"] boolValue];
[pool release];
}
[self setCommittable: isCommittable];
return [super arrangeObjects: matchedObjects];
}
// - dealloc:
- (void) dealloc
{
[self setSearchString: nil];
[super dealloc];
}
// - searchString:
- (NSString*) searchString
{
return searchString;
}
// - setSearchString:
- (void) setSearchString: (NSString*) newSearchString
{
if (searchString != newSearchString)
{
[searchString autorelease];
searchString = [newSearchString copy];
}
}
//----------------------------------------------------------------------------------------
- (BOOL) committable
{
return committable;
}
//----------------------------------------------------------------------------------------
- (void) setCommittable: (BOOL) isCommittable
{
committable = isCommittable;
}
@end