/[gnustep]/gnustep/usr-apps/gworkspace/GWorkspace/Shelf/Shelf.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/GWorkspace/Shelf/Shelf.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Tue Sep 30 15:38:05 2003 UTC (20 years, 6 months ago) by esersale
Branch: MAIN
Changes since 1.2: +4 -2 lines
*** empty log message ***

1 /* Shelf.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 "GWFunctions.h"
31 #include "GWNotifications.h"
32 #else
33 #include <GWorkspace/GWLib.h>
34 #include <GWorkspace/GWFunctions.h>
35 #include <GWorkspace/GWNotifications.h>
36 #endif
37 #include "Shelf.h"
38 #include "IconViewsIcon.h"
39 #include "GWorkspace.h"
40 #include "GNUstep.h"
41
42 @interface IconViewsIcon (ShelfSorting)
43 - (NSComparisonResult)iconCompare:(IconViewsIcon *)other;
44 @end
45
46 @implementation IconViewsIcon (ShelfSorting)
47
48 - (NSComparisonResult)iconCompare:(IconViewsIcon *)other
49 {
50 if ([other gridindex] > [self gridindex]) {
51 return NSOrderedAscending;
52 } else {
53 return NSOrderedDescending;
54 }
55
56 return NSOrderedSame;
57 }
58
59 @end
60
61 @implementation Shelf
62
63 - (void) dealloc
64 {
65 [[NSNotificationCenter defaultCenter] removeObserver: self];
66 [self unsetWatchers];
67 if (gpoints != NULL) {
68 NSZoneFree (NSDefaultMallocZone(), gpoints);
69 }
70 RELEASE (icons);
71 TEST_RELEASE (viewerPath);
72 RELEASE (watchedPaths);
73 TEST_RELEASE (dragImage);
74 [super dealloc];
75 }
76
77 - (id)initWithIconsDicts:(NSArray *)iconsDicts rootPath:(NSString *)rpath
78 {
79 self = [super init];
80 if (self) {
81 int i, j;
82
83 fm = [NSFileManager defaultManager];
84 gw = [GWorkspace gworkspace];
85
86 makePosSel = @selector(makePositions);
87 makePos = (IMP)[self methodForSelector: makePosSel];
88
89 gridPointSel = @selector(gridPointNearestToPoint:);
90 gridPoint = (GridPointIMP)[self methodForSelector: gridPointSel];
91
92 cellsWidth = [gw shelfCellsWidth];
93
94 if (rpath != nil) {
95 ASSIGN (viewerPath, rpath);
96 } else {
97 viewerPath = nil;
98 }
99
100 watchedPaths = [[NSMutableArray alloc] initWithCapacity: 1];
101
102 icons = [[NSMutableArray alloc] initWithCapacity: 1];
103
104 for (i = 0; i < [iconsDicts count]; i++) {
105 NSDictionary *iconDict = [iconsDicts objectAtIndex: i];
106 NSArray *iconpaths = [iconDict objectForKey: @"paths"];
107 int index = [[iconDict objectForKey: @"index"] intValue];
108 BOOL canadd = YES;
109
110 for (j = 0; j < [iconpaths count]; j++) {
111 NSString *p = [iconpaths objectAtIndex: j];
112 if ([fm fileExistsAtPath: p] == YES) {
113
114 if (viewerPath != nil) {
115 if ((subPathOfPath(viewerPath, p) == NO)
116 && ([viewerPath isEqualToString: p] == NO)) {
117 canadd = NO;
118 break;
119 }
120 }
121
122 } else {
123 canadd = NO;
124 break;
125 }
126 }
127
128 if ((canadd == YES) && (index != -1)) {
129 [self addIconWithPaths: iconpaths withGridIndex: index];
130 }
131 }
132
133 gpoints = NULL;
134 pcount = 0;
135 isDragTarget = NO;
136 dragImage = nil;
137 isShiftClick = NO;
138
139 [self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
140
141 [[NSNotificationCenter defaultCenter] addObserver: self
142 selector: @selector(cellsWidthChanged:)
143 name: GWShelfCellsWidthChangedNotification
144 object: nil];
145
146 [[NSNotificationCenter defaultCenter] addObserver: self
147 selector: @selector(fileSystemWillChange:)
148 name: GWFileSystemWillChangeNotification
149 object: nil];
150
151 [[NSNotificationCenter defaultCenter] addObserver: self
152 selector: @selector(fileSystemDidChange:)
153 name: GWFileSystemDidChangeNotification
154 object: nil];
155
156 [[NSNotificationCenter defaultCenter] addObserver: self
157 selector: @selector(watcherNotification:)
158 name: GWFileWatcherFileDidChangeNotification
159 object: nil];
160 }
161 return self;
162 }
163
164 - (NSArray *)iconsDicts
165 {
166 NSMutableArray *iconsdicts = [NSMutableArray arrayWithCapacity: 1];
167 int i;
168
169 for (i = 0; i < [icons count]; i++) {
170 NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity: 1];
171 IconViewsIcon *icon = [icons objectAtIndex: i];
172 int index;
173
174 [dict setObject: [icon paths] forKey: @"paths"];
175 index = [icon gridindex];
176 [dict setObject: [NSString stringWithFormat: @"%i", index] forKey: @"index"];
177
178 [iconsdicts addObject: dict];
179 }
180
181 return iconsdicts;
182 }
183
184 - (void)addIconWithPaths:(NSArray *)iconpaths
185 withGridIndex:(int)index
186 {
187 ShelfIcon *icon = [[ShelfIcon alloc] initForPaths: iconpaths
188 gridIndex: index inContainer: self];
189 NSString *watched = [[iconpaths objectAtIndex: 0] stringByDeletingLastPathComponent];
190
191 if (gpoints != NULL) {
192 if (index < pcount) {
193 gpoints[index].used = 1;
194 }
195 }
196
197 [icons addObject: icon];
198 [self addSubview: icon];
199 [self addSubview: [icon myLabel]];
200 RELEASE (icon);
201 [self sortIcons];
202 [self resizeWithOldSuperviewSize: [self frame].size];
203
204 if ([watchedPaths containsObject: watched] == NO) {
205 [watchedPaths addObject: watched];
206 [self setWatcherForPath: watched];
207 }
208 }
209
210 - (void)sortIcons
211 {
212 NSArray *sortedIcons = [icons sortedArrayUsingSelector: @selector(iconCompare:)];
213 [icons removeAllObjects];
214 [icons addObjectsFromArray: sortedIcons];
215 }
216
217 - (NSArray *)icons
218 {
219 return icons;
220 }
221
222 - (void)updateIcons
223 {
224 int i;
225
226 for (i = 0; i < [icons count]; i++) {
227 [[icons objectAtIndex: i] renewIcon];
228 }
229 }
230
231 - (void)cellsWidthChanged:(NSNotification *)notification
232 {
233 int i;
234
235 cellsWidth = [gw shelfCellsWidth];
236 for (i = 0; i < [icons count]; i++) {
237 [[icons objectAtIndex: i] setLabelWidth];
238 }
239 [self resizeWithOldSuperviewSize: [self frame].size];
240 }
241
242 - (void)fileSystemWillChange:(NSNotification *)notification
243 {
244 NSDictionary *dict = (NSDictionary *)[notification object];
245 NSString *operation = [dict objectForKey: @"operation"];
246 NSString *source = [dict objectForKey: @"source"];
247 NSArray *files = [dict objectForKey: @"files"];
248
249 if (operation == NSWorkspaceMoveOperation
250 || operation == NSWorkspaceDestroyOperation
251 || operation == GWorkspaceRenameOperation
252 || operation == NSWorkspaceRecycleOperation
253 || operation == GWorkspaceRecycleOutOperation
254 || operation == GWorkspaceEmptyRecyclerOperation) {
255
256 NSMutableArray *paths = [NSMutableArray arrayWithCapacity: 1];
257 NSArray *iconpaths;
258 int i, j, m;
259
260 for (i = 0; i < [files count]; i++) {
261 NSString *s = [source stringByAppendingPathComponent: [files objectAtIndex: i]];
262 [paths addObject: s];
263 }
264
265 for (i = 0; i < [icons count]; i++) {
266 IconViewsIcon *icon = [icons objectAtIndex: i];
267
268 iconpaths = [icon paths];
269
270 for (j = 0; j < [iconpaths count]; j++) {
271 NSString *op = [iconpaths objectAtIndex: j];
272
273 for (m = 0; m < [paths count]; m++) {
274 NSString *fp = [paths objectAtIndex: m];
275
276 if ([op hasPrefix: fp]) {
277 [icon setLocked: YES];
278 break;
279 }
280 }
281 }
282 }
283 }
284 }
285
286 - (void)fileSystemDidChange:(NSNotification *)notification
287 {
288 NSDictionary *dict;
289 NSString *operation, *source, *destination;
290 NSArray *files;
291 NSMutableArray *paths;
292 IconViewsIcon *icon;
293 NSArray *iconpaths;
294 int count;
295 int i, j, m;
296
297 dict = (NSDictionary *)[notification object];
298 operation = [dict objectForKey: @"operation"];
299 source = [dict objectForKey: @"source"];
300 destination = [dict objectForKey: @"destination"];
301 files = [dict objectForKey: @"files"];
302
303 if (operation == GWorkspaceRenameOperation) {
304 for (i = 0; i < [icons count]; i++) {
305 icon = [icons objectAtIndex: i];
306 if ([icon isSinglePath] == YES) {
307 if ([[[icon paths] objectAtIndex: 0] isEqualToString: source]) {
308 [icon setPaths: [NSArray arrayWithObject: destination]];
309 [icon setNeedsDisplay: YES];
310 [self resizeWithOldSuperviewSize: [self frame].size];
311 break;
312 }
313 }
314 }
315 }
316
317 if (operation == GWorkspaceRenameOperation) {
318 files = [NSArray arrayWithObject: [source lastPathComponent]];
319 source = [source stringByDeletingLastPathComponent];
320 }
321
322 if (operation == NSWorkspaceMoveOperation
323 || operation == NSWorkspaceDestroyOperation
324 || operation == GWorkspaceRenameOperation
325 || operation == NSWorkspaceRecycleOperation
326 || operation == GWorkspaceRecycleOutOperation
327 || operation == GWorkspaceEmptyRecyclerOperation) {
328
329 paths = [NSMutableArray arrayWithCapacity: 1];
330 for (i = 0; i < [files count]; i++) {
331 NSString *s = [source stringByAppendingPathComponent: [files objectAtIndex: i]];
332 [paths addObject: s];
333 }
334
335 count = [icons count];
336 for (i = 0; i < count; i++) {
337 BOOL deleted = NO;
338 icon = [icons objectAtIndex: i];
339 iconpaths = [icon paths];
340
341 for (j = 0; j < [iconpaths count]; j++) {
342 NSString *op = [iconpaths objectAtIndex: j];
343
344 for (m = 0; m < [paths count]; m++) {
345 NSString *fp = [paths objectAtIndex: m];
346
347 if ([op hasPrefix: fp]) {
348 [self removeIcon: icon];
349 count--;
350 i--;
351 deleted = YES;
352 break;
353 }
354
355 if (deleted) {
356 break;
357 }
358
359 }
360
361 if (deleted) {
362 break;
363 }
364 }
365 }
366 }
367 }
368
369 - (void)watcherNotification:(NSNotification *)notification
370 {
371 NSDictionary *notifdict = (NSDictionary *)[notification object];
372 NSString *path = [notifdict objectForKey: @"path"];
373 NSString *event = [notifdict objectForKey: @"event"];
374 BOOL contained = NO;
375 int i;
376
377 if (event == GWFileCreatedInWatchedDirectory) {
378 return;
379 }
380
381 for (i = 0; i < [watchedPaths count]; i++) {
382 NSString *wpath = [watchedPaths objectAtIndex: i];
383 if (([wpath isEqualToString: path]) || (subPathOfPath(path, wpath))) {
384 contained = YES;
385 break;
386 }
387 }
388
389 if (contained) {
390 id icon;
391 NSArray *ipaths;
392 NSString *ipath;
393 int count = [icons count];
394
395 if (event == GWWatchedDirectoryDeleted) {
396 for (i = 0; i < count; i++) {
397 icon = [icons objectAtIndex: i];
398 ipaths = [icon paths];
399 ipath = [ipaths objectAtIndex: 0];
400
401 if (subPathOfPath(path, ipath)) {
402 [self removeIcon: icon];
403 count--;
404 i--;
405 }
406 }
407 return;
408 }
409
410 if (event == GWFileDeletedInWatchedDirectory) {
411 NSArray *files = [notifdict objectForKey: @"files"];
412
413 for (i = 0; i < count; i++) {
414 int j;
415
416 icon = [icons objectAtIndex: i];
417 ipaths = [icon paths];
418
419 if ([ipaths count] == 1) {
420 ipath = [ipaths objectAtIndex: 0];
421
422 for (j = 0; j < [files count]; j++) {
423 NSString *fname = [files objectAtIndex: j];
424 NSString *fullPath = [path stringByAppendingPathComponent: fname];
425
426 if ((subPathOfPath(fullPath, ipath))
427 || ([ipath isEqualToString: fullPath])) {
428 [self removeIcon: icon];
429 count--;
430 i--;
431 break;
432 }
433 }
434
435 } else {
436
437 for (j = 0; j < [files count]; j++) {
438 NSString *fname = [files objectAtIndex: j];
439 NSString *fullPath = [path stringByAppendingPathComponent: fname];
440 BOOL deleted = NO;
441 int m;
442
443 if (deleted) {
444 break;
445 }
446
447 ipath = [ipaths objectAtIndex: 0];
448 if (subPathOfPath(fullPath, ipath)) {
449 [self removeIcon: icon];
450 count--;
451 i--;
452 break;
453 }
454
455 for (m = 0; m < [ipaths count]; m++) {
456 ipath = [ipaths objectAtIndex: m];
457
458 if ([ipath isEqualToString: fullPath]) {
459 NSMutableArray *newpaths;
460
461 if ([ipaths count] == 1) {
462 [self removeIcon: icon];
463 count--;
464 i--;
465 deleted = YES;
466 break;
467 }
468
469 newpaths = [ipaths mutableCopy];
470 [newpaths removeObject: ipath];
471 [icon setPaths: newpaths];
472 ipaths = [icon paths];
473 RELEASE (newpaths);
474 }
475 }
476
477 }
478 }
479 }
480 }
481 }
482 }
483
484 - (void)setWatchers
485 {
486 int i;
487
488 for (i = 0; i < [watchedPaths count]; i++) {
489 [self setWatcherForPath: [watchedPaths objectAtIndex: i]];
490 }
491 }
492
493 - (void)setWatcherForPath:(NSString *)path
494 {
495 [GWLib addWatcherForPath: path];
496 }
497
498 - (void)unsetWatchers
499 {
500 int i;
501
502 for (i = 0; i < [watchedPaths count]; i++) {
503 [self unsetWatcherForPath: [watchedPaths objectAtIndex: i]];
504 }
505 }
506
507 - (void)unsetWatcherForPath:(NSString *)path
508 {
509 [GWLib removeWatcherForPath: path];
510 }
511
512 - (void)makePositions
513 {
514 float wdt, hgt, x, y;
515 int posx, posy;
516 int i;
517
518 wdt = [self frame].size.width;
519 hgt = [self frame].size.height;
520
521 pcount = (int)((int)((wdt - 16) / cellsWidth) * (int)(MAXSHELFHEIGHT / 75));
522
523 if (gpoints != NULL) {
524 NSZoneFree (NSDefaultMallocZone(), gpoints);
525 }
526 gpoints = NSZoneMalloc (NSDefaultMallocZone(), sizeof(gridpoint) * pcount);
527
528 x = 16;
529 y = hgt - 55;
530 posx = 0;
531 posy = 0;
532
533 for (i = 0; i < pcount; i++) {
534 if (i > 0) {
535 x += cellsWidth;
536 }
537 if (x >= (wdt - cellsWidth)) {
538 x = 16;
539 y -= 75;
540 posx = 0;
541 posy++;
542 }
543
544 gpoints[i].x = x;
545 gpoints[i].y = y;
546 gpoints[i].index = i;
547 gpoints[i].used = 0;
548
549 posx++;
550 }
551 }
552
553 - (gridpoint *)gridPointNearestToPoint:(NSPoint)p
554 {
555 float maxx = [self frame].size.width;
556 float maxy = [self frame].size.height;
557 float px = p.x;
558 float py = p.y;
559 float minx = maxx;
560 float miny = maxy;
561 int pos = -1;
562 int i;
563
564 for (i = 0; i < pcount; i++) {
565 if (gpoints[i].y > 0) {
566 float dx = max(px, gpoints[i].x) - min(px, gpoints[i].x);
567 float dy = max(py, gpoints[i].y) - min(py, gpoints[i].y);
568
569 if ((dx <= minx) && (dy <= miny)) {
570 minx = dx;
571 miny = dy;
572 pos = i;
573 }
574 }
575 }
576
577 return &gpoints[pos];
578 }
579
580 - (BOOL)isFreePosition:(NSPoint)pos
581 {
582 int i;
583
584 for (i = 0; i < [icons count]; i++) {
585 NSPoint p = [[icons objectAtIndex: i] position];
586 if (NSEqualPoints(pos, p)) {
587 return NO;
588 }
589 }
590
591 return YES;
592 }
593
594 - (void)setFrame:(NSRect)frameRect
595 {
596 [super setFrame: frameRect];
597 makePos(self, makePosSel);
598 }
599
600 - (void)resizeWithOldSuperviewSize:(NSSize)oldFrameSize
601 {
602 int i;
603
604 if (gpoints == NULL) {
605 [super resizeWithOldSuperviewSize: oldFrameSize];
606 return;
607 }
608
609 for (i = 0; i < pcount; i++) {
610 gpoints[i].used = 0;
611 }
612
613 for (i = 0; i < [icons count]; i++) {
614 id icon = [icons objectAtIndex: i];
615 int index = [icon gridindex];
616 gridpoint gpoint = gpoints[index];
617 NSPoint p = NSMakePoint(gpoint.x, gpoint.y);
618 NSRect r = NSMakeRect(p.x, p.y, 64, 52);
619
620 [icon setPosition: p];
621 [icon setFrame: r];
622 gpoints[index].used = 1;
623 [self setLabelRectOfIcon: icon];
624 }
625
626 [self sortIcons];
627 [self setNeedsDisplay: YES];
628 }
629
630 - (void)mouseDown:(NSEvent *)theEvent
631 {
632 [self unselectOtherIcons: nil];
633 }
634
635 - (void)drawRect:(NSRect)rect
636 {
637 [super drawRect: rect];
638
639 if (dragImage != nil) {
640 gridpoint *gpoint = [self gridPointNearestToPoint: dragPoint];
641
642 if (gpoint->used == 0) {
643 NSPoint p = NSMakePoint(dragPoint.x + 8, dragPoint.y);
644 [dragImage dissolveToPoint: p fraction: 0.3];
645 }
646 }
647 }
648
649 //
650 // IconViewsProtocol
651 //
652 - (void)addIconWithPaths:(NSArray *)iconpaths
653 {
654 }
655
656 - (void)removeIcon:(id)anIcon
657 {
658 IconViewsIcon *icon = (IconViewsIcon *)anIcon;
659 int index = [icon gridindex];
660 NSString *watched = [[[icon paths] objectAtIndex: 0] stringByDeletingLastPathComponent];
661
662 if ([watchedPaths containsObject: watched]) {
663 [watchedPaths removeObject: watched];
664 [self unsetWatcherForPath: watched];
665 }
666
667 gpoints[index].used = 0;
668 [[icon myLabel] removeFromSuperview];
669 [icon removeFromSuperview];
670 [icons removeObject: icon];
671 [self resizeWithOldSuperviewSize: [self frame].size];
672 }
673
674 - (void)setLabelRectOfIcon:(id)anIcon
675 {
676 IconViewsIcon *icon;
677 NSTextField *label;
678 float iconwidth, labwidth, labxpos;
679 NSRect labelRect;
680
681 icon = (IconViewsIcon *)anIcon;
682 label = [icon myLabel];
683
684 iconwidth = [icon frame].size.width;
685 labwidth = [label frame].size.width;
686
687 if(iconwidth > labwidth) {
688 labxpos = [icon frame].origin.x + ((iconwidth - labwidth) / 2);
689 } else {
690 labxpos = [icon frame].origin.x - ((labwidth - iconwidth) / 2);
691 }
692
693 labelRect = NSMakeRect(labxpos, [icon frame].origin.y - 15, labwidth, 14);
694 [label setFrame: labelRect];
695 }
696
697 - (void)unselectOtherIcons:(id)anIcon
698 {
699 int i;
700
701 for (i = 0; i < [icons count]; i++) {
702 IconViewsIcon *icon = [icons objectAtIndex: i];
703 if (icon != anIcon) {
704 [icon unselect];
705 }
706 }
707 }
708
709 - (void)setShiftClick:(BOOL)value
710 {
711 isShiftClick = value;
712 }
713
714 - (void)setCurrentSelection:(NSArray *)paths
715 {
716 [delegate shelf: self setCurrentSelection: paths];
717 }
718
719 - (void)setCurrentSelection:(NSArray *)paths
720 animateImage:(NSImage *)image
721 startingAtPoint:(NSPoint)startp
722 {
723 [delegate shelf: self setCurrentSelection: paths
724 animateImage: image startingAtPoint: startp];
725 }
726
727 - (void)openCurrentSelection:(NSArray *)paths newViewer:(BOOL)newv
728 {
729 [delegate shelf: self openCurrentSelection: paths newViewer: newv];
730 }
731
732 - (NSArray *)currentSelection
733 {
734 return nil;
735 }
736
737 - (void)keyDown:(NSEvent *)theEvent
738 {
739 [delegate shelf: self keyDown: theEvent];
740 }
741
742 - (int)cellsWidth
743 {
744 return cellsWidth;
745 }
746
747 - (void)setDelegate:(id)anObject
748 {
749 delegate = anObject;
750 }
751
752 - (id)delegate
753 {
754 return delegate;
755 }
756
757 @end
758
759 @implementation Shelf(DraggingDestination)
760
761 - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
762 {
763 NSPasteboard *pb = [sender draggingPasteboard];
764 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
765 gridpoint *gpoint;
766
767 if ((sourceDragMask == NSDragOperationCopy)
768 || (sourceDragMask == NSDragOperationLink)) {
769 return NSDragOperationNone;
770 }
771
772 if ([[pb types] indexOfObject: NSFilenamesPboardType] != NSNotFound) {
773 isDragTarget = YES;
774 DESTROY (dragImage);
775 dragPoint = [sender draggedImageLocation];
776 dragPoint = [self convertPoint: dragPoint
777 fromView: [[self window] contentView]];
778 gpoint = [self gridPointNearestToPoint: dragPoint];
779 dragPoint = NSMakePoint(gpoint->x, gpoint->y);
780 ASSIGN (dragImage, [sender draggedImage]);
781 dragRect = NSMakeRect(dragPoint.x + 8, dragPoint.y, [dragImage size].width, [dragImage size].height);
782 [self setNeedsDisplay: YES];
783 return NSDragOperationAll;
784 }
785 isDragTarget = NO;
786 return NSDragOperationNone;
787 }
788
789 - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
790 {
791 NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
792 NSPoint p = [sender draggedImageLocation];
793 p = [self convertPoint: p fromView: [[self window] contentView]];
794
795 if (isDragTarget == NO) {
796 return NSDragOperationNone;
797 }
798
799 if ((sourceDragMask == NSDragOperationCopy)
800 || (sourceDragMask == NSDragOperationLink)) {
801 return NSDragOperationNone;
802 }
803
804 if (NSEqualPoints(dragPoint, p) == NO) {
805 gridpoint *gpoint;
806
807 if ([self isFreePosition: dragPoint]) {
808 [self setNeedsDisplayInRect: dragRect];
809 }
810
811 gpoint = gridPoint(self, gridPointSel, p);
812 dragPoint = NSMakePoint(gpoint->x, gpoint->y);
813
814 if (gpoint->used == 0) {
815 dragRect = NSMakeRect(dragPoint.x + 8, dragPoint.y, [dragImage size].width, [dragImage size].height);
816 if (dragImage == nil) {
817 ASSIGN (dragImage, [sender draggedImage]);
818 }
819 [self setNeedsDisplayInRect: dragRect];
820
821 } else {
822 if (dragImage != nil) {
823 DESTROY (dragImage);
824 }
825 return NSDragOperationNone;
826 }
827 }
828
829 return NSDragOperationAll;
830 }
831
832 - (void)draggingExited:(id <NSDraggingInfo>)sender
833 {
834 if (dragImage != nil) {
835 DESTROY (dragImage);
836 [self setNeedsDisplay: YES];
837 }
838
839 isDragTarget = NO;
840 }
841
842 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
843 {
844 return isDragTarget;
845 }
846
847 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
848 {
849 return YES;
850 }
851
852 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
853 {
854 NSPasteboard *pb = [sender draggingPasteboard];
855 NSArray *sourcePaths = [pb propertyListForType: NSFilenamesPboardType];
856
857 isDragTarget = NO;
858
859 if (dragImage != nil) {
860 DESTROY (dragImage);
861 [self setNeedsDisplay: YES];
862 }
863
864 if (sourcePaths) {
865 NSPoint p = [sender draggedImageLocation];
866 gridpoint *gpoint;
867 int index, i;
868
869 if (viewerPath != nil) {
870 for (i = 0; i < [sourcePaths count]; i++) {
871 NSString *s = [sourcePaths objectAtIndex: i];
872
873 if ((subPathOfPath(viewerPath, s) == NO)
874 && ([viewerPath isEqualToString: s] == NO)) {
875 return;
876 }
877 }
878 }
879
880 p = [self convertPoint: p fromView: [[self window] contentView]];
881 gpoint = [self gridPointNearestToPoint: p];
882 p = NSMakePoint(gpoint->x, gpoint->y);
883 index = gpoint->index;
884
885 if (gpoint->used == 0) {
886 for (i = 0; i < [icons count]; i++) {
887 IconViewsIcon *icon = [icons objectAtIndex: i];
888 if ([[icon paths] isEqualToArray: sourcePaths]) {
889 gpoints[[icon gridindex]].used = 0;
890 gpoint->used = 1;
891 [icon setGridIndex: index];
892 [self resizeWithOldSuperviewSize: [self frame].size];
893 return;
894 }
895 }
896
897 [self addIconWithPaths: sourcePaths withGridIndex: index];
898 }
899
900 // if ([delegate respondsToSelector: @selector(getSelectedPaths)]) {
901 // NSArray *paths = [delegate getSelectedPaths];
902 // [delegate shelf: self setCurrentSelection: paths];
903 // }
904 }
905 }
906
907 @end

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