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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Wed Aug 27 10:13:53 2003 UTC (20 years, 8 months ago) by esersale
Branch: MAIN
Changes since 1.1: +19 -18 lines
*** empty log message ***

1 /* SmallIcon.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 "SmallIcon.h"
40 #include "SmallIconLabel.h"
41 #include "GNUstep.h"
42
43 #define CHECK_LOCK if (locked) return
44 #define CHECK_LOCK_RET(x) if (locked) return x
45
46 @implementation SmallIcon
47
48 - (void)dealloc
49 {
50 RELEASE (path);
51 RELEASE (name);
52 RELEASE (type);
53 RELEASE (namelabel);
54 RELEASE (icon);
55 RELEASE (highlight);
56 [super dealloc];
57 }
58
59 - (id)initForPath:(NSString *)apath delegate:(id)adelegate
60 {
61 self = [super init];
62 if (self) {
63 #ifdef GNUSTEP
64 Class gwclass = [[NSBundle mainBundle] principalClass];
65 #else
66 Class gwclass = [[NSBundle mainBundle] classNamed: @"GWorkspace"];
67 #endif
68 NSString *defApp = nil, *t = nil;
69
70 gworkspace = (id<GWProtocol>)[gwclass gworkspace];
71
72 ASSIGN (path, apath);
73 [self setDelegate: adelegate];
74
75 [self setFrame: NSMakeRect(0, 0, 32, 26)];
76 isSelect = NO;
77 locked = NO;
78
79 fm = [NSFileManager defaultManager];
80
81 ASSIGN (name, [path lastPathComponent]);
82
83 [[NSWorkspace sharedWorkspace] getInfoForFile: path
84 application: &defApp
85 type: &t];
86 ASSIGN (type, t);
87 isPakage = [gworkspace isPakageAtPath: path];
88
89 ASSIGN (icon, [gworkspace smallIconForFile: path]);
90 ASSIGN (highlight, [NSImage imageNamed: @"SmallCellHighlight.tiff"]);
91
92 namelabel = [[SmallIconLabel alloc] initForIcon: self];
93 [namelabel setFont: [NSFont systemFontOfSize: 12]];
94 [namelabel setBezeled: NO];
95 [namelabel setEditable: NO];
96 [namelabel setSelectable: NO];
97 [namelabel setAlignment: NSLeftTextAlignment];
98 [namelabel setBackgroundColor: [NSColor windowBackgroundColor]];
99 [namelabel setTextColor: [NSColor controlTextColor]];
100 [namelabel setStringValue: name];
101
102 [self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
103
104 position = NSMakePoint(0, 0);
105 center = NSMakePoint(0, 0);
106 gridindex = -1;
107 dragdelay = 0;
108 isDragTarget = NO;
109 onSelf = NO;
110 }
111
112 return self;
113 }
114
115 - (id)initForPath:(NSString *)apath
116 gridIndex:(int)index
117 delegate:(id)adelegate
118 {
119 [self initForPath: apath delegate: adelegate];
120 gridindex = index;
121 return self;
122 }
123
124 - (void)setPath:(NSString *)apath
125 {
126 NSString *defApp = nil, *t = nil;
127
128 ASSIGN (path, apath);
129 ASSIGN (icon, [gworkspace smallIconForFile: path]);
130
131 [[NSWorkspace sharedWorkspace] getInfoForFile: path
132 application: &defApp
133 type: &t];
134 ASSIGN (type, t);
135 isPakage = [gworkspace isPakageAtPath: path];
136 ASSIGN (name, [path lastPathComponent]);
137 [namelabel setStringValue: name];
138 [self setLabelFrame];
139 }
140
141 - (void)select
142 {
143 if (isSelect) {
144 return;
145 }
146 if ([fm fileExistsAtPath: path] == NO) {
147 return;
148 }
149 isSelect = YES;
150 [namelabel setBackgroundColor: [NSColor whiteColor]];
151 [self setNeedsDisplay: YES];
152 [(NSView *)delegate setNeedsDisplayInRect: [namelabel frame]];
153 [delegate unselectIconsDifferentFrom: self];
154 [delegate setTheCurrentSelection];
155 }
156
157 - (void)unselect
158 {
159 if (isSelect == NO) {
160 return;
161 }
162 isSelect = NO;
163 [self setNeedsDisplay: YES];
164 [namelabel setBackgroundColor: [NSColor windowBackgroundColor]];
165 [namelabel setEditable: NO];
166 [namelabel setSelectable: NO];
167 [(NSView *)delegate setNeedsDisplayInRect: [namelabel frame]];
168 [delegate setTheCurrentSelection];
169 }
170
171 - (void)clickOnLabel
172 {
173 CHECK_LOCK;
174 [self select];
175 [namelabel setSelectable: YES];
176 [namelabel setEditable: YES];
177 }
178
179 - (void)setLabelFrame
180 {
181 NSPoint p = [namelabel frame].origin;
182 labelWidth = [[NSFont systemFontOfSize: 12] widthOfString: name] + 8;
183 [namelabel setFrame: NSMakeRect(p.x, p.y, labelWidth, 14)];
184 [namelabel setNeedsDisplay: YES];
185 }
186
187 - (void)setPosition:(NSPoint)pos
188 {
189 position = NSMakePoint(pos.x, pos.y);
190 center = NSMakePoint(_frame.origin.x + (_frame.size.width / 2),
191 _frame.origin.y + (_frame.size.height / 2));
192 }
193
194 - (void)setPosition:(NSPoint)pos gridIndex:(int)index
195 {
196 [self setPosition: pos];
197 gridindex = index;
198 }
199
200 - (NSPoint)position
201 {
202 return position;
203 }
204
205 - (NSPoint)center
206 {
207 return center;
208 }
209
210 - (void)setGridIndex:(int)index
211 {
212 gridindex = index;
213 }
214
215 - (int)gridindex
216 {
217 return gridindex;
218 }
219
220 - (NSTextField *)label
221 {
222 return namelabel;
223 }
224
225 - (NSString *)type
226 {
227 return type;
228 }
229
230 - (NSString *)path
231 {
232 return path;
233 }
234
235 - (NSString *)myName
236 {
237 return name;
238 }
239
240 - (int)labelWidth
241 {
242 return labelWidth;
243 }
244
245 - (NSSize)iconShift
246 {
247 NSRect r = [self frame];
248 NSSize s = [icon size];
249
250 return NSMakeSize((r.size.width - s.width) / 2, (r.size.height - s.height) / 2);
251 }
252
253 - (BOOL)isSelect
254 {
255 return isSelect;
256 }
257
258 - (void)setLocked:(BOOL)value
259 {
260 if (locked == value) {
261 return;
262 }
263 locked = value;
264 [namelabel setTextColor: (locked ? [NSColor disabledControlTextColor]
265 : [NSColor controlTextColor])];
266 [namelabel setEditable: !locked];
267 [namelabel setSelectable: !locked];
268 [self setNeedsDisplay: YES];
269 [namelabel setNeedsDisplay: YES];
270 }
271
272 - (BOOL)isLocked
273 {
274 return locked;
275 }
276
277 - (id)delegate
278 {
279 return delegate;
280 }
281
282 - (void)setDelegate:(id)aDelegate
283 {
284 delegate = aDelegate;
285 }
286
287 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
288 {
289 return YES;
290 }
291
292 - (void)setFrame:(NSRect)frameRect
293 {
294 [super setFrame: frameRect];
295 [self setLabelFrame];
296 }
297
298 - (void)drawRect:(NSRect)rect
299 {
300 NSRect r = [self bounds];
301 NSSize s = [icon size];
302 NSPoint p = NSMakePoint((r.size.width - s.width) / 2, (r.size.height - s.height) / 2);
303
304 if(isSelect) {
305 [highlight compositeToPoint: NSZeroPoint operation: NSCompositeSourceOver];
306 }
307
308 if (icon != nil) {
309 if (locked) {
310 [icon dissolveToPoint: p fraction: 0.3];
311 } else {
312 [icon compositeToPoint: p operation: NSCompositeSourceOver];
313 }
314 }
315 }
316
317 - (void)mouseUp:(NSEvent *)theEvent
318 {
319 int count = [theEvent clickCount];
320
321 CHECK_LOCK;
322
323 if(count > 1) {
324 unsigned int modifier = [theEvent modifierFlags];
325
326 if ([fm fileExistsAtPath: path] == NO) {
327 return;
328 }
329
330 [delegate openTheCurrentSelection: [NSArray arrayWithObject: path]
331 newViewer: (modifier == NSControlKeyMask)];
332 }
333 }
334
335 - (void)mouseDown:(NSEvent *)theEvent
336 {
337 int count = [theEvent clickCount];
338
339 CHECK_LOCK;
340
341 if(count == 1) {
342 if([theEvent modifierFlags] == 2) {
343 [delegate setShiftClickValue: YES];
344 if (isSelect == YES) {
345 [self unselect];
346 return;
347 } else {
348 [self select];
349 }
350 } else {
351 [delegate setShiftClickValue: NO];
352 if (isSelect == NO) {
353 [self select];
354 }
355 }
356 }
357 }
358
359 - (void)mouseDragged:(NSEvent *)theEvent
360 {
361 if ([fm fileExistsAtPath: path] == NO) {
362 return;
363 }
364
365 if(dragdelay < 5) {
366 dragdelay++;
367 return;
368 }
369
370 [self startExternalDragOnEvent: theEvent];
371 }
372
373 - (NSMenu *)menuForEvent:(NSEvent *)theEvent
374 {
375 if (([theEvent type] == NSRightMouseDown) && isSelect) {
376 return [delegate menuForRightMouseEvent: theEvent];
377 }
378
379 return [super menuForEvent: theEvent];
380 }
381
382 //
383 // SmallIconLabel delegate methods
384 //
385 - (void)controlTextDidChange:(NSNotification *)aNotification
386 {
387 NSDictionary *info = [aNotification userInfo];
388 NSText *text = [info objectForKey: @"NSFieldEditor"];
389 NSString *current = [text string];
390 NSPoint p = [namelabel frame].origin;
391
392 labelWidth = [[NSFont systemFontOfSize: 12] widthOfString: current] + 8;
393 [namelabel setFrame: NSMakeRect(p.x, p.y, labelWidth, 14)];
394 }
395
396 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
397 {
398 NSDictionary *info;
399 NSString *basePath, *newpath, *newname;
400 NSString *title, *msg1, *msg2;
401 NSMutableDictionary *notifObj;
402 NSArray *dirContents;
403 NSCharacterSet *notAllowSet;
404 NSRange range;
405 BOOL samename;
406 // NSEvent *e;
407 int i;
408
409 #define CLEAREDITING \
410 [namelabel setStringValue: name]; \
411 [self setLabelFrame]; \
412 return
413
414 info = [aNotification userInfo];
415 newname = [[info objectForKey: @"NSFieldEditor"] string];
416
417 basePath = [path stringByDeletingLastPathComponent]; // QUA
418
419 if ([fm fileExistsAtPath: path] == NO) {
420 notifObj = [NSMutableDictionary dictionaryWithCapacity: 1];
421 [notifObj setObject: NSWorkspaceDestroyOperation forKey: @"operation"];
422 [notifObj setObject: basePath forKey: @"source"];
423 [notifObj setObject: basePath forKey: @"destination"];
424 [notifObj setObject: [NSArray arrayWithObjects: path, nil] forKey: @"files"];
425
426 [[NSNotificationCenter defaultCenter]
427 postNotificationName: GWFileSystemWillChangeNotification
428 object: notifObj];
429
430 RETAIN (self);
431
432 [[NSNotificationCenter defaultCenter]
433 postNotificationName: GWFileSystemDidChangeNotification
434 object: notifObj];
435
436 AUTORELEASE (self);
437
438 return;
439 }
440
441 title = NSLocalizedString(@"Error", @"");
442 msg1 = NSLocalizedString(@"You have not write permission\nfor ", @"");
443 msg2 = NSLocalizedString(@"Continue", @"");
444 if ([fm isWritableFileAtPath: path] == NO) {
445 NSRunAlertPanel(title, [NSString stringWithFormat: @"%@\"%@\"!\n", msg1, path], msg2, nil, nil);
446 CLEAREDITING;
447 } else if ([fm isWritableFileAtPath: basePath] == NO) {
448 NSRunAlertPanel(title, [NSString stringWithFormat: @"%@\"%@\"!\n", msg1, basePath], msg2, nil, nil);
449 CLEAREDITING;
450 }
451
452 notAllowSet = [NSCharacterSet characterSetWithCharactersInString: @"/\\*$|~\'\"`^!?"];
453 range = [newname rangeOfCharacterFromSet: notAllowSet];
454
455 if (range.length > 0) {
456 msg1 = NSLocalizedString(@"Invalid char in name", @"");
457 NSRunAlertPanel(title, msg1, msg2, nil, nil);
458 CLEAREDITING;
459 }
460
461 dirContents = [fm directoryContentsAtPath: basePath];
462
463 samename = NO;
464 for (i = 0; i < [dirContents count]; i++) {
465 if ([newname isEqualToString: [dirContents objectAtIndex:i]]) {
466 if ([newname isEqualToString: name]) {
467 CLEAREDITING;
468 } else {
469 samename = YES;
470 break;
471 }
472 }
473 }
474 if (samename == YES) {
475 NSString *msg3 = NSLocalizedString(@"The name ", @"");
476 msg1 = NSLocalizedString(@" is already in use!", @"");
477 NSRunAlertPanel(title, [NSString stringWithFormat: @"%@'%@'%@!", msg3, newname, msg1], msg2, nil, nil);
478 CLEAREDITING;
479 }
480
481 // e = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSKeyUpMask];
482 // [[self window] flushWindow];
483
484 newpath = [basePath stringByAppendingPathComponent: newname];
485
486 notifObj = [NSMutableDictionary dictionaryWithCapacity: 1];
487 [notifObj setObject: GWorkspaceRenameOperation forKey: @"operation"];
488 [notifObj setObject: path forKey: @"source"];
489 [notifObj setObject: newpath forKey: @"destination"];
490 [notifObj setObject: [NSArray arrayWithObjects: @"", nil] forKey: @"files"];
491
492 [[NSNotificationCenter defaultCenter]
493 postNotificationName: GWFileSystemWillChangeNotification
494 object: notifObj];
495
496 [fm movePath: path toPath: newpath handler: self];
497
498 RETAIN (self);
499
500 [[NSNotificationCenter defaultCenter]
501 postNotificationName: GWFileSystemDidChangeNotification
502 object: notifObj];
503
504 AUTORELEASE (self);
505 }
506
507 - (BOOL)fileManager:(NSFileManager *)manager
508 shouldProceedAfterError:(NSDictionary *)errorDict
509 {
510 NSString *title = NSLocalizedString(@"Error", @"");
511 NSString *msg1 = NSLocalizedString(@"Cannot rename ", @"");
512 NSString *msg2 = NSLocalizedString(@"Continue", @"");
513
514 NSRunAlertPanel(title, [NSString stringWithFormat: @"%@'%@'!", msg1, name], msg2, nil, nil);
515 return NO;
516 }
517
518 - (void)fileManager:(NSFileManager *)manager willProcessPath:(NSString *)path
519 {
520 }
521
522 @end
523
524 @implementation SmallIcon (DraggingSource)
525
526 - (void)startExternalDragOnEvent:(NSEvent *)event
527 {
528 NSEvent *nextEvent;
529 NSPoint dragPoint;
530 NSPasteboard *pb;
531 NSArray *selection;
532 NSImage *dragIcon;
533
534 nextEvent = [[self window] nextEventMatchingMask:
535 NSLeftMouseUpMask | NSLeftMouseDraggedMask];
536
537 if([nextEvent type] != NSLeftMouseDragged) {
538 return;
539 }
540
541 dragPoint = [nextEvent locationInWindow];
542 dragPoint = [self convertPoint: dragPoint fromView: nil];
543
544 pb = [NSPasteboard pasteboardWithName: NSDragPboard];
545 [self declareAndSetShapeOnPasteboard: pb];
546
547 selection = [delegate getTheCurrentSelection];
548
549 if ([selection count] > 1) {
550 dragIcon = [NSImage imageNamed: @"MultipleSelection.tiff"];
551 } else {
552 dragIcon = [gworkspace iconForFile: path ofType: type];
553 }
554
555 [self dragImage: dragIcon
556 at: dragPoint
557 offset: NSZeroSize
558 event: event
559 pasteboard: pb
560 source: self
561 slideBack: [gworkspace animateSlideBack]];
562 }
563
564 - (void)draggedImage:(NSImage *)anImage
565 endedAt:(NSPoint)aPoint
566 deposited:(BOOL)flag
567 {
568 dragdelay = 0;
569 onSelf = NO;
570 }
571
572 - (void)declareAndSetShapeOnPasteboard:(NSPasteboard *)pb
573 {
574 NSArray *dndtypes;
575 NSArray *selection;
576
577 dndtypes = [NSArray arrayWithObject: NSFilenamesPboardType];
578 [pb declareTypes: dndtypes owner: nil];
579 selection = [delegate getTheCurrentSelection];
580
581 if ([pb setPropertyList: selection forType: NSFilenamesPboardType] == NO) {
582 return;
583 }
584 }
585
586 - (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
587 {
588 return NSDragOperationAll;
589 }
590
591 @end
592
593 @implementation SmallIcon (DraggingDestination)
594
595 - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
596 {
597 NSPasteboard *pb;
598 NSDragOperation sourceDragMask;
599 NSArray *sourcePaths;
600 NSString *fromPath;
601 NSString *buff;
602 NSString *iconPath;
603 int i, count;
604
605 CHECK_LOCK_RET (NSDragOperationNone);
606
607 pb = [sender draggingPasteboard];
608 if([[pb types] indexOfObject: NSFilenamesPboardType] != NSNotFound) {
609 sourcePaths = [pb propertyListForType: NSFilenamesPboardType];
610 count = [sourcePaths count];
611
612 if ((count == 1) && ([path isEqualToString: [sourcePaths objectAtIndex: 0]])) {
613 onSelf = YES;
614 isDragTarget = YES;
615 return NSDragOperationAll;
616 }
617
618 if ((([type isEqualToString: NSDirectoryFileType] == NO)
619 && ([type isEqualToString: NSFilesystemFileType] == NO)) || isPakage) {
620 return NSDragOperationNone;
621 }
622
623 fromPath = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent];
624
625 if (count == 0) {
626 return NSDragOperationNone;
627 }
628
629 if ([fm isWritableFileAtPath: path] == NO) {
630 return NSDragOperationNone;
631 }
632
633 if ([path isEqualToString: fromPath]) {
634 return NSDragOperationNone;
635 }
636
637 for (i = 0; i < count; i++) {
638 if ([path isEqualToString: [sourcePaths objectAtIndex: i]]) {
639 return NSDragOperationNone;
640 }
641 }
642
643 buff = [NSString stringWithString: path];
644 while (1) {
645 for (i = 0; i < count; i++) {
646 if ([buff isEqualToString: [sourcePaths objectAtIndex: i]]) {
647 return NSDragOperationNone;
648 }
649 }
650 if ([buff isEqualToString: fixPath(@"/", 0)] == YES) {
651 break;
652 }
653 buff = [buff stringByDeletingLastPathComponent];
654 }
655
656 isDragTarget = YES;
657
658 iconPath = [path stringByAppendingPathComponent: @".opendir.tiff"];
659
660 if ([fm isReadableFileAtPath: iconPath]) {
661 NSImage *img = [[NSImage alloc] initWithContentsOfFile: iconPath];
662
663 if (img) {
664 NSSize size = [img size];
665 [img setScalesWhenResized: YES];
666 [img setSize: NSMakeSize(size.width / 2, size.height / 2)];
667 ASSIGN (icon, img);
668 RELEASE (img);
669 } else {
670 ASSIGN (icon, [NSImage imageNamed: @"FileIcon_Directory_Open_Small.tiff"]);
671 }
672 } else {
673 ASSIGN (icon, [NSImage imageNamed: @"FileIcon_Directory_Open_Small.tiff"]);
674 }
675
676 [self setNeedsDisplay: YES];
677
678 sourceDragMask = [sender draggingSourceOperationMask];
679
680 if (sourceDragMask == NSDragOperationCopy) {
681 return NSDragOperationCopy;
682 } else if (sourceDragMask == NSDragOperationLink) {
683 return NSDragOperationLink;
684 } else {
685 return NSDragOperationAll;
686 }
687 }
688
689 return NSDragOperationNone;
690 }
691
692 - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
693 {
694 NSDragOperation sourceDragMask;
695
696 CHECK_LOCK_RET (NSDragOperationNone);
697
698 if (isPakage) {
699 return NSDragOperationNone;
700 }
701 if (isDragTarget == NO) {
702 return NSDragOperationNone;
703 }
704
705 sourceDragMask = [sender draggingSourceOperationMask];
706
707 if (sourceDragMask == NSDragOperationCopy) {
708 return NSDragOperationCopy;
709 } else if (sourceDragMask == NSDragOperationLink) {
710 return NSDragOperationLink;
711 } else {
712 return NSDragOperationAll;
713 }
714
715 return NSDragOperationNone;
716 }
717
718 - (void)draggingExited:(id <NSDraggingInfo>)sender
719 {
720 if(isDragTarget == YES) {
721 isDragTarget = NO;
722 if (onSelf == NO) {
723 ASSIGN (icon, [gworkspace smallIconForFile: path]);
724 [self setNeedsDisplay: YES];
725 }
726 onSelf = NO;
727 }
728 }
729
730 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
731 {
732 CHECK_LOCK_RET (NO);
733 return isDragTarget;
734 }
735
736 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
737 {
738 CHECK_LOCK_RET (NO);
739 return YES;
740 }
741
742 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
743 {
744 NSPasteboard *pb;
745 NSDragOperation sourceDragMask;
746 NSArray *sourcePaths;
747 NSString *operation, *source;
748 NSMutableArray *files;
749 NSMutableDictionary *opDict;
750 NSString *trashPath;
751 int i;
752
753 CHECK_LOCK;
754
755 isDragTarget = NO;
756
757 if (onSelf == YES) {
758 onSelf = NO;
759 return;
760 }
761
762 ASSIGN (icon, [gworkspace smallIconForFile: path]);
763 [self setNeedsDisplay: YES];
764
765 sourceDragMask = [sender draggingSourceOperationMask];
766 pb = [sender draggingPasteboard];
767 sourcePaths = [pb propertyListForType: NSFilenamesPboardType];
768 source = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent];
769
770 trashPath = [gworkspace trashPath];
771
772 if ([source isEqualToString: trashPath]) {
773 operation = GWorkspaceRecycleOutOperation;
774 } else {
775 if (sourceDragMask == NSDragOperationCopy) {
776 operation = NSWorkspaceCopyOperation;
777 } else if (sourceDragMask == NSDragOperationLink) {
778 operation = NSWorkspaceLinkOperation;
779 } else {
780 operation = NSWorkspaceMoveOperation;
781 }
782 }
783
784 files = [NSMutableArray arrayWithCapacity: 1];
785 for(i = 0; i < [sourcePaths count]; i++) {
786 [files addObject: [[sourcePaths objectAtIndex: i] lastPathComponent]];
787 }
788
789 opDict = [NSMutableDictionary dictionaryWithCapacity: 4];
790 [opDict setObject: operation forKey: @"operation"];
791 [opDict setObject: source forKey: @"source"];
792 [opDict setObject: path forKey: @"destination"];
793 [opDict setObject: files forKey: @"files"];
794
795 [gworkspace performFileOperationWithDictionary: opDict];
796 }
797
798 @end

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