1 |
/* FileOpsPref.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 "GWFunctions.h" |
30 |
#include "GWNotifications.h" |
31 |
#else |
32 |
#include <GWorkspace/GWFunctions.h> |
33 |
#include <GWorkspace/GWNotifications.h> |
34 |
#endif |
35 |
#include "FileOpsPref.h" |
36 |
#include "GWorkspace.h" |
37 |
#include "GNUstep.h" |
38 |
|
39 |
static NSString *nibName = @"FileOpsPref"; |
40 |
|
41 |
#define MOVEOP 0 |
42 |
#define COPYOP 1 |
43 |
#define LINKOP 2 |
44 |
#define RECYCLEOP 3 |
45 |
#define DUPLICATEOP 4 |
46 |
#define DESTROYOP 5 |
47 |
|
48 |
@implementation FileOpsPref |
49 |
|
50 |
- (void)dealloc |
51 |
{ |
52 |
TEST_RELEASE (prefbox); |
53 |
[super dealloc]; |
54 |
} |
55 |
|
56 |
- (id)init |
57 |
{ |
58 |
self = [super init]; |
59 |
|
60 |
if (self) { |
61 |
if ([NSBundle loadNibNamed: nibName owner: self] == NO) { |
62 |
NSLog(@"failed to load %@!", nibName); |
63 |
} else { |
64 |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
65 |
NSArray *cells; |
66 |
NSString *confirmString; |
67 |
id butt; |
68 |
|
69 |
RETAIN (prefbox); |
70 |
RELEASE (win); |
71 |
|
72 |
gw = [GWorkspace gworkspace]; |
73 |
|
74 |
statusItem = [tabView tabViewItemAtIndex: 0]; |
75 |
[statusItem setLabel: NSLocalizedString(@"Status Window", @"")]; |
76 |
|
77 |
confirmItem = [tabView tabViewItemAtIndex: 1]; |
78 |
[confirmItem setLabel: NSLocalizedString(@"Confirmation", @"")]; |
79 |
|
80 |
showstatus = [gw showFileOpStatus]; |
81 |
[statChooseButt setState: (showstatus ? NSOnState : NSOffState)]; |
82 |
|
83 |
cells = [confMatrix cells]; |
84 |
|
85 |
butt = [cells objectAtIndex: MOVEOP]; |
86 |
confirmString = [NSWorkspaceMoveOperation stringByAppendingString: @"Confirm"]; |
87 |
[butt setState: !([defaults boolForKey: confirmString])]; |
88 |
|
89 |
butt = [cells objectAtIndex: COPYOP]; |
90 |
confirmString = [NSWorkspaceCopyOperation stringByAppendingString: @"Confirm"]; |
91 |
[butt setState: !([defaults boolForKey: confirmString])]; |
92 |
|
93 |
butt = [cells objectAtIndex: LINKOP]; |
94 |
confirmString = [NSWorkspaceLinkOperation stringByAppendingString: @"Confirm"]; |
95 |
[butt setState: !([defaults boolForKey: confirmString])]; |
96 |
|
97 |
butt = [cells objectAtIndex: RECYCLEOP]; |
98 |
confirmString = [NSWorkspaceRecycleOperation stringByAppendingString: @"Confirm"]; |
99 |
[butt setState: !([defaults boolForKey: confirmString])]; |
100 |
|
101 |
butt = [cells objectAtIndex: DUPLICATEOP]; |
102 |
confirmString = [NSWorkspaceDuplicateOperation stringByAppendingString: @"Confirm"]; |
103 |
[butt setState: !([defaults boolForKey: confirmString])]; |
104 |
|
105 |
butt = [cells objectAtIndex: DESTROYOP]; |
106 |
confirmString = [NSWorkspaceDestroyOperation stringByAppendingString: @"Confirm"]; |
107 |
[butt setState: !([defaults boolForKey: confirmString])]; |
108 |
|
109 |
/* Internationalization */ |
110 |
[statActivButt setTitle: NSLocalizedString(@"Set", @"")]; |
111 |
[confActivButt setTitle: NSLocalizedString(@"Set", @"")]; |
112 |
[confirmBox setTitle: NSLocalizedString(@"Confirmation", @"")]; |
113 |
[statusBox setTitle: NSLocalizedString(@"Status Window", @"")]; |
114 |
[[confMatrix cellAtRow:0 column:0] setStringValue: NSLocalizedString(@"Move", @"")]; |
115 |
[[confMatrix cellAtRow:1 column:0] setStringValue: NSLocalizedString(@"Copy", @"")]; |
116 |
[[confMatrix cellAtRow:2 column:0] setStringValue: NSLocalizedString(@"Link", @"")]; |
117 |
[[confMatrix cellAtRow:3 column:0] setStringValue: NSLocalizedString(@"Recycler", @"")]; |
118 |
[[confMatrix cellAtRow:4 column:0] setStringValue: NSLocalizedString(@"Duplicate", @"")]; |
119 |
[[confMatrix cellAtRow:5 column:0] setStringValue: NSLocalizedString(@"Destroy", @"")]; |
120 |
[labelinfo1 setStringValue: NSLocalizedString(@"Uncheck the buttons to allow automatic confirmation", @"")]; |
121 |
[labelinfo2 setStringValue: NSLocalizedString(@"of file operations", @"")]; |
122 |
[statusinfo1 setStringValue: NSLocalizedString(@"Check this option to show a status window", @"")]; |
123 |
[statusinfo2 setStringValue: NSLocalizedString(@"during the file operations", @"")]; |
124 |
[statuslabel setStringValue: NSLocalizedString(@"Show status window", @"")]; |
125 |
} |
126 |
} |
127 |
|
128 |
return self; |
129 |
} |
130 |
|
131 |
- (NSView *)prefView |
132 |
{ |
133 |
return prefbox; |
134 |
} |
135 |
|
136 |
- (NSString *)prefName |
137 |
{ |
138 |
return NSLocalizedString(@"File Operations", @""); |
139 |
} |
140 |
|
141 |
- (void)setUnsetStatWin:(id)sender |
142 |
{ |
143 |
int state = [sender state]; |
144 |
|
145 |
if (showstatus) { |
146 |
if (state == NSOffState) { |
147 |
showstatus = NO; |
148 |
[statActivButt setEnabled: YES]; |
149 |
} |
150 |
} else { |
151 |
if (state == NSOnState) { |
152 |
showstatus = YES; |
153 |
[statActivButt setEnabled: YES]; |
154 |
} |
155 |
} |
156 |
} |
157 |
|
158 |
- (void)activateStatWinChanges:(id)sender |
159 |
{ |
160 |
[gw setShowFileOpStatus: showstatus]; |
161 |
[statActivButt setEnabled: NO]; |
162 |
} |
163 |
|
164 |
- (void)setUnsetFileOp:(id)sender |
165 |
{ |
166 |
[confActivButt setEnabled: YES]; |
167 |
} |
168 |
|
169 |
- (void)activateFileOpChanges:(id)sender |
170 |
{ |
171 |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
172 |
NSArray *cells = [confMatrix cells]; |
173 |
NSString *confirmString; |
174 |
|
175 |
#define CHECK_CONFIRM(x, s) \ |
176 |
confirmString = [s stringByAppendingString: @"Confirm"]; \ |
177 |
[defaults setBool: (([[cells objectAtIndex: x] state] == NSOnState) ? NO : YES) \ |
178 |
forKey: confirmString] |
179 |
|
180 |
CHECK_CONFIRM (MOVEOP, NSWorkspaceMoveOperation); |
181 |
CHECK_CONFIRM (COPYOP, NSWorkspaceCopyOperation); |
182 |
CHECK_CONFIRM (LINKOP, NSWorkspaceLinkOperation); |
183 |
CHECK_CONFIRM (RECYCLEOP, NSWorkspaceRecycleOperation); |
184 |
CHECK_CONFIRM (RECYCLEOP, GWorkspaceRecycleOutOperation); |
185 |
CHECK_CONFIRM (RECYCLEOP, GWorkspaceEmptyRecyclerOperation); |
186 |
CHECK_CONFIRM (DUPLICATEOP, NSWorkspaceDuplicateOperation); |
187 |
CHECK_CONFIRM (DESTROYOP, NSWorkspaceDestroyOperation); |
188 |
|
189 |
[defaults synchronize]; |
190 |
[confActivButt setEnabled: NO]; |
191 |
} |
192 |
|
193 |
@end |