-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseFileController.j
More file actions
178 lines (153 loc) · 5.63 KB
/
BaseFileController.j
File metadata and controls
178 lines (153 loc) · 5.63 KB
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
// (c) 2010-2011 by Anton Korenyushkin
@import "SmartScrollView.j"
@import "EditorView.j"
@import "BasePresentationController.j"
@import "GoToLinePanelController.j"
@implementation BaseFileController : BasePresentationController
{
CPView view @accessors(readonly);
GoToLinePanelController goToLinePanelController;
CPView searchView;
CPSearchField searchField;
CPSegmentedControl segmentedControl;
EditorView editorView;
SmartScrollView scrollView;
CPImageView spinnerImageView;
}
- (id)initWithApp:(App)anApp
buffer:(Buffer)aBuffer
fileName:(CPString)fileName
fileURL:(CPString)fileURL
readOnly:(BOOL)readOnly // public
{
self = [super initWithApp:anApp buffer:aBuffer];
if (!self)
return self;
view = [CPView new];
var dotIndex = fileName.lastIndexOf(".");
var extension = dotIndex == -1 ? "" : fileName.substring(dotIndex + 1).toLowerCase();
if (["jpg", "jpeg", "gif", "png", "bmp"].indexOf(extension) == -1) {
goToLinePanelController = [[GoToLinePanelController alloc] initWithTarget:self action:@selector(goToLine:)];
searchView = [CPView new];
[searchView setAutoresizingMask:CPViewWidthSizable];
[searchView setBackgroundColor:[CPColor colorWithPatternImage:[CPImage imageFromPath:"SearchViewBackground.png"]]];
var doneButton = [[CPButton alloc] initWithFrame:CGRectMake(-58, 3, 50, 24)];
[doneButton setAutoresizingMask:CPViewMinXMargin];
[doneButton setKeyEquivalent:CPEscapeFunctionKey];
[doneButton setTitle:"Done"];
[doneButton setTarget:self];
[doneButton setAction:@selector(hideFind)];
[searchView addSubview:doneButton];
searchField = [[CPSearchField alloc] initWithFrame:CGRectMake(-270, 0, 207, 30)];
[searchField setAutoresizingMask:CPViewMinXMargin];
[searchField setTarget:self];
[searchField setAction:@selector(find)];
var searchButton = [searchField searchButton];
[searchView addSubview:searchField];
segmentedControl = [[CPSegmentedControl alloc] initWithFrame:CGRectMake(-335, 3, 0, 24)];
[segmentedControl setAutoresizingMask:CPViewMinXMargin];
[segmentedControl setTrackingMode:CPSegmentSwitchTrackingMomentary];
[segmentedControl setTarget:self];
[segmentedControl setAction:@selector(didClickOnSegmentedControl)];
[segmentedControl setSegmentCount:2];
[segmentedControl setLabel:"◀" forSegment:0];
[segmentedControl setWidth:30 forSegment:0];
[segmentedControl setLabel:"▶" forSegment:1];
[segmentedControl setWidth:31 forSegment:1];
[searchView addSubview:segmentedControl];
editorView = [[EditorView alloc] initWithFrame:CGRectMakeZero() syntax:extension readOnly:readOnly];
[editorView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[editorView setDelegate:self];
if ([self fileContent] !== nil) {
[self setupEditor];
return self;
}
[self load];
} else {
scrollView = [[SmartScrollView alloc] initWithFrame:CGRectMakeZero()];
[scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[scrollView setAutohidesScrollers:YES];
var imageView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
[imageView setImageScaling:CPScaleNone];
var image = [[CPImage alloc] initWithContentsOfFile:fileURL];
[image setDelegate:self];
[imageView setImage:image];
[scrollView setDocumentView:imageView];
[view addSubview:scrollView];
}
spinnerImageView = [[CPImageView alloc] initWithFrame:[view bounds]];
[spinnerImageView setImage:[CPImage imageFromPath:"WhiteSpinner32.gif"]];
[spinnerImageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[spinnerImageView setImageScaling:CPScaleNone];
[view addSubview:spinnerImageView];
[buffer setProcessing:YES];
return self;
}
- (void)focus // public
{
if (editorView)
[[view window] makeFirstResponder:editorView];
else
window.focus();
}
- (void)setupEditor // private
{
[spinnerImageView removeFromSuperview];
[editorView setFrame:[view bounds]];
[editorView setStringValue:[self fileContent]];
[view addSubview:editorView];
[self focus];
[buffer setEditable:YES];
}
- (void)showGoToLine // public
{
[goToLinePanelController showWindow:nil];
}
- (void)goToLine:(unsigned)lineNumber // private
{
[editorView setLineNumber:lineNumber];
[self focus];
}
- (void)showFind // public
{
if (![searchView superview]) {
var boundsSize = [view boundsSize];
[editorView setFrame:CGRectMake(0, 31, boundsSize.width, boundsSize.height - 31)];
[searchView setFrame:CGRectMake(0, 0, boundsSize.width, 31)];
[view addSubview:searchView];
}
[[view window] makeFirstResponder:searchField];
}
- (void)hideFind // private
{
[searchView removeFromSuperview];
[editorView setFrame:[view bounds]];
[self focus];
}
- (void)find // private
{
[editorView find:[searchField stringValue]];
}
- (void)didClickOnSegmentedControl // private
{
if ([segmentedControl selectedSegment] == 0)
[editorView findPrevious];
else
[editorView findNext];
[[view window] makeFirstResponder:searchField];
}
- (void)findNext // public
{
[editorView findNext];
}
- (void)findPrevious // public
{
[editorView findPrevious];
}
- (void)imageDidLoad:(CPImage)image // private
{
[buffer setProcessing:NO];
[spinnerImageView removeFromSuperview];
[scrollView setBaseSize:[image size]];
}
@end