~ubuntu-branches/ubuntu/vivid/projectcenter.app/vivid

« back to all changes in this revision

Viewing changes to Modules/Preferences/Misc/PCMiscPrefs.m

  • Committer: Bazaar Package Importer
  • Author(s): Yavor Doganov
  • Date: 2010-06-03 16:04:52 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100603160452-dcsmkjwdtwxuitdo
Tags: 0.5.3~20100601-1
* New upstream release.
* debian/compat: Set to 7.
* debian/control (Section): Change to `gnustep'.
  (Build-Depends): Require debhelper >= 7, remove version constraints
  for libgnustep-gui-dev (obsolete).
  (Depends): Add ${gnustep:Depends}.
  (Standards-Version): Compliant with 3.8.4 as of this release.
  (Vcs-Arch): New field.
  (Description): Do not praise NextStep.
* debian/rules: Export GNUSTEP_MAKEFILES and get rid of gs_make.
  (OPTFLAG): No longer define; rework noopt handling to be compatible
  with gnustep-make/2.4.x (Closes: #581976).
  (build-stamp): Pass GDB=/usr/bin/gdb for the PCDefaultDebugger
  define.
  (install): Replace dh_clean -k with dh_prep.
  (binary-arch): Adjust dh_installchangelogs' argument.  Rework the
  FHS_ME_HARDER snippet; PC's supporting executables are no longer
  installed as Bundles.
* debian/patches/05_link-libs.dpatch: Update; the fix was merged
  upstream, but now -lm is required as well.
* debian/patches/10_bundles-install-dir.dpatch: Remove; obsolete with
  the new way of FHS-compliance handling.
* debian/links: Delete; no longer needed.
* debian/menu: Adjust command.
* debian/source/format:
* debian/README.source:
* debian/preinst: New file.
* debian/copyright: Bump copyright years, add more upstream authors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
 
3
//
 
4
// Copyright (C) 2001-2009 Free Software Foundation
 
5
//
 
6
// Authors: Sergii Stoian
 
7
//
 
8
// Description: 
 
9
//
 
10
// This file is part of GNUstep.
 
11
//
 
12
// This application is free software; you can redistribute it and/or
 
13
// modify it under the terms of the GNU General Public License as published 
 
14
// by the Free Software Foundation; either version 2 of the License, or 
 
15
// (at your option) any later version.
 
16
//
 
17
// This application is distributed in the hope that it will be useful,
 
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
20
// Library General Public License for more details.
 
21
//
 
22
// You should have received a copy of the GNU General Public
 
23
// License along with this library; if not, write to the Free Software 
 
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
25
 
 
26
#import <ProjectCenter/PCFileManager.h>
 
27
 
 
28
#import "PCMiscPrefs.h"
 
29
 
 
30
@implementation PCMiscPrefs
 
31
 
 
32
// ----------------------------------------------------------------------------
 
33
// --- Init and free
 
34
// ----------------------------------------------------------------------------
 
35
 
 
36
- (id)initWithPrefController:(id <PCPreferences>)aPrefs
 
37
{
 
38
  self = [super init];
 
39
 
 
40
  if ([NSBundle loadNibNamed:@"MiscPrefs" owner:self] == NO)
 
41
    {
 
42
      NSLog(@"PCMiscPrefs: error loading NIB file!");
 
43
    }
 
44
 
 
45
  prefs = aPrefs;
 
46
 
 
47
  RETAIN(miscView);
 
48
 
 
49
  return self;
 
50
}
 
51
 
 
52
- (void)awakeFromNib
 
53
{
 
54
  [promptWhenQuit setRefusesFirstResponder:YES];
 
55
  [fullPathInFilePanels setRefusesFirstResponder:YES];
 
56
  [rememberWindows setRefusesFirstResponder:YES];
 
57
  [displayLog setRefusesFirstResponder:YES];
 
58
  [useTearOffWindows setRefusesFirstResponder:YES];
 
59
 
 
60
  [debuggerButton setRefusesFirstResponder:YES];
 
61
  [editorButton setRefusesFirstResponder:YES];
 
62
}
 
63
 
 
64
- (void)dealloc
 
65
{
 
66
#ifdef DEBUG
 
67
  NSLog (@"PCMiscPrefs: dealloc");
 
68
#endif
 
69
 
 
70
  [[NSNotificationCenter defaultCenter] removeObserver:self];
 
71
 
 
72
  RELEASE(miscView);
 
73
 
 
74
  [super dealloc];
 
75
}
 
76
 
 
77
// Protocol
 
78
- (void)readPreferences
 
79
{
 
80
  NSString *val;
 
81
  BOOL     bVal;
 
82
  int      state;
 
83
 
 
84
  bVal = [prefs boolForKey:PromptOnQuit defaultValue:YES];
 
85
  state = bVal ? NSOnState : NSOffState;
 
86
  [promptWhenQuit setState:state];
 
87
 
 
88
  bVal = [prefs boolForKey:FullPathInFilePanels defaultValue:YES];
 
89
  state = bVal ? NSOnState : NSOffState;
 
90
  [fullPathInFilePanels setState:state];
 
91
 
 
92
  bVal = [prefs boolForKey:RememberWindows defaultValue:YES];
 
93
  state = bVal ? NSOnState : NSOffState;
 
94
  [rememberWindows setState:state];
 
95
     
 
96
  bVal = [prefs boolForKey:DisplayLog defaultValue:NO];
 
97
  state = bVal ? NSOnState : NSOffState;
 
98
  [displayLog setState:state];
 
99
 
 
100
  bVal = [prefs boolForKey:UseTearOffWindows defaultValue:YES];
 
101
  state = bVal ? NSOnState : NSOffState;
 
102
  [useTearOffWindows setState:state];
 
103
 
 
104
  val = [prefs stringForKey:Debugger defaultValue:PCDefaultDebugger];
 
105
  [debuggerField setStringValue:val];
 
106
 
 
107
  val = [prefs stringForKey:Editor defaultValue:@"ProjectCenter"];
 
108
  [editorField setStringValue:val];
 
109
}
 
110
 
 
111
- (NSView *)view
 
112
{
 
113
  return miscView;
 
114
}
 
115
 
 
116
// Actions
 
117
- (void)setPromptWhenQuit:(id)sender
 
118
{
 
119
  BOOL state;
 
120
 
 
121
  if (promptWhenQuit == nil)
 
122
    {// HACK!!! need to be fixed in GNUstep
 
123
      promptWhenQuit = sender;
 
124
      return;
 
125
    }
 
126
 
 
127
  state = ([sender state] == NSOffState) ? NO : YES;
 
128
  [prefs setBool:state forKey:PromptOnQuit notify:YES];
 
129
}
 
130
 
 
131
- (void)setFullPathInFilePanels:(id)sender
 
132
{
 
133
  BOOL state;
 
134
 
 
135
  if (fullPathInFilePanels == nil)
 
136
    {// HACK!!! need to be fixed in GNUstep
 
137
      fullPathInFilePanels = sender;
 
138
      return;
 
139
    }
 
140
 
 
141
  state = ([sender state] == NSOffState) ? NO : YES;
 
142
  [prefs setBool:state forKey:FullPathInFilePanels notify:YES];
 
143
}
 
144
 
 
145
- (void)setRememberWindows:(id)sender
 
146
{
 
147
  BOOL state;
 
148
 
 
149
  if (rememberWindows == nil)
 
150
    {
 
151
      rememberWindows = sender;
 
152
      return;
 
153
    }
 
154
 
 
155
  state = ([sender state] == NSOffState) ? NO : YES;
 
156
  [prefs setBool:state forKey:RememberWindows notify:YES];
 
157
}
 
158
 
 
159
- (void)setDisplayLog:(id)sender
 
160
{
 
161
  BOOL state;
 
162
 
 
163
  if (displayLog == nil)
 
164
    {
 
165
      displayLog = sender;
 
166
      return;
 
167
    }
 
168
 
 
169
  state = ([sender state] == NSOffState) ? NO : YES;
 
170
  [prefs setBool:state forKey:DisplayLog notify:YES];
 
171
}
 
172
 
 
173
- (void)setUseTearOffWindows:(id)sender
 
174
{
 
175
  BOOL state;
 
176
 
 
177
  if (useTearOffWindows == nil)
 
178
    {
 
179
      useTearOffWindows = sender;
 
180
      return;
 
181
    }
 
182
 
 
183
  state = ([sender state] == NSOffState) ? NO : YES;
 
184
  [prefs setBool:state forKey:UseTearOffWindows notify:YES];
 
185
}
 
186
 
 
187
- (void)setDebugger:(id)sender
 
188
{
 
189
  NSArray       *files;
 
190
  NSString      *path;
 
191
  NSFileManager *fm = [NSFileManager defaultManager];
 
192
 
 
193
  // Choose
 
194
  if ((sender == debuggerField))
 
195
    {
 
196
      path = [debuggerField stringValue];
 
197
    }
 
198
  else
 
199
    {
 
200
      files = [[PCFileManager defaultManager] 
 
201
        filesOfTypes:nil
 
202
           operation:PCOpenFileOperation
 
203
            multiple:NO
 
204
               title:@"Choose Debugger Tool"
 
205
             accView:nil];
 
206
      path = [files objectAtIndex:0];
 
207
    }
 
208
 
 
209
  [[miscView window] makeFirstResponder:debuggerField];
 
210
  if (!path)
 
211
    {
 
212
      return;
 
213
    }
 
214
 
 
215
  // Check
 
216
  if (path && ![fm fileExistsAtPath:path])
 
217
    {
 
218
      NSRunAlertPanel(@"Set Debugger Tool",
 
219
                      @"File %@ doesn't exist!\n"
 
220
                      "Setting field to default value.",
 
221
                      @"Close", nil, nil, path);
 
222
      path = @"";
 
223
    } 
 
224
  else if (path && ![fm isExecutableFileAtPath:path])
 
225
    {
 
226
      NSRunAlertPanel(@"Set Debugger Tool",
 
227
                      @"File %@ exists but is not executable!\n"
 
228
                      "Setting field to default value.",
 
229
                      @"Close", nil, nil, path);
 
230
      path = @"";
 
231
    }
 
232
 
 
233
  if ([path isEqualToString:@""])
 
234
    {
 
235
      path = PCDefaultDebugger;
 
236
    }
 
237
 
 
238
  // Set
 
239
  [debuggerField setStringValue:path];
 
240
  [prefs setString:path forKey:Debugger notify:YES];
 
241
}
 
242
 
 
243
- (void)setEditor:(id)sender
 
244
{
 
245
  NSArray       *files;
 
246
  NSString      *path;
 
247
  NSString      *editorPath;
 
248
  NSFileManager *fm = [NSFileManager defaultManager];
 
249
  NSWorkspace   *ws = [NSWorkspace sharedWorkspace];
 
250
 
 
251
  // Choose
 
252
  if ((sender == debuggerField))
 
253
    {
 
254
      path = [debuggerField stringValue];
 
255
    }
 
256
  else if ([path = [editorField stringValue] isEqualToString:@""])
 
257
    {
 
258
      files = [[PCFileManager defaultManager] 
 
259
        filesOfTypes:nil
 
260
           operation:PCOpenFileOperation
 
261
            multiple:NO
 
262
               title:@"Choose Editor"
 
263
             accView:nil];
 
264
      path = [files objectAtIndex:0];
 
265
    }
 
266
  
 
267
  [[miscView window] makeFirstResponder:editorField];
 
268
  if (!path)
 
269
    {
 
270
      return;
 
271
    }
 
272
 
 
273
  // Check
 
274
  if (path && ![ws fullPathForApplication:path])
 
275
    {
 
276
      editorPath = [[path componentsSeparatedByString:@" "] objectAtIndex:0];
 
277
      if (![fm fileExistsAtPath:editorPath])
 
278
        {
 
279
          [editorField selectText:self];
 
280
          NSRunAlertPanel(@"Set Editor",
 
281
                          @"Editor %@ doesn't exist!\n"
 
282
                          @"Setting field to default value.",
 
283
                          @"Close", nil, nil, path);
 
284
          path = @"";
 
285
        }
 
286
      else if (path && ![fm isExecutableFileAtPath:editorPath])
 
287
        {
 
288
          [editorField selectText:self];
 
289
          NSRunAlertPanel(@"Set Editor",
 
290
                          @"File %@ exists but is not executable!\n"
 
291
                          "Setting field to default value.",
 
292
                          @"Close", nil, nil, path);
 
293
          path = @"";
 
294
        }
 
295
    }
 
296
  
 
297
  if ([path isEqualToString:@""] || !path)
 
298
    {
 
299
      path = @"ProjectCenter";
 
300
    }
 
301
 
 
302
  // Set
 
303
  [editorField setStringValue:path];
 
304
  [prefs setString:path forKey:Editor notify:YES];
 
305
}
 
306
 
 
307
@end
 
308