/[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.4 - (show annotations) (download)
Tue Sep 30 15:38:06 2003 UTC (20 years, 6 months ago) by esersale
Branch: MAIN
Changes since 1.3: +10 -18 lines
*** empty log message ***

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 [icon select];
497 return;
498 }
499 }
500 }
501
502 - (SmallIcon *)iconWithNamePrefix:(NSString *)prefix
503 inRange:(NSRange)range
504 {
505 int i;
506
507 if (range.length == 0) {
508 return nil;
509 }
510
511 for (i = range.location; i < range.location + range.length; i++) {
512 SmallIcon *icon = [icons objectAtIndex: i];
513 if ([[icon myName] hasPrefix: charBuffer]) {
514 return icon;
515 }
516 }
517
518 return nil;
519 }
520
521 - (NSPoint)locationOfIconWithName:(NSString *)name
522 {
523 int i;
524
525 for (i = 0; i < [icons count]; i++) {
526 SmallIcon *icon = [icons objectAtIndex: i];
527
528 if ([[icon myName] isEqualToString: name]) {
529 NSPoint p = [icon frame].origin;
530 NSSize s = [icon iconShift];
531 return NSMakePoint(p.x + s.width, p.y + s.height);
532 }
533 }
534
535 return NSMakePoint(0, 0);
536 }
537
538 - (void)selectIconsWithPaths:(NSArray *)paths
539 {
540 int i;
541
542 isShiftClick = YES;
543
544 for (i = 0; i < [icons count]; i++) {
545 SmallIcon *icon = [icons objectAtIndex: i];
546 NSString *ipath = [icon path];
547
548 if ([paths containsObject: ipath] == YES) {
549 [icon select];
550 }
551 }
552
553 isShiftClick = NO;
554 }
555
556 - (void)selectIconInPrevLine
557 {
558 NSPoint sp;
559 NSRect r[2];
560 NSRect irect;
561 int i, startpos = -1;
562
563 for (i = [icons count] -1; i >= 0; i--) {
564 SmallIcon *icon = [icons objectAtIndex: i];
565
566 if ([icon isSelect]) {
567 r[0] = [icon frame];
568 r[1] = [[icon label] frame];
569 startpos = i;
570 sp = [icon position];
571 break;
572 }
573 }
574
575 if (startpos != -1) {
576 for (i = startpos; i >= 0; i--) {
577 SmallIcon *icon = [icons objectAtIndex: i];
578 NSPoint p = [icon position];
579
580 if ((p.x == sp.x) && (p.y > sp.y)) {
581 [icon select];
582 [self setNeedsDisplayInRect: r[0]];
583 [self setNeedsDisplayInRect: r[1]];
584
585 irect = NSUnionRect([icon frame], [[icon label] frame]);
586 irect.origin.y -= ICON_FRAME_MARGIN;
587 irect.size.height += ICON_FRAME_MARGIN * 2;
588 [self scrollRectToVisible: irect];
589 break;
590 }
591 }
592 }
593 }
594
595 - (void)selectIconInNextLine
596 {
597 NSPoint sp;
598 NSRect r[2];
599 NSRect irect;
600 int i, startpos = -1;
601
602 for (i = 0; i < [icons count]; i++) {
603 SmallIcon *icon = [icons objectAtIndex: i];
604
605 if ([icon isSelect]) {
606 r[0] = [icon frame];
607 r[1] = [[icon label] frame];
608 startpos = i;
609 sp = [icon position];
610 break;
611 }
612 }
613
614 if (startpos != -1) {
615 for (i = startpos; i < [icons count]; i++) {
616 SmallIcon *icon = [icons objectAtIndex: i];
617 NSPoint p = [icon position];
618
619 if ((p.x == sp.x) && (p.y < sp.y)) {
620 [icon select];
621 [self setNeedsDisplayInRect: r[0]];
622 [self setNeedsDisplayInRect: r[1]];
623
624 irect = NSUnionRect([icon frame], [[icon label] frame]);
625 irect.origin.y -= ICON_FRAME_MARGIN;
626 irect.size.height += ICON_FRAME_MARGIN * 2;
627 [self scrollRectToVisible: irect];
628 break;
629 }
630 }
631 }
632 }
633
634 - (void)selectPrevIcon
635 {
636 int i;
637
638 for(i = 0; i < [icons count]; i++) {
639 SmallIcon *icon = [icons objectAtIndex: i];
640
641 if([icon isSelect]) {
642 if (i > 0) {
643 NSRect irect = NSUnionRect([icon frame], [[icon label] frame]);
644
645 [self unselectOtherIcons: icon];
646 icon = [icons objectAtIndex: i - 1];
647 [icon select];
648 [self setNeedsDisplayInRect: irect];
649
650 irect = NSUnionRect([icon frame], [[icon label] frame]);
651 irect.origin.y -= ICON_FRAME_MARGIN;
652 irect.size.height += ICON_FRAME_MARGIN * 2;
653 [self scrollRectToVisible: irect];
654 return;
655 } else {
656 return;
657 }
658 }
659 }
660 }
661
662 - (void)selectNextIcon
663 {
664 int i, count = [icons count];
665
666 for(i = 0; i < [icons count]; i++) {
667 SmallIcon *icon = [icons objectAtIndex: i];
668
669 if([icon isSelect]) {
670 if (i < (count - 1)) {
671 NSRect irect = NSUnionRect([icon frame], [[icon label] frame]);
672
673 [self unselectOtherIcons: icon];
674 icon = [icons objectAtIndex: i + 1];
675 [icon select];
676 [self setNeedsDisplayInRect: irect];
677
678 irect = NSUnionRect([icon frame], [[icon label] frame]);
679 irect.origin.y -= ICON_FRAME_MARGIN;
680 irect.size.height += ICON_FRAME_MARGIN * 2;
681 [self scrollRectToVisible: irect];
682 return;
683 } else {
684 return;
685 }
686 }
687 }
688 }
689
690 - (void)selectAllIcons
691 {
692 int i;
693
694 isShiftClick = YES;
695 selectInProgress = YES;
696 for(i = 0; i < [icons count]; i++) {
697 [[icons objectAtIndex: i] select];
698 }
699 selectInProgress = NO;
700 [self setCurrentSelection];
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 SmallIcon *icon = [icons objectAtIndex: i];
714 if (icon != anIcon) {
715 [icon unselect];
716 }
717 }
718 }
719
720 - (void)extendSelectionWithDimmedFiles:(NSArray *)files
721 startingAtPath:(NSString *)bpath
722 {
723 if ([currentPath isEqual: bpath]) {
724 [self addIconsWithNames: files dimmed: YES];
725
726 } else if (subPathOfPath(bpath, currentPath)) {
727 int i;
728
729 for (i = 0; i < [files count]; i++) {
730 NSString *fname = [files objectAtIndex: i];
731 NSString *fpath = [bpath stringByAppendingPathComponent: fname];
732
733 if (([fpath isEqual: currentPath]) || (subPathOfPath(fpath, currentPath))) {
734 [self lockAllIcons];
735 break;
736 }
737 }
738 }
739 }
740
741 - (void)openSelectionWithApp:(id)sender
742 {
743 NSString *appName = (NSString *)[sender representedObject];
744 NSArray *selection = [self currentSelection];
745
746 if (selection && [selection count]) {
747 int i;
748
749 for (i = 0; i < [selection count]; i++) {
750 [[NSWorkspace sharedWorkspace] openFile: [selection objectAtIndex: i]
751 withApplication: appName];
752 }
753 }
754 }
755
756 - (void)openSelectionWith:(id)sender
757 {
758 [[GWLib workspaceApp] openSelectedPathsWith];
759 }
760
761 - (void)addIconWithPath:(NSString *)iconpath dimmed:(BOOL)isdimmed;
762 {
763 SmallIcon *icon = [self iconWithPath: iconpath];
764
765 if (icon) {
766 [icon setLocked: isdimmed];
767 } else {
768 icon = [[SmallIcon alloc] initForPath: iconpath delegate: self];
769 [icon setLocked: isdimmed];
770 [icons addObject: icon];
771 [self addSubview: icon];
772 [self addSubview: [icon label]];
773 RELEASE (icon);
774 }
775 }
776
777 - (void)addIconsWithPaths:(NSArray *)iconpaths
778 {
779 int i;
780
781 for (i = 0; i < [iconpaths count]; i++) {
782 NSString *s = [iconpaths objectAtIndex: i];
783 SmallIcon *icon = [[SmallIcon alloc] initForPath: s delegate: self];
784
785 [icon setLocked: [GWLib isLockedPath: s]];
786
787 [icons addObject: icon];
788 [self addSubview: icon];
789 [self addSubview: [icon label]];
790 [icon setLabelFrame];
791 RELEASE (icon);
792 }
793 }
794
795 - (void)addIconsWithNames:(NSArray *)names dimmed:(BOOL)isdimmed
796 {
797 NSArray *files = [self checkHiddenFiles: names atPath: currentPath];
798
799 if ([files count]) {
800 int i;
801
802 for (i = 0; i < [files count]; i++) {
803 NSString *s = [currentPath stringByAppendingPathComponent: [files objectAtIndex: i]];
804 [self addIconWithPath: s dimmed: isdimmed];
805 }
806 [self sortIcons];
807 [self tile];
808 }
809 }
810
811 - (void)removeIcon:(id)anIcon
812 {
813 SmallIcon *icon = (SmallIcon *)anIcon;
814 [[icon label] removeFromSuperview];
815 [icon removeFromSuperview];
816 [icons removeObject: icon];
817 [self tile];
818 }
819
820 - (void)removeIconsWithNames:(NSArray *)names
821 {
822 int i, count = [icons count];
823
824 for (i = 0; i < count; i++) {
825 SmallIcon *icon = [icons objectAtIndex: i];
826 NSString *name = [icon myName];
827
828 if ([names containsObject: name] == YES) {
829 [[icon label] removeFromSuperview];
830 [icon removeFromSuperview];
831 [icons removeObject: icon];
832 count--;
833 i--;
834 }
835 }
836
837 [self tile];
838 }
839
840 - (void)lockIconsWithNames:(NSArray *)names
841 {
842 int i;
843
844 for (i = 0; i < [icons count]; i++) {
845 SmallIcon *icon = [icons objectAtIndex: i];
846 if ([names containsObject: [icon myName]]) {
847 [icon setLocked: YES];
848 }
849 }
850 }
851
852 - (void)unLockIconsWithNames:(NSArray *)names
853 {
854 int i;
855
856 for (i = 0; i < [icons count]; i++) {
857 SmallIcon *icon = [icons objectAtIndex: i];
858 if ([names containsObject: [icon myName]]) {
859 [icon setLocked: NO];
860 }
861 }
862 }
863
864 - (void)lockAllIcons
865 {
866 int i;
867
868 for (i = 0; i < [icons count]; i++) {
869 SmallIcon *icon = [icons objectAtIndex: i];
870 if ([icon isLocked] == NO) {
871 [icon setLocked: YES];
872 }
873 }
874 }
875
876 - (void)unLockAllIcons
877 {
878 int i;
879
880 for (i = 0; i < [icons count]; i++) {
881 SmallIcon *icon = [icons objectAtIndex: i];
882 if ([icon isLocked]) {
883 [icon setLocked: NO];
884 }
885 }
886 }
887
888 - (void)setLabelRectOfIcon:(id)anIcon
889 {
890 SmallIcon *icon = (SmallIcon *)anIcon;
891 NSTextField *label = [icon label];
892
893 [label setFrame: NSMakeRect([icon frame].origin.x + ICNWIDTH,
894 [icon frame].origin.y + ((ICNHEIGHT - LABHEIGHT) / 2),
895 [icon labelWidth], LABHEIGHT)];
896 [label setNeedsDisplay: YES];
897 }
898
899 - (int)cellsWidth
900 {
901 return cellsWidth;
902 }
903
904 - (void)cellsWidthChanged:(NSNotification *)notification
905 {
906 cellsWidth = [(NSNumber *)[notification object] intValue];
907 [self tile];
908 }
909
910 - (void)setShiftClick:(BOOL)value
911 {
912 isShiftClick = value;
913 }
914
915 - (void)openCurrentSelection:(NSArray *)paths newViewer:(BOOL)newv
916 {
917 [delegate openTheCurrentSelection: (*currSelection)(self, currSelectionSel)
918 newViewer: newv];
919 }
920
921 - (id)delegate
922 {
923 return delegate;
924 }
925
926 - (void)setDelegate:(id)anObject
927 {
928 delegate = anObject;
929 }
930
931 - (void)resizeWithOldSuperviewSize:(NSSize)oldFrameSize
932 {
933 [self tile];
934 }
935
936 - (NSMenu *)menuForEvent:(NSEvent *)theEvent
937 {
938 if ([theEvent type] == NSRightMouseDown) {
939 NSArray *selection = [self currentSelection];
940
941 if (contestualMenu == NO) {
942 return [super menuForEvent: theEvent];
943 }
944
945 if (selection && [selection count]) {
946 if ([theEvent modifierFlags] == NSControlKeyMask) {
947 return [super menuForEvent: theEvent];
948 } else {
949 NSMenu *menu;
950 NSMenuItem *menuItem;
951 NSString *firstext;
952 NSDictionary *apps;
953 NSEnumerator *app_enum;
954 id key;
955 int i;
956
957 firstext = [[selection objectAtIndex: 0] pathExtension];
958
959 for (i = 0; i < [selection count]; i++) {
960 NSString *selpath = [selection objectAtIndex: i];
961 NSString *ext = [selpath pathExtension];
962 NSString *defApp = nil;
963 NSString *fType = nil;
964
965 if ([ext isEqual: firstext] == NO) {
966 return [super menuForEvent: theEvent];
967 }
968
969 [[NSWorkspace sharedWorkspace] getInfoForFile: selpath
970 application: &defApp
971 type: &fType];
972
973 if (([fType isEqual: NSPlainFileType] == NO)
974 && ([fType isEqual: NSShellCommandFileType] == NO)) {
975 return [super menuForEvent: theEvent];
976 }
977 }
978
979 menu = [[NSMenu alloc] initWithTitle: NSLocalizedString(@"Open with", @"")];
980 apps = [[NSWorkspace sharedWorkspace] infoForExtension: firstext];
981 app_enum = [[apps allKeys] objectEnumerator];
982
983 while ((key = [app_enum nextObject])) {
984 NSDictionary *dict = [apps objectForKey: key];
985 NSString *role = [dict objectForKey: @"NSRole"];
986
987 menuItem = [NSMenuItem new];
988
989 if (role) {
990 [menuItem setTitle: [NSString stringWithFormat: @"%@ - %@", key, role]];
991 } else {
992 [menuItem setTitle: [NSString stringWithFormat: @"%@", key]];
993 }
994
995 [menuItem setTarget: self];
996 [menuItem setAction: @selector(openSelectionWithApp:)];
997 [menuItem setRepresentedObject: key];
998 [menu addItem: menuItem];
999 RELEASE (menuItem);
1000 }
1001
1002 menuItem = [NSMenuItem new];
1003 [menuItem setTitle: NSLocalizedString(@"Open with...", @"")];
1004 [menuItem setTarget: self];
1005 [menuItem setAction: @selector(openSelectionWith:)];
1006 [menu addItem: menuItem];
1007 RELEASE (menuItem);
1008
1009 return [menu autorelease];
1010 }
1011
1012 } else {
1013 return [super menuForEvent: theEvent];
1014 }
1015 }
1016
1017 return [super menuForEvent: theEvent];
1018 }
1019
1020 - (void)mouseDown:(NSEvent *)theEvent
1021 {
1022 [[self window] makeFirstResponder: self];
1023
1024 if([theEvent modifierFlags] != 2) {
1025 isShiftClick = NO;
1026 selectInProgress = YES;
1027 [self unselectOtherIcons: nil];
1028 selectInProgress = NO;
1029 [delegate setSelectedPathsFromIcons: [NSArray arrayWithObject: currentPath]];
1030 }
1031 }
1032
1033 - (void)mouseDragged:(NSEvent *)theEvent
1034 {
1035 unsigned int eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSPeriodicMask;
1036 NSDate *future = [NSDate distantFuture];
1037 NSPoint startp, sp;
1038 NSPoint p, pp;
1039 NSRect visibleRect;
1040 NSRect oldRect;
1041 NSRect r, wr;
1042 NSRect selrect;
1043 float x, y, w, h;
1044 int i;
1045
1046 #define scrollPointToVisible(p) \
1047 { \
1048 NSRect sr; \
1049 sr.origin = p; \
1050 sr.size.width = sr.size.height = 0.1; \
1051 [self scrollRectToVisible: sr]; \
1052 }
1053
1054 #define CONVERT_CHECK \
1055 pp = [self convertPoint: p fromView: nil]; \
1056 if (pp.x < 1) \
1057 pp.x = 1; \
1058 if (pp.x >= NSMaxX([self bounds])) \
1059 pp.x = NSMaxX([self bounds]) - 1
1060
1061 p = [theEvent locationInWindow];
1062 sp = [self convertPoint: p fromView: nil];
1063 startp = [self convertPoint: p fromView: nil];
1064
1065 oldRect = NSZeroRect;
1066
1067 [[self window] disableFlushWindow];
1068 [self lockFocus];
1069
1070 [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.05];
1071
1072 while ([theEvent type] != NSLeftMouseUp) {
1073 CREATE_AUTORELEASE_POOL (arp);
1074
1075 theEvent = [NSApp nextEventMatchingMask: eventMask
1076 untilDate: future
1077 inMode: NSEventTrackingRunLoopMode
1078 dequeue: YES];
1079
1080 if ([theEvent type] != NSPeriodic) {
1081 p = [theEvent locationInWindow];
1082 }
1083
1084 CONVERT_CHECK;
1085
1086 visibleRect = [self visibleRect];
1087
1088 if (NSPointInRect(pp, [self visibleRect]) == NO) {
1089 scrollPointToVisible(pp);
1090 CONVERT_CHECK;
1091 visibleRect = [self visibleRect];
1092 }
1093
1094 if ((sp.y < visibleRect.origin.y)
1095 || (sp.y > (visibleRect.origin.y + visibleRect.size.height))) {
1096 if (sp.y < visibleRect.origin.y) {
1097 sp.y = visibleRect.origin.y - 1;
1098 }
1099 if (sp.y > (visibleRect.origin.y + visibleRect.size.height)) {
1100 sp.y = (visibleRect.origin.y + visibleRect.size.height + 1);
1101 }
1102 }
1103
1104 x = (pp.x >= sp.x) ? sp.x : pp.x;
1105 y = (pp.y >= sp.y) ? sp.y : pp.y;
1106 w = max(pp.x, sp.x) - min(pp.x, sp.x);
1107 w = (w == 0) ? 1 : w;
1108 h = max(pp.y, sp.y) - min(pp.y, sp.y);
1109 h = (h == 0) ? 1 : h;
1110
1111 r = NSMakeRect(x, y, w, h);
1112
1113 wr = [self convertRect: r toView: nil];
1114
1115 sp = startp;
1116
1117 if (NSEqualRects(oldRect, NSZeroRect) == NO) {
1118 [verticalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect))
1119 fromRect: NSMakeRect(0.0, 0.0, 1.0, oldRect.size.height)
1120 operation: NSCompositeCopy];
1121
1122 [verticalImage compositeToPoint: NSMakePoint(NSMaxX(oldRect)-1, NSMinY(oldRect))
1123 fromRect: NSMakeRect(1.0, 0.0, 1.0, oldRect.size.height)
1124 operation: NSCompositeCopy];
1125
1126 [horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect))
1127 fromRect: NSMakeRect(0.0, 0.0, oldRect.size.width, 1.0)
1128 operation: NSCompositeCopy];
1129
1130 [horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMaxY(oldRect)-1)
1131 fromRect: NSMakeRect(0.0, 1.0, oldRect.size.width, 1.0)
1132 operation: NSCompositeCopy];
1133 }
1134 [self displayIfNeeded];
1135
1136 [verticalImage lockFocus];
1137 NSCopyBits([[self window] gState],
1138 NSMakeRect(NSMinX(wr), NSMinY(wr),
1139 1.0, r.size.height),
1140 NSMakePoint(0.0, 0.0));
1141 NSCopyBits([[self window] gState],
1142 NSMakeRect(NSMaxX(wr) -1, NSMinY(wr),
1143 1.0, r.size.height),
1144 NSMakePoint(1.0, 0.0));
1145 [verticalImage unlockFocus];
1146
1147 [horizontalImage lockFocus];
1148 NSCopyBits([[self window] gState],
1149 NSMakeRect(NSMinX(wr), NSMinY(wr),
1150 r.size.width, 1.0),
1151 NSMakePoint(0.0, 0.0));
1152 NSCopyBits([[self window] gState],
1153 NSMakeRect(NSMinX(wr), NSMaxY(wr) -1,
1154 r.size.width, 1.0),
1155 NSMakePoint(0.0, 1.0));
1156 [horizontalImage unlockFocus];
1157
1158 [[NSColor darkGrayColor] set];
1159 NSFrameRect(r);
1160 oldRect = r;
1161
1162 [[self window] enableFlushWindow];
1163 [[self window] flushWindow];
1164 [[self window] disableFlushWindow];
1165
1166 DESTROY (arp);
1167 }
1168
1169 [NSEvent stopPeriodicEvents];
1170 [[self window] postEvent: theEvent atStart: NO];
1171
1172 if (NSEqualRects(oldRect, NSZeroRect) == NO) {
1173 [verticalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect))
1174 fromRect: NSMakeRect(0.0, 0.0, 1.0, oldRect.size.height)
1175 operation: NSCompositeCopy];
1176
1177 [verticalImage compositeToPoint: NSMakePoint(NSMaxX(oldRect)-1, NSMinY(oldRect))
1178 fromRect: NSMakeRect(1.0, 0.0, 1.0, oldRect.size.height)
1179 operation: NSCompositeCopy];
1180
1181 [horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect))
1182 fromRect: NSMakeRect(0.0, 0.0, oldRect.size.width, 1.0)
1183 operation: NSCompositeCopy];
1184
1185 [horizontalImage compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMaxY(oldRect)-1)
1186 fromRect: NSMakeRect(0.0, 1.0, oldRect.size.width, 1.0)
1187 operation: NSCompositeCopy];
1188 }
1189
1190 [[self window] enableFlushWindow];
1191 [[self window] flushWindow];
1192 [self unlockFocus];
1193
1194 [self setShiftClick: YES];
1195 selectInProgress = YES;
1196
1197 x = (pp.x >= startp.x) ? startp.x : pp.x;
1198 y = (pp.y >= startp.y) ? startp.y : pp.y;
1199 w = max(pp.x, startp.x) - min(pp.x, startp.x);
1200 w = (w == 0) ? 1 : w;
1201 h = max(pp.y, startp.y) - min(pp.y, startp.y);
1202 h = (h == 0) ? 1 : h;
1203
1204 selrect = NSMakeRect(x, y, w, h);
1205
1206 for (i = 0; i < [icons count]; i++) {
1207 SmallIcon *icon = [icons objectAtIndex: i];
1208
1209 if (NSIntersectsRect(selrect, [icon frame])) {
1210 [icon select];
1211 }
1212 }
1213
1214 selectInProgress = NO;
1215 [self setCurrentSelection];
1216 [self setShiftClick: NO];
1217 }
1218
1219 - (void)keyDown:(NSEvent *)theEvent
1220 {
1221 NSString *characters;
1222 unichar character;
1223 NSRect vRect, hiddRect;
1224 NSPoint p;
1225 float x, y, w, h;
1226
1227 characters = [theEvent characters];
1228 character = 0;
1229
1230 if ([characters length] > 0) {
1231 character = [characters characterAtIndex: 0];
1232 }
1233
1234 switch (character) {
1235 case NSPageUpFunctionKey:
1236 vRect = [self visibleRect];
1237 p = vRect.origin;
1238 x = p.x;
1239 y = p.y + vRect.size.height;
1240 w = vRect.size.width;
1241 h = vRect.size.height;
1242 hiddRect = NSMakeRect(x, y, w, h);
1243 [self scrollRectToVisible: hiddRect];
1244 return;
1245
1246 case NSPageDownFunctionKey:
1247 vRect = [self visibleRect];
1248 p = vRect.origin;
1249 x = p.x;
1250 y = p.y - vRect.size.height;
1251 w = vRect.size.width;
1252 h = vRect.size.height;
1253 hiddRect = NSMakeRect(x, y, w, h);
1254 [self scrollRectToVisible: hiddRect];
1255 return;
1256
1257 case NSUpArrowFunctionKey:
1258 isShiftClick = NO;
1259 [self selectIconInPrevLine];
1260 return;
1261
1262 case NSDownArrowFunctionKey:
1263 isShiftClick = NO;
1264 [self selectIconInNextLine];
1265 return;
1266
1267 case NSLeftArrowFunctionKey:
1268 {
1269 if ([theEvent modifierFlags] & NSControlKeyMask) {
1270 [super keyDown: theEvent];
1271 } else {
1272 isShiftClick = NO;
1273 [self selectPrevIcon];
1274 }
1275 }
1276 return;
1277
1278 case NSRightArrowFunctionKey:
1279 {
1280 if ([theEvent modifierFlags] & NSControlKeyMask) {
1281 [super keyDown: theEvent];
1282 } else {
1283 isShiftClick = NO;
1284 [self selectNextIcon];
1285 }
1286 }
1287 return;
1288
1289 case 13:
1290 [self openCurrentSelection: (*currSelection)(self, currSelectionSel)
1291 newViewer: NO];
1292 return;
1293
1294 case NSTabCharacter:
1295 {
1296 if ([theEvent modifierFlags] & NSShiftKeyMask) {
1297 [[self window] selectKeyViewPrecedingView: self];
1298 } else {
1299 [[self window] selectKeyViewFollowingView: self];
1300 }
1301 }
1302 return;
1303
1304 break;
1305 }
1306
1307 if ((character < 0xF700) && ([characters length] > 0)) {
1308 SEL iwnpSel = @selector(iconWithNamePrefix:inRange:);
1309 IMP iwnp = [self methodForSelector: iwnpSel];
1310 SmallIcon *icon;
1311 NSRect r;
1312 int i, s, count;
1313
1314 s = -1;
1315 count = [icons count];
1316
1317 if (charBuffer == nil) {
1318 charBuffer = [characters substringToIndex: 1];
1319 RETAIN (charBuffer);
1320 } else {
1321 if ([theEvent timestamp] - lastKeyPressed < 2000.0) {
1322 ASSIGN (charBuffer, ([charBuffer stringByAppendingString:
1323 [characters substringToIndex: 1]]));
1324 } else {
1325 ASSIGN (charBuffer, ([characters substringToIndex: 1]));
1326 }
1327 }
1328
1329 lastKeyPressed = [theEvent timestamp];
1330
1331 [self setShiftClick: NO];
1332
1333 for (i = 0; i < count; i++) {
1334 icon = [icons objectAtIndex: i];
1335
1336 if ([icon isSelect]) {
1337 if ([[icon myName] hasPrefix: charBuffer]) {
1338 r = [icon frame];
1339 r.origin.y -= ICON_FRAME_MARGIN;
1340 r.size.height += ICON_FRAME_MARGIN * 2;
1341 [self scrollRectToVisible: r];
1342 return;
1343 } else {
1344 s = i;
1345 break;
1346 }
1347 }
1348 }
1349
1350 icon = (*iwnp)(self, iwnpSel, charBuffer, NSMakeRange(s + 1, count -s -1));
1351 if (icon) {
1352 [icon select];
1353 r = [icon frame];
1354 r.origin.y -= ICON_FRAME_MARGIN;
1355 r.size.height += ICON_FRAME_MARGIN * 2;
1356 [self scrollRectToVisible: r];
1357 return;
1358 }
1359
1360 s = (s == -1) ? count - 1 : s;
1361
1362 icon = (*iwnp)(self, iwnpSel, charBuffer, NSMakeRange(0, s));
1363 if (icon) {
1364 [icon select];
1365 r = [icon frame];
1366 r.origin.y -= ICON_FRAME_MARGIN;
1367 r.size.height += ICON_FRAME_MARGIN * 2;
1368 [self scrollRectToVisible: r];
1369 return;
1370 }
1371
1372 lastKeyPressed = 0.;
1373 }
1374
1375 [super keyDown: theEvent];
1376 }
1377
1378 - (BOOL)acceptsFirstResponder
1379 {
1380 return YES;
1381 }
1382
1383 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
1384 {
1385 return YES;
1386 }
1387
1388 @end
1389
1390 @implementation SmallIconsPanel (DraggingDestination)
1391
1392 - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
1393 {
1394 NSPasteboard *pb;
1395 NSDragOperation sourceDragMask;
1396 NSArray *sourcePaths;
1397 NSString *fromPath;
1398 NSString *buff;
1399 int i, count;
1400
1401 isDragTarget = NO;
1402
1403 pb = [sender draggingPasteboard];
1404 if ([[pb types] indexOfObject: NSFilenamesPboardType] != NSNotFound) {
1405 sourcePaths = [pb propertyListForType: NSFilenamesPboardType];
1406
1407 count = [sourcePaths count];
1408 fromPath = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent];
1409
1410 if (count == 0) {
1411 return NSDragOperationNone;
1412 }
1413
1414 if ([fm isWritableFileAtPath: currentPath] == NO) {
1415 return NSDragOperationNone;
1416 }
1417
1418 if ([currentPath isEqualToString: fromPath]) {
1419 return NSDragOperationNone;
1420 }
1421
1422 for (i = 0; i < count; i++) {
1423 if ([currentPath isEqualToString: [sourcePaths objectAtIndex: i]]) {
1424 return NSDragOperationNone;
1425 }
1426 }
1427
1428 buff = [NSString stringWithString: currentPath];
1429 while (1) {
1430 for (i = 0; i < count; i++) {
1431 if ([buff isEqualToString: [sourcePaths objectAtIndex: i]]) {
1432 return NSDragOperationNone;
1433 }
1434 }
1435 if ([buff isEqualToString: fixPath(@"/", 0)] == YES) {
1436 break;
1437 }
1438 buff = [buff stringByDeletingLastPathComponent];
1439 }
1440
1441 isDragTarget = YES;
1442
1443 sourceDragMask = [sender draggingSourceOperationMask];
1444
1445 if (sourceDragMask == NSDragOperationCopy) {
1446 return NSDragOperationCopy;
1447 } else if (sourceDragMask == NSDragOperationLink) {
1448 return NSDragOperationLink;
1449 } else {
1450 return NSDragOperationAll;
1451 }
1452 return NSDragOperationAll;
1453 }
1454
1455 isDragTarget = NO;
1456 return NSDragOperationNone;
1457 }
1458
1459 - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
1460 {
1461 NSDragOperation sourceDragMask;
1462
1463 if (isDragTarget == NO) {
1464 return NSDragOperationNone;
1465 }
1466
1467 sourceDragMask = [sender draggingSourceOperationMask];
1468
1469 if (sourceDragMask == NSDragOperationCopy) {
1470 return NSDragOperationCopy;
1471 } else if (sourceDragMask == NSDragOperationLink) {
1472 return NSDragOperationLink;
1473 } else {
1474 return NSDragOperationAll;
1475 }
1476
1477 return NSDragOperationNone;
1478 }
1479
1480 - (void)draggingExited:(id <NSDraggingInfo>)sender
1481 {
1482 isDragTarget = NO;
1483 }
1484
1485 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
1486 {
1487 return isDragTarget;
1488 }
1489
1490 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
1491 {
1492 return YES;
1493 }
1494
1495 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
1496 {
1497 NSPasteboard *pb;
1498 NSDragOperation sourceDragMask;
1499 NSArray *sourcePaths;
1500 NSString *operation, *source;
1501 NSMutableArray *files;
1502 NSMutableDictionary *opDict;
1503 NSString *trashPath;
1504 int i;
1505
1506 isDragTarget = NO;
1507
1508 sourceDragMask = [sender draggingSourceOperationMask];
1509 pb = [sender draggingPasteboard];
1510 sourcePaths = [pb propertyListForType: NSFilenamesPboardType];
1511 source = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent];
1512
1513 trashPath = [[GWLib workspaceApp] trashPath];
1514 if ([source isEqualToString: trashPath]) {
1515 operation = GWorkspaceRecycleOutOperation;
1516 } else {
1517 if (sourceDragMask == NSDragOperationCopy) {
1518 operation = NSWorkspaceCopyOperation;
1519 } else if (sourceDragMask == NSDragOperationLink) {
1520 operation = NSWorkspaceLinkOperation;
1521 } else {
1522 operation = NSWorkspaceMoveOperation;
1523 }
1524 }
1525
1526 files = [NSMutableArray arrayWithCapacity: 1];
1527 for(i = 0; i < [sourcePaths count]; i++) {
1528 [files addObject: [[sourcePaths objectAtIndex: i] lastPathComponent]];
1529 }
1530
1531 opDict = [NSMutableDictionary dictionaryWithCapacity: 4];
1532 [opDict setObject: operation forKey: @"operation"];
1533 [opDict setObject: source forKey: @"source"];
1534 [opDict setObject: currentPath forKey: @"destination"];
1535 [opDict setObject: files forKey: @"files"];
1536
1537 [[GWLib workspaceApp] performFileOperationWithDictionary: opDict];
1538 }
1539
1540 @end
1541
1542 //
1543 // SmallIcon Delegate Methods
1544 //
1545 @implementation SmallIconsPanel (SmallIconDelegateMethods)
1546
1547 - (void)unselectIconsDifferentFrom:(id)aicon
1548 {
1549 [self unselectOtherIcons: aicon];
1550 }
1551
1552 - (void)setShiftClickValue:(BOOL)value
1553 {
1554 [self setShiftClick: value];
1555 }
1556
1557 - (void)setTheCurrentSelection
1558 {
1559 [self setCurrentSelection];
1560 }
1561
1562 - (NSArray *)getTheCurrentSelection
1563 {
1564 return (*currSelection)(self, currSelectionSel);
1565 }
1566
1567 - (void)openTheCurrentSelection:(id)paths newViewer:(BOOL)newv
1568 {
1569 [self openCurrentSelection: paths newViewer: newv];
1570 }
1571
1572 - (id)menuForRightMouseEvent:(NSEvent *)theEvent
1573 {
1574 return [self menuForEvent: theEvent];
1575 }
1576
1577 @end

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