/[gnustep]/gnustep/usr-apps/gworkspace/Viewers/SmallIconsViewer/SmallIconsPanel.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/Viewers/SmallIconsViewer/SmallIconsPanel.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Sat Oct 4 14:45:19 2003 UTC (20 years, 6 months ago) by esersale
Branch: MAIN
Changes since 1.4: +4 -0 lines

2003-10-03 Enrico Sersale  <enrico@imago.ro>

  * GWorkspace/FileOperations/FileOperation.m
    -calculateNumFiles doesn't block anymore.
    the stop button now works.

  * Viewers/SmallIconsViewer/SmallIconsPanel.m
    in -selectIconWithPath: now the view scroll to show the icon.
-

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

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26