1 |
/* BColumn.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 |
#include "GWProtocol.h" |
29 |
#include "GWFunctions.h" |
30 |
#include "GWNotifications.h" |
31 |
#include "GWLib.h" |
32 |
#include "BColumn.h" |
33 |
#include "BMatrix.h" |
34 |
#include "BCell.h" |
35 |
#include "BIcon.h" |
36 |
#include "Browser2.h" |
37 |
#include "GNUstep.h" |
38 |
|
39 |
#define ICON_FRAME_HEIGHT 52 |
40 |
#define ICON_SIZE_WIDTH 48 |
41 |
#define ICON_VOFFSET 14 |
42 |
|
43 |
#define CELLS_HEIGHT 15 |
44 |
#define ICON_CELLS_HEIGHT 30 |
45 |
|
46 |
#define CHECKRECT(rct) \ |
47 |
if (rct.size.width < 0) rct.size.width = 0; \ |
48 |
if (rct.size.height < 0) rct.size.height = 0 |
49 |
|
50 |
#define CHECKSIZE(sz) \ |
51 |
if (sz.width < 0) sz.width = 0; \ |
52 |
if (sz.height < 0) sz.height = 0 |
53 |
|
54 |
@implementation BColumn |
55 |
|
56 |
- (void)dealloc |
57 |
{ |
58 |
TEST_RELEASE (icon); |
59 |
TEST_RELEASE (iconView); |
60 |
TEST_RELEASE (matrix); |
61 |
TEST_RELEASE (scroll); |
62 |
RELEASE (cellPrototype); |
63 |
TEST_RELEASE (remoteHostName); |
64 |
TEST_RELEASE (path); |
65 |
TEST_RELEASE (oldpath); |
66 |
[super dealloc]; |
67 |
} |
68 |
|
69 |
- (id)initInBrowser:(Browser2 *)aBrowser |
70 |
atIndex:(int)ind |
71 |
cellPrototype:(BCell *)cell |
72 |
styleMask:(int)mask |
73 |
remoteHost:(NSString *)rhost |
74 |
|
75 |
{ |
76 |
self = [super init]; |
77 |
|
78 |
if (self) { |
79 |
#ifdef GNUSTEP |
80 |
Class gwclass = [[NSBundle mainBundle] principalClass]; |
81 |
#else |
82 |
Class gwclass = [[NSBundle mainBundle] classNamed: @"GWorkspace"]; |
83 |
#endif |
84 |
NSRect rect = NSMakeRect(0, 0, 150, 100); |
85 |
styleMask = mask; |
86 |
|
87 |
gworkspace = (id<GWProtocol>)[gwclass gworkspace]; |
88 |
|
89 |
if (rhost) { |
90 |
isRemote = YES; |
91 |
ASSIGN (remoteHostName, rhost); |
92 |
} else { |
93 |
isRemote = NO; |
94 |
remoteHostName = nil; |
95 |
} |
96 |
|
97 |
fm = [NSFileManager defaultManager]; |
98 |
ws = [NSWorkspace sharedWorkspace]; |
99 |
|
100 |
browser = aBrowser; |
101 |
index = ind; |
102 |
ASSIGN (cellPrototype, cell); |
103 |
|
104 |
path = nil; |
105 |
oldpath = nil; |
106 |
matrix = nil; |
107 |
icon = nil; |
108 |
iconView = nil; |
109 |
isLoaded = NO; |
110 |
isLeaf = NO; |
111 |
|
112 |
[self setFrame: rect]; |
113 |
|
114 |
scroll = [[NSScrollView alloc] initWithFrame: rect]; |
115 |
[scroll setBorderType: NSBezelBorder]; |
116 |
[scroll setHasHorizontalScroller: NO]; |
117 |
[scroll setHasVerticalScroller: YES]; |
118 |
[scroll setBorderType: NSNoBorder]; |
119 |
|
120 |
[self addSubview: scroll]; |
121 |
|
122 |
if (styleMask & GWColumnIconMask) { |
123 |
iconView = [NSView new]; |
124 |
} |
125 |
|
126 |
if (styleMask & GWIconCellsMask) { |
127 |
cellsHeight = ICON_CELLS_HEIGHT; |
128 |
|
129 |
if (isRemote == NO) { |
130 |
[self registerForDraggedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]]; |
131 |
} else { |
132 |
[self registerForDraggedTypes: [NSArray arrayWithObject: GWRemoteFilenamesPboardType]]; |
133 |
} |
134 |
} else { |
135 |
cellsHeight = CELLS_HEIGHT; |
136 |
} |
137 |
} |
138 |
|
139 |
return self; |
140 |
} |
141 |
|
142 |
- (void)setCurrentPaths:(NSArray *)cpaths |
143 |
{ |
144 |
NSMutableArray *iconPaths = nil; |
145 |
NSString *apath = nil; |
146 |
BOOL exists = YES; |
147 |
NSArray *savedSelection = nil; |
148 |
NSMutableArray *visibleCellsNames = nil; |
149 |
float scrollTune = 0; |
150 |
int i = 0; |
151 |
|
152 |
if (cpaths) { |
153 |
iconPaths = [NSMutableArray arrayWithCapacity: 1]; |
154 |
|
155 |
for (i = 0; i < [cpaths count]; i++) { |
156 |
NSString *ipath = [cpaths objectAtIndex: i]; |
157 |
|
158 |
if ([gworkspace server: remoteHostName fileExistsAtPath: ipath]) { |
159 |
[iconPaths addObject: ipath]; |
160 |
} |
161 |
} |
162 |
|
163 |
if ([iconPaths count]) { |
164 |
if ([iconPaths count] == 1) { |
165 |
apath = [cpaths objectAtIndex: 0]; |
166 |
exists = [gworkspace server: remoteHostName fileExistsAtPath: apath]; |
167 |
} |
168 |
} else { |
169 |
iconPaths = nil; |
170 |
} |
171 |
} |
172 |
|
173 |
if (oldpath && apath && [oldpath isEqual: apath] && exists) { |
174 |
savedSelection = [self selection]; |
175 |
if (savedSelection) { |
176 |
RETAIN (savedSelection); |
177 |
} |
178 |
|
179 |
if (matrix) { |
180 |
NSArray *vnames = [matrix getNamesOfVisibleCellsAndTuneSpace: &scrollTune]; |
181 |
|
182 |
if (vnames) { |
183 |
visibleCellsNames = [NSMutableArray new]; |
184 |
[visibleCellsNames addObjectsFromArray: vnames]; |
185 |
} |
186 |
} |
187 |
} |
188 |
|
189 |
if (matrix) { |
190 |
[matrix removeFromSuperviewWithoutNeedingDisplay]; |
191 |
[scroll setDocumentView: nil]; |
192 |
DESTROY (matrix); |
193 |
} |
194 |
|
195 |
DESTROY (path); |
196 |
DESTROY (oldpath); |
197 |
|
198 |
if ((iconPaths == nil) || (exists == NO)) { |
199 |
TEST_RELEASE (savedSelection); |
200 |
if ((styleMask & GWColumnIconMask) && icon) { |
201 |
[icon removeFromSuperview]; |
202 |
[[icon label] removeFromSuperview]; |
203 |
DESTROY (icon); |
204 |
} |
205 |
isLoaded = NO; |
206 |
return; |
207 |
|
208 |
} else { |
209 |
id cell = nil; |
210 |
BColumn *col = nil; |
211 |
|
212 |
if (apath) { |
213 |
ASSIGN (oldpath, apath); |
214 |
ASSIGN (path, apath); |
215 |
} |
216 |
|
217 |
if (styleMask & GWColumnIconMask) { |
218 |
if (icon == nil) { |
219 |
icon = [[BIcon alloc] initForRemoteHost: remoteHostName]; |
220 |
[icon setDelegate: self]; |
221 |
[iconView addSubview: icon]; |
222 |
[iconView addSubview: [icon label]]; |
223 |
[icon setPaths: iconPaths]; |
224 |
[icon setLocked: NO]; |
225 |
[icon select]; |
226 |
} else { |
227 |
[icon setPaths: iconPaths]; |
228 |
[icon setLocked: NO]; |
229 |
} |
230 |
|
231 |
if (isRemote == NO) { |
232 |
for (i = 0; i < [iconPaths count]; i++) { |
233 |
NSString *ipath = [iconPaths objectAtIndex: i]; |
234 |
|
235 |
if ([gworkspace server: remoteHostName isLockedPath: ipath]) { |
236 |
[icon setLocked: YES]; |
237 |
break; |
238 |
} |
239 |
} |
240 |
} |
241 |
} |
242 |
|
243 |
[self setLeaf: YES]; |
244 |
|
245 |
if (path) { |
246 |
[self createRowsInMatrix]; |
247 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
248 |
[self adjustMatrix]; |
249 |
|
250 |
if (savedSelection) { |
251 |
NSMutableArray *savedNames = [NSMutableArray arrayWithCapacity: 1]; |
252 |
|
253 |
for (i = 0; i < [savedSelection count]; i++) { |
254 |
NSString *savedSel = [savedSelection objectAtIndex: i]; |
255 |
|
256 |
if ([gworkspace server: remoteHostName fileExistsAtPath: savedSel]) { |
257 |
[savedNames addObject: [savedSel lastPathComponent]]; |
258 |
} |
259 |
} |
260 |
|
261 |
if ([savedNames count]) { |
262 |
[self selectMatrixCellsWithNames: savedNames sendAction: NO]; |
263 |
} |
264 |
} |
265 |
|
266 |
if (visibleCellsNames) { |
267 |
NSArray *cells = [matrix cells]; |
268 |
|
269 |
if (cells && [cells count]) { |
270 |
NSMutableArray *cellsNames = [NSMutableArray arrayWithCapacity: 1]; |
271 |
int count = [visibleCellsNames count]; |
272 |
|
273 |
for (i = 0; i < [cells count]; i++) { |
274 |
[cellsNames addObject: [[cells objectAtIndex: i] stringValue]]; |
275 |
} |
276 |
|
277 |
for (i = 0; i < count; i++) { |
278 |
NSString *vname = [visibleCellsNames objectAtIndex: i]; |
279 |
|
280 |
if ([cellsNames containsObject: vname] == NO) { |
281 |
[visibleCellsNames removeObjectAtIndex: i]; |
282 |
count--; |
283 |
i--; |
284 |
} |
285 |
} |
286 |
|
287 |
if ([visibleCellsNames count]) { |
288 |
cell = [self cellWithName: [visibleCellsNames objectAtIndex: 0]]; |
289 |
[matrix scrollToFirstPositionCell: cell withScrollTune: scrollTune]; |
290 |
} |
291 |
} |
292 |
} |
293 |
} |
294 |
|
295 |
isLoaded = YES; |
296 |
|
297 |
TEST_RELEASE (savedSelection); |
298 |
TEST_RELEASE (visibleCellsNames); |
299 |
|
300 |
col = [browser columnBeforeColumn: self]; |
301 |
if (col) { |
302 |
[col setLeaf: NO]; |
303 |
} |
304 |
} |
305 |
} |
306 |
|
307 |
- (void)createRowsInMatrix |
308 |
{ |
309 |
NSArray *files; |
310 |
int i, count; |
311 |
BOOL is_dir; |
312 |
|
313 |
if ([gworkspace server: remoteHostName |
314 |
existsAndIsDirectoryFileAtPath: path] == NO) { |
315 |
return; |
316 |
} else { |
317 |
if ([gworkspace server: remoteHostName isPakageAtPath: path] |
318 |
&& (!(styleMask & GWViewsPaksgesMask))) { |
319 |
return; |
320 |
} |
321 |
} |
322 |
|
323 |
matrix = [[BMatrix alloc] initInColumn: self withFrame: [self frame] |
324 |
mode: NSListModeMatrix prototype: cellPrototype |
325 |
numberOfRows: 0 numberOfColumns: 0 |
326 |
acceptDnd: (styleMask & GWIconCellsMask) |
327 |
remoteHost: remoteHostName]; |
328 |
|
329 |
[matrix setIntercellSpacing: NSMakeSize(0, 0)]; |
330 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
331 |
[matrix setAutoscroll: YES]; |
332 |
[matrix setAllowsEmptySelection: YES]; |
333 |
[matrix setTarget: self]; |
334 |
[matrix setAction: @selector(doClick:)]; |
335 |
[matrix setDoubleAction: @selector(doDoubleClick:)]; |
336 |
[scroll setDocumentView: matrix]; |
337 |
|
338 |
files = [gworkspace server: remoteHostName |
339 |
sortedDirectoryContentsAtPath: path]; |
340 |
files = [gworkspace server: remoteHostName |
341 |
checkHiddenFiles: files |
342 |
atPath: path]; |
343 |
|
344 |
count = [files count]; |
345 |
if (count == 0) { |
346 |
return; |
347 |
} |
348 |
|
349 |
[matrix addColumn]; |
350 |
|
351 |
for (i = 0; i < count; ++i) { |
352 |
NSString *s = [path stringByAppendingPathComponent: [files objectAtIndex: i]]; |
353 |
id cell; |
354 |
|
355 |
if (i != 0) { |
356 |
[matrix insertRow: i]; |
357 |
} |
358 |
|
359 |
cell = [matrix cellAtRow: i column: 0]; |
360 |
[cell setLoaded: YES]; |
361 |
[cell setEnabled: YES]; |
362 |
|
363 |
if (styleMask & GWIconCellsMask) { |
364 |
[cell setPaths: [NSArray arrayWithObject: s]]; |
365 |
} else { |
366 |
[cell setStringValue: [files objectAtIndex: i]]; |
367 |
} |
368 |
|
369 |
is_dir = [gworkspace server: remoteHostName |
370 |
existsAndIsDirectoryFileAtPath: s]; |
371 |
if (is_dir == YES) { |
372 |
[cell setLeaf: (([gworkspace server: remoteHostName isPakageAtPath: s]) |
373 |
? (!(styleMask & GWViewsPaksgesMask)) : NO)]; |
374 |
} else { |
375 |
[cell setLeaf: YES]; |
376 |
} |
377 |
|
378 |
if (isRemote == NO) { |
379 |
[cell setEnabled: !([gworkspace server: remoteHostName isLockedPath: s])]; |
380 |
} else { |
381 |
[cell setEnabled: YES]; |
382 |
} |
383 |
} |
384 |
} |
385 |
|
386 |
- (void)addMatrixCellsWithNames:(NSArray *)names |
387 |
{ |
388 |
NSArray *files = [gworkspace server: remoteHostName |
389 |
checkHiddenFiles: names |
390 |
atPath: path]; |
391 |
|
392 |
if ([files count]) { |
393 |
BCell *cell; |
394 |
NSArray *selectedCells; |
395 |
NSMutableDictionary *sortDict; |
396 |
int stype; |
397 |
BOOL isdir; |
398 |
int i; |
399 |
|
400 |
[matrix setIntercellSpacing: NSMakeSize(0, 0)]; |
401 |
|
402 |
selectedCells = [matrix selectedCells]; |
403 |
|
404 |
for (i = 0; i < [names count]; i++) { |
405 |
NSString *name = [names objectAtIndex: i]; |
406 |
NSString *cellpath = [path stringByAppendingPathComponent: name]; |
407 |
|
408 |
isdir = [gworkspace server: remoteHostName |
409 |
existsAndIsDirectoryFileAtPath: cellpath]; |
410 |
|
411 |
cell = [self cellWithName: name]; |
412 |
if (cell == nil) { |
413 |
[matrix addRow]; |
414 |
cell = [matrix cellAtRow: [[matrix cells] count] -1 column: 0]; |
415 |
|
416 |
if (styleMask & GWIconCellsMask) { |
417 |
[cell setPaths: [NSArray arrayWithObject: cellpath]]; |
418 |
} else { |
419 |
[cell setStringValue: name]; |
420 |
} |
421 |
|
422 |
if (isdir) { |
423 |
[cell setLeaf: (([gworkspace server: remoteHostName |
424 |
isPakageAtPath: cellpath]) |
425 |
? (!(styleMask & GWViewsPaksgesMask)) : NO)]; |
426 |
} else { |
427 |
[cell setLeaf: YES]; |
428 |
} |
429 |
|
430 |
[cell setLoaded: YES]; |
431 |
[cell setEnabled: YES]; |
432 |
|
433 |
} else { |
434 |
[cell setEnabled: YES]; |
435 |
} |
436 |
} |
437 |
|
438 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
439 |
|
440 |
if (isRemote == NO) { |
441 |
stype = [gworkspace sortTypeForDirectoryAtPath: path]; |
442 |
sortDict = [NSMutableDictionary dictionaryWithCapacity: 1]; |
443 |
[sortDict setObject: path forKey: @"path"]; |
444 |
[sortDict setObject: [NSNumber numberWithInt: stype] forKey: @"type"]; |
445 |
[matrix sortUsingFunction: (int (*)(id, id, void*))compareCells context: (void *)sortDict]; |
446 |
} else { |
447 |
[matrix sortUsingFunction: (int (*)(id, id, void*))compareCellsRemote context: (void *)nil]; |
448 |
} |
449 |
|
450 |
[self adjustMatrix]; |
451 |
[matrix sizeToCells]; |
452 |
|
453 |
if (selectedCells != nil) { |
454 |
[self selectMatrixCells: selectedCells sendAction: NO]; |
455 |
} |
456 |
|
457 |
[matrix setNeedsDisplay: YES]; |
458 |
} |
459 |
} |
460 |
|
461 |
- (void)addDimmedMatrixCellsWithNames:(NSArray *)names |
462 |
{ |
463 |
NSArray *files = [gworkspace server: remoteHostName |
464 |
checkHiddenFiles: names |
465 |
atPath: path]; |
466 |
|
467 |
if ([files count]) { |
468 |
BCell *cell; |
469 |
NSArray *selectedCells; |
470 |
int i; |
471 |
|
472 |
[matrix setIntercellSpacing: NSMakeSize(0, 0)]; |
473 |
|
474 |
selectedCells = [matrix selectedCells]; |
475 |
|
476 |
for (i = 0; i < [names count]; i++) { |
477 |
NSString *name = [names objectAtIndex: i]; |
478 |
|
479 |
cell = [self cellWithName: name]; |
480 |
if (cell == nil) { |
481 |
[matrix addRow]; |
482 |
cell = [matrix cellAtRow: [[matrix cells] count] -1 column: 0]; |
483 |
[cell setStringValue: name]; |
484 |
[cell setLeaf: YES]; |
485 |
[cell setLoaded: YES]; |
486 |
[cell setEnabled: NO]; |
487 |
|
488 |
} else { |
489 |
[cell setEnabled: NO]; |
490 |
} |
491 |
} |
492 |
|
493 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
494 |
|
495 |
[self adjustMatrix]; |
496 |
[matrix sizeToCells]; |
497 |
|
498 |
if (selectedCells != nil) { |
499 |
[self selectMatrixCells: selectedCells sendAction: NO]; |
500 |
} |
501 |
|
502 |
[matrix setNeedsDisplay: YES]; |
503 |
} |
504 |
} |
505 |
|
506 |
- (void)removeMatrixCellsWithNames:(NSArray *)names |
507 |
{ |
508 |
NSMutableArray *selectedCells = nil; |
509 |
NSMutableArray *visibleCellsNames = nil; |
510 |
BColumn *col = nil; |
511 |
id cell = nil; |
512 |
float scrollTune = 0; |
513 |
int i = 0; |
514 |
BOOL updatesel = NO; |
515 |
|
516 |
selectedCells = [[matrix selectedCells] mutableCopy]; |
517 |
AUTORELEASE (selectedCells); |
518 |
|
519 |
visibleCellsNames = [[matrix getNamesOfVisibleCellsAndTuneSpace: &scrollTune] mutableCopy]; |
520 |
AUTORELEASE (visibleCellsNames); |
521 |
|
522 |
for (i = 0; i < [names count]; i++) { |
523 |
NSString *cname = [names objectAtIndex: i]; |
524 |
|
525 |
cell = [self cellWithName: cname]; |
526 |
|
527 |
if (cell) { |
528 |
int row, col; |
529 |
|
530 |
if ([selectedCells containsObject: cell]) { |
531 |
[selectedCells removeObject: cell]; |
532 |
updatesel = YES; |
533 |
} |
534 |
|
535 |
if ([visibleCellsNames containsObject: cname]) { |
536 |
[visibleCellsNames removeObject: cname]; |
537 |
} |
538 |
|
539 |
[matrix getRow: &row column: &col ofCell: cell]; |
540 |
[matrix removeRow: row]; |
541 |
} |
542 |
} |
543 |
|
544 |
[matrix sizeToCells]; |
545 |
[matrix setNeedsDisplay: YES]; |
546 |
|
547 |
if (updatesel) { |
548 |
if ([selectedCells count] > 0) { |
549 |
[self selectMatrixCells: selectedCells sendAction: NO]; |
550 |
[matrix setNeedsDisplay: YES]; |
551 |
|
552 |
col = [browser columnAfterColumn: self]; |
553 |
if (col) { |
554 |
[col updateIcon]; |
555 |
} |
556 |
|
557 |
if ([visibleCellsNames count]) { |
558 |
cell = [self cellWithName: [visibleCellsNames objectAtIndex: 0]]; |
559 |
[matrix scrollToFirstPositionCell: cell withScrollTune: scrollTune]; |
560 |
} |
561 |
|
562 |
} else { |
563 |
if (index != 0) { |
564 |
if ((index - 1) >= [browser firstVisibleColumn]) { |
565 |
col = [browser columnBeforeColumn: self]; |
566 |
cell = [col cellWithName: [path lastPathComponent]]; |
567 |
|
568 |
[col selectMatrixCells: [NSArray arrayWithObject: cell] |
569 |
sendAction: YES]; |
570 |
} |
571 |
} else { |
572 |
[browser setLastColumn: index]; |
573 |
} |
574 |
} |
575 |
|
576 |
} else if ([visibleCellsNames count]) { |
577 |
cell = [self cellWithName: [visibleCellsNames objectAtIndex: 0]]; |
578 |
[matrix scrollToFirstPositionCell: cell withScrollTune: scrollTune]; |
579 |
} |
580 |
} |
581 |
|
582 |
- (BOOL)selectMatrixCellsWithNames:(NSArray *)names sendAction:(BOOL)act |
583 |
{ |
584 |
NSArray *cells = [matrix cells]; |
585 |
int i = 0; |
586 |
BOOL found = NO; |
587 |
|
588 |
[matrix deselectAllCells]; |
589 |
|
590 |
for (i = 0; i < [cells count]; i++) { |
591 |
NSCell *cell = [cells objectAtIndex: i]; |
592 |
|
593 |
if ([names containsObject: [cell stringValue]]) { |
594 |
[matrix selectCell: cell]; |
595 |
found = YES; |
596 |
} |
597 |
} |
598 |
|
599 |
if (act) { |
600 |
[matrix sendAction]; |
601 |
} |
602 |
|
603 |
return found; |
604 |
} |
605 |
|
606 |
- (void)selectMatrixCells:(NSArray *)cells sendAction:(BOOL)act |
607 |
{ |
608 |
int i; |
609 |
|
610 |
[matrix deselectAllCells]; |
611 |
|
612 |
for (i = 0; i < [cells count]; i++) { |
613 |
[matrix selectCell: [cells objectAtIndex: i]]; |
614 |
} |
615 |
|
616 |
if (act) { |
617 |
[matrix sendAction]; |
618 |
} |
619 |
} |
620 |
|
621 |
- (BOOL)selectFirstCell |
622 |
{ |
623 |
if (matrix && [[matrix cells] count]) { |
624 |
[matrix selectCellAtRow: 0 column: 0]; |
625 |
[matrix sendAction]; |
626 |
return YES; |
627 |
} |
628 |
return NO; |
629 |
} |
630 |
|
631 |
- (BOOL)selectCellWithPrefix:(NSString *)prefix |
632 |
{ |
633 |
if (matrix && [[matrix cells] count]) { |
634 |
int n = [matrix numberOfRows]; |
635 |
int s = [matrix selectedRow]; |
636 |
NSString *cellstr = nil; |
637 |
int i = 0; |
638 |
|
639 |
cellstr = [[matrix cellAtRow: s column: 0] stringValue]; |
640 |
|
641 |
if (([cellstr length] > 0) && ([cellstr hasPrefix: prefix])) { |
642 |
return YES; |
643 |
} |
644 |
|
645 |
for (i = s + 1; i < n; i++) { |
646 |
cellstr = [[matrix cellAtRow: i column: 0] stringValue]; |
647 |
|
648 |
if (([cellstr length] > 0) && ([cellstr hasPrefix: prefix])) { |
649 |
[matrix deselectAllCells]; |
650 |
[matrix selectCellAtRow: i column: 0]; |
651 |
[matrix scrollCellToVisibleAtRow: i column: 0]; |
652 |
[matrix sendAction]; |
653 |
return YES; |
654 |
} |
655 |
} |
656 |
|
657 |
for (i = 0; i < s; i++) { |
658 |
cellstr = [[matrix cellAtRow: i column: 0] stringValue]; |
659 |
|
660 |
if (([cellstr length] > 0) && ([cellstr hasPrefix: prefix])) { |
661 |
[matrix deselectAllCells]; |
662 |
[matrix selectCellAtRow: i column: 0]; |
663 |
[matrix scrollCellToVisibleAtRow: i column: 0]; |
664 |
[matrix sendAction]; |
665 |
return YES; |
666 |
} |
667 |
} |
668 |
} |
669 |
return NO; |
670 |
} |
671 |
|
672 |
- (void)selectIcon |
673 |
{ |
674 |
if (styleMask & GWColumnIconMask) { |
675 |
[icon select]; |
676 |
} |
677 |
} |
678 |
|
679 |
- (void)selectAll |
680 |
{ |
681 |
if (matrix && [[matrix cells] count]) { |
682 |
[matrix selectAll: nil]; |
683 |
[matrix sendAction]; |
684 |
} else { |
685 |
BColumn *col = [browser columnBeforeColumn: self]; |
686 |
|
687 |
if (col) { |
688 |
[col selectAll]; |
689 |
} |
690 |
} |
691 |
} |
692 |
|
693 |
- (NSArray *)selection |
694 |
{ |
695 |
NSArray *selected = [matrix selectedCells]; |
696 |
|
697 |
if (selected == nil) { |
698 |
return nil; |
699 |
|
700 |
} else { |
701 |
NSMutableArray *selection = [NSMutableArray array]; |
702 |
NSMutableArray *cellsnames = [NSMutableArray array]; |
703 |
int count = [selected count]; |
704 |
BOOL fileMissing = NO; |
705 |
int i; |
706 |
|
707 |
for (i = 0; i < count; i++) { |
708 |
NSString *cellname = [[selected objectAtIndex: i] stringValue]; |
709 |
NSString *cellpath = [path stringByAppendingPathComponent: cellname]; |
710 |
|
711 |
if ([gworkspace server: remoteHostName fileExistsAtPath: cellpath]) { |
712 |
[selection addObject: cellpath]; |
713 |
[cellsnames addObject: cellname]; |
714 |
} else { |
715 |
fileMissing = YES; |
716 |
} |
717 |
} |
718 |
|
719 |
if (fileMissing) { |
720 |
[matrix deselectAllCells]; |
721 |
if ([cellsnames count]) { |
722 |
[self selectMatrixCellsWithNames: cellsnames sendAction: YES]; |
723 |
} |
724 |
} |
725 |
|
726 |
if ([selection count] > 0) { |
727 |
return selection; |
728 |
} |
729 |
} |
730 |
|
731 |
return nil; |
732 |
} |
733 |
|
734 |
- (void)lockCellsWithNames:(NSArray *)names |
735 |
{ |
736 |
int i; |
737 |
BOOL found = NO; |
738 |
|
739 |
for (i = 0; i < [names count]; i++) { |
740 |
BCell *cell = [self cellWithName: [names objectAtIndex: i]]; |
741 |
if (cell != nil) { |
742 |
if ([cell isEnabled]) { |
743 |
[cell setEnabled: NO]; |
744 |
found = YES; |
745 |
} |
746 |
} |
747 |
} |
748 |
|
749 |
[matrix setNeedsDisplay: found]; |
750 |
} |
751 |
|
752 |
- (void)unLockCellsWithNames:(NSArray *)names |
753 |
{ |
754 |
int i; |
755 |
BOOL found = NO; |
756 |
|
757 |
for (i = 0; i < [names count]; i++) { |
758 |
BCell *cell = [self cellWithName: [names objectAtIndex: i]]; |
759 |
if (cell != nil) { |
760 |
if ([cell isEnabled] == NO) { |
761 |
[cell setEnabled: YES]; |
762 |
found = YES; |
763 |
} |
764 |
} |
765 |
} |
766 |
|
767 |
[matrix setNeedsDisplay: found]; |
768 |
} |
769 |
|
770 |
- (void)lock |
771 |
{ |
772 |
NSArray *cells; |
773 |
int i, count; |
774 |
|
775 |
if ((styleMask & GWColumnIconMask) && icon && ([icon isLocked] == NO)) { |
776 |
[icon setLocked: YES]; |
777 |
[icon setNeedsDisplay: YES]; |
778 |
[[icon label] setNeedsDisplay: YES]; |
779 |
} |
780 |
|
781 |
if (matrix == nil) { |
782 |
return; |
783 |
} |
784 |
|
785 |
cells = [matrix cells]; |
786 |
if (cells == nil) { |
787 |
return; |
788 |
} |
789 |
|
790 |
count = [cells count]; |
791 |
|
792 |
if (count) { |
793 |
for (i = 0; i < count; i++) { |
794 |
id cell = [cells objectAtIndex: i]; |
795 |
|
796 |
if ([cell isEnabled]) { |
797 |
[cell setEnabled: NO]; |
798 |
} |
799 |
} |
800 |
|
801 |
[matrix setNeedsDisplay: YES]; |
802 |
} |
803 |
} |
804 |
|
805 |
- (void)unLock |
806 |
{ |
807 |
NSArray *cells; |
808 |
int i, count; |
809 |
|
810 |
if ((styleMask & GWColumnIconMask) && icon && [icon isLocked]) { |
811 |
[icon setLocked: NO]; |
812 |
[icon setNeedsDisplay: YES]; |
813 |
[[icon label] setNeedsDisplay: YES]; |
814 |
} |
815 |
|
816 |
if (matrix == nil) { |
817 |
return; |
818 |
} |
819 |
|
820 |
cells = [matrix cells]; |
821 |
if (cells == nil) { |
822 |
return; |
823 |
} |
824 |
|
825 |
count = [cells count]; |
826 |
|
827 |
if (count) { |
828 |
for (i = 0; i < count; i++) { |
829 |
id cell = [cells objectAtIndex: i]; |
830 |
|
831 |
if ([cell isEnabled] == NO) { |
832 |
[cell setEnabled: YES]; |
833 |
} |
834 |
} |
835 |
|
836 |
[matrix setNeedsDisplay: count]; |
837 |
} |
838 |
} |
839 |
|
840 |
- (void)adjustMatrix |
841 |
{ |
842 |
[matrix setCellSize: NSMakeSize([scroll contentSize].width, cellsHeight)]; |
843 |
[matrix sizeToCells]; |
844 |
} |
845 |
|
846 |
- (void)updateIcon |
847 |
{ |
848 |
if ((styleMask & GWColumnIconMask) && icon) { |
849 |
[icon setPaths: [browser selectionInColumnBeforeColumn: self]]; |
850 |
|
851 |
if ((matrix == nil) || ([[matrix selectedCells] count] == 0)) { |
852 |
[self setLeaf: YES]; |
853 |
} |
854 |
} |
855 |
} |
856 |
|
857 |
- (id)cellWithName:(NSString *)name |
858 |
{ |
859 |
NSArray *cells = [matrix cells]; |
860 |
int i = 0; |
861 |
|
862 |
for (i = 0; i < [cells count]; i++) { |
863 |
id cell = [cells objectAtIndex: i]; |
864 |
if ([[cell stringValue] isEqualToString: name]) { |
865 |
return cell; |
866 |
} |
867 |
} |
868 |
|
869 |
return nil; |
870 |
} |
871 |
|
872 |
- (void)setLeaf:(BOOL)value |
873 |
{ |
874 |
isLeaf = value; |
875 |
|
876 |
if (icon == nil) { |
877 |
return; |
878 |
} else { |
879 |
if ([icon isBranch] == value) { |
880 |
[icon setBranch: !value]; |
881 |
|
882 |
if (isLeaf && matrix) { |
883 |
[matrix deselectAllCells]; |
884 |
} |
885 |
} |
886 |
} |
887 |
} |
888 |
|
889 |
- (Browser2 *)browser |
890 |
{ |
891 |
return browser; |
892 |
} |
893 |
|
894 |
- (NSMatrix *)cmatrix |
895 |
{ |
896 |
return matrix; |
897 |
} |
898 |
|
899 |
- (NSView *)iconView |
900 |
{ |
901 |
return iconView; |
902 |
} |
903 |
|
904 |
- (BIcon *)myIcon |
905 |
{ |
906 |
return icon; |
907 |
} |
908 |
|
909 |
- (NSTextField *)iconLabel |
910 |
{ |
911 |
return (icon ? [icon label] : nil); |
912 |
} |
913 |
|
914 |
- (NSString *)currentPath |
915 |
{ |
916 |
return path; |
917 |
} |
918 |
|
919 |
- (int)index |
920 |
{ |
921 |
return index; |
922 |
} |
923 |
|
924 |
- (BOOL)isLoaded |
925 |
{ |
926 |
return isLoaded; |
927 |
} |
928 |
|
929 |
- (BOOL)isSelected |
930 |
{ |
931 |
if (isLoaded && matrix) { |
932 |
return ([matrix selectedCell] ? YES : NO); |
933 |
} |
934 |
|
935 |
return NO; |
936 |
} |
937 |
|
938 |
- (BOOL)isLeaf |
939 |
{ |
940 |
return isLeaf; |
941 |
} |
942 |
|
943 |
- (void)doClick:(id)sender |
944 |
{ |
945 |
[browser clickInMatrixOfColumn: self]; |
946 |
} |
947 |
|
948 |
- (void)doDoubleClick:(id)sender |
949 |
{ |
950 |
[browser doubleClickInMatrixOfColumn: self]; |
951 |
} |
952 |
|
953 |
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender |
954 |
inMatrixCell:(id)aCell |
955 |
{ |
956 |
BCell *cell; |
957 |
NSPasteboard *pb; |
958 |
NSData *pbData; |
959 |
NSDragOperation sourceDragMask; |
960 |
NSArray *sourcePaths; |
961 |
NSString *fromPath; |
962 |
NSString *targetPath; |
963 |
NSString *buff; |
964 |
int count; |
965 |
|
966 |
cell = (BCell *)aCell; |
967 |
|
968 |
if ([cell isLeaf] || ([cell isEnabled] == NO)) { |
969 |
return NSDragOperationNone; |
970 |
} |
971 |
|
972 |
pb = [sender draggingPasteboard]; |
973 |
|
974 |
if (isRemote == NO) { |
975 |
if ([[pb types] indexOfObject: NSFilenamesPboardType] == NSNotFound) { |
976 |
return NSDragOperationNone; |
977 |
} |
978 |
} else { |
979 |
if ([[pb types] indexOfObject: GWRemoteFilenamesPboardType] == NSNotFound) { |
980 |
return NSDragOperationNone; |
981 |
} |
982 |
} |
983 |
|
984 |
if (isRemote == NO) { |
985 |
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
986 |
} else { |
987 |
NSDictionary *dndDict; |
988 |
|
989 |
pbData = [pb dataForType: GWRemoteFilenamesPboardType]; |
990 |
dndDict = [NSUnarchiver unarchiveObjectWithData: pbData]; |
991 |
|
992 |
sourcePaths = [dndDict objectForKey: @"paths"]; |
993 |
} |
994 |
|
995 |
count = [sourcePaths count]; |
996 |
|
997 |
if (count == 0) { |
998 |
return NSDragOperationNone; |
999 |
} |
1000 |
|
1001 |
fromPath = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent]; |
1002 |
targetPath = [path stringByAppendingPathComponent: [cell stringValue]]; |
1003 |
|
1004 |
if ([targetPath isEqualToString: fromPath] |
1005 |
|| [sourcePaths containsObject: targetPath]) { |
1006 |
return NSDragOperationNone; |
1007 |
} |
1008 |
|
1009 |
if ([gworkspace server: remoteHostName isWritableFileAtPath: targetPath] == NO) { |
1010 |
return NSDragOperationNone; |
1011 |
} |
1012 |
|
1013 |
buff = [NSString stringWithString: targetPath]; |
1014 |
while (1) { |
1015 |
if ([sourcePaths containsObject: buff]) { |
1016 |
return NSDragOperationNone; |
1017 |
} |
1018 |
if ([buff isEqualToString: fixPath(@"/", 0)] == YES) { |
1019 |
break; |
1020 |
} |
1021 |
buff = [buff stringByDeletingLastPathComponent]; |
1022 |
} |
1023 |
|
1024 |
sourceDragMask = [sender draggingSourceOperationMask]; |
1025 |
|
1026 |
if (sourceDragMask == NSDragOperationCopy) { |
1027 |
return NSDragOperationCopy; |
1028 |
} else if (sourceDragMask == NSDragOperationLink) { |
1029 |
return NSDragOperationLink; |
1030 |
} else { |
1031 |
return NSDragOperationAll; |
1032 |
} |
1033 |
|
1034 |
return NSDragOperationNone; |
1035 |
} |
1036 |
|
1037 |
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender |
1038 |
inMatrixCell:(id)aCell |
1039 |
{ |
1040 |
NSPasteboard *pb; |
1041 |
NSDragOperation sourceDragMask; |
1042 |
NSData *pbData; |
1043 |
NSArray *sourcePaths; |
1044 |
NSString *targetPath; |
1045 |
NSString *operation, *source; |
1046 |
NSMutableArray *files; |
1047 |
NSMutableDictionary *opDict; |
1048 |
NSString *trashPath; |
1049 |
NSString *sourceHost; |
1050 |
BCell *cell; |
1051 |
int i; |
1052 |
|
1053 |
cell = (BCell *)aCell; |
1054 |
if ([cell isLeaf] || ([cell isEnabled] == NO)) { |
1055 |
return; |
1056 |
} |
1057 |
|
1058 |
sourceDragMask = [sender draggingSourceOperationMask]; |
1059 |
pb = [sender draggingPasteboard]; |
1060 |
|
1061 |
if (isRemote == NO) { |
1062 |
if ([[pb types] indexOfObject: NSFilenamesPboardType] == NSNotFound) { |
1063 |
return; |
1064 |
} |
1065 |
} else { |
1066 |
if ([[pb types] indexOfObject: GWRemoteFilenamesPboardType] == NSNotFound) { |
1067 |
return; |
1068 |
} |
1069 |
} |
1070 |
|
1071 |
sourceHost = nil; |
1072 |
|
1073 |
if (isRemote == NO) { |
1074 |
sourcePaths = [pb propertyListForType: NSFilenamesPboardType]; |
1075 |
} else { |
1076 |
NSDictionary *dndDict; |
1077 |
|
1078 |
pbData = [pb dataForType: GWRemoteFilenamesPboardType]; |
1079 |
dndDict = [NSUnarchiver unarchiveObjectWithData: pbData]; |
1080 |
|
1081 |
sourcePaths = [dndDict objectForKey: @"paths"]; |
1082 |
sourceHost = [dndDict objectForKey: @"host"]; |
1083 |
} |
1084 |
|
1085 |
source = [[sourcePaths objectAtIndex: 0] stringByDeletingLastPathComponent]; |
1086 |
targetPath = [path stringByAppendingPathComponent: [cell stringValue]]; |
1087 |
|
1088 |
if (isRemote == NO) { |
1089 |
trashPath = [gworkspace trashPath]; |
1090 |
|
1091 |
if ([source isEqualToString: trashPath]) { |
1092 |
operation = GWorkspaceRecycleOutOperation; |
1093 |
} else { |
1094 |
if (sourceDragMask == NSDragOperationCopy) { |
1095 |
operation = NSWorkspaceCopyOperation; |
1096 |
} else if (sourceDragMask == NSDragOperationLink) { |
1097 |
operation = NSWorkspaceLinkOperation; |
1098 |
} else { |
1099 |
operation = NSWorkspaceMoveOperation; |
1100 |
} |
1101 |
} |
1102 |
} else { |
1103 |
if (sourceDragMask == NSDragOperationCopy) { |
1104 |
operation = NSWorkspaceCopyOperation; |
1105 |
} else if (sourceDragMask == NSDragOperationLink) { |
1106 |
operation = NSWorkspaceLinkOperation; |
1107 |
} else { |
1108 |
operation = NSWorkspaceMoveOperation; |
1109 |
} |
1110 |
} |
1111 |
|
1112 |
files = [NSMutableArray arrayWithCapacity: 1]; |
1113 |
for(i = 0; i < [sourcePaths count]; i++) { |
1114 |
[files addObject: [[sourcePaths objectAtIndex: i] lastPathComponent]]; |
1115 |
} |
1116 |
|
1117 |
opDict = [NSMutableDictionary dictionaryWithCapacity: 4]; |
1118 |
[opDict setObject: operation forKey: @"operation"]; |
1119 |
[opDict setObject: source forKey: @"source"]; |
1120 |
[opDict setObject: targetPath forKey: @"destination"]; |
1121 |
[opDict setObject: files forKey: @"files"]; |
1122 |
|
1123 |
[gworkspace performFileOperationWithDictionary: opDict |
1124 |
fromSourceHost: sourceHost |
1125 |
toDestinationHost: remoteHostName]; |
1126 |
} |
1127 |
|
1128 |
- (void)setFrame:(NSRect)frameRect |
1129 |
{ |
1130 |
NSRect r = NSMakeRect(0, 0, frameRect.size.width, frameRect.size.height); |
1131 |
|
1132 |
CHECKRECT (frameRect); |
1133 |
[super setFrame: frameRect]; |
1134 |
|
1135 |
CHECKRECT (r); |
1136 |
[scroll setFrame: r]; |
1137 |
|
1138 |
if ((styleMask & GWColumnIconMask) && icon) { |
1139 |
NSRect icnRect = NSMakeRect(0, ICON_VOFFSET, |
1140 |
[iconView frame].size.width, ICON_FRAME_HEIGHT); |
1141 |
|
1142 |
CHECKRECT (icnRect); |
1143 |
[icon setFrame: icnRect]; |
1144 |
[iconView setNeedsDisplay: YES]; |
1145 |
} |
1146 |
|
1147 |
if (matrix) { |
1148 |
[self adjustMatrix]; |
1149 |
} |
1150 |
} |
1151 |
|
1152 |
@end |
1153 |
|
1154 |
// |
1155 |
// BIcon Delegate Methods |
1156 |
// |
1157 |
@implementation BColumn (BIconDelegateMethods) |
1158 |
|
1159 |
- (void)icon:(BIcon *)sender setFrameOfLabel:(NSTextField *)label |
1160 |
{ |
1161 |
float icnwidth, labwidth, labxpos, labypos; |
1162 |
NSRect labRect; |
1163 |
|
1164 |
icnwidth = [sender frame].size.width; |
1165 |
labwidth = [label frame].size.width; |
1166 |
labypos = [sender frame].origin.y - 14; |
1167 |
|
1168 |
if(icnwidth > labwidth) { |
1169 |
labxpos = [sender frame].origin.x + ((icnwidth - labwidth) / 2); |
1170 |
} else { |
1171 |
labxpos = [sender frame].origin.x - ((labwidth - icnwidth) / 2); |
1172 |
} |
1173 |
|
1174 |
labRect = NSMakeRect(labxpos, labypos, labwidth, 14); |
1175 |
CHECKRECT (labRect); |
1176 |
[label setFrame: labRect]; |
1177 |
[label setNeedsDisplay: YES]; |
1178 |
} |
1179 |
|
1180 |
- (void)unselectOtherIcons:(BIcon *)selicon |
1181 |
{ |
1182 |
NSArray *otherCols = [browser columnsDifferentFromColumn: self]; |
1183 |
int i; |
1184 |
|
1185 |
for (i = 0; i < [otherCols count]; i++) { |
1186 |
BIcon *icn = [[otherCols objectAtIndex: i] myIcon]; |
1187 |
|
1188 |
if ([icn isSelect]) { |
1189 |
[icn unselect]; |
1190 |
} |
1191 |
} |
1192 |
} |
1193 |
|
1194 |
- (void)unselectNameEditor |
1195 |
{ |
1196 |
[browser unselectNameEditor]; |
1197 |
} |
1198 |
|
1199 |
- (void)restoreSelectionAfterDndOfIcon:(BIcon *)dndicon |
1200 |
{ |
1201 |
[browser restoreSelectionAfterDndOfIcon: dndicon]; |
1202 |
} |
1203 |
|
1204 |
- (void)clickOnIcon:(BIcon *)clicked |
1205 |
{ |
1206 |
[self setLeaf: YES]; |
1207 |
[browser clickOnIcon: icon ofColumn: self]; |
1208 |
} |
1209 |
|
1210 |
- (void)doubleClickOnIcon:(BIcon *)clicked newViewer:(BOOL)isnew |
1211 |
{ |
1212 |
[browser doubleClickOnIcon: clicked ofColumn: self newViewer: isnew]; |
1213 |
} |
1214 |
|
1215 |
@end |
1216 |
|
1217 |
|