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