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