-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorkspaceController.j
150 lines (132 loc) · 4.98 KB
/
WorkspaceController.j
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
// (c) 2010-2011 by Anton Korenyushkin
@import "BufferManager.j"
@import "WorkspaceItemView.j"
var DragType = "WorkspaceDragType";
@implementation WorkspaceController : CPObject
{
App app;
BufferManager bufferManager;
CPTableView tableView;
CPImageView spinnerImageView;
}
- (id)initWithApp:(App)anApp view:(CPView)superview bufferManager:(BufferManager)aBufferManager // public
{
if (self = [super init]) {
app = anApp;
bufferManager = aBufferManager;
[app addObserver:self forKeyPath:"buffers"];
[app addObserver:self forKeyPath:"bufferIndex"];
var scrollView = [[CPScrollView alloc] initWithFrame:[superview bounds]];
[scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[scrollView setHasHorizontalScroller:NO];
[scrollView setAutohidesScrollers:YES];
[superview addSubview:scrollView];
tableView = [[CPTableView alloc] initWithFrame:[scrollView bounds]];
[tableView setHidden:YES];
[tableView setAllowsEmptySelection:NO];
[tableView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[tableView setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
[tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
[tableView registerForDraggedTypes:[DragType]];
[tableView setDraggingDestinationFeedbackStyle:CPTableViewDropAbove];
var column = [CPTableColumn new];
[column setDataView:[WorkspaceItemView new]];
[[column headerView] setStringValue:"Workspace"];
[[column headerView] setValue:[[column headerView] valueForThemeAttribute:"background-color"]
forThemeAttribute:"background-color"];
[tableView addTableColumn:column];
[scrollView setDocumentView:tableView];
[tableView sizeLastColumnToFit];
var superviewSize = [superview boundsSize];
spinnerImageView =
[[CPImageView alloc] initWithFrame:CGRectMake(superviewSize.width / 2 - 16, superviewSize.height / 2 - 4, 32, 32)];
[spinnerImageView setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[spinnerImageView setImage:[CPImage imageFromPath:"WhiteSpinner32.gif"]];
[superview addSubview:spinnerImageView];
}
return self;
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(id)context // private
{
switch (keyPath) {
case "buffers":
if ([tableView isHidden]) {
[spinnerImageView removeFromSuperview];
[tableView setDataSource:self];
[tableView setDelegate:self];
[tableView setHidden:NO];
} else {
[tableView reloadData];
}
break;
case "bufferIndex":
[tableView scrollRowToVisible:app.bufferIndex];
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:app.bufferIndex] byExtendingSelection:NO];
break;
}
}
- (unsigned)numberOfRowsInTableView:(CPTableView)aTableView // private
{
return app.buffers.length;
}
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(unsigned)column row:(unsigned)row // private
{
return app.buffers[row];
}
- (BOOL)tableView:(CPTableView)aTableView
writeRowsWithIndexes:(CPIndexSet)rowIndexes
toPasteboard:(CPPasteboard)pasteboard // private
{
[pasteboard declareTypes:[DragType] owner:self];
[pasteboard setData:rowIndexes forType:DragType];
return YES;
}
- (CPDragOperation)tableView:(CPTableView)aTableView
validateDrop:(id)info
proposedRow:(CPInteger)row
proposedDropOperation:(CPTableViewDropOperation)operation // private
{
[tableView setDropRow:row dropOperation:CPTableViewDropAbove];
return CPDragOperationMove;
}
- (BOOL)tableView:(CPTableView)aTableView
acceptDrop:(id)info
row:(int)row
dropOperation:(CPTableViewDropOperation)operation // private
{
[bufferManager moveBufferWithIndex:[[[info draggingPasteboard] dataForType:DragType] firstIndex] to:row];
return YES;
}
- (void)tableViewSelectionDidChange:(id)sender // private
{
[app setBufferIndex:[tableView selectedRow]];
}
- (void)switchToEdit // public
{
if ([bufferManager openBufferOfClass:FileBuffer])
return;
var entry = [app.code childWithName:"main.js"];
if ([entry isKindOfClass:File])
[bufferManager openNewBuffer:[[CodeFileBuffer alloc] initWithFile:entry]];
}
- (void)switchToCommit // public
{
[bufferManager openBuffer:[CommitBuffer new]];
}
- (void)switchToGit // public
{
[bufferManager openBuffer:[GitBuffer new]];
}
- (void)closeCurrentBuffer // public
{
[bufferManager closeBuffer:app.buffer askToSave:YES];
}
- (void)switchToPreviousBuffer // public
{
[app setBufferIndex:(app.bufferIndex || app.buffers.length) - 1];
}
- (void)switchToNextBuffer // public
{
[app setBufferIndex:(app.bufferIndex + 1) % app.buffers.length];
}
@end