22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
*/ |
*/ |
24 |
|
|
|
|
|
25 |
#include <Foundation/Foundation.h> |
#include <Foundation/Foundation.h> |
26 |
#include <AppKit/AppKit.h> |
#include <AppKit/AppKit.h> |
27 |
#include "GWProtocol.h" |
#include "GWProtocol.h" |
59 |
TEST_RELEASE (matrix); |
TEST_RELEASE (matrix); |
60 |
TEST_RELEASE (scroll); |
TEST_RELEASE (scroll); |
61 |
RELEASE (cellPrototype); |
RELEASE (cellPrototype); |
|
TEST_RELEASE (remoteHostName); |
|
62 |
TEST_RELEASE (path); |
TEST_RELEASE (path); |
63 |
TEST_RELEASE (oldpath); |
TEST_RELEASE (oldpath); |
64 |
[super dealloc]; |
[super dealloc]; |
68 |
atIndex:(int)ind |
atIndex:(int)ind |
69 |
cellPrototype:(BCell *)cell |
cellPrototype:(BCell *)cell |
70 |
styleMask:(int)mask |
styleMask:(int)mask |
|
remoteHost:(NSString *)rhost |
|
71 |
|
|
72 |
{ |
{ |
73 |
self = [super init]; |
self = [super init]; |
82 |
styleMask = mask; |
styleMask = mask; |
83 |
|
|
84 |
gworkspace = (id<GWProtocol>)[gwclass gworkspace]; |
gworkspace = (id<GWProtocol>)[gwclass gworkspace]; |
85 |
|
|
|
if (rhost) { |
|
|
isRemote = YES; |
|
|
ASSIGN (remoteHostName, rhost); |
|
|
} else { |
|
|
isRemote = NO; |
|
|
remoteHostName = nil; |
|
|
} |
|
|
|
|
86 |
fm = [NSFileManager defaultManager]; |
fm = [NSFileManager defaultManager]; |
87 |
ws = [NSWorkspace sharedWorkspace]; |
ws = [NSWorkspace sharedWorkspace]; |
88 |
|
|
115 |
if (styleMask & GWIconCellsMask) { |
if (styleMask & GWIconCellsMask) { |
116 |
cellsHeight = ICON_CELLS_HEIGHT; |
cellsHeight = ICON_CELLS_HEIGHT; |
117 |
|
|
118 |
if (isRemote == NO) { |
[self registerForDraggedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]]; |
|
[self registerForDraggedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]]; |
|
|
} else { |
|
|
[self registerForDraggedTypes: [NSArray arrayWithObject: GWRemoteFilenamesPboardType]]; |
|
|
} |
|
119 |
} else { |
} else { |
120 |
cellsHeight = CELLS_HEIGHT; |
cellsHeight = CELLS_HEIGHT; |
121 |
} |
} |
140 |
for (i = 0; i < [cpaths count]; i++) { |
for (i = 0; i < [cpaths count]; i++) { |
141 |
NSString *ipath = [cpaths objectAtIndex: i]; |
NSString *ipath = [cpaths objectAtIndex: i]; |
142 |
|
|
143 |
if ([gworkspace server: remoteHostName fileExistsAtPath: ipath]) { |
if ([fm fileExistsAtPath: ipath]) { |
144 |
[iconPaths addObject: ipath]; |
[iconPaths addObject: ipath]; |
145 |
} |
} |
146 |
} |
} |
148 |
if ([iconPaths count]) { |
if ([iconPaths count]) { |
149 |
if ([iconPaths count] == 1) { |
if ([iconPaths count] == 1) { |
150 |
apath = [cpaths objectAtIndex: 0]; |
apath = [cpaths objectAtIndex: 0]; |
151 |
exists = [gworkspace server: remoteHostName fileExistsAtPath: apath]; |
exists = [fm fileExistsAtPath: apath]; |
152 |
} |
} |
153 |
} else { |
} else { |
154 |
iconPaths = nil; |
iconPaths = nil; |
201 |
|
|
202 |
if (styleMask & GWColumnIconMask) { |
if (styleMask & GWColumnIconMask) { |
203 |
if (icon == nil) { |
if (icon == nil) { |
204 |
icon = [[BIcon alloc] initForRemoteHost: remoteHostName]; |
icon = [[BIcon alloc] init]; |
205 |
[icon setDelegate: self]; |
[icon setDelegate: self]; |
206 |
[iconView addSubview: icon]; |
[iconView addSubview: icon]; |
207 |
[iconView addSubview: [icon label]]; |
[iconView addSubview: [icon label]]; |
213 |
[icon setLocked: NO]; |
[icon setLocked: NO]; |
214 |
} |
} |
215 |
|
|
216 |
if (isRemote == NO) { |
for (i = 0; i < [iconPaths count]; i++) { |
217 |
for (i = 0; i < [iconPaths count]; i++) { |
NSString *ipath = [iconPaths objectAtIndex: i]; |
218 |
NSString *ipath = [iconPaths objectAtIndex: i]; |
|
219 |
|
if ([gworkspace isLockedPath: ipath]) { |
220 |
if ([gworkspace server: remoteHostName isLockedPath: ipath]) { |
[icon setLocked: YES]; |
221 |
[icon setLocked: YES]; |
break; |
222 |
break; |
} |
223 |
} |
} |
|
} |
|
|
} |
|
224 |
} |
} |
225 |
|
|
226 |
[self setLeaf: YES]; |
[self setLeaf: YES]; |
236 |
for (i = 0; i < [savedSelection count]; i++) { |
for (i = 0; i < [savedSelection count]; i++) { |
237 |
NSString *savedSel = [savedSelection objectAtIndex: i]; |
NSString *savedSel = [savedSelection objectAtIndex: i]; |
238 |
|
|
239 |
if ([gworkspace server: remoteHostName fileExistsAtPath: savedSel]) { |
if ([fm fileExistsAtPath: savedSel]) { |
240 |
[savedNames addObject: [savedSel lastPathComponent]]; |
[savedNames addObject: [savedSel lastPathComponent]]; |
241 |
} |
} |
242 |
} |
} |
293 |
int i, count; |
int i, count; |
294 |
BOOL is_dir; |
BOOL is_dir; |
295 |
|
|
296 |
if ([gworkspace server: remoteHostName |
if ([gworkspace existsAndIsDirectoryFileAtPath: path] == NO) { |
|
existsAndIsDirectoryFileAtPath: path] == NO) { |
|
297 |
return; |
return; |
298 |
} else { |
} else { |
299 |
if ([gworkspace server: remoteHostName isPakageAtPath: path] |
if ([gworkspace isPakageAtPath: path] && (!(styleMask & GWViewsPaksgesMask))) { |
|
&& (!(styleMask & GWViewsPaksgesMask))) { |
|
300 |
return; |
return; |
301 |
} |
} |
302 |
} |
} |
304 |
matrix = [[BMatrix alloc] initInColumn: self withFrame: [self frame] |
matrix = [[BMatrix alloc] initInColumn: self withFrame: [self frame] |
305 |
mode: NSListModeMatrix prototype: cellPrototype |
mode: NSListModeMatrix prototype: cellPrototype |
306 |
numberOfRows: 0 numberOfColumns: 0 |
numberOfRows: 0 numberOfColumns: 0 |
307 |
acceptDnd: (styleMask & GWIconCellsMask) |
acceptDnd: (styleMask & GWIconCellsMask)]; |
|
remoteHost: remoteHostName]; |
|
308 |
|
|
309 |
[matrix setIntercellSpacing: NSMakeSize(0, 0)]; |
[matrix setIntercellSpacing: NSMakeSize(0, 0)]; |
310 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
315 |
[matrix setDoubleAction: @selector(doDoubleClick:)]; |
[matrix setDoubleAction: @selector(doDoubleClick:)]; |
316 |
[scroll setDocumentView: matrix]; |
[scroll setDocumentView: matrix]; |
317 |
|
|
318 |
files = [gworkspace server: remoteHostName |
files = [gworkspace sortedDirectoryContentsAtPath: path]; |
319 |
sortedDirectoryContentsAtPath: path]; |
files = [gworkspace checkHiddenFiles: files atPath: path]; |
|
files = [gworkspace server: remoteHostName |
|
|
checkHiddenFiles: files |
|
|
atPath: path]; |
|
320 |
|
|
321 |
count = [files count]; |
count = [files count]; |
322 |
if (count == 0) { |
if (count == 0) { |
343 |
[cell setStringValue: [files objectAtIndex: i]]; |
[cell setStringValue: [files objectAtIndex: i]]; |
344 |
} |
} |
345 |
|
|
346 |
is_dir = [gworkspace server: remoteHostName |
is_dir = [gworkspace existsAndIsDirectoryFileAtPath: s]; |
|
existsAndIsDirectoryFileAtPath: s]; |
|
347 |
if (is_dir == YES) { |
if (is_dir == YES) { |
348 |
[cell setLeaf: (([gworkspace server: remoteHostName isPakageAtPath: s]) |
[cell setLeaf: (([gworkspace isPakageAtPath: s]) |
349 |
? (!(styleMask & GWViewsPaksgesMask)) : NO)]; |
? (!(styleMask & GWViewsPaksgesMask)) : NO)]; |
350 |
} else { |
} else { |
351 |
[cell setLeaf: YES]; |
[cell setLeaf: YES]; |
352 |
} |
} |
353 |
|
|
354 |
if (isRemote == NO) { |
[cell setEnabled: !([gworkspace isLockedPath: s])]; |
|
[cell setEnabled: !([gworkspace server: remoteHostName isLockedPath: s])]; |
|
|
} else { |
|
|
[cell setEnabled: YES]; |
|
|
} |
|
355 |
} |
} |
356 |
} |
} |
357 |
|
|
358 |
- (void)addMatrixCellsWithNames:(NSArray *)names |
- (void)addMatrixCellsWithNames:(NSArray *)names |
359 |
{ |
{ |
360 |
NSArray *files = [gworkspace server: remoteHostName |
NSArray *files = [gworkspace checkHiddenFiles: names atPath: path]; |
|
checkHiddenFiles: names |
|
|
atPath: path]; |
|
361 |
|
|
362 |
if ([files count]) { |
if ([files count]) { |
363 |
BCell *cell; |
BCell *cell; |
375 |
NSString *name = [names objectAtIndex: i]; |
NSString *name = [names objectAtIndex: i]; |
376 |
NSString *cellpath = [path stringByAppendingPathComponent: name]; |
NSString *cellpath = [path stringByAppendingPathComponent: name]; |
377 |
|
|
378 |
isdir = [gworkspace server: remoteHostName |
isdir = [gworkspace existsAndIsDirectoryFileAtPath: cellpath]; |
|
existsAndIsDirectoryFileAtPath: cellpath]; |
|
379 |
|
|
380 |
cell = [self cellWithName: name]; |
cell = [self cellWithName: name]; |
381 |
if (cell == nil) { |
if (cell == nil) { |
389 |
} |
} |
390 |
|
|
391 |
if (isdir) { |
if (isdir) { |
392 |
[cell setLeaf: (([gworkspace server: remoteHostName |
[cell setLeaf: (([gworkspace isPakageAtPath: cellpath]) |
|
isPakageAtPath: cellpath]) |
|
393 |
? (!(styleMask & GWViewsPaksgesMask)) : NO)]; |
? (!(styleMask & GWViewsPaksgesMask)) : NO)]; |
394 |
} else { |
} else { |
395 |
[cell setLeaf: YES]; |
[cell setLeaf: YES]; |
405 |
|
|
406 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
407 |
|
|
408 |
if (isRemote == NO) { |
stype = [gworkspace sortTypeForDirectoryAtPath: path]; |
409 |
stype = [gworkspace sortTypeForDirectoryAtPath: path]; |
sortDict = [NSMutableDictionary dictionaryWithCapacity: 1]; |
410 |
sortDict = [NSMutableDictionary dictionaryWithCapacity: 1]; |
[sortDict setObject: path forKey: @"path"]; |
411 |
[sortDict setObject: path forKey: @"path"]; |
[sortDict setObject: [NSNumber numberWithInt: stype] forKey: @"type"]; |
412 |
[sortDict setObject: [NSNumber numberWithInt: stype] forKey: @"type"]; |
[matrix sortUsingFunction: (int (*)(id, id, void*))compareCells context: (void *)sortDict]; |
|
[matrix sortUsingFunction: (int (*)(id, id, void*))compareCells context: (void *)sortDict]; |
|
|
} else { |
|
|
[matrix sortUsingFunction: (int (*)(id, id, void*))compareCellsRemote context: (void *)nil]; |
|
|
} |
|
|
|
|
413 |
[self adjustMatrix]; |
[self adjustMatrix]; |
414 |
[matrix sizeToCells]; |
[matrix sizeToCells]; |
415 |
|
|
423 |
|
|
424 |
- (void)addDimmedMatrixCellsWithNames:(NSArray *)names |
- (void)addDimmedMatrixCellsWithNames:(NSArray *)names |
425 |
{ |
{ |
426 |
NSArray *files = [gworkspace server: remoteHostName |
NSArray *files = [gworkspace checkHiddenFiles: names atPath: path]; |
|
checkHiddenFiles: names |
|
|
atPath: path]; |
|
427 |
|
|
428 |
if ([files count]) { |
if ([files count]) { |
429 |
BCell *cell; |
BCell *cell; |
669 |
NSString *cellname = [[selected objectAtIndex: i] stringValue]; |
NSString *cellname = [[selected objectAtIndex: i] stringValue]; |
670 |
NSString *cellpath = [path stringByAppendingPathComponent: cellname]; |
NSString *cellpath = [path stringByAppendingPathComponent: cellname]; |
671 |
|
|
672 |
if ([gworkspace server: remoteHostName fileExistsAtPath: cellpath]) { |
if ([fm fileExistsAtPath: cellpath]) { |
673 |
[selection addObject: cellpath]; |
[selection addObject: cellpath]; |
674 |
[cellsnames addObject: cellname]; |
[cellsnames addObject: cellname]; |
675 |
} else { |
} else { |
916 |
{ |
{ |
917 |
BCell *cell; |
BCell *cell; |
918 |
NSPasteboard *pb; |
NSPasteboard *pb; |
|
NSData *pbData; |
|
919 |
NSDragOperation sourceDragMask; |
NSDragOperation sourceDragMask; |
920 |
NSArray *sourcePaths; |
NSArray *sourcePaths; |
921 |
NSString *fromPath; |
NSString *fromPath; |
931 |
|
|
932 |
pb = [sender draggingPasteboard]; |
pb = [sender draggingPasteboard]; |
933 |
|
|
934 |
if (isRemote == NO) { |
if ([[pb types] indexOfObject: NSFilenamesPboardType] == NSNotFound) { |
935 |
if ([[pb types] indexOfObject: NSFilenamesPboardType] == NSNotFound) { |
return NSDragOperationNone; |
|
return NSDragOperationNone; |
|
|
} |
|
|
} else { |
|
|
if ([[pb types] indexOfObject: GWRemoteFilenamesPboardType] == NSNotFound) { |
|
|
return NSDragOperationNone; |
|
|
} |
|
|
} |
|
|
|
|
|
if (isRemote == NO) { |
|
|
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
|
|
} else { |
|
|
NSDictionary *dndDict; |
|
|
|
|
|
pbData = [pb dataForType: GWRemoteFilenamesPboardType]; |
|
|
dndDict = [NSUnarchiver unarchiveObjectWithData: pbData]; |
|
|
|
|
|
sourcePaths = [dndDict objectForKey: @"paths"]; |
|
936 |
} |
} |
937 |
|
|
938 |
|
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
939 |
count = [sourcePaths count]; |
count = [sourcePaths count]; |
940 |
|
|
941 |
if (count == 0) { |
if (count == 0) { |
950 |
return NSDragOperationNone; |
return NSDragOperationNone; |
951 |
} |
} |
952 |
|
|
953 |
if ([gworkspace server: remoteHostName isWritableFileAtPath: targetPath] == NO) { |
if ([fm isWritableFileAtPath: targetPath] == NO) { |
954 |
return NSDragOperationNone; |
return NSDragOperationNone; |
955 |
} |
} |
956 |
|
|
983 |
{ |
{ |
984 |
NSPasteboard *pb; |
NSPasteboard *pb; |
985 |
NSDragOperation sourceDragMask; |
NSDragOperation sourceDragMask; |
|
NSData *pbData; |
|
986 |
NSArray *sourcePaths; |
NSArray *sourcePaths; |
987 |
NSString *targetPath; |
NSString *targetPath; |
988 |
NSString *operation, *source; |
NSString *operation, *source; |
989 |
NSMutableArray *files; |
NSMutableArray *files; |
990 |
NSMutableDictionary *opDict; |
NSMutableDictionary *opDict; |
991 |
NSString *trashPath; |
NSString *trashPath; |
|
NSString *sourceHost; |
|
992 |
BCell *cell; |
BCell *cell; |
993 |
int i; |
int i; |
994 |
|
|
1000 |
sourceDragMask = [sender draggingSourceOperationMask]; |
sourceDragMask = [sender draggingSourceOperationMask]; |
1001 |
pb = [sender draggingPasteboard]; |
pb = [sender draggingPasteboard]; |
1002 |
|
|
1003 |
if (isRemote == NO) { |
if ([[pb types] indexOfObject: NSFilenamesPboardType] == NSNotFound) { |
1004 |
if ([[pb types] indexOfObject: NSFilenamesPboardType] == NSNotFound) { |
return; |
|
return; |
|
|
} |
|
|
} else { |
|
|
if ([[pb types] indexOfObject: GWRemoteFilenamesPboardType] == NSNotFound) { |
|
|
return; |
|
|
} |
|
1005 |
} |
} |
|
|
|
|
sourceHost = nil; |
|
|
|
|
|
if (isRemote == NO) { |
|
|
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
|
|
} else { |
|
|
NSDictionary *dndDict; |
|
1006 |
|
|
1007 |
pbData = [pb dataForType: GWRemoteFilenamesPboardType]; |
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
|
dndDict = [NSUnarchiver unarchiveObjectWithData: pbData]; |
|
|
|
|
|
sourcePaths = [dndDict objectForKey: @"paths"]; |
|
|
sourceHost = [dndDict objectForKey: @"host"]; |
|
|
} |
|
|
|
|
1008 |
source = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent]; |
source = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent]; |
1009 |
targetPath = [path stringByAppendingPathComponent: [cell stringValue]]; |
targetPath = [path stringByAppendingPathComponent: [cell stringValue]]; |
1010 |
|
trashPath = [gworkspace trashPath]; |
1011 |
|
|
1012 |
if (isRemote == NO) { |
if ([source isEqualToString: trashPath]) { |
1013 |
trashPath = [gworkspace trashPath]; |
operation = GWorkspaceRecycleOutOperation; |
1014 |
|
} else { |
|
if ([source isEqualToString: trashPath]) { |
|
|
operation = GWorkspaceRecycleOutOperation; |
|
|
} else { |
|
|
if (sourceDragMask == NSDragOperationCopy) { |
|
|
operation = NSWorkspaceCopyOperation; |
|
|
} else if (sourceDragMask == NSDragOperationLink) { |
|
|
operation = NSWorkspaceLinkOperation; |
|
|
} else { |
|
|
operation = NSWorkspaceMoveOperation; |
|
|
} |
|
|
} |
|
|
} else { |
|
1015 |
if (sourceDragMask == NSDragOperationCopy) { |
if (sourceDragMask == NSDragOperationCopy) { |
1016 |
operation = NSWorkspaceCopyOperation; |
operation = NSWorkspaceCopyOperation; |
1017 |
} else if (sourceDragMask == NSDragOperationLink) { |
} else if (sourceDragMask == NSDragOperationLink) { |
1032 |
[opDict setObject: targetPath forKey: @"destination"]; |
[opDict setObject: targetPath forKey: @"destination"]; |
1033 |
[opDict setObject: files forKey: @"files"]; |
[opDict setObject: files forKey: @"files"]; |
1034 |
|
|
1035 |
[gworkspace performFileOperationWithDictionary: opDict |
[gworkspace performFileOperationWithDictionary: opDict]; |
|
fromSourceHost: sourceHost |
|
|
toDestinationHost: remoteHostName]; |
|
1036 |
} |
} |
1037 |
|
|
1038 |
- (void)setFrame:(NSRect)frameRect |
- (void)setFrame:(NSRect)frameRect |