2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 // $Id: Browser.m 1 2004-08-20 11:17:52Z znek $
23 #import <NGObjWeb/WOComponent.h>
25 @class NSFileManager, NSArray, NSString;
27 @interface Browser : WOComponent < NSCoding >
32 NSString *currentPathString;
38 @implementation Browser
41 if ((self = [super init])) {
42 self->fm = [[NSFileManager defaultManager] retain];
44 // [self setCurrentPath:nil];
50 RELEASE(self->currentPathString);
51 RELEASE(self->currentPath);
56 - (void)setCurrentPath:(NSArray *)_p {
60 ASSIGN(self->currentPath, _p);
62 RELEASE(self->currentPathString); self->currentPathString = nil;
63 self->currentPathString = [[_p componentsJoinedByString:@"/"] copy];
65 - (NSArray *)currentPath {
66 return self->currentPath;
68 - (NSString *)currentPathString {
69 return self->currentPathString;
72 - (NSFileManager *)fileManager {
76 - (NSArray *)rootFolder {
77 return [[self fileManager] directoryContentsAtPath:@"."];
80 - (NSString *)bgColor {
83 cf = [self valueForKey:@"currentFolder"];
84 if ([cf isEqualToString:[self currentPathString]])
86 if ([cf hasPrefix:[self currentPathString]])
89 return @"white"; // default bg
92 - (BOOL)currentIsDirectory {
95 if (![self->fm fileExistsAtPath:[self currentPathString] isDirectory:&isDir])
101 - (NSString *)currentImage {
102 if ([self currentIsDirectory]) {
106 cf = [self valueForKey:@"currentFolder"];
108 if ([cf hasPrefix:[self currentPathString]])
109 return @"folder_opened.gif";
111 return @"folder_closed.gif";
116 - (NSArray *)dirContents {
117 if (![self currentIsDirectory])
120 return [[self fileManager] directoryContentsAtPath:[self currentPathString]];
124 NSLog(@"clicked: path is %@", [self currentPathString]);
125 NSLog(@"clicked: item is %@", [self valueForKey:@"item"]);
126 [self takeValue:[self currentPathString] forKey:@"currentFolder"];
132 - (void)encodeWithCoder:(NSCoder *)_coder {
133 [super encodeWithCoder:_coder];
135 [_coder encodeObject:self->currentPath];
136 [_coder encodeObject:self->currentPathString];
138 - (id)initWithCoder:(NSCoder *)_coder {
139 if ((self = [super initWithCoder:_coder])) {
140 self->fm = [[NSFileManager defaultManager] retain];
142 self->currentPath = [[_coder decodeObject] retain];
143 self->currentPathString = [[_coder decodeObject] retain];