-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutlinerDataSource.m
157 lines (116 loc) · 4.63 KB
/
OutlinerDataSource.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
#import "OutlinerDataSource.h"
#import "MyWorkingCopy.h"
#import "MyWorkingCopyController.h"
#import "IconTextCell.h"
@implementation OutlinerDataSource
//----------------------------------------------------------------------------------------
// Data Source methods
- (int) outlineView: (NSOutlineView*) outlineView
numberOfChildrenOfItem: (id) item
{
#pragma unused(outlineView)
return (item == nil) ? 1 : [item childCount];
}
- (BOOL) outlineView: (NSOutlineView*) outlineView
isItemExpandable: (id) item
{
#pragma unused(outlineView)
return (item == nil) || [item childCount] > 0;
}
- (id) outlineView: (NSOutlineView*) outlineView
child: (int) index
ofItem: (WCTreeEntry*) item
{
#pragma unused(outlineView)
return (item == nil) ? [document svnDirectories] : [item childAtIndex: index];
}
- (id) outlineView: (NSOutlineView*) outlineView
objectValueForTableColumn: (NSTableColumn*) tableColumn
byItem: (id) item
{
#pragma unused(outlineView, tableColumn)
return (item == nil) ? @"/" : [item name];
}
//----------------------------------------------------------------------------------------
// Delegate methods
- (BOOL) outlineView: (NSOutlineView*) outlineView
shouldEditTableColumn: (NSTableColumn*) tableColumn
item: (id) item
{
#pragma unused(outlineView, tableColumn, item)
return NO;
}
//----------------------------------------------------------------------------------------
- (void) outlineViewSelectionDidChange: (NSNotification*) notification
{
NSOutlineView* const ov = [notification object];
NSString* treePath = [[ov itemAtRow: [ov selectedRow]] path];
if (treePath)
[document setOutlineSelectedPath: treePath];
else
[controller selectTreePath: [document outlineSelectedPath]];
[controller performSelector: @selector(prefsChanged) withObject: nil afterDelay: 0];
}
//----------------------------------------------------------------------------------------
- (void) outlineView: (NSOutlineView*) outlineView
willDisplayCell: (id) cell
forTableColumn: (NSTableColumn*) tableColumn
item: (id) item
{
#pragma unused(outlineView, tableColumn)
[cell setIconRef: [item icon: document]];
}
//----------------------------------------------------------------------------------------
- (void) outlineViewItemDidCollapse: (NSNotification*) notification
{
#pragma unused(notification)
[controller performSelector: @selector(calcTreeExpanded) withObject: nil afterDelay: 0];
}
//----------------------------------------------------------------------------------------
- (void) outlineViewItemDidExpand: (NSNotification*) notification
{
#pragma unused(notification)
[controller performSelector: @selector(calcTreeExpanded) withObject: nil afterDelay: 0];
}
//----------------------------------------------------------------------------------------
// Dragging
- (NSDragOperation) outlineView: (NSOutlineView*) outlineView
validateDrop: (id<NSDraggingInfo>) sender
proposedItem: (id) item
proposedChildIndex: (int) childIndex
{
#pragma unused(outlineView, item)
if (childIndex != -1 || [sender draggingSource] != [controller valueForKey: @"tableResult"])
return NSDragOperationNone; // childIndex = -1 : inside the folder
// we want to return the correct mask in order to let the system show the appropriate "drag icon"
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
if (sourceDragMask & NSDragOperationMove)
return NSDragOperationMove;
if (sourceDragMask & NSDragOperationCopy)
return NSDragOperationCopy;
// default
return NSDragOperationNone;
}
//----------------------------------------------------------------------------------------
- (BOOL) outlineView: (NSOutlineView*) outlineView
acceptDrop: (id<NSDraggingInfo>) sender
item: (id) targetItem
childIndex: (int) childIndex
{
#pragma unused(outlineView, childIndex)
// NSPasteboard* pboard = [sender draggingPasteboard];
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
NSString* fullPath = [[document workingCopyPath] stringByAppendingPathComponent: [targetItem path]];
if (sourceDragMask & NSDragOperationMove)
{
//NSLog(@"move to : %@", fullPath);
[controller requestSvnMoveSelectedItemsToDestination: fullPath];
}
else if (sourceDragMask & NSDragOperationCopy)
{
//NSLog(@"copy to : %@", fullPath);
[controller requestSvnCopySelectedItemsToDestination: fullPath];
}
return YES;
}
@end