1 |
/* SmallIconsPanel.m |
2 |
* |
3 |
* Copyright (C) 2003 Free Software Foundation, Inc. |
4 |
* |
5 |
* Author: Enrico Sersale <enrico@imago.ro> |
6 |
* Date: August 2001 |
7 |
* |
8 |
* This file is part of the GNUstep GWorkspace application |
9 |
* |
10 |
* This program is free software; you can redistribute it and/or modify |
11 |
* it under the terms of the GNU General Public License as published by |
12 |
* the Free Software Foundation; either version 2 of the License, or |
13 |
* (at your option) any later version. |
14 |
* |
15 |
* This program is distributed in the hope that it will be useful, |
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* GNU General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
*/ |
24 |
|
25 |
|
26 |
#include <Foundation/Foundation.h> |
27 |
#include <AppKit/AppKit.h> |
28 |
#ifdef GNUSTEP |
29 |
#include "GWLib.h" |
30 |
#include "GWProtocol.h" |
31 |
#include "GWFunctions.h" |
32 |
#include "GWNotifications.h" |
33 |
#else |
34 |
#include <GWorkspace/GWLib.h> |
35 |
#include <GWorkspace/GWProtocol.h> |
36 |
#include <GWorkspace/GWFunctions.h> |
37 |
#include <GWorkspace/GWNotifications.h> |
38 |
#endif |
39 |
#include "SmallIconsPanel.h" |
40 |
#include "SmallIcon.h" |
41 |
#include "GNUstep.h" |
42 |
|
43 |
#ifndef max |
44 |
#define max(a,b) ((a) >= (b) ? (a):(b)) |
45 |
#endif |
46 |
|
47 |
#ifndef min |
48 |
#define min(a,b) ((a) <= (b) ? (a):(b)) |
49 |
#endif |
50 |
|
51 |
#define ICNWIDTH 32 |
52 |
#define ICNHEIGHT 26 |
53 |
#define LABHEIGHT 14 |
54 |
#define ROWSHEIGHT 32 |
55 |
#define LEFTMARGIN 16 |
56 |
#define ICON_FRAME_MARGIN 6 |
57 |
|
58 |
#define SETRECT(o, x, y, w, h) { \ |
59 |
NSRect rct = NSMakeRect(x, y, w, h); \ |
60 |
if (rct.size.width < 0) rct.size.width = 0; \ |
61 |
if (rct.size.height < 0) rct.size.height = 0; \ |
62 |
[o setFrame: rct]; \ |
63 |
} |
64 |
|
65 |
#define CHECKRECT(rct) \ |
66 |
if (rct.size.width < 0) rct.size.width = 0; \ |
67 |
if (rct.size.height < 0) rct.size.height = 0 |
68 |
|
69 |
@implementation SmallIconsPanel |
70 |
|
71 |
- (void)dealloc |
72 |
{ |
73 |
[[NSNotificationCenter defaultCenter] removeObserver: self]; |
74 |
RELEASE (icons); |
75 |
RELEASE (currentPath); |
76 |
TEST_RELEASE (horizontalImage); |
77 |
TEST_RELEASE (verticalImage); |
78 |
TEST_RELEASE(charBuffer); |
79 |
[super dealloc]; |
80 |
} |
81 |
|
82 |
- (id)initAtPath:(NSString *)path |
83 |
delegate:(id)adelegate |
84 |
{ |
85 |
self = [super initWithFrame: NSZeroRect]; |
86 |
if (self) { |
87 |
#ifdef GNUSTEP |
88 |
Class gwclass = [[NSBundle mainBundle] principalClass]; |
89 |
#else |
90 |
Class gwclass = [[NSBundle mainBundle] classNamed: @"GWorkspace"]; |
91 |
#endif |
92 |
|
93 |
gworkspace = (id<GWProtocol>)[gwclass gworkspace]; |
94 |
|
95 |
ASSIGN (currentPath, path); |
96 |
[self setDelegate: adelegate]; |
97 |
|
98 |
cellsWidth = [delegate iconCellsWidth]; |
99 |
[self setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; |
100 |
icons = [[NSMutableArray alloc] initWithCapacity: 1]; |
101 |
currSelectionSel = @selector(currentSelection); |
102 |
currSelection = [self methodForSelector: currSelectionSel]; |
103 |
isDragTarget = NO; |
104 |
isShiftClick = NO; |
105 |
horizontalImage = nil; |
106 |
verticalImage = nil; |
107 |
selectInProgress = NO; |
108 |
|
109 |
lastKeyPressed = 0.; |
110 |
charBuffer = nil; |
111 |
|
112 |
contestualMenu = [gworkspace usesContestualMenu]; |
113 |
|
114 |
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; |
115 |
|
116 |
[[NSNotificationCenter defaultCenter] addObserver: self |
117 |
selector: @selector(cellsWidthChanged:) |
118 |
name: GWIconsCellsWidthChangedNotification |
119 |
object: nil]; |
120 |
|
121 |
fm = [NSFileManager defaultManager]; |
122 |
[self makeFileIcons]; |
123 |
} |
124 |
|
125 |
return self; |
126 |
} |
127 |
|
128 |
- (void)setPath:(NSString *)path |
129 |
{ |
130 |
ASSIGN (currentPath, path); |
131 |
[self makeFileIcons]; |
132 |
} |
133 |
|
134 |
- (void)setCurrentSelection |
135 |
{ |
136 |
if (selectInProgress) { |
137 |
return; |
138 |
} |
139 |
[delegate setSelectedPathsFromIcons: (*currSelection)(self, currSelectionSel)]; |
140 |
} |
141 |
|
142 |
- (void)reloadFromPath:(NSString *)path |
143 |
{ |
144 |
NSArray *csel = nil; |
145 |
NSMutableArray *selection = nil; |
146 |
int i, count; |
147 |
|
148 |
csel = [self currentSelection]; |
149 |
|
150 |
if (csel && [csel count]) { |
151 |
selection = [csel mutableCopy]; |
152 |
count = [selection count]; |
153 |
|
154 |
for (i = 0; i < count; i++) { |
155 |
NSString *spath = [selection objectAtIndex: i]; |
156 |
|
157 |
if ([fm fileExistsAtPath: spath] == NO) { |
158 |
[selection removeObject: spath]; |
159 |
count--; |
160 |
i--; |
161 |
} |
162 |
} |
163 |
} |
164 |
|
165 |
if ([currentPath isEqual: path]) { |
166 |
[self makeFileIcons]; |
167 |
|
168 |
if (selection && [selection count]) { |
169 |
[self selectIconsWithPaths: selection]; |
170 |
[delegate setSelectedPathsFromIcons: selection]; |
171 |
} else { |
172 |
[delegate setTheSelectedPaths: [NSArray arrayWithObject: currentPath]]; |
173 |
} |
174 |
|
175 |
} else if (subPathOfPath(path, currentPath)) { |
176 |
NSRange range = [currentPath rangeOfString: path]; |
177 |
NSString *s = [currentPath substringFromIndex: (range.length + 1)]; |
178 |
NSArray *components = [s pathComponents]; |
179 |
NSString *bpath = [NSString stringWithString: path]; |
180 |
|
181 |
for (i = 0; i < [components count]; i++) { |
182 |
NSString *component = [components objectAtIndex: i]; |
183 |
BOOL isdir = NO; |
184 |
|
185 |
bpath = [bpath stringByAppendingPathComponent: component]; |
186 |
|
187 |
if (([fm fileExistsAtPath: bpath isDirectory: &isdir] && isdir) == NO) { |
188 |
bpath = [bpath stringByDeletingLastPathComponent]; |
189 |
[self setPath: bpath]; |
190 |
[self scrollFirstIconToVisible]; |
191 |
[delegate setTheSelectedPaths: [NSArray arrayWithObject: currentPath]]; |
192 |
break; |
193 |
} |
194 |
} |
195 |
|
196 |
[self unLockAllIcons]; |
197 |
} |
198 |
|
199 |
TEST_RELEASE (selection); |
200 |
} |
201 |
|
202 |
- (NSArray *)checkHiddenFiles:(NSArray *)files atPath:(NSString *)path |
203 |
{ |
204 |
NSArray *checkedFiles; |
205 |
NSArray *hiddenFiles; |
206 |
BOOL hideSysFiles; |
207 |
NSString *h; |
208 |
|
209 |
h = [path stringByAppendingPathComponent: @".hidden"]; |
210 |
if ([fm fileExistsAtPath: h]) { |
211 |
h = [NSString stringWithContentsOfFile: h]; |
212 |
hiddenFiles = [h componentsSeparatedByString: @"\n"]; |
213 |
} else { |
214 |
hiddenFiles = nil; |
215 |
} |
216 |
hideSysFiles = [gworkspace hideSysFiles]; |
217 |
|
218 |
if (hiddenFiles != nil || hideSysFiles) { |
219 |
NSMutableArray *mutableFiles = AUTORELEASE ([files mutableCopy]); |
220 |
|
221 |
if (hiddenFiles != nil) { |
222 |
[mutableFiles removeObjectsInArray: hiddenFiles]; |
223 |
} |
224 |
|
225 |
if (hideSysFiles) { |
226 |
int j = [mutableFiles count] - 1; |
227 |
|
228 |
while (j >= 0) { |
229 |
NSString *file = (NSString *)[mutableFiles objectAtIndex: j]; |
230 |
|
231 |
if ([file hasPrefix: @"."]) { |
232 |
[mutableFiles removeObjectAtIndex: j]; |
233 |
} |
234 |
j--; |
235 |
} |
236 |
} |
237 |
|
238 |
checkedFiles = mutableFiles; |
239 |
|
240 |
} else { |
241 |
checkedFiles = files; |
242 |
} |
243 |
|
244 |
return checkedFiles; |
245 |
} |
246 |
|
247 |
- (void)makeFileIcons |
248 |
{ |
249 |
NSArray *files; |
250 |
NSMutableArray *paths; |
251 |
int i, count; |
252 |
|
253 |
for (i = 0; i < [icons count]; i++) { |
254 |
SmallIcon *icon = [icons objectAtIndex: i]; |
255 |
NSTextField *label = [icon label]; |
256 |
[label setDelegate: nil]; |
257 |
[label setEditable: NO]; |
258 |
[label removeFromSuperviewWithoutNeedingDisplay]; |
259 |
[icon removeFromSuperviewWithoutNeedingDisplay]; |
260 |
} |
261 |
|
262 |
[icons removeAllObjects]; |
263 |
|
264 |
files = [gworkspace server: nil sortedDirectoryContentsAtPath: currentPath]; |
265 |
files = [gworkspace server: nil checkHiddenFiles: files atPath: currentPath]; |
266 |
|
267 |
count = [files count]; |
268 |
if (count == 0) { |
269 |
[self tile]; |
270 |
return; |
271 |
} |
272 |
|
273 |
paths = [NSMutableArray arrayWithCapacity: 1]; |
274 |
|
275 |
for (i = 0; i < count; ++i) { |
276 |
NSString *s = [currentPath stringByAppendingPathComponent: [files objectAtIndex: i]]; |
277 |
[paths addObject: s]; |
278 |
} |
279 |
|
280 |
for (i = 0; i < count; ++i) { |
281 |
NSString *ipath = [paths objectAtIndex: i]; |
282 |
SmallIcon *icon = [[SmallIcon alloc] initForPath: ipath delegate: self]; |
283 |
|
284 |
[icon setLocked: [gworkspace isLockedPath: ipath]]; |
285 |
[icons addObject: icon]; |
286 |
RELEASE (icon); |
287 |
} |
288 |
|
289 |
for (i = 0; i < [icons count]; ++i) { |
290 |
SmallIcon *icon = [icons objectAtIndex: i]; |
291 |
[self addSubview: icon]; |
292 |
[self addSubview: [icon label]]; |
293 |
[icon setLabelFrame]; |
294 |
} |
295 |
|
296 |
[self tile]; |
297 |
[self setNeedsDisplay: YES]; |
298 |
} |
299 |
|
300 |
- (void)sortIcons |
301 |
{ |
302 |
NSMutableDictionary *sortDict = [NSMutableDictionary dictionaryWithCapacity: 1]; |
303 |
int stype = [gworkspace sortTypeForDirectoryAtPath: currentPath]; |
304 |
|
305 |
[sortDict setObject: currentPath forKey: @"path"]; |
306 |
[sortDict setObject: [NSString stringWithFormat: @"%i", stype] forKey: @"type"]; |
307 |
|
308 |
[icons sortUsingFunction: (int (*)(id, id, void*))compIcons |
309 |
context: (void *)sortDict]; |
310 |
} |
311 |
|
312 |
- (void)tile |
313 |
{ |
314 |
float sfw = [[self superview] frame].size.width; |
315 |
float sfh = [[self superview] frame].size.height; |
316 |
float ox = [self frame].origin.x; |
317 |
float oy = [self frame].origin.y; |
318 |
NSRect maxr = [[NSScreen mainScreen] frame]; |
319 |
float px = LEFTMARGIN; |
320 |
float py = ROWSHEIGHT; |
321 |
NSSize sz; |
322 |
float shiftx = 0; |
323 |
int count = [icons count]; |
324 |
NSRect *irects = NSZoneMalloc (NSDefaultMallocZone(), sizeof(NSRect) * count); |
325 |
NSCachedImageRep *rep = nil; |
326 |
int i; |
327 |
|
328 |
#define CHECK_SIZE(s) \ |
329 |
if (s.width < 1) s.width = 1; \ |
330 |
if (s.height < 1) s.height = 1; \ |
331 |
if (s.width > maxr.size.width) s.width = maxr.size.width; \ |
332 |
if (s.height > maxr.size.height) s.height = maxr.size.height |
333 |
|
334 |
for (i = 0; i < count; i++) { |
335 |
SmallIcon *icon = [icons objectAtIndex: i]; |
336 |
float labwidth = [icon labelWidth]; |
337 |
float iconwidth = [icon frame].size.width + labwidth; |
338 |
|
339 |
px += shiftx; |
340 |
|
341 |
if (px >= (sfw - iconwidth)) { |
342 |
px = LEFTMARGIN; |
343 |
shiftx = 0; |
344 |
py += ROWSHEIGHT; |
345 |
} |
346 |
|
347 |
irects[i] = NSMakeRect(px, py, ICNWIDTH, ICNHEIGHT); |
348 |
|
349 |
while (iconwidth > shiftx) { |
350 |
shiftx += cellsWidth; |
351 |
} |
352 |
} |
353 |
|
354 |
py += (ROWSHEIGHT / 2); |
355 |
py = (py < sfh) ? sfh : py; |
356 |
|
357 |
SETRECT (self, ox, oy, sfw, py); |
358 |
|
359 |
DESTROY (horizontalImage); |
360 |
sz = NSMakeSize(sfw, 2); |
361 |
CHECK_SIZE (sz); |
362 |
horizontalImage = [[NSImage allocWithZone: (NSZone *)[(NSObject *)self zone]] |
363 |
initWithSize: sz]; |
364 |
|
365 |
rep = [[NSCachedImageRep allocWithZone: (NSZone *)[(NSObject *)self zone]] |
366 |
initWithSize: sz |
367 |
depth: [NSWindow defaultDepthLimit] |
368 |
separate: YES |
369 |
alpha: YES]; |
370 |
|
371 |
[horizontalImage addRepresentation: rep]; |
372 |
RELEASE (rep); |
373 |
|
374 |
DESTROY (verticalImage); |
375 |
sz = NSMakeSize(2, py); |
376 |
CHECK_SIZE (sz); |
377 |
verticalImage = [[NSImage allocWithZone: (NSZone *)[(NSObject *)self zone]] |
378 |
initWithSize: sz]; |
379 |
|
380 |
rep = [[NSCachedImageRep allocWithZone: (NSZone *)[(NSObject *)self zone]] |
381 |
initWithSize: sz |
382 |
depth: [NSWindow defaultDepthLimit] |
383 |
separate: YES |
384 |
alpha: YES]; |
385 |
|
386 |
[verticalImage addRepresentation: rep]; |
387 |
RELEASE (rep); |
388 |
|
389 |
for (i = 0; i < count; i++) { |
390 |
SmallIcon *icon = [icons objectAtIndex: i]; |
391 |
irects[i].origin.y = py - irects[i].origin.y; |
392 |
[icon setFrame: irects[i]]; |
393 |
[icon setPosition: irects[i].origin gridIndex: i]; |
394 |
[icon setNeedsDisplay: YES]; |
395 |
[self setLabelRectOfIcon: icon]; |
396 |
} |
397 |
|
398 |
NSZoneFree (NSDefaultMallocZone(), irects); |
399 |
} |
400 |
|
401 |
- (void)scrollFirstIconToVisible |
402 |
{ |
403 |
[self scrollRectToVisible: NSMakeRect(0, [self frame].size.height - 10, 10, 10)]; |
404 |
} |
405 |
|
406 |
- (void)scrollToVisibleIconsWithPaths:(NSArray *)paths |
407 |
{ |
408 |
SmallIcon *icon = [self iconWithPath: [paths objectAtIndex: 0]]; |
409 |
|
410 |
if (icon) { |
411 |
NSRect vrect = [self visibleRect]; |
412 |
NSRect r = NSUnionRect([icon frame], [[icon label] frame]); |
413 |
|
414 |
if (NSContainsRect(vrect, r) == NO) { |
415 |
r.origin.y -= ICON_FRAME_MARGIN; |
416 |
r.size.height += ICON_FRAME_MARGIN * 2; |
417 |
[self scrollRectToVisible: r]; |
418 |
} |
419 |
} |
420 |
} |
421 |
|
422 |
- (NSString *)currentPath |
423 |
{ |
424 |
return currentPath; |
425 |
} |
426 |
|
427 |
- (BOOL)isOnBasePath:(NSString *)bpath withFiles:(NSArray *)files |
428 |
{ |
429 |
if ([currentPath isEqual: bpath]) { |
430 |
return YES; |
431 |
|
432 |
} else if (subPathOfPath(bpath, currentPath)) { |
433 |
int i; |
434 |
|
435 |
if (files == nil) { |
436 |
return YES; |
437 |
|
438 |
} else { |
439 |
for (i = 0; i < [files count]; i++) { |
440 |
NSString *fname = [files objectAtIndex: i]; |
441 |
NSString *fpath = [bpath stringByAppendingPathComponent: fname]; |
442 |
|
443 |
if (([fpath isEqual: currentPath]) || (subPathOfPath(fpath, currentPath))) { |
444 |
return YES; |
445 |
} |
446 |
} |
447 |
} |
448 |
} |
449 |
|
450 |
return NO; |
451 |
} |
452 |
|
453 |
- (NSArray *)currentSelection |
454 |
{ |
455 |
NSMutableArray *allpaths = [NSMutableArray arrayWithCapacity: 1]; |
456 |
int i; |
457 |
|
458 |
for (i = 0; i < [icons count]; i++) { |
459 |
SmallIcon *icon = [icons objectAtIndex: i]; |
460 |
if ([icon isSelect] == YES) { |
461 |
NSString *ipath = [icon path]; |
462 |
|
463 |
if ([fm fileExistsAtPath: ipath]) { |
464 |
[allpaths addObject: ipath]; |
465 |
} |
466 |
} |
467 |
} |
468 |
|
469 |
if ([allpaths count] == 0) { |
470 |
return nil; |
471 |
} |
472 |
|
473 |
return allpaths; |
474 |
} |
475 |
|
476 |
- (SmallIcon *)iconWithPath:(NSString *)path |
477 |
{ |
478 |
int i; |
479 |
|
480 |
for (i = 0; i < [icons count]; i++) { |
481 |
SmallIcon *icon = [icons objectAtIndex: i]; |
482 |
|
483 |
if ([[icon path] isEqual: path]) { |
484 |
return icon; |
485 |
} |
486 |
} |
487 |
|
488 |
return nil; |
489 |
} |
490 |
|
491 |
- (NSArray *)iconsWithPaths:(NSArray *)paths |
492 |
{ |
493 |
return [NSArray array]; |
494 |
} |
495 |
|
496 |
- (void)selectIconWithPath:(NSString *)path |
497 |
{ |
498 |
int i; |
499 |
|
500 |
for (i = 0; i < [icons count]; i++) { |
501 |
SmallIcon *icon = [icons objectAtIndex: i]; |
502 |
|
503 |
if ([[icon path] isEqual: path]) { |
504 |
[icon select]; |
505 |
return; |
506 |
} |
507 |
} |
508 |
} |
509 |
|
510 |
- (SmallIcon *)iconWithNamePrefix:(NSString *)prefix |
511 |
inRange:(NSRange)range |
512 |
{ |
513 |
int i; |
514 |
|
515 |
if (range.length == 0) { |
516 |
return nil; |
517 |
} |
518 |
|
519 |
for (i = range.location; i < range.location + range.length; i++) { |
520 |
SmallIcon *icon = [icons objectAtIndex: i]; |
521 |
if ([[icon myName] hasPrefix: charBuffer]) { |
522 |
return icon; |
523 |
} |
524 |
} |
525 |
|
526 |
return nil; |
527 |
} |
528 |
|
529 |
- (NSPoint)locationOfIconWithName:(NSString *)name |
530 |
{ |
531 |
int i; |
532 |
|
533 |
for (i = 0; i < [icons count]; i++) { |
534 |
SmallIcon *icon = [icons objectAtIndex: i]; |
535 |
|
536 |
if ([[icon myName] isEqualToString: name]) { |
537 |
NSPoint p = [icon frame].origin; |
538 |
NSSize s = [icon iconShift]; |
539 |
return NSMakePoint(p.x + s.width, p.y + s.height); |
540 |
} |
541 |
} |
542 |
|
543 |
return NSMakePoint(0, 0); |
544 |
} |
545 |
|
546 |
- (void)selectIconsWithPaths:(NSArray *)paths |
547 |
{ |
548 |
int i; |
549 |
|
550 |
isShiftClick = YES; |
551 |
|
552 |
for (i = 0; i < [icons count]; i++) { |
553 |
SmallIcon *icon = [icons objectAtIndex: i]; |
554 |
NSString *ipath = [icon path]; |
555 |
|
556 |
if ([paths containsObject: ipath] == YES) { |
557 |
[icon select]; |
558 |
} |
559 |
} |
560 |
|
561 |
isShiftClick = NO; |
562 |
} |
563 |
|
564 |
- (void)selectIconInPrevLine |
565 |
{ |
566 |
NSPoint sp; |
567 |
NSRect r[2]; |
568 |
NSRect irect; |
569 |
int i, startpos = -1; |
570 |
|
571 |
for (i = [icons count] -1; i >= 0; i--) { |
572 |
SmallIcon *icon = [icons objectAtIndex: i]; |
573 |
|
574 |
if ([icon isSelect]) { |
575 |
r[0] = [icon frame]; |
576 |
r[1] = [[icon label] frame]; |
577 |
startpos = i; |
578 |
sp = [icon position]; |
579 |
break; |
580 |
} |
581 |
} |
582 |
|
583 |
if (startpos != -1) { |
584 |
for (i = startpos; i >= 0; i--) { |
585 |
SmallIcon *icon = [icons objectAtIndex: i]; |
586 |
NSPoint p = [icon position]; |
587 |
|
588 |
if ((p.x == sp.x) && (p.y > sp.y)) { |
589 |
[icon select]; |
590 |
[self setNeedsDisplayInRect: r[0]]; |
591 |
[self setNeedsDisplayInRect: r[1]]; |
592 |
|
593 |
irect = NSUnionRect([icon frame], [[icon label] frame]); |
594 |
irect.origin.y -= ICON_FRAME_MARGIN; |
595 |
irect.size.height += ICON_FRAME_MARGIN * 2; |
596 |
[self scrollRectToVisible: irect]; |
597 |
break; |
598 |
} |
599 |
} |
600 |
} |
601 |
} |
602 |
|
603 |
- (void)selectIconInNextLine |
604 |
{ |
605 |
NSPoint sp; |
606 |
NSRect r[2]; |
607 |
NSRect irect; |
608 |
int i, startpos = -1; |
609 |
|
610 |
for (i = 0; i < [icons count]; i++) { |
611 |
SmallIcon *icon = [icons objectAtIndex: i]; |
612 |
|
613 |
if ([icon isSelect]) { |
614 |
r[0] = [icon frame]; |
615 |
r[1] = [[icon label] frame]; |
616 |
startpos = i; |
617 |
sp = [icon position]; |
618 |
break; |
619 |
} |
620 |
} |
621 |
|
622 |
if (startpos != -1) { |
623 |
for (i = startpos; i < [icons count]; i++) { |
624 |
SmallIcon *icon = [icons objectAtIndex: i]; |
625 |
NSPoint p = [icon position]; |
626 |
|
627 |
if ((p.x == sp.x) && (p.y < sp.y)) { |
628 |
[icon select]; |
629 |
[self setNeedsDisplayInRect: r[0]]; |
630 |
[self setNeedsDisplayInRect: r[1]]; |
631 |
|
632 |
irect = NSUnionRect([icon frame], [[icon label] frame]); |
633 |
irect.origin.y -= ICON_FRAME_MARGIN; |
634 |
irect.size.height += ICON_FRAME_MARGIN * 2; |
635 |
[self scrollRectToVisible: irect]; |
636 |
break; |
637 |
} |
638 |
} |
639 |
} |
640 |
} |
641 |
|
642 |
- (void)selectPrevIcon |
643 |
{ |
644 |
int i; |
645 |
|
646 |
for(i = 0; i < [icons count]; i++) { |
647 |
SmallIcon *icon = [icons objectAtIndex: i]; |
648 |
|
649 |
if([icon isSelect]) { |
650 |
if (i > 0) { |
651 |
NSRect irect = NSUnionRect([icon frame], [[icon label] frame]); |
652 |
|
653 |
[self unselectOtherIcons: icon]; |
654 |
icon = [icons objectAtIndex: i - 1]; |
655 |
[icon select]; |
656 |
[self setNeedsDisplayInRect: irect]; |
657 |
|
658 |
irect = NSUnionRect([icon frame], [[icon label] frame]); |
659 |
irect.origin.y -= ICON_FRAME_MARGIN; |
660 |
irect.size.height += ICON_FRAME_MARGIN * 2; |
661 |
[self scrollRectToVisible: irect]; |
662 |
return; |
663 |
} else { |
664 |
return; |
665 |
} |
666 |
} |
667 |
} |
668 |
} |
669 |
|
670 |
- (void)selectNextIcon |
671 |
{ |
672 |
int i, count = [icons count]; |
673 |
|
674 |
for(i = 0; i < [icons count]; i++) { |
675 |
SmallIcon *icon = [icons objectAtIndex: i]; |
676 |
|
677 |
if([icon isSelect]) { |
678 |
if (i < (count - 1)) { |
679 |
NSRect irect = NSUnionRect([icon frame], [[icon label] frame]); |
680 |
|
681 |
[self unselectOtherIcons: icon]; |
682 |
icon = [icons objectAtIndex: i + 1]; |
683 |
[icon select]; |
684 |
[self setNeedsDisplayInRect: irect]; |
685 |
|
686 |
irect = NSUnionRect([icon frame], [[icon label] frame]); |
687 |
irect.origin.y -= ICON_FRAME_MARGIN; |
688 |
irect.size.height += ICON_FRAME_MARGIN * 2; |
689 |
[self scrollRectToVisible: irect]; |
690 |
return; |
691 |
} else { |
692 |
return; |
693 |
} |
694 |
} |
695 |
} |
696 |
} |
697 |
|
698 |
- (void)selectAllIcons |
699 |
{ |
700 |
int i; |
701 |
|
702 |
isShiftClick = YES; |
703 |
selectInProgress = YES; |
704 |
for(i = 0; i < [icons count]; i++) { |
705 |
[[icons objectAtIndex: i] select]; |
706 |
} |
707 |
selectInProgress = NO; |
708 |
[self setCurrentSelection]; |
709 |
isShiftClick = NO; |
710 |
} |
711 |
|
712 |
- (void)unselectOtherIcons:(id)anIcon |
713 |
{ |
714 |
int i; |
715 |
|
716 |
if(isShiftClick == YES) { |
717 |
return; |
718 |
} |
719 |
|
720 |
for (i = 0; i < [icons count]; i++) { |
721 |
SmallIcon *icon = [icons objectAtIndex: i]; |
722 |
if (icon != anIcon) { |
723 |
[icon unselect]; |
724 |
} |
725 |
} |
726 |
} |
727 |
|
728 |
- (void)extendSelectionWithDimmedFiles:(NSArray *)files |
729 |
startingAtPath:(NSString *)bpath |
730 |
{ |
731 |
if ([currentPath isEqual: bpath]) { |
732 |
[self addIconsWithNames: files dimmed: YES]; |
733 |
|
734 |
} else if (subPathOfPath(bpath, currentPath)) { |
735 |
int i; |
736 |
|
737 |
for (i = 0; i < [files count]; i++) { |
738 |
NSString *fname = [files objectAtIndex: i]; |
739 |
NSString *fpath = [bpath stringByAppendingPathComponent: fname]; |
740 |
|
741 |
if (([fpath isEqual: currentPath]) || (subPathOfPath(fpath, currentPath))) { |
742 |
[self lockAllIcons]; |
743 |
break; |
744 |
} |
745 |
} |
746 |
} |
747 |
} |
748 |
|
749 |
- (void)openSelectionWithApp:(id)sender |
750 |
{ |
751 |
NSString *appName = (NSString *)[sender representedObject]; |
752 |
NSArray *selection = [self currentSelection]; |
753 |
|
754 |
if (selection && [selection count]) { |
755 |
int i; |
756 |
|
757 |
for (i = 0; i < [selection count]; i++) { |
758 |
[[NSWorkspace sharedWorkspace] openFile: [selection objectAtIndex: i] |
759 |
withApplication: appName]; |
760 |
} |
761 |
} |
762 |
} |
763 |
|
764 |
- (void)openSelectionWith:(id)sender |
765 |
{ |
766 |
[gworkspace openSelectedPathsWith]; |
767 |
} |
768 |
|
769 |
- (void)addIconWithPath:(NSString *)iconpath dimmed:(BOOL)isdimmed; |
770 |
{ |
771 |
SmallIcon *icon = [self iconWithPath: iconpath]; |
772 |
|
773 |
if (icon) { |
774 |
[icon setLocked: isdimmed]; |
775 |
} else { |
776 |
icon = [[SmallIcon alloc] initForPath: iconpath delegate: self]; |
777 |
[icon setLocked: isdimmed]; |
778 |
[icons addObject: icon]; |
779 |
[self addSubview: icon]; |
780 |
[self addSubview: [icon label]]; |
781 |
RELEASE (icon); |
782 |
} |
783 |
} |
784 |
|
785 |
- (void)addIconsWithPaths:(NSArray *)iconpaths |
786 |
{ |
787 |
int i; |
788 |
|
789 |
for (i = 0; i < [iconpaths count]; i++) { |
790 |
NSString *s = [iconpaths objectAtIndex: i]; |
791 |
SmallIcon *icon = [[SmallIcon alloc] initForPath: s delegate: self]; |
792 |
|
793 |
[icon setLocked: [gworkspace isLockedPath: s]]; |
794 |
|
795 |
[icons addObject: icon]; |
796 |
[self addSubview: icon]; |
797 |
[self addSubview: [icon label]]; |
798 |
[icon setLabelFrame]; |
799 |
RELEASE (icon); |
800 |
} |
801 |
} |
802 |
|
803 |
- (void)addIconsWithNames:(NSArray *)names dimmed:(BOOL)isdimmed |
804 |
{ |
805 |
NSArray *files = [self checkHiddenFiles: names atPath: currentPath]; |
806 |
|
807 |
if ([files count]) { |
808 |
int i; |
809 |
|
810 |
for (i = 0; i < [files count]; i++) { |
811 |
NSString *s = [currentPath stringByAppendingPathComponent: [files objectAtIndex: i]]; |
812 |
[self addIconWithPath: s dimmed: isdimmed]; |
813 |
} |
814 |
[self sortIcons]; |
815 |
[self tile]; |
816 |
} |
817 |
} |
818 |
|
819 |
- (void)removeIcon:(id)anIcon |
820 |
{ |
821 |
SmallIcon *icon = (SmallIcon *)anIcon; |
822 |
[[icon label] removeFromSuperview]; |
823 |
[icon removeFromSuperview]; |
824 |
[icons removeObject: icon]; |
825 |
[self tile]; |
826 |
} |
827 |
|
828 |
- (void)removeIconsWithNames:(NSArray *)names |
829 |
{ |
830 |
int i, count = [icons count]; |
831 |
|
832 |
for (i = 0; i < count; i++) { |
833 |
SmallIcon *icon = [icons objectAtIndex: i]; |
834 |
NSString *name = [icon myName]; |
835 |
|
836 |
if ([names containsObject: name] == YES) { |
837 |
[[icon label] removeFromSuperview]; |
838 |
[icon removeFromSuperview]; |
839 |
[icons removeObject: icon]; |
840 |
count--; |
841 |
i--; |
842 |
} |
843 |
} |
844 |
|
845 |
[self tile]; |
846 |
} |
847 |
|
848 |
- (void)lockIconsWithNames:(NSArray *)names |
849 |
{ |
850 |
int i; |
851 |
|
852 |
for (i = 0; i < [icons count]; i++) { |
853 |
SmallIcon *icon = [icons objectAtIndex: i]; |
854 |
if ([names containsObject: [icon myName]]) { |
855 |
[icon setLocked: YES]; |
856 |
} |
857 |
} |
858 |
} |
859 |
|
860 |
- (void)unLockIconsWithNames:(NSArray *)names |
861 |
{ |
862 |
int i; |
863 |
|
864 |
for (i = 0; i < [icons count]; i++) { |
865 |
SmallIcon *icon = [icons objectAtIndex: i]; |
866 |
if ([names containsObject: [icon myName]]) { |
867 |
[icon setLocked: NO]; |
868 |
} |
869 |
} |
870 |
} |
871 |
|
872 |
- (void)lockAllIcons |
873 |
{ |
874 |
int i; |
875 |
|
876 |
for (i = 0; i < [icons count]; i++) { |
877 |
SmallIcon *icon = [icons objectAtIndex: i]; |
878 |
if ([icon isLocked] == NO) { |
879 |
[icon setLocked: YES]; |
880 |
} |
881 |
} |
882 |
} |
883 |
|
884 |
- (void)unLockAllIcons |
885 |
{ |
886 |
int i; |
887 |
|
888 |
for (i = 0; i < [icons count]; i++) { |
889 |
SmallIcon *icon = [icons objectAtIndex: i]; |
890 |
if ([icon isLocked]) { |
891 |
[icon setLocked: NO]; |
892 |
} |
893 |
} |
894 |
} |
895 |
|
896 |
- (void)setLabelRectOfIcon:(id)anIcon |
897 |
{ |
898 |
SmallIcon *icon = (SmallIcon *)anIcon; |
899 |
NSTextField *label = [icon label]; |
900 |
|
901 |
[label setFrame: NSMakeRect([icon frame].origin.x + ICNWIDTH, |
902 |
[icon frame].origin.y + ((ICNHEIGHT - LABHEIGHT) / 2), |
903 |
[icon labelWidth], LABHEIGHT)]; |
904 |
[label setNeedsDisplay: YES]; |
905 |
} |
906 |
|
907 |
- (int)cellsWidth |
908 |
{ |
909 |
return cellsWidth; |
910 |
} |
911 |
|
912 |
- (void)cellsWidthChanged:(NSNotification *)notification |
913 |
{ |
914 |
cellsWidth = [(NSNumber *)[notification object] intValue]; |
915 |
[self tile]; |
916 |
} |
917 |
|
918 |
- (void)setShiftClick:(BOOL)value |
919 |
{ |
920 |
isShiftClick = value; |
921 |
} |
922 |
|
923 |
- (void)openCurrentSelection:(NSArray *)paths newViewer:(BOOL)newv |
924 |
{ |
925 |
[delegate openTheCurrentSelection: (*currSelection)(self, currSelectionSel) |
926 |
newViewer: newv]; |
927 |
} |
928 |
|
929 |
- (id)delegate |
930 |
{ |
931 |
return delegate; |
932 |
} |
933 |
|
934 |
- (void)setDelegate:(id)anObject |
935 |
{ |
936 |
delegate = anObject; |
937 |
} |
938 |
|
939 |
- (void)resizeWithOldSuperviewSize:(NSSize)oldFrameSize |
940 |
{ |
941 |
[self tile]; |
942 |
} |
943 |
|
944 |
- (NSMenu *)menuForEvent:(NSEvent *)theEvent |
945 |
{ |
946 |
if ([theEvent type] == NSRightMouseDown) { |
947 |
NSArray *selection = [self currentSelection]; |
948 |
|
949 |
if (contestualMenu == NO) { |
950 |
return [super menuForEvent: theEvent]; |
951 |
} |
952 |
|
953 |
if (selection && [selection count]) { |
954 |
if ([theEvent modifierFlags] == NSControlKeyMask) { |
955 |
return [super menuForEvent: theEvent]; |
956 |
} else { |
957 |
NSMenu *menu; |
958 |
NSMenuItem *menuItem; |
959 |
NSString *firstext; |
960 |
NSDictionary *apps; |
961 |
NSEnumerator *app_enum; |
962 |
id key; |
963 |
int i; |
964 |
|
965 |
firstext = [[selection objectAtIndex: 0] pathExtension]; |
966 |
|
967 |
for (i = 0; i < [selection count]; i++) { |
968 |
NSString *selpath = [selection objectAtIndex: i]; |
969 |
NSString *ext = [selpath pathExtension]; |
970 |
NSString *defApp = nil; |
971 |
NSString *fType = nil; |
972 |
|
973 |
if ([ext isEqual: firstext] == NO) { |
974 |
return [super menuForEvent: theEvent]; |
975 |
} |
976 |
|
977 |
[[NSWorkspace sharedWorkspace] getInfoForFile: selpath |
978 |
application: &defApp |
979 |
type: &fType]; |
980 |
|
981 |
if (([fType isEqual: NSPlainFileType] == NO) |
982 |
&& ([fType isEqual: NSShellCommandFileType] == NO)) { |
983 |
return [super menuForEvent: theEvent]; |
984 |
} |
985 |
} |
986 |
|
987 |
menu = [[NSMenu alloc] initWithTitle: NSLocalizedString(@"Open with", @"")]; |
988 |
apps = [[NSWorkspace sharedWorkspace] infoForExtension: firstext]; |
989 |
app_enum = [[apps allKeys] objectEnumerator]; |
990 |
|
991 |
while ((key = [app_enum nextObject])) { |
992 |
NSDictionary *dict = [apps objectForKey: key]; |
993 |
NSString *role = [dict objectForKey: @"NSRole"]; |
994 |
|
995 |
menuItem = [NSMenuItem new]; |
996 |
|
997 |
if (role) { |
998 |
[menuItem setTitle: [NSString stringWithFormat: @"%@ - %@", key, role]]; |
999 |
} else { |
1000 |
[menuItem setTitle: [NSString stringWithFormat: @"%@", key]]; |
1001 |
} |
1002 |
|
1003 |
[menuItem setTarget: self]; |
1004 |
[menuItem setAction: @selector(openSelectionWithApp:)]; |
1005 |
[menuItem setRepresentedObject: key]; |
1006 |
[menu addItem: menuItem]; |
1007 |
RELEASE (menuItem); |
1008 |
} |
1009 |
|
1010 |
menuItem = [NSMenuItem new]; |
1011 |
[menuItem setTitle: NSLocalizedString(@"Open with...", @"")]; |
1012 |
[menuItem setTarget: self]; |
1013 |
[menuItem setAction: @selector(openSelectionWith:)]; |
1014 |
[menu addItem: menuItem]; |
1015 |
RELEASE (menuItem); |
1016 |
|
1017 |
return [menu autorelease]; |
1018 |
} |
1019 |
|
1020 |
} else { |
1021 |
return [super menuForEvent: theEvent]; |
1022 |
} |
1023 |
} |
1024 |
|
1025 |
return [super menuForEvent: theEvent]; |
1026 |
} |
1027 |
|
1028 |
- (void)mouseDown:(NSEvent *)theEvent |
1029 |
{ |
1030 |
[[self window] makeFirstResponder: self]; |
1031 |
|
1032 |
if([theEvent modifierFlags] != 2) { |
1033 |
isShiftClick = NO; |
1034 |
selectInProgress = YES; |
1035 |
[self unselectOtherIcons: nil]; |
1036 |
selectInProgress = NO; |
1037 |
[delegate setSelectedPathsFromIcons: [NSArray arrayWithObject: currentPath]]; |
1038 |
} |
1039 |
} |
1040 |
|
1041 |
- (void)mouseDragged:(NSEvent *)theEvent |
1042 |
{ |
1043 |
unsigned int eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSPeriodicMask; |
1044 |
NSDate *future = [NSDate distantFuture]; |
1045 |
NSPoint startp, sp; |
1046 |
NSPoint p, pp; |
1047 |
NSRect visibleRect; |
1048 |
NSRect oldRect; |
1049 |
NSRect r, wr; |
1050 |
NSRect selrect; |
1051 |
float x, y, w, h; |
1052 |
int i; |
1053 |
|
1054 |
#define scrollPointToVisible(p) \ |
1055 |
{ \ |
1056 |
NSRect sr; \ |
1057 |
sr.origin = p; \ |
1058 |
sr.size.width = sr.size.height = 0.1; \ |
1059 |
[self scrollRectToVisible: sr]; \ |
1060 |
} |
1061 |
|
1062 |
#define CONVERT_CHECK \ |
1063 |
pp = [self convertPoint: p fromView: nil]; \ |
1064 |
if (pp.x < 1) \ |
1065 |
pp.x = 1; \ |
1066 |
if (pp.x >= NSMaxX([self bounds])) \ |
1067 |
pp.x = NSMaxX([self bounds]) - 1 |
1068 |
|
1069 |
p = [theEvent locationInWindow]; |
1070 |
sp = [self convertPoint: p fromView: nil]; |
1071 |
startp = [self convertPoint: p fromView: nil]; |
1072 |
|
1073 |
oldRect = NSZeroRect; |
1074 |
|
1075 |
[[self window] disableFlushWindow]; |
1076 |
[self lockFocus]; |
1077 |
|
1078 |
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.05]; |
1079 |
|
1080 |
while ([theEvent type] != NSLeftMouseUp) { |
1081 |
CREATE_AUTORELEASE_POOL (arp); |
1082 |
|
1083 |
theEvent = [NSApp nextEventMatchingMask: eventMask |
1084 |
untilDate: future |
1085 |
inMode: NSEventTrackingRunLoopMode |
1086 |
dequeue: YES]; |
1087 |
|
1088 |
if ([theEvent type] != NSPeriodic) { |
1089 |
p = [theEvent locationInWindow]; |
1090 |
} |
1091 |
|
1092 |
CONVERT_CHECK; |
1093 |
|
1094 |
visibleRect = [self visibleRect]; |
1095 |
|
1096 |
if (NSPointInRect(pp, [self visibleRect]) == NO) { |
1097 |
scrollPointToVisible(pp); |
1098 |
CONVERT_CHECK; |
1099 |
visibleRect = [self visibleRect]; |
1100 |
} |
1101 |
|
1102 |
if ((sp.y < visibleRect.origin.y) |
1103 |
|| (sp.y > (visibleRect.origin.y + visibleRect.size.height))) { |
1104 |
if (sp.y < visibleRect.origin.y) { |
1105 |
sp.y = visibleRect.origin.y - 1; |
1106 |
} |
1107 |
if (sp.y > (visibleRect.origin.y + visibleRect.size.height)) { |
1108 |
sp.y = (visibleRect.origin.y + visibleRect.size.height + 1); |
1109 |
} |
1110 |
} |
1111 |
|
1112 |
x = (pp.x >= sp.x) ? sp.x : pp.x; |
1113 |
y = (pp.y >= sp.y) ? sp.y : pp.y; |
1114 |
w = max(pp.x, sp.x) - min(pp.x, sp.x); |
1115 |
w = (w == 0) ? 1 : w; |
1116 |
h = max(pp.y, sp.y) - min(pp.y, sp.y); |
1117 |
h = (h == 0) ? 1 : h; |
1118 |
|
1119 |
r = NSMakeRect(x, y, w, h); |
1120 |
|
1121 |
wr = [self convertRect: r toView: nil]; |
1122 |
|
1123 |
sp = startp; |
1124 |
|
1125 |
if (NSEqualRects(oldRect, NSZeroRect) == NO) { |
1126 |
[verticalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect)) |
1127 |
fromRect: NSMakeRect(0.0, 0.0, 1.0, oldRect.size.height) |
1128 |
operation: NSCompositeCopy]; |
1129 |
|
1130 |
[verticalImage compositeToPoint: NSMakePoint(NSMaxX(oldRect)-1, NSMinY(oldRect)) |
1131 |
fromRect: NSMakeRect(1.0, 0.0, 1.0, oldRect.size.height) |
1132 |
operation: NSCompositeCopy]; |
1133 |
|
1134 |
[horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect)) |
1135 |
fromRect: NSMakeRect(0.0, 0.0, oldRect.size.width, 1.0) |
1136 |
operation: NSCompositeCopy]; |
1137 |
|
1138 |
[horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMaxY(oldRect)-1) |
1139 |
fromRect: NSMakeRect(0.0, 1.0, oldRect.size.width, 1.0) |
1140 |
operation: NSCompositeCopy]; |
1141 |
} |
1142 |
[self displayIfNeeded]; |
1143 |
|
1144 |
[verticalImage lockFocus]; |
1145 |
NSCopyBits([[self window] gState], |
1146 |
NSMakeRect(NSMinX(wr), NSMinY(wr), |
1147 |
1.0, r.size.height), |
1148 |
NSMakePoint(0.0, 0.0)); |
1149 |
NSCopyBits([[self window] gState], |
1150 |
NSMakeRect(NSMaxX(wr) -1, NSMinY(wr), |
1151 |
1.0, r.size.height), |
1152 |
NSMakePoint(1.0, 0.0)); |
1153 |
[verticalImage unlockFocus]; |
1154 |
|
1155 |
[horizontalImage lockFocus]; |
1156 |
NSCopyBits([[self window] gState], |
1157 |
NSMakeRect(NSMinX(wr), NSMinY(wr), |
1158 |
r.size.width, 1.0), |
1159 |
NSMakePoint(0.0, 0.0)); |
1160 |
NSCopyBits([[self window] gState], |
1161 |
NSMakeRect(NSMinX(wr), NSMaxY(wr) -1, |
1162 |
r.size.width, 1.0), |
1163 |
NSMakePoint(0.0, 1.0)); |
1164 |
[horizontalImage unlockFocus]; |
1165 |
|
1166 |
[[NSColor darkGrayColor] set]; |
1167 |
NSFrameRect(r); |
1168 |
oldRect = r; |
1169 |
|
1170 |
[[self window] enableFlushWindow]; |
1171 |
[[self window] flushWindow]; |
1172 |
[[self window] disableFlushWindow]; |
1173 |
|
1174 |
DESTROY (arp); |
1175 |
} |
1176 |
|
1177 |
[NSEvent stopPeriodicEvents]; |
1178 |
[[self window] postEvent: theEvent atStart: NO]; |
1179 |
|
1180 |
if (NSEqualRects(oldRect, NSZeroRect) == NO) { |
1181 |
[verticalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect)) |
1182 |
fromRect: NSMakeRect(0.0, 0.0, 1.0, oldRect.size.height) |
1183 |
operation: NSCompositeCopy]; |
1184 |
|
1185 |
[verticalImage compositeToPoint: NSMakePoint(NSMaxX(oldRect)-1, NSMinY(oldRect)) |
1186 |
fromRect: NSMakeRect(1.0, 0.0, 1.0, oldRect.size.height) |
1187 |
operation: NSCompositeCopy]; |
1188 |
|
1189 |
[horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect)) |
1190 |
fromRect: NSMakeRect(0.0, 0.0, oldRect.size.width, 1.0) |
1191 |
operation: NSCompositeCopy]; |
1192 |
|
1193 |
[horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMaxY(oldRect)-1) |
1194 |
fromRect: NSMakeRect(0.0, 1.0, oldRect.size.width, 1.0) |
1195 |
operation: NSCompositeCopy]; |
1196 |
} |
1197 |
|
1198 |
[[self window] enableFlushWindow]; |
1199 |
[[self window] flushWindow]; |
1200 |
[self unlockFocus]; |
1201 |
|
1202 |
[self setShiftClick: YES]; |
1203 |
selectInProgress = YES; |
1204 |
|
1205 |
x = (pp.x >= startp.x) ? startp.x : pp.x; |
1206 |
y = (pp.y >= startp.y) ? startp.y : pp.y; |
1207 |
w = max(pp.x, startp.x) - min(pp.x, startp.x); |
1208 |
w = (w == 0) ? 1 : w; |
1209 |
h = max(pp.y, startp.y) - min(pp.y, startp.y); |
1210 |
h = (h == 0) ? 1 : h; |
1211 |
|
1212 |
selrect = NSMakeRect(x, y, w, h); |
1213 |
|
1214 |
for (i = 0; i < [icons count]; i++) { |
1215 |
SmallIcon *icon = [icons objectAtIndex: i]; |
1216 |
|
1217 |
if (NSIntersectsRect(selrect, [icon frame])) { |
1218 |
[icon select]; |
1219 |
} |
1220 |
} |
1221 |
|
1222 |
selectInProgress = NO; |
1223 |
[self setCurrentSelection]; |
1224 |
[self setShiftClick: NO]; |
1225 |
} |
1226 |
|
1227 |
- (void)keyDown:(NSEvent *)theEvent |
1228 |
{ |
1229 |
NSString *characters; |
1230 |
unichar character; |
1231 |
NSRect vRect, hiddRect; |
1232 |
NSPoint p; |
1233 |
float x, y, w, h; |
1234 |
|
1235 |
characters = [theEvent characters]; |
1236 |
character = 0; |
1237 |
|
1238 |
if ([characters length] > 0) { |
1239 |
character = [characters characterAtIndex: 0]; |
1240 |
} |
1241 |
|
1242 |
switch (character) { |
1243 |
case NSPageUpFunctionKey: |
1244 |
vRect = [self visibleRect]; |
1245 |
p = vRect.origin; |
1246 |
x = p.x; |
1247 |
y = p.y + vRect.size.height; |
1248 |
w = vRect.size.width; |
1249 |
h = vRect.size.height; |
1250 |
hiddRect = NSMakeRect(x, y, w, h); |
1251 |
[self scrollRectToVisible: hiddRect]; |
1252 |
return; |
1253 |
|
1254 |
case NSPageDownFunctionKey: |
1255 |
vRect = [self visibleRect]; |
1256 |
p = vRect.origin; |
1257 |
x = p.x; |
1258 |
y = p.y - vRect.size.height; |
1259 |
w = vRect.size.width; |
1260 |
h = vRect.size.height; |
1261 |
hiddRect = NSMakeRect(x, y, w, h); |
1262 |
[self scrollRectToVisible: hiddRect]; |
1263 |
return; |
1264 |
|
1265 |
case NSUpArrowFunctionKey: |
1266 |
isShiftClick = NO; |
1267 |
[self selectIconInPrevLine]; |
1268 |
return; |
1269 |
|
1270 |
case NSDownArrowFunctionKey: |
1271 |
isShiftClick = NO; |
1272 |
[self selectIconInNextLine]; |
1273 |
return; |
1274 |
|
1275 |
case NSLeftArrowFunctionKey: |
1276 |
{ |
1277 |
if ([theEvent modifierFlags] & NSControlKeyMask) { |
1278 |
[super keyDown: theEvent]; |
1279 |
} else { |
1280 |
isShiftClick = NO; |
1281 |
[self selectPrevIcon]; |
1282 |
} |
1283 |
} |
1284 |
return; |
1285 |
|
1286 |
case NSRightArrowFunctionKey: |
1287 |
{ |
1288 |
if ([theEvent modifierFlags] & NSControlKeyMask) { |
1289 |
[super keyDown: theEvent]; |
1290 |
} else { |
1291 |
isShiftClick = NO; |
1292 |
[self selectNextIcon]; |
1293 |
} |
1294 |
} |
1295 |
return; |
1296 |
|
1297 |
case 13: |
1298 |
[self openCurrentSelection: (*currSelection)(self, currSelectionSel) |
1299 |
newViewer: NO]; |
1300 |
return; |
1301 |
|
1302 |
case NSTabCharacter: |
1303 |
{ |
1304 |
if ([theEvent modifierFlags] & NSShiftKeyMask) { |
1305 |
[[self window] selectKeyViewPrecedingView: self]; |
1306 |
} else { |
1307 |
[[self window] selectKeyViewFollowingView: self]; |
1308 |
} |
1309 |
} |
1310 |
return; |
1311 |
|
1312 |
break; |
1313 |
} |
1314 |
|
1315 |
if ((character < 0xF700) && ([characters length] > 0)) { |
1316 |
SEL iwnpSel = @selector(iconWithNamePrefix:inRange:); |
1317 |
IMP iwnp = [self methodForSelector: iwnpSel]; |
1318 |
SmallIcon *icon; |
1319 |
NSRect r; |
1320 |
int i, s, count; |
1321 |
|
1322 |
s = -1; |
1323 |
count = [icons count]; |
1324 |
|
1325 |
if (charBuffer == nil) { |
1326 |
charBuffer = [characters substringToIndex: 1]; |
1327 |
RETAIN (charBuffer); |
1328 |
} else { |
1329 |
if ([theEvent timestamp] - lastKeyPressed < 2000.0) { |
1330 |
ASSIGN (charBuffer, ([charBuffer stringByAppendingString: |
1331 |
[characters substringToIndex: 1]])); |
1332 |
} else { |
1333 |
ASSIGN (charBuffer, ([characters substringToIndex: 1])); |
1334 |
} |
1335 |
} |
1336 |
|
1337 |
lastKeyPressed = [theEvent timestamp]; |
1338 |
|
1339 |
[self setShiftClick: NO]; |
1340 |
|
1341 |
for (i = 0; i < count; i++) { |
1342 |
icon = [icons objectAtIndex: i]; |
1343 |
|
1344 |
if ([icon isSelect]) { |
1345 |
if ([[icon myName] hasPrefix: charBuffer]) { |
1346 |
r = [icon frame]; |
1347 |
r.origin.y -= ICON_FRAME_MARGIN; |
1348 |
r.size.height += ICON_FRAME_MARGIN * 2; |
1349 |
[self scrollRectToVisible: r]; |
1350 |
return; |
1351 |
} else { |
1352 |
s = i; |
1353 |
break; |
1354 |
} |
1355 |
} |
1356 |
} |
1357 |
|
1358 |
icon = (*iwnp)(self, iwnpSel, charBuffer, NSMakeRange(s + 1, count -s -1)); |
1359 |
if (icon) { |
1360 |
[icon select]; |
1361 |
r = [icon frame]; |
1362 |
r.origin.y -= ICON_FRAME_MARGIN; |
1363 |
r.size.height += ICON_FRAME_MARGIN * 2; |
1364 |
[self scrollRectToVisible: r]; |
1365 |
return; |
1366 |
} |
1367 |
|
1368 |
s = (s == -1) ? count - 1 : s; |
1369 |
|
1370 |
icon = (*iwnp)(self, iwnpSel, charBuffer, NSMakeRange(0, s)); |
1371 |
if (icon) { |
1372 |
[icon select]; |
1373 |
r = [icon frame]; |
1374 |
r.origin.y -= ICON_FRAME_MARGIN; |
1375 |
r.size.height += ICON_FRAME_MARGIN * 2; |
1376 |
[self scrollRectToVisible: r]; |
1377 |
return; |
1378 |
} |
1379 |
|
1380 |
lastKeyPressed = 0.; |
1381 |
} |
1382 |
|
1383 |
[super keyDown: theEvent]; |
1384 |
} |
1385 |
|
1386 |
- (BOOL)acceptsFirstResponder |
1387 |
{ |
1388 |
return YES; |
1389 |
} |
1390 |
|
1391 |
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent |
1392 |
{ |
1393 |
return YES; |
1394 |
} |
1395 |
|
1396 |
@end |
1397 |
|
1398 |
@implementation SmallIconsPanel (DraggingDestination) |
1399 |
|
1400 |
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender |
1401 |
{ |
1402 |
NSPasteboard *pb; |
1403 |
NSDragOperation sourceDragMask; |
1404 |
NSArray *sourcePaths; |
1405 |
NSString *fromPath; |
1406 |
NSString *buff; |
1407 |
int i, count; |
1408 |
|
1409 |
isDragTarget = NO; |
1410 |
|
1411 |
pb = [sender draggingPasteboard]; |
1412 |
if ([[pb types] indexOfObject: NSFilenamesPboardType] != NSNotFound) { |
1413 |
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
1414 |
|
1415 |
count = [sourcePaths count]; |
1416 |
fromPath = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent]; |
1417 |
|
1418 |
if (count == 0) { |
1419 |
return NSDragOperationNone; |
1420 |
} |
1421 |
|
1422 |
if ([fm isWritableFileAtPath: currentPath] == NO) { |
1423 |
return NSDragOperationNone; |
1424 |
} |
1425 |
|
1426 |
if ([currentPath isEqualToString: fromPath]) { |
1427 |
return NSDragOperationNone; |
1428 |
} |
1429 |
|
1430 |
for (i = 0; i < count; i++) { |
1431 |
if ([currentPath isEqualToString: [sourcePaths objectAtIndex: i]]) { |
1432 |
return NSDragOperationNone; |
1433 |
} |
1434 |
} |
1435 |
|
1436 |
buff = [NSString stringWithString: currentPath]; |
1437 |
while (1) { |
1438 |
for (i = 0; i < count; i++) { |
1439 |
if ([buff isEqualToString: [sourcePaths objectAtIndex: i]]) { |
1440 |
return NSDragOperationNone; |
1441 |
} |
1442 |
} |
1443 |
if ([buff isEqualToString: fixPath(@"/", 0)] == YES) { |
1444 |
break; |
1445 |
} |
1446 |
buff = [buff stringByDeletingLastPathComponent]; |
1447 |
} |
1448 |
|
1449 |
isDragTarget = YES; |
1450 |
|
1451 |
sourceDragMask = [sender draggingSourceOperationMask]; |
1452 |
|
1453 |
if (sourceDragMask == NSDragOperationCopy) { |
1454 |
return NSDragOperationCopy; |
1455 |
} else if (sourceDragMask == NSDragOperationLink) { |
1456 |
return NSDragOperationLink; |
1457 |
} else { |
1458 |
return NSDragOperationAll; |
1459 |
} |
1460 |
return NSDragOperationAll; |
1461 |
} |
1462 |
|
1463 |
isDragTarget = NO; |
1464 |
return NSDragOperationNone; |
1465 |
} |
1466 |
|
1467 |
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender |
1468 |
{ |
1469 |
NSDragOperation sourceDragMask; |
1470 |
|
1471 |
if (isDragTarget == NO) { |
1472 |
return NSDragOperationNone; |
1473 |
} |
1474 |
|
1475 |
sourceDragMask = [sender draggingSourceOperationMask]; |
1476 |
|
1477 |
if (sourceDragMask == NSDragOperationCopy) { |
1478 |
return NSDragOperationCopy; |
1479 |
} else if (sourceDragMask == NSDragOperationLink) { |
1480 |
return NSDragOperationLink; |
1481 |
} else { |
1482 |
return NSDragOperationAll; |
1483 |
} |
1484 |
|
1485 |
return NSDragOperationNone; |
1486 |
} |
1487 |
|
1488 |
- (void)draggingExited:(id <NSDraggingInfo>)sender |
1489 |
{ |
1490 |
isDragTarget = NO; |
1491 |
} |
1492 |
|
1493 |
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender |
1494 |
{ |
1495 |
return isDragTarget; |
1496 |
} |
1497 |
|
1498 |
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender |
1499 |
{ |
1500 |
return YES; |
1501 |
} |
1502 |
|
1503 |
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender |
1504 |
{ |
1505 |
NSPasteboard *pb; |
1506 |
NSDragOperation sourceDragMask; |
1507 |
NSArray *sourcePaths; |
1508 |
NSString *operation, *source; |
1509 |
NSMutableArray *files; |
1510 |
NSMutableDictionary *opDict; |
1511 |
NSString *trashPath; |
1512 |
int i; |
1513 |
|
1514 |
isDragTarget = NO; |
1515 |
|
1516 |
sourceDragMask = [sender draggingSourceOperationMask]; |
1517 |
pb = [sender draggingPasteboard]; |
1518 |
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
1519 |
source = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent]; |
1520 |
|
1521 |
trashPath = [gworkspace trashPath]; |
1522 |
if ([source isEqualToString: trashPath]) { |
1523 |
operation = GWorkspaceRecycleOutOperation; |
1524 |
} else { |
1525 |
if (sourceDragMask == NSDragOperationCopy) { |
1526 |
operation = NSWorkspaceCopyOperation; |
1527 |
} else if (sourceDragMask == NSDragOperationLink) { |
1528 |
operation = NSWorkspaceLinkOperation; |
1529 |
} else { |
1530 |
operation = NSWorkspaceMoveOperation; |
1531 |
} |
1532 |
} |
1533 |
|
1534 |
files = [NSMutableArray arrayWithCapacity: 1]; |
1535 |
for(i = 0; i < [sourcePaths count]; i++) { |
1536 |
[files addObject: [[sourcePaths objectAtIndex: i] lastPathComponent]]; |
1537 |
} |
1538 |
|
1539 |
opDict = [NSMutableDictionary dictionaryWithCapacity: 4]; |
1540 |
[opDict setObject: operation forKey: @"operation"]; |
1541 |
[opDict setObject: source forKey: @"source"]; |
1542 |
[opDict setObject: currentPath forKey: @"destination"]; |
1543 |
[opDict setObject: files forKey: @"files"]; |
1544 |
|
1545 |
[gworkspace performFileOperationWithDictionary: opDict]; |
1546 |
} |
1547 |
|
1548 |
@end |
1549 |
|
1550 |
// |
1551 |
// SmallIcon Delegate Methods |
1552 |
// |
1553 |
@implementation SmallIconsPanel (SmallIconDelegateMethods) |
1554 |
|
1555 |
- (void)unselectIconsDifferentFrom:(id)aicon |
1556 |
{ |
1557 |
[self unselectOtherIcons: aicon]; |
1558 |
} |
1559 |
|
1560 |
- (void)setShiftClickValue:(BOOL)value |
1561 |
{ |
1562 |
[self setShiftClick: value]; |
1563 |
} |
1564 |
|
1565 |
- (void)setTheCurrentSelection |
1566 |
{ |
1567 |
[self setCurrentSelection]; |
1568 |
} |
1569 |
|
1570 |
- (NSArray *)getTheCurrentSelection |
1571 |
{ |
1572 |
return (*currSelection)(self, currSelectionSel); |
1573 |
} |
1574 |
|
1575 |
- (void)openTheCurrentSelection:(id)paths newViewer:(BOOL)newv |
1576 |
{ |
1577 |
[self openCurrentSelection: paths newViewer: newv]; |
1578 |
} |
1579 |
|
1580 |
- (id)menuForRightMouseEvent:(NSEvent *)theEvent |
1581 |
{ |
1582 |
return [self menuForEvent: theEvent]; |
1583 |
} |
1584 |
|
1585 |
@end |