/[gnustep]/gnustep/usr-apps/gworkspace/Viewers/IconsViewer/IconsViewer.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/Viewers/IconsViewer/IconsViewer.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Tue Sep 30 15:38:06 2003 UTC (20 years, 6 months ago) by esersale
Branch: MAIN
Changes since 1.3: +7 -14 lines
*** empty log message ***

1 /* IconsViewer.m
2 *
3 * Copyright (C) 2003 Free Software Foundation, Inc.
4 *
5 * Author: Enrico Sersale <enrico@imago.ro>
6 * Date: August 2001
7 *
8 * This file is part of the GNUstep GWorkspace application
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25
26 #include <Foundation/Foundation.h>
27 #include <AppKit/AppKit.h>
28 #ifdef GNUSTEP
29 #include "GWLib.h"
30 #include "GWProtocol.h"
31 #include "GWFunctions.h"
32 #include "GWNotifications.h"
33 #else
34 #include <GWorkspace/GWLib.h>
35 #include <GWorkspace/GWProtocol.h>
36 #include <GWorkspace/GWFunctions.h>
37 #include <GWorkspace/GWNotifications.h>
38 #endif
39 #include "IconsViewer.h"
40 #include "IconsPath.h"
41 #include "PathIcon.h"
42 #include "IconsPanel.h"
43 #include "GWScrollView.h"
44 #include "IconsViewerPref.h"
45 #include "GNUstep.h"
46
47 #define ICNWIDTH 64
48
49 @implementation IconsViewer
50
51 - (void)dealloc
52 {
53 [[NSNotificationCenter defaultCenter] removeObserver: self];
54 TEST_RELEASE (rootPath);
55 TEST_RELEASE (lastPath);
56 TEST_RELEASE (selectedPaths);
57 TEST_RELEASE (savedSelection);
58 TEST_RELEASE (watchedPaths);
59 TEST_RELEASE (iconsPath);
60 TEST_RELEASE (pathsScroll);
61 TEST_RELEASE (panelScroll);
62 TEST_RELEASE (panel);
63 TEST_RELEASE (prefs);
64 [super dealloc];
65 }
66
67 - (id)init
68 {
69 self = [super initWithFrame: NSZeroRect];
70
71 if (self) {
72 usesShelf = YES;
73 rootPath = nil;
74 lastPath = nil;
75 selectedPaths = nil;
76 watchedPaths = nil;
77 iconsPath = nil;
78 pathsScroll = nil;
79 panelScroll = nil;
80 panel = nil;
81 prefs = nil;
82 }
83
84 return self;
85 }
86
87 //
88 // NSCopying
89 //
90 - (id)copyWithZone:(NSZone *)zone
91 {
92 IconsViewer *vwr = [[IconsViewer alloc] init];
93 return vwr;
94 }
95
96 //
97 // ViewersProtocol
98 //
99 - (void)setRootPath:(NSString *)rpath
100 viewedPath:(NSString *)vpath
101 selection:(NSArray *)selection
102 delegate:(id)adelegate
103 viewApps:(BOOL)canview
104 {
105 int colswidth, winwidth;
106
107 fm = [NSFileManager defaultManager];
108 [self checkUsesShelf];
109 [self setDelegate: adelegate];
110 ASSIGN (rootPath, rpath);
111 viewsapps = canview;
112 [self setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
113
114 colswidth = [delegate browserColumnsWidth];
115 resizeIncrement = colswidth;
116 winwidth = [delegate getWindowFrameWidth];
117 columns = (int)winwidth / resizeIncrement;
118 columnsWidth = (winwidth - 16) / columns;
119 autoSynchronize = YES;
120
121 TEST_RELEASE (iconsPath);
122
123 if (pathsScroll != nil) {
124 [pathsScroll removeFromSuperview];
125 RELEASE (pathsScroll);
126 }
127
128 pathsScroll = [[GWScrollView alloc] init];
129 [pathsScroll setBorderType: NSBezelBorder];
130 [pathsScroll setHasHorizontalScroller: YES];
131 [pathsScroll setHasVerticalScroller: NO];
132 [pathsScroll setLineScroll: columnsWidth];
133 [pathsScroll setAutoresizingMask: NSViewWidthSizable];
134 [pathsScroll setDelegate: self];
135
136 iconsPath = [[IconsPath alloc] initWithRootAtPath: rootPath
137 columnsWidth: columnsWidth delegate: self];
138
139 [pathsScroll setDocumentView: iconsPath];
140 [self addSubview: pathsScroll];
141
142 TEST_RELEASE (panel);
143
144 if (panelScroll != nil) {
145 [panelScroll removeFromSuperview];
146 RELEASE (panelScroll);
147 }
148
149 panelScroll = [NSScrollView new];
150 [panelScroll setBorderType: NSBezelBorder];
151 [panelScroll setHasHorizontalScroller: YES];
152 [panelScroll setHasVerticalScroller: YES];
153 [panelScroll setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
154 [self addSubview: panelScroll];
155
156 panel = [[IconsPanel alloc] initAtPath: rootPath delegate: self];
157 [panelScroll setDocumentView: panel];
158
159 [[NSNotificationCenter defaultCenter] removeObserver: self];
160
161 [[NSNotificationCenter defaultCenter] addObserver: self
162 selector: @selector(fileSystemWillChange:)
163 name: GWFileSystemWillChangeNotification
164 object: nil];
165
166 [[NSNotificationCenter defaultCenter] addObserver: self
167 selector: @selector(fileSystemDidChange:)
168 name: GWFileSystemDidChangeNotification
169 object: nil];
170
171 [[NSNotificationCenter defaultCenter] addObserver: self
172 selector: @selector(sortTypeDidChange:)
173 name: GWSortTypeDidChangeNotification
174 object: nil];
175
176 if (watchedPaths != nil) {
177 [self unsetWatchers];
178 DESTROY (watchedPaths);
179 }
180
181 [self setSelectedPaths: [NSArray arrayWithObject: rootPath]];
182
183 if (vpath) {
184 [self setSelectedPaths: [NSArray arrayWithObject: vpath]];
185 [panel setPath: vpath];
186 [panel scrollFirstIconToVisible];
187
188 if (selection && [selection count]) {
189 [panel selectIconsWithPaths: selection];
190 }
191 [delegate addPathToHistory: [NSArray arrayWithObject: vpath]];
192 } else {
193 [delegate addPathToHistory: [NSArray arrayWithObject: rootPath]];
194 }
195
196 [delegate updateTheInfoString];
197
198 firstResize = YES;
199 }
200
201 - (NSString *)menuName
202 {
203 return @"Icon";
204 }
205
206 - (NSString *)shortCut
207 {
208 return @"i";
209 }
210
211 - (BOOL)usesShelf
212 {
213 return usesShelf;
214 }
215
216 - (NSSize)resizeIncrements
217 {
218 return NSZeroSize;
219 }
220
221 - (NSImage *)miniicon
222 {
223 NSBundle *bundle = [NSBundle bundleForClass: [self class]];
224 NSString *imgpath = [bundle pathForResource: @"miniwindow" ofType: @"tiff"];
225 NSImage *img = [[NSImage alloc] initWithContentsOfFile: imgpath];
226 return AUTORELEASE (img);
227 }
228
229 - (BOOL)hasPreferences
230 {
231 return YES;
232 }
233
234 - (id)prefController
235 {
236 if (prefs == nil) {
237 prefs = [[IconsViewerPref alloc] init];
238 }
239
240 return prefs;
241 }
242
243 - (void)setSelectedPaths:(NSArray *)paths
244 {
245 NSString *newPath;
246 NSArray *components;
247 NSMutableArray *wpaths;
248 NSString *s;
249 BOOL isDir;
250 int i, j;
251
252 if (([paths count] == 0)
253 || ([paths isEqualToArray: selectedPaths])) {
254 return;
255 }
256
257 ASSIGN (selectedPaths, paths);
258 [delegate setTheSelectedPaths: paths];
259
260 [self synchronize];
261
262 newPath = [paths objectAtIndex: 0];
263 [fm fileExistsAtPath: newPath isDirectory: &isDir];
264 if ((isDir == NO) || ([paths count] > 1)) {
265 newPath = [newPath stringByDeletingLastPathComponent];
266 } else {
267 if (([GWLib isPakageAtPath: newPath]) && (viewsapps == NO)) {
268 newPath = [newPath stringByDeletingLastPathComponent];
269 }
270 }
271
272 if (lastPath && [lastPath isEqual: newPath]) {
273 return;
274 } else {
275 ASSIGN (lastPath, newPath);
276 }
277
278 components = [newPath pathComponents];
279 wpaths = [NSMutableArray arrayWithCapacity: 1];
280 s = [NSString string];
281
282 for (i = 0; i < [components count]; i++) {
283 s = [s stringByAppendingPathComponent: [components objectAtIndex: i]];
284 [wpaths addObject: s];
285 }
286
287 if (watchedPaths == nil) {
288 watchedPaths = [wpaths mutableCopy];
289 [self setWatchers];
290
291 } else {
292 int count = [wpaths count];
293
294 for (i = 0; i < [watchedPaths count]; i++) {
295 NSString *s1, *s2;
296
297 s1 = [watchedPaths objectAtIndex: i];
298
299 if (count > i) {
300 s2 = [wpaths objectAtIndex: i];
301 } else {
302 i = count;
303 break;
304 }
305
306 if ([s1 isEqualToString: s2] == NO) {
307 break;
308 }
309 }
310
311 for (j = i; j < [watchedPaths count]; j++) {
312 [self unsetWatcherForPath: [watchedPaths objectAtIndex: j]];
313 }
314
315 for (j = i; j < [wpaths count]; j++) {
316 [self setWatcherForPath: [wpaths objectAtIndex: j]];
317 }
318
319 TEST_RELEASE (watchedPaths);
320 watchedPaths = [wpaths mutableCopy];
321 }
322 }
323
324 - (void)setCurrentSelection:(NSArray *)paths
325 {
326 NSString *path;
327 NSArray *selection;
328
329 if ([paths count] == 0) {
330 return;
331 }
332
333 [self setSelectedPaths: paths];
334
335 path = [paths objectAtIndex: 0];
336
337 if ([paths count] > 1) {
338 path = [path stringByDeletingLastPathComponent];
339 selection = [NSArray arrayWithArray: selectedPaths];
340 } else {
341 BOOL isdir;
342
343 [fm fileExistsAtPath: path isDirectory: &isdir];
344
345 if (isdir == NO) {
346 path = [path stringByDeletingLastPathComponent];
347 selection = [NSArray arrayWithArray: selectedPaths];
348 } else {
349 if ([GWLib isPakageAtPath: path] && (viewsapps == NO)) {
350 path = [path stringByDeletingLastPathComponent];
351 selection = [NSArray arrayWithArray: selectedPaths];
352 } else {
353 selection = [NSArray array];
354 }
355 }
356 }
357
358 [panel setPath: path];
359 [panel scrollFirstIconToVisible];
360 [panel selectIconsWithPaths: selection];
361 [panel setNeedsDisplay: YES];
362 [delegate updateTheInfoString];
363 }
364
365 - (NSPoint)positionForSlidedImage
366 {
367 NSPoint p = [iconsPath positionForSlidedImage];
368 p.y += [pathsScroll frame].origin.y;
369 return [[self window] convertBaseToScreen: p];
370 }
371
372 - (void)selectAll
373 {
374 [panel selectAllIcons];
375 }
376
377 - (NSArray *)selectedPaths
378 {
379 return selectedPaths;
380 }
381
382 - (NSString *)currentViewedPath
383 {
384 return [panel currentPath];
385 }
386
387 - (NSPoint)locationOfIconForPath:(NSString *)path
388 {
389 if ([selectedPaths containsObject: path]) {
390 NSPoint p = [iconsPath positionOfLastIcon];
391
392 if (p.x > ([self frame].size.width - ICNWIDTH)) {
393 return NSZeroPoint;
394 }
395
396 p.y += [pathsScroll frame].origin.y;
397 return [self convertPoint: p toView: nil];
398 }
399
400 return NSZeroPoint;
401 }
402
403 - (void)unsetWatchers
404 {
405 int i;
406
407 [[NSNotificationCenter defaultCenter] removeObserver: self
408 name: GWFileWatcherFileDidChangeNotification object: nil];
409
410 for (i = 0; i < [watchedPaths count]; i++) {
411 [self unsetWatcherForPath: [watchedPaths objectAtIndex: i]];
412 }
413 }
414
415 - (void)setResizeIncrement:(int)increment
416 {
417 int winwidth = [delegate getWindowFrameWidth];
418
419 resizeIncrement = [delegate browserColumnsWidth];
420 columns = (int)winwidth / resizeIncrement;
421 columnsWidth = (winwidth - 16) / columns;
422
423 [pathsScroll setLineScroll: columnsWidth];
424 [iconsPath setColumnWidth: columnsWidth];
425 }
426
427 - (void)setAutoSynchronize:(BOOL)value
428 {
429 autoSynchronize = value;
430 }
431
432 - (void)thumbnailsDidChangeInPaths:(NSArray *)paths
433 {
434 if (paths == nil) {
435 [panel makeFileIcons];
436 [panel resizeWithOldSuperviewSize: [panel frame].size];
437 [[iconsPath lastIcon] renewIcon];
438 } else {
439 int i;
440
441 for (i = 0; i < [paths count]; i++) {
442 NSString *dir = [paths objectAtIndex: i];
443
444 if ([panel isOnBasePath: dir withFiles: nil]) {
445 [panel reloadFromPath: dir];
446 [[iconsPath lastIcon] renewIcon];
447 [self setNeedsDisplay: YES];
448 }
449 }
450 }
451 }
452
453 - (id)viewerView
454 {
455 return panel;
456 }
457
458 - (BOOL)viewsApps
459 {
460 return viewsapps;
461 }
462
463 - (id)delegate
464 {
465 return delegate;
466 }
467
468 - (void)setDelegate:(id)anObject
469 {
470 delegate = anObject;
471 }
472
473 //
474 // End of ViewersProtocol
475 //
476
477 - (void)checkUsesShelf
478 {
479 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
480 usesShelf = ![defaults boolForKey: @"viewersDontUsesShelf"];
481 }
482
483 - (void)validateRootPathAfterOperation:(NSDictionary *)opdict
484 {
485 if ([rootPath isEqualToString: fixPath(@"/", 0)]) {
486 return;
487 } else {
488 NSString *operation = [opdict objectForKey: @"operation"];
489 NSString *source = [opdict objectForKey: @"source"];
490 NSArray *files = [opdict objectForKey: @"files"];
491 int i;
492
493 if (operation == NSWorkspaceMoveOperation
494 || operation == NSWorkspaceDestroyOperation
495 || operation == GWorkspaceRenameOperation
496 || operation == NSWorkspaceRecycleOperation
497 || operation == GWorkspaceRecycleOutOperation
498 || operation == GWorkspaceEmptyRecyclerOperation) {
499
500 if (operation == GWorkspaceRenameOperation) {
501 files = [NSArray arrayWithObject: [source lastPathComponent]];
502 source = [source stringByDeletingLastPathComponent];
503 }
504
505 for (i = 0; i < [files count]; i++) {
506 NSString *fpath = [source stringByAppendingPathComponent: [files objectAtIndex: i]];
507
508 if ((subPathOfPath(fpath, rootPath) == YES)
509 || ([fpath isEqualToString: rootPath] == YES)) {
510 [self closeNicely];
511 break;
512 }
513 }
514 }
515 }
516 }
517
518 - (void)fileSystemWillChange:(NSNotification *)notification
519 {
520 NSDictionary *dict = (NSDictionary *)[notification object];
521 NSString *operation = [dict objectForKey: @"operation"];
522 NSString *source = [dict objectForKey: @"source"];
523 NSString *destination = [dict objectForKey: @"destination"];
524 NSArray *files = [dict objectForKey: @"files"];
525
526 [self validateRootPathAfterOperation: dict];
527
528 [delegate startIndicatorForOperation: operation];
529
530 if (operation == NSWorkspaceMoveOperation
531 || operation == NSWorkspaceCopyOperation
532 || operation == NSWorkspaceLinkOperation
533 || operation == NSWorkspaceDuplicateOperation
534 || operation == NSWorkspaceRecycleOperation
535 || operation == GWorkspaceRecycleOutOperation) {
536
537 if ([panel isOnBasePath: destination withFiles: files]) {
538 [self unsetWatchersFromPath: destination];
539
540 [panel extendSelectionWithDimmedFiles: files
541 startingAtPath: destination];
542
543 [iconsPath lockIconsFromPath: destination];
544 }
545 }
546
547 if (operation == GWorkspaceRenameOperation) {
548 NSString *dest = [destination stringByDeletingLastPathComponent];
549
550 if ([panel isOnBasePath: dest withFiles: nil]) {
551 [self unsetWatchersFromPath: dest];
552 }
553 }
554
555 if (operation == GWorkspaceCreateFileOperation
556 || operation == GWorkspaceCreateDirOperation) {
557 if ([panel isOnBasePath: destination withFiles: nil]) {
558 [self unsetWatchersFromPath: destination];
559 }
560 }
561
562 if (operation == NSWorkspaceMoveOperation
563 || operation == NSWorkspaceDestroyOperation
564 || operation == NSWorkspaceRecycleOperation
565 || operation == GWorkspaceRecycleOutOperation
566 || operation == GWorkspaceEmptyRecyclerOperation) {
567
568 if ([panel isOnBasePath: source withFiles: files]) {
569 [self unsetWatchersFromPath: source];
570
571 [panel extendSelectionWithDimmedFiles: files
572 startingAtPath: source];
573
574 [iconsPath lockIconsFromPath: source];
575 }
576 }
577 }
578
579 - (void)fileSystemDidChange:(NSNotification *)notification
580 {
581 NSMutableDictionary *dict;
582 NSString *operation, *source, *destination;
583 NSArray *files;
584
585 dict = [NSMutableDictionary dictionaryWithCapacity: 1];
586 [dict addEntriesFromDictionary: (NSDictionary *)[notification object]];
587
588 operation = [dict objectForKey: @"operation"];
589 source = [dict objectForKey: @"source"];
590 destination = [dict objectForKey: @"destination"];
591 files = [dict objectForKey: @"files"];
592
593 [delegate stopIndicatorForOperation: operation];
594
595 if (operation == NSWorkspaceMoveOperation
596 || operation == NSWorkspaceCopyOperation
597 || operation == NSWorkspaceLinkOperation
598 || operation == NSWorkspaceDuplicateOperation
599 || operation == NSWorkspaceRecycleOperation
600 || operation == GWorkspaceRecycleOutOperation) {
601
602 if ([panel isOnBasePath: destination withFiles: files]) {
603 [iconsPath unlockIconsFromPath: destination];
604 [panel reloadFromPath: destination];
605 [self reSetWatchersFromPath: destination];
606 }
607 }
608
609 if (operation == NSWorkspaceMoveOperation
610 || operation == NSWorkspaceDestroyOperation
611 || operation == NSWorkspaceRecycleOperation
612 || operation == GWorkspaceRecycleOutOperation
613 || operation == GWorkspaceEmptyRecyclerOperation) {
614
615 if ([panel isOnBasePath: source withFiles: files]) {
616 [iconsPath unlockIconsFromPath: source];
617 [panel reloadFromPath: source];
618 [self reSetWatchersFromPath: source];
619 }
620 }
621
622 if (operation == GWorkspaceRenameOperation) {
623 NSString *dest = [destination stringByDeletingLastPathComponent];
624
625 if ([panel isOnBasePath: dest withFiles: nil]) {
626 [panel reloadFromPath: dest];
627
628 if ([[self window] isKeyWindow]) {
629 [panel selectIconWithPath: destination];
630 }
631
632 [self reSetWatchersFromPath: dest];
633 }
634 }
635
636 if (operation == GWorkspaceCreateFileOperation
637 || operation == GWorkspaceCreateDirOperation) {
638
639 if ([panel isOnBasePath: destination withFiles: nil]) {
640 [panel reloadFromPath: destination];
641
642 if ([[self window] isKeyWindow]) {
643 NSString *fileName = [files objectAtIndex: 0];
644 NSString *filePath = [destination stringByAppendingPathComponent: fileName];
645
646 [self setCurrentSelection: [NSArray arrayWithObject: destination]];
647
648 [panel selectIconWithPath: filePath];
649 [self synchronize];
650 }
651
652 [self reSetWatchersFromPath: destination];
653 }
654 }
655
656 [delegate updateTheInfoString];
657 [self setNeedsDisplay: YES];
658 }
659
660 - (void)sortTypeDidChange:(NSNotification *)notification
661 {
662 NSString *notifPath = [notification object];
663
664 if (notifPath != nil) {
665 if ([[panel currentPath] isEqualToString: notifPath]) {
666 [panel makeFileIcons];
667 }
668 } else {
669 [panel makeFileIcons];
670 }
671 [panel resizeWithOldSuperviewSize: [panel frame].size];
672 }
673
674 - (void)watcherNotification:(NSNotification *)notification
675 {
676 NSDictionary *notifdict = (NSDictionary *)[notification object];
677 NSString *path = [notifdict objectForKey: @"path"];
678
679 if ([watchedPaths containsObject: path] == NO) {
680 return;
681
682 } else {
683 NSString *event = [notifdict objectForKey: @"event"];
684
685 if (event == GWWatchedDirectoryDeleted) {
686 if ((subPathOfPath(path, rootPath)) || ([path isEqualToString: rootPath])) {
687 [self closeNicely];
688 return;
689 } else {
690 NSString *s = [path stringByDeletingLastPathComponent];
691
692 [self unsetWatcherForPath: path];
693
694 if ([panel isOnBasePath: s withFiles: nil]) {
695 [panel reloadFromPath: s];
696 [self setNeedsDisplay: YES];
697 }
698
699 return;
700 }
701 }
702
703 if (event == GWFileDeletedInWatchedDirectory) {
704 if ([path isEqualToString: [panel currentPath]]) {
705 [panel reloadFromPath: path];
706 [self setNeedsDisplay: YES];
707 return;
708 }
709 }
710
711 if (event == GWFileCreatedInWatchedDirectory) {
712 if ([path isEqualToString: [panel currentPath]]) {
713 [panel addIconsWithNames: [notifdict objectForKey: @"files"]
714 dimmed: NO];
715 }
716 }
717 }
718
719 [delegate updateTheInfoString];
720 [self setNeedsDisplay: YES];
721 }
722
723 - (void)setWatchers
724 {
725 int i;
726
727 for (i = 0; i < [watchedPaths count]; i++) {
728 [self setWatcherForPath: [watchedPaths objectAtIndex: i]];
729 }
730
731 [[NSNotificationCenter defaultCenter] addObserver: self
732 selector: @selector(watcherNotification:)
733 name: GWFileWatcherFileDidChangeNotification
734 object: nil];
735 }
736
737 - (void)setWatcherForPath:(NSString *)path
738 {
739 [GWLib addWatcherForPath: path];
740 }
741
742 - (void)unsetWatcherForPath:(NSString *)path
743 {
744 [GWLib removeWatcherForPath: path];
745 }
746
747 - (void)unsetWatchersFromPath:(NSString *)path
748 {
749 unsigned index = [watchedPaths indexOfObject: path];
750
751 if (index != NSNotFound) {
752 int i;
753
754 for (i = index; i < [watchedPaths count]; i++) {
755 [self unsetWatcherForPath: [watchedPaths objectAtIndex: i]];
756 }
757 }
758 }
759
760 - (void)reSetWatchersFromPath:(NSString *)path
761 {
762 unsigned index = [watchedPaths indexOfObject: path];
763
764 if (index != NSNotFound) {
765 int i, count;
766 BOOL isdir;
767
768 count = [watchedPaths count];
769
770 for (i = index; i < count; i++) {
771 NSString *wpath = [watchedPaths objectAtIndex: i];
772
773 if ([fm fileExistsAtPath: wpath isDirectory: &isdir] && isdir) {
774 [self setWatcherForPath: wpath];
775 } else {
776 [watchedPaths removeObjectAtIndex: i];
777 count--;
778 i--;
779 }
780 }
781 }
782 }
783
784 - (void)closeNicely
785 {
786 NSTimer *t;
787
788 [self unsetWatchers];
789 [[NSNotificationCenter defaultCenter] removeObserver: self];
790
791 t = [NSTimer timerWithTimeInterval: 2 target: self
792 selector: @selector(close:) userInfo: nil repeats: NO];
793 [[NSRunLoop currentRunLoop] addTimer: t forMode: NSDefaultRunLoopMode];
794 }
795
796 - (void)close:(id)sender
797 {
798 [[self window] performClose: nil];
799 }
800
801 - (void)resizeWithOldSuperviewSize:(NSSize)oldFrameSize
802 {
803 NSRect r = [self frame];
804 int col = columns;
805 int winwidth;
806
807 [pathsScroll setFrame: NSMakeRect(0, r.size.height - 98, r.size.width, 98)];
808 [panelScroll setFrame: NSMakeRect(0, 0, r.size.width, r.size.height - 104)];
809
810 if (firstResize) {
811 NSArray *currSel = [panel currentSelection];
812
813 [panel scrollFirstIconToVisible];
814
815 if (currSel) {
816 [panel scrollToVisibleIconsWithPaths: currSel];
817 }
818
819 firstResize = NO;
820 }
821
822 winwidth = [delegate getWindowFrameWidth];
823 columns = (int)winwidth / resizeIncrement;
824 columnsWidth = (winwidth - 16) / columns;
825
826 if (col != columns) {
827 [pathsScroll setLineScroll: columnsWidth];
828 [iconsPath setColumnWidth: columnsWidth];
829 }
830
831 [self synchronize];
832 }
833
834 - (void)clickOnIcon:(PathIcon *)icon
835 {
836 NSArray *ipaths = RETAIN ([icon paths]);
837 NSString *type = [icon type];
838 BOOL chdir = NO;
839
840 if (type && ((type == NSDirectoryFileType) || (type == NSFilesystemFileType))) {
841 if (([icon isPakage] == NO) || ([icon isPakage] && viewsapps)) {
842 chdir = YES;
843 }
844 }
845
846 if (chdir && (icon == [iconsPath lastIcon])) {
847 [self setSelectedPaths: ipaths];
848 [panel scrollToVisibleIconsWithPaths: ipaths];
849 [panel selectIconsWithPaths: ipaths];
850
851 } else {
852 [self setCurrentSelection: ipaths];
853
854 if (chdir) {
855 [panel scrollFirstIconToVisible];
856 } else {
857 [panel scrollToVisibleIconsWithPaths: ipaths];
858 [panel selectIconsWithPaths: ipaths];
859 }
860 }
861
862 RELEASE (ipaths);
863 }
864
865 - (void)doubleClickOnIcon:(PathIcon *)icon newViewer:(BOOL)isnew
866 {
867 [self clickOnIcon: icon];
868 [self openCurrentSelection: [icon paths] newViewer: isnew];
869 }
870
871 - (void)synchronize
872 {
873 NSClipView *clip;
874 float x, y;
875 int nicons;
876
877 if (autoSynchronize == NO) {
878 return;
879 }
880
881 [iconsPath setIconsForSelection: selectedPaths];
882 nicons = [iconsPath numberOfIcons];
883 clip = [pathsScroll contentView];
884 x = [clip bounds].origin.x;
885 y = [clip bounds].origin.y;
886
887 if (nicons > columns) {
888 x += columnsWidth * (nicons - columns);
889 [clip scrollToPoint: NSMakePoint(x, y)];
890 }
891 }
892
893 - (void)openCurrentSelection:(NSArray *)paths newViewer:(BOOL)newv
894 {
895 [self setSelectedPaths: paths];
896
897 if (newv == YES) {
898 [[GWLib workspaceApp] openSelectedPaths: paths newViewer: YES];
899 return;
900
901 } else {
902 NSMutableArray *allfiles = [NSMutableArray arrayWithCapacity: 1];
903 NSMutableArray *dirs = [NSMutableArray arrayWithCapacity: 1];
904 int count = [paths count];
905 int i;
906
907 [allfiles addObjectsFromArray: paths];
908
909 for (i = 0; i < count; i++) {
910 NSString *fpath = [allfiles objectAtIndex: i];
911 NSString *defApp = nil;
912 NSString *type = nil;
913
914 [[NSWorkspace sharedWorkspace] getInfoForFile: fpath
915 application: &defApp
916 type: &type];
917
918 if (([type isEqualToString: NSDirectoryFileType])
919 || ([type isEqualToString: NSFilesystemFileType])) {
920 if ([GWLib isPakageAtPath: fpath] == NO) {
921 [dirs addObject: fpath];
922 [allfiles removeObject: fpath];
923 count--;
924 i--;
925 }
926 }
927 }
928
929 if ([allfiles count]) {
930 [[GWLib workspaceApp] openSelectedPaths: allfiles newViewer: newv];
931 }
932
933 if ([dirs count] == 1) {
934 [self setSelectedPaths: dirs];
935 [panel setPath: [dirs objectAtIndex: 0]];
936 [panel scrollFirstIconToVisible];
937 [panel setNeedsDisplay: YES];
938 }
939 }
940 }
941
942 //
943 // scrollview delegate methods
944 //
945 - (void)gwscrollView:(GWScrollView *)sender
946 scrollViewScrolled:(NSClipView *)clip
947 hitPart:(NSScrollerPart)hitpart
948 {
949 if (autoSynchronize == NO) {
950 return;
951 } else {
952 int x = (int)[clip bounds].origin.x;
953 int y = (int)[clip bounds].origin.y;
954 int rem = x % (int)columnsWidth;
955
956 if (rem != 0) {
957 if (rem <= columnsWidth / 2) {
958 x -= rem;
959 } else {
960 x += columnsWidth - rem;
961 }
962
963 [clip scrollToPoint: NSMakePoint(x, y)];
964 [iconsPath setNeedsDisplay: YES];
965 }
966 }
967 }
968
969 @end
970
971 //
972 // IconsPanel delegate methods
973 //
974 @implementation IconsViewer (IconsPanelDelegateMethods)
975
976 - (void)setTheSelectedPaths:(id)paths
977 {
978 [delegate addPathToHistory: paths];
979 [self setSelectedPaths: paths];
980 }
981
982 - (void)openTheCurrentSelection:(id)paths newViewer:(BOOL)newv
983 {
984 [self openCurrentSelection: paths newViewer: newv];
985 }
986
987 - (int)iconCellsWidth
988 {
989 return [delegate iconCellsWidth];
990 }
991
992 @end
993
994 //
995 // IconsPath delegate methods
996 //
997
998 @implementation IconsViewer (IconsPathDelegateMethods)
999
1000 - (void)clickedIcon:(id)anicon
1001 {
1002 [self clickOnIcon: anicon];
1003 }
1004
1005 - (void)doubleClickedIcon:(id)anicon newViewer:(BOOL)isnew
1006 {
1007 [self doubleClickOnIcon: anicon newViewer: isnew];
1008 }
1009
1010 @end

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