-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFLController.m
More file actions
209 lines (175 loc) · 5.07 KB
/
FLController.m
File metadata and controls
209 lines (175 loc) · 5.07 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
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
/* Copyright (C) 1996 Dave Vasilevsky
* This file is licensed under the GNU General Public License,
* see the file Copying.txt for details. */
#import "FLController.h"
#import "FLDirectoryDataSource.h"
static NSString *ToolbarID = @"Filelight Toolbar";
static NSString *ToolbarItemUpID = @"Up ToolbarItem";
static NSString *ToolbarItemRefreshID = @"Refresh ToolbarItem";
@implementation FLController
#pragma mark Toolbar
- (void) setupToolbar
{
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: ToolbarID];
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: YES];
[toolbar setAutosavesConfiguration: YES];
[window setToolbar: toolbar];
}
- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar
itemForItemIdentifier: (NSString *) itemID
willBeInsertedIntoToolbar: (BOOL) willInsert
{
NSToolbarItem *item = [[NSToolbarItem alloc]
initWithItemIdentifier: itemID];
if ([itemID isEqual: ToolbarItemUpID]) {
[item setLabel: @"Up"];
[item setToolTip: @"Go to the parent directory"];
[item setImage: [NSImage imageNamed: @"arrowUp"]];
[item setAction: @selector(parentDir:)];
} else if ([itemID isEqual: ToolbarItemRefreshID]) {
[item setLabel: @"Refresh"];
[item setToolTip: @"Rescan the current directory"];
[item setImage: [NSImage imageNamed: @"reload"]];
[item setAction: @selector(refresh:)];
} else {
[item release];
return nil;
}
if (![item paletteLabel]) {
[item setPaletteLabel: [item label]];
}
if (![item target]) {
[item setTarget: self];
}
return [item autorelease];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
{
return [NSArray arrayWithObjects:
ToolbarItemUpID,
ToolbarItemRefreshID,
nil];
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
{
return [NSArray arrayWithObjects:
ToolbarItemUpID,
ToolbarItemRefreshID,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
nil];
}
- (BOOL) validateToolbarItem: (NSToolbarItem *) item
{
if ([[item itemIdentifier] isEqual: ToolbarItemUpID]) {
return ![FLScanner isMountPoint: [[self rootDir] path]];
}
return YES;
}
#pragma mark Scanning
- (FLDirectory *) scanDir
{
return m_scanDir;
}
- (void) setScanDir: (FLDirectory *) dir
{
[dir retain];
if (m_scanDir) [m_scanDir release];
m_scanDir = dir;
}
- (BOOL) startScan: (NSString *) path
{
if (m_scanner) {
return NO;
}
[tabView selectTabViewItemWithIdentifier: @"Progress"];
[progress setDoubleValue: [progress minValue]];
[scanDisplay setStringValue: @""];
[window makeKeyAndOrderFront: self];
m_scanner = [[FLScanner alloc] initWithPath: path
progress: progress
display: scanDisplay];
[m_scanner scanThenPerform: @selector(finishScan:)
on: self];
return YES;
}
- (void) finishScan: (id) data
{
if ([m_scanner scanError]) {
if (![m_scanner isCancelled]) {
NSRunAlertPanel(@"Directory scan could not complete",
[m_scanner scanError], nil, nil, nil);
}
[window orderOut: self];
} else {
[self setScanDir: [m_scanner scanResult]];
[self setRootDir: [self scanDir]];
[tabView selectTabViewItemWithIdentifier: @"Filelight"];
}
[m_scanner release];
m_scanner = nil;
}
- (IBAction) cancelScan: (id) sender
{
if (m_scanner) {
[m_scanner cancel];
}
}
#pragma mark Misc
- (BOOL) application: (NSApplication *) app openFile: (NSString *) filename
{
return [self startScan: filename];
}
- (void) awakeFromNib
{
m_scanner = nil;
m_scanDir = nil;
[self setupToolbar];
}
- (IBAction) open: (id) sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories: YES];
[openPanel setCanChooseFiles: NO];
int result = [openPanel runModal];
if (result == NSOKButton) {
NSURL *fileURL = [[openPanel URLs] objectAtIndex: 0];
NSString *path = [fileURL path];
[self startScan: path];
}
}
- (void) applicationDidFinishLaunching: (NSNotification*) notification
{
if (![window isVisible]) {
[self open: self];
}
}
- (void) setRootDir: (FLDirectory *) dir
{
[[sizer dataSource] setRootDir: dir];
[sizer setNeedsDisplay: YES];
[window setTitle: [dir path]];
}
- (FLDirectory *) rootDir
{
return [[sizer dataSource] rootDir];
}
- (void) parentDir: (id) sender
{
FLDirectory *parent = [[self rootDir] parent];
if (parent) {
[self setRootDir: parent];
} else {
NSString *path = [[self rootDir] path];
path = [path stringByDeletingLastPathComponent];
[self startScan: path];
}
}
- (void) refresh: (id) sender
{
[self startScan: [[self rootDir] path]];
}
@end