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