File: FolderViewer.m

package info (click to toggle)
gworkspace 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,124 kB
  • sloc: objc: 71,982; sh: 488; makefile: 43
file content (254 lines) | stat: -rw-r--r-- 7,342 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* FolderViewer.m
 *  
 * Copyright (C) 2004-2025 Free Software Foundation, Inc.
 *
 * Author: Enrico Sersale
 * Date: January 2004
 *
 * This file is part of the GNUstep Inspector application
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
 */

#import <AppKit/AppKit.h>
#import "FolderViewer.h"

#define byname 0
#define bykind 1
#define bydate 2
#define bysize 3
#define byowner 4

#define STYPES 5

@implementation FolderViewer

- (void)dealloc
{
  TEST_RELEASE (currentPath);
  [super dealloc];
}

- (id)initWithFrame:(NSRect)frameRect
          inspector:(id)insp
{
  self = [super initWithFrame: frameRect];

  if (self)
    {
      id cell;
      id label;

      sortBox = [[NSBox alloc] initWithFrame: NSMakeRect(57, 125, 137, 135)];
      [sortBox setBorderType: NSGrooveBorder];
      [sortBox setTitle: NSLocalizedString(@"Sort by", @"")];
      [sortBox setTitlePosition: NSAtTop];
      [sortBox setContentViewMargins: NSMakeSize(2, 2)];
      [self addSubview: sortBox];
      RELEASE (sortBox);

      cell = [NSButtonCell new];
      [cell setButtonType: NSRadioButton];
      [cell setBordered: NO];
      [cell setImagePosition: NSImageLeft];

      matrix = [[NSMatrix alloc]
				  initWithFrame: NSMakeRect(40, 12, 80, 95)
					   mode: NSRadioModeMatrix prototype: cell
				   numberOfRows: 5 numberOfColumns: 1];
      RELEASE (cell);

      [matrix setCellSize: NSMakeSize(80, 16)];
      [matrix setIntercellSpacing: NSMakeSize(1, 2)];
      [sortBox setContentView: matrix];
      [matrix setFrame: NSMakeRect(40, 12, 80, 95)];
      RELEASE (matrix);

      cell = [matrix cellAtRow: byname column: 0];
      [cell setTitle: NSLocalizedString(@"Name", @"")];
      [cell setTag: byname];
      cell = [matrix cellAtRow: bykind column: 0];
      [cell setTitle: NSLocalizedString(@"Type", @"")];
      [cell setTag: bykind];
      cell = [matrix cellAtRow: bydate column: 0];
      [cell setTitle: NSLocalizedString(@"Date", @"")];
      [cell setTag: bydate];
      cell = [matrix cellAtRow: bysize column: 0];
      [cell setTitle: NSLocalizedString(@"Size", @"")];
      [cell setTag: bysize];
      cell = [matrix cellAtRow: byowner column: 0];
      [cell setTitle: NSLocalizedString(@"Owner", @"")];
      [cell setTag: byowner];

      [matrix sizeToCells];
      [matrix setTarget: self];
      [matrix setAction: @selector(setNewSortType:)];

      label = [[NSTextField alloc] initWithFrame: NSMakeRect(8, 55, 240, 60)];
      [label setFont: [NSFont systemFontOfSize: 12]];
      [label setAlignment: NSCenterTextAlignment];
      [label setBackgroundColor: [NSColor windowBackgroundColor]];
      [label setTextColor: [NSColor darkGrayColor]];
      [label setBezeled: NO];
      [label setEditable: NO];
      [label setSelectable: NO];
      [label setStringValue: NSLocalizedString(@"Sort method applies to the\ncontents of the selected folder,\nNOT to its parent folder", @"")];
      [self addSubview: label];
      RELEASE (label);

      okButt = [[NSButton alloc] initWithFrame: NSMakeRect(141, 10, 115, 25)];
      [okButt setButtonType: NSMomentaryLight];
      [okButt setImage: [NSImage imageNamed: @"common_ret.tiff"]];
      [okButt setImagePosition: NSImageRight];
      [okButt setTitle: NSLocalizedString(@"Ok", @"")];
      [okButt setEnabled: NO];
      [self addSubview: okButt];
      RELEASE (okButt);

      currentPath = nil;

      inspector = insp;
      fm = [NSFileManager defaultManager];
      ws = [NSWorkspace sharedWorkspace];

      valid = YES;

      [self setContextHelp];
    }

  return self;
}

- (void)displayPath:(NSString *)path
{
	BOOL writable;
  int i;
  
  if ([self superview]) {      
    [inspector contentsReadyAt: path];
  }

  ASSIGN (currentPath, path);    
  writable = [fm isWritableFileAtPath: currentPath];
  
  for (i = 0; i < STYPES; i++) {
    [[matrix cellAtRow: i column: 0] setEnabled: writable];
  }

	[matrix selectCellAtRow: [self sortTypeForPath: path] column: 0];
}

- (void)displayData:(NSData *)data 
             ofType:(NSString *)type
{
}

- (NSString *)path
{
  return currentPath;
}

- (void)stopTasks
{
}

- (BOOL)canDisplayPath:(NSString *)path
{
  NSString *defApp, *fileType;

  [ws getInfoForFile: path application: &defApp type: &fileType];
  return ([fileType isEqual: NSFilesystemFileType]
                          || [fileType isEqual: NSDirectoryFileType]);
}

- (BOOL)canDisplayDataOfType:(NSString *)type
{
  return NO;
}

- (NSString *)winname
{
	return NSLocalizedString(@"Folder Inspector", @"");
}

- (NSString *)description
{
	return NSLocalizedString(@"This Inspector allow you to sort the contents of a Folder", @"");	
}

- (int)sortTypeForPath:(NSString *)path
{
  if ([fm isWritableFileAtPath: path]) {
    NSString *dictPath = [path stringByAppendingPathComponent: @".gwsort"];
    
    if ([fm fileExistsAtPath: dictPath]) {
      NSDictionary *sortDict = [NSDictionary dictionaryWithContentsOfFile: dictPath];
       
      if (sortDict) {
        return [[sortDict objectForKey: @"sort"] intValue];
      }   
    }
  } 
  
  return byname;
}

- (void)setNewSortType:(id)sender
{
  sortType = [[sender selectedCell] tag];

  if ([fm isWritableFileAtPath: currentPath]) {
    NSString *sortstr = [NSString stringWithFormat: @"%i", sortType];
    NSDictionary *dict = [NSDictionary dictionaryWithObject: sortstr 
                                                     forKey: @"sort"];

    [dict writeToFile: [currentPath stringByAppendingPathComponent: @".gwsort"] 
           atomically: YES];

    [[NSDistributedNotificationCenter defaultCenter]
          postNotificationName: @"GWSortTypeDidChangeNotification"
                        object: currentPath
                      userInfo: dict];
  }	
}

- (void)setContextHelp
{
  NSString *bpath = [[NSBundle bundleForClass: [self class]] bundlePath];
  NSString *resPath = [bpath stringByAppendingPathComponent: @"Resources"];
  NSArray *languages = [NSUserDefaults userLanguages];
  unsigned i;

  for (i = 0; i < [languages count]; i++) {
    NSString *language = [languages objectAtIndex: i];
    NSString *langDir = [NSString stringWithFormat: @"%@.lproj", language];  
    NSString *helpPath = [langDir stringByAppendingPathComponent: @"Help.rtfd"];
  
    helpPath = [resPath stringByAppendingPathComponent: helpPath];
  
    if ([fm fileExistsAtPath: helpPath]) {
      NSAttributedString *help = [[NSAttributedString alloc] initWithPath: helpPath
                                                       documentAttributes: NULL];
      if (help) {
        [[NSHelpManager sharedHelpManager] setContextHelp: help forObject: self];
        RELEASE (help);
      }
    }
  }
}

@end