/[gnustep]/gnustep/usr-apps/gworkspace/GWLib/BColumn.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/GWLib/BColumn.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Mon Sep 29 13:20:28 2003 UTC (20 years, 7 months ago) by esersale
Branch: MAIN
Changes since 1.2: +44 -134 lines
*** empty log message ***

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

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