1 |
/* FolderViewer.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 "GWProtocol.h" |
30 |
#include "GWLib.h" |
31 |
#include "InspectorsProtocol.h" |
32 |
#else |
33 |
#include <GWorkspace/GWProtocol.h> |
34 |
#include <GWorkspace/GWLib.h> |
35 |
#include <GWorkspace/InspectorsProtocol.h> |
36 |
#endif |
37 |
#include "FolderViewer.h" |
38 |
#include "GNUstep.h" |
39 |
|
40 |
@implementation FolderViewer |
41 |
|
42 |
#define byname 0 |
43 |
#define bykind 1 |
44 |
#define bydate 2 |
45 |
#define bysize 3 |
46 |
#define byowner 4 |
47 |
|
48 |
- (void)dealloc |
49 |
{ |
50 |
TEST_RELEASE (matrix); |
51 |
RELEASE (sortBox); |
52 |
RELEASE (label); |
53 |
TEST_RELEASE (myPath); |
54 |
RELEASE (bundlePath); |
55 |
[super dealloc]; |
56 |
} |
57 |
|
58 |
- (id)initInPanel:(id)apanel withFrame:(NSRect)frame index:(int)idx |
59 |
{ |
60 |
self = [super init]; |
61 |
if(self) { |
62 |
#ifdef GNUSTEP |
63 |
Class gwclass = [[NSBundle mainBundle] principalClass]; |
64 |
#else |
65 |
Class gwclass = [[NSBundle mainBundle] classNamed: @"GWorkspace"]; |
66 |
#endif |
67 |
|
68 |
gworkspace = (id<GWProtocol>)[gwclass gworkspace]; |
69 |
|
70 |
panel = (id<InspectorsProtocol>)apanel; |
71 |
ws = [NSWorkspace sharedWorkspace]; |
72 |
[self setFrame: frame]; |
73 |
index = idx; |
74 |
|
75 |
sortBox = [[NSBox alloc] initWithFrame: NSMakeRect(57, 93, 137, 125)]; |
76 |
[sortBox setBorderType: NSGrooveBorder]; |
77 |
[sortBox setTitle: NSLocalizedString(@"Sort by", @"")]; |
78 |
[sortBox setTitlePosition: NSAtTop]; |
79 |
[sortBox setContentViewMargins: NSMakeSize(2, 2)]; |
80 |
[self addSubview: sortBox]; |
81 |
|
82 |
label = [[NSTextField alloc] initWithFrame: NSMakeRect(8, 7, 240, 60)]; |
83 |
[label setFont: [NSFont systemFontOfSize: 12]]; |
84 |
[label setAlignment: NSCenterTextAlignment]; |
85 |
[label setBackgroundColor: [NSColor windowBackgroundColor]]; |
86 |
[label setTextColor: [NSColor grayColor]]; |
87 |
[label setBezeled: NO]; |
88 |
[label setEditable: NO]; |
89 |
[label setSelectable: NO]; |
90 |
localizedStr = NSLocalizedString(@"Sort method applies to the\ncontents of the selected folder,\nNOT to its parent folder", @""); |
91 |
[label setStringValue: localizedStr]; |
92 |
[self addSubview: label]; |
93 |
|
94 |
matrix = nil; |
95 |
} |
96 |
return self; |
97 |
} |
98 |
|
99 |
- (void)setBundlePath:(NSString *)path |
100 |
{ |
101 |
ASSIGN (bundlePath, path); |
102 |
} |
103 |
|
104 |
- (NSString *)bundlePath |
105 |
{ |
106 |
return bundlePath; |
107 |
} |
108 |
|
109 |
- (void)setIndex:(int)idx |
110 |
{ |
111 |
index = idx; |
112 |
} |
113 |
|
114 |
- (void)activateForPath:(NSString *)path |
115 |
{ |
116 |
id cell; |
117 |
BOOL writable; |
118 |
|
119 |
ASSIGN (myPath, path); |
120 |
writable = [[NSFileManager defaultManager] isWritableFileAtPath: myPath]; |
121 |
|
122 |
oldSortType = [gworkspace sortTypeForDirectoryAtPath: path]; |
123 |
newSortType = oldSortType; |
124 |
|
125 |
if (matrix != nil) { |
126 |
[matrix removeFromSuperview]; |
127 |
RELEASE (matrix); |
128 |
} |
129 |
|
130 |
cell = [NSButtonCell new]; |
131 |
[cell setButtonType: NSRadioButton]; |
132 |
[cell setBordered: NO]; |
133 |
[cell setImagePosition: NSImageLeft]; |
134 |
AUTORELEASE (cell); |
135 |
|
136 |
matrix = [[NSMatrix alloc] |
137 |
initWithFrame: NSMakeRect(40, 8, 80, 108) |
138 |
mode: NSRadioModeMatrix prototype: cell |
139 |
numberOfRows: 5 numberOfColumns: 1]; |
140 |
|
141 |
[matrix setCellSize: NSMakeSize(80, 16)]; |
142 |
[matrix setIntercellSpacing: NSMakeSize(1, 2)]; |
143 |
[sortBox addSubview: matrix]; |
144 |
|
145 |
|
146 |
cell = [matrix cellAtRow: 0 column: 0]; |
147 |
[cell setTitle: NSLocalizedString(@"Name", @"")]; |
148 |
[cell setTag: byname]; |
149 |
[cell setEnabled: writable]; |
150 |
cell = [matrix cellAtRow: 1 column: 0]; |
151 |
[cell setTitle: NSLocalizedString(@"Kind", @"")]; |
152 |
[cell setTag: bykind]; |
153 |
[cell setEnabled: writable]; |
154 |
cell = [matrix cellAtRow: 2 column: 0]; |
155 |
[cell setTitle: NSLocalizedString(@"Date", @"")]; |
156 |
[cell setTag: bydate]; |
157 |
[cell setEnabled: writable]; |
158 |
cell = [matrix cellAtRow: 3 column: 0]; |
159 |
[cell setTitle: NSLocalizedString(@"Size", @"")]; |
160 |
[cell setTag: bysize]; |
161 |
[cell setEnabled: writable]; |
162 |
cell = [matrix cellAtRow: 4 column: 0]; |
163 |
[cell setTitle: NSLocalizedString(@"Owner", @"")]; |
164 |
[cell setTag: byowner]; |
165 |
[cell setEnabled: writable]; |
166 |
|
167 |
[matrix sizeToCells]; |
168 |
[matrix setTarget: self]; |
169 |
[matrix setAction: @selector(newSortType:)]; |
170 |
|
171 |
buttCancel = [panel revertButton]; |
172 |
[buttCancel setEnabled: NO]; |
173 |
[buttCancel setTarget: self]; |
174 |
[buttCancel setAction: @selector(revertToOldSortType:)]; |
175 |
|
176 |
buttOk = [panel okButton]; |
177 |
[buttOk setEnabled: NO]; |
178 |
[buttOk setTarget: self]; |
179 |
[buttOk setAction: @selector(setNewSortType:)]; |
180 |
|
181 |
[matrix selectCellAtRow: oldSortType column: 0]; |
182 |
[self setNeedsDisplay: YES]; |
183 |
} |
184 |
|
185 |
- (BOOL)stopTasks |
186 |
{ |
187 |
return YES; |
188 |
} |
189 |
|
190 |
- (void)deactivate |
191 |
{ |
192 |
[self removeFromSuperview]; |
193 |
} |
194 |
|
195 |
- (BOOL)canDisplayFileAtPath:(NSString *)path |
196 |
{ |
197 |
NSString *defApp, *fileType; |
198 |
|
199 |
[ws getInfoForFile: path application: &defApp type: &fileType]; |
200 |
|
201 |
if ([fileType isEqual: NSFilesystemFileType] |
202 |
|| [fileType isEqual: NSDirectoryFileType]) { |
203 |
if ([gworkspace isPakageAtPath: path] == NO) { |
204 |
return YES; |
205 |
} |
206 |
} |
207 |
|
208 |
return NO; |
209 |
} |
210 |
|
211 |
- (int)index |
212 |
{ |
213 |
return index; |
214 |
} |
215 |
|
216 |
- (NSString *)winname |
217 |
{ |
218 |
return NSLocalizedString(@"Folder Inspector", @""); |
219 |
} |
220 |
|
221 |
- (void)newSortType:(id)sender |
222 |
{ |
223 |
newSortType = [[sender selectedCell] tag]; |
224 |
[buttOk setEnabled: YES]; |
225 |
[buttCancel setEnabled: YES]; |
226 |
} |
227 |
|
228 |
- (void)setNewSortType:(id)sender |
229 |
{ |
230 |
if(newSortType == oldSortType) { |
231 |
return; |
232 |
} |
233 |
oldSortType = newSortType; |
234 |
[gworkspace setSortType: newSortType forDirectoryAtPath: myPath]; |
235 |
[buttCancel setEnabled: NO]; |
236 |
[buttOk setEnabled: NO]; |
237 |
} |
238 |
|
239 |
- (void)revertToOldSortType:(id)sender |
240 |
{ |
241 |
[matrix selectCellAtRow: oldSortType column: 0]; |
242 |
newSortType = oldSortType; |
243 |
[buttCancel setEnabled: NO]; |
244 |
[buttOk setEnabled: NO]; |
245 |
} |
246 |
|
247 |
@end |