PageRenderTime 42ms CodeModel.GetById 14ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/XcodePlugin/GTMXcodePreferences.m

http://macfuse.googlecode.com/
Objective C | 108 lines | 58 code | 15 blank | 35 comment | 7 complexity | 91815bd9a087118a46dec000b83186a3 MD5 | raw file
  1//
  2//  GTMXcodePreferences.m
  3//
  4//  Copyright 2007-2009 Google Inc.
  5//
  6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7//  use this file except in compliance with the License.  You may obtain a copy
  8//  of the License at
  9//
 10//  http://www.apache.org/licenses/LICENSE-2.0
 11//
 12//  Unless required by applicable law or agreed to in writing, software
 13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 15//  License for the specific language governing permissions and limitations under
 16//  the License.
 17//
 18
 19#import "GTMXcodePreferences.h"
 20#import "GTMXcodePlugin.h"
 21#import "GTMDefines.h"
 22
 23NSString *GTMXcodePreferencesMenuItemPrefChanged
 24  = @"GTMXcodePreferencesMenuItemPrefChanged";
 25NSString *GTMXcodeCorrectWhiteSpaceOnSave
 26  = @"GTMXcodeCorrectWhiteSpaceOnSave";
 27NSString *GTMXCodeSuppressMenuItemIcon
 28  = @"GTMXCodeSuppressMenuItemIcon";
 29
 30@implementation GTMXcodePreferences
 31
 32// Set our minimum size for the pane
 33- (NSSize)minModuleSize {
 34  return NSMakeSize(268, 80);
 35}
 36
 37// Return our nice little icon
 38- (id)imageForPreferenceNamed:(id)parameter1 {
 39  NSBundle *bundle = [GTMXcodePlugin pluginBundle];
 40  NSString *path =  [bundle pathForImageResource:@"GTM"];
 41  NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
 42  [image setScalesWhenResized:YES];
 43  [image setSize:NSMakeSize(32, 32)];
 44  return image;
 45}
 46
 47// This gets called everytime preferences are pulled up so that we can
 48// set up our state.
 49- (void)initializeFromDefaults {
 50  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 51
 52  // Handle menuitem icon (pref is suppress, button is show)
 53  // NOTE: this preference is negative, but the UI works as the positive, this
 54  // is done so the lack of the preference (ie-the default) will turn on the
 55  // icons.
 56  NSInteger state = NSOffState;
 57  if (![defaults boolForKey:GTMXCodeSuppressMenuItemIcon]) {
 58    state = NSOnState;
 59  }
 60  [showImageOnMenuItems_ setState:state];
 61
 62  state = [defaults boolForKey:GTMXcodeCorrectWhiteSpaceOnSave] ? NSOnState
 63                                                                : NSOffState;
 64  [correctWhiteSpace_ setState:state];
 65}
 66
 67// This gets called on Apply or OK is "hasChangesPending" returns YES.
 68- (void)saveChanges {
 69  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 70
 71  // Handle menuitem icon (pref is suppress, button is show)
 72  // NOTE: this preference is negative, but the UI works as the positive, this
 73  // is done so the lack of the preference (ie-the default) will turn on the
 74  // icons.
 75  BOOL newSetting = ([showImageOnMenuItems_ state] == NSOnState);
 76  BOOL oldSetting = ![defaults boolForKey:GTMXCodeSuppressMenuItemIcon];
 77  if (newSetting != oldSetting) {
 78    if (newSetting) {
 79      [defaults removeObjectForKey:GTMXCodeSuppressMenuItemIcon];
 80    } else {
 81      [defaults setBool:YES forKey:GTMXCodeSuppressMenuItemIcon];
 82    }
 83    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
 84    [nc postNotificationName:GTMXcodePreferencesMenuItemPrefChanged
 85                      object:self];
 86  }
 87
 88  BOOL setting = ([correctWhiteSpace_ state] == NSOnState);
 89  [defaults setBool:setting forKey:GTMXcodeCorrectWhiteSpaceOnSave];
 90
 91  // save out our settings
 92  [defaults synchronize];
 93}
 94
 95
 96// Currently we'll always return YES as it doesn't hurt at all.
 97- (BOOL)hasChangesPending {
 98  return YES;
 99}
100
101+ (BOOL)showImageOnMenuItems {
102  // NOTE: this preference is negative, but the UI works as the positive, this
103  // is done so the lack of the preference (ie-the default) will turn on the
104  // icons.
105  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
106  return ![defaults boolForKey:GTMXCodeSuppressMenuItemIcon];
107}
108@end