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