| 1 |
/* |
| 2 |
* Copyright (c) 2004-2005 The Lupin Project. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without modification, are permitted |
| 5 |
* provided that the following conditions are met: |
| 6 |
* |
| 7 |
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
| 8 |
* and the following disclaimer. |
| 9 |
* |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of |
| 11 |
* conditions and the following disclaimer in the documentation and/or other materials provided |
| 12 |
* with the distribution. |
| 13 |
* |
| 14 |
* THIS SOFTWARE IS PROVIDED BY THE LUPIN PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 15 |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LUPIN PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 17 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 18 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 19 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 20 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 21 |
* POSSIBILITY OF SUCH DAMAGE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#import "LPPreferencesController.h" |
| 25 |
|
| 26 |
@implementation LPPreferencesController |
| 27 |
|
| 28 |
- (IBAction)showWindow:(id)sender |
| 29 |
{ |
| 30 |
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 31 |
|
| 32 |
int state,row; |
| 33 |
NSString* string; |
| 34 |
row = [defaults integerForKey:@"generalArchiveDropped"]; |
| 35 |
[_generalArchiveDropped selectCellAtRow:row column:0]; |
| 36 |
row = [defaults integerForKey:@"generalFileDropped"]; |
| 37 |
[_generalFileDropped selectCellAtRow:row column:0]; |
| 38 |
|
| 39 |
row = [defaults integerForKey:@"compressCreateAtMatrix"]; |
| 40 |
[_compressCreateAtMatrix selectCellAtRow:row column:0]; |
| 41 |
string = [defaults stringForKey:@"compressCreateAt"]; |
| 42 |
[_compressCreateAtField setStringValue:string]; |
| 43 |
state = ([defaults boolForKey:@"compressExcludePeriodFile"]) ? NSOnState : NSOffState; |
| 44 |
[_compressExcludePeriodFile setState:state]; |
| 45 |
state = ([defaults boolForKey:@"compressExcludeDSStore"]) ? NSOnState : NSOffState; |
| 46 |
[_compressExcludeDSStore setState:state]; |
| 47 |
state = ([defaults boolForKey:@"compressExcludeResourceFile"]) ? NSOnState : NSOffState; |
| 48 |
[_compressExcludeResourceFile setState:state]; |
| 49 |
|
| 50 |
row = [defaults integerForKey:@"uncompressCreateAtMatrix"]; |
| 51 |
[_uncompressCreateAtMatrix selectCellAtRow:row column:0]; |
| 52 |
string = [defaults stringForKey:@"uncompressCreateAt"]; |
| 53 |
[_uncompressCreateAtField setStringValue:string]; |
| 54 |
row = [defaults integerForKey:@"uncompressExistMatrix"]; |
| 55 |
[_uncompressExistMatrix selectCellAtRow:row column:0]; |
| 56 |
row = [defaults integerForKey:@"uncompressOverwriteMatrix"]; |
| 57 |
[_uncompressOverwriteMatrix selectCellAtRow:row column:0]; |
| 58 |
|
| 59 |
state = ([defaults boolForKey:@"inspectIsHierarchy"]) ? NSOnState : NSOffState; |
| 60 |
[_inspectIsHierarchy setState:state]; |
| 61 |
|
| 62 |
[super showWindow:sender]; |
| 63 |
} |
| 64 |
|
| 65 |
- (void)setPreference |
| 66 |
{ |
| 67 |
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 68 |
//NSMutableDictionary* defaults; |
| 69 |
|
| 70 |
[defaults setInteger:[_generalArchiveDropped selectedRow] forKey:@"generalArchiveDropped"]; |
| 71 |
[defaults setInteger:[_generalFileDropped selectedRow] forKey:@"generalFileDropped"]; |
| 72 |
|
| 73 |
[defaults setInteger:[_compressCreateAtMatrix selectedRow] forKey:@"compressCreateAtMatrix"]; |
| 74 |
[defaults setObject:[_compressCreateAtField stringValue] forKey:@"compressCreateAt"]; |
| 75 |
[defaults setBool:([_compressExcludePeriodFile state] == NSOnState) forKey:@"compressExcludePeriodFile"]; |
| 76 |
[defaults setBool:([_compressExcludeDSStore state] == NSOnState) forKey:@"compressExcludeDSStore"]; |
| 77 |
[defaults setBool:([_compressExcludeResourceFile state] == NSOnState) forKey:@"compressExcludeResourceFile"]; |
| 78 |
|
| 79 |
[defaults setInteger:[_uncompressCreateAtMatrix selectedRow] forKey:@"uncompressCreateAtMatrix"]; |
| 80 |
[defaults setObject:[_uncompressCreateAtField stringValue] forKey:@"uncompressCreateAt"]; |
| 81 |
[defaults setInteger:[_uncompressExistMatrix selectedRow] forKey:@"uncompressExistMatrix"]; |
| 82 |
[defaults setInteger:[_uncompressOverwriteMatrix selectedRow] forKey:@"uncompressOverwriteMatrix"]; |
| 83 |
|
| 84 |
[defaults setBool:([_inspectIsHierarchy state] == NSOnState) forKey:@"inspectIsHierarchy"]; |
| 85 |
} |
| 86 |
|
| 87 |
- (void)setDefaultPreference |
| 88 |
{ |
| 89 |
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 90 |
[defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: |
| 91 |
[NSNumber numberWithInt:2], @"generalArchiveDropped", |
| 92 |
[NSNumber numberWithInt:2], @"generalFileDropped", |
| 93 |
|
| 94 |
[NSNumber numberWithInt:0], @"compressCreateAtMatrix", |
| 95 |
NSHomeDirectory(), @"compressCreateAt", |
| 96 |
[NSNumber numberWithBool:NO], @"compressExcludePeriodFile", |
| 97 |
[NSNumber numberWithBool:NO], @"compressExcludeDSStore", |
| 98 |
[NSNumber numberWithBool:NO], @"compressExcludeResourceFile", |
| 99 |
|
| 100 |
[NSNumber numberWithInt:3], @"uncompressCreateAtMatrix", |
| 101 |
NSHomeDirectory(), @"uncompressCreateAt", |
| 102 |
[NSNumber numberWithInt:0], @"uncompressExistMatrix", |
| 103 |
[NSNumber numberWithInt:0], @"uncompressOverwriteMatrix", |
| 104 |
|
| 105 |
[NSNumber numberWithBool:YES], @"inspectIsHierarchy", |
| 106 |
nil]]; |
| 107 |
} |
| 108 |
|
| 109 |
// called when preference window will close. |
| 110 |
- (void)windowWillClose:(NSNotification *)aNotification |
| 111 |
{ |
| 112 |
[self setPreference]; |
| 113 |
} |
| 114 |
|
| 115 |
- (IBAction)chooseCompressAt:(id)sender |
| 116 |
{ |
| 117 |
NSOpenPanel* openPanel = [NSOpenPanel openPanel]; |
| 118 |
[openPanel setTitle:NSLocalizedString(@"DialogUncompressChooseDestinationTitle",nil)]; |
| 119 |
[openPanel setMessage:NSLocalizedString(@"DialogUncompressChooseDestinationMessage",nil)]; |
| 120 |
[openPanel setPrompt:NSLocalizedString(@"DialogChooseFolderButtonTitle",nil)]; |
| 121 |
[openPanel setCanChooseDirectories:YES]; |
| 122 |
[openPanel setCanChooseFiles:NO]; |
| 123 |
[openPanel beginSheetForDirectory:NSHomeDirectory() file:nil types:nil modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(chooseCompressAtDidEnd:returnCode:contextInfo:) contextInfo:NULL]; |
| 124 |
} |
| 125 |
|
| 126 |
- (void)chooseCompressAtDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo |
| 127 |
{ |
| 128 |
if (returnCode == NSOKButton) { |
| 129 |
[_compressCreateAtField setEnabled:YES]; |
| 130 |
[_compressCreateAtField setStringValue:[sheet filename]]; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
- (IBAction)chooseCompressAtOther:(id)sender |
| 135 |
{ |
| 136 |
[_compressCreateAtField setEnabled:NO]; |
| 137 |
} |
| 138 |
|
| 139 |
- (IBAction)chooseUncompressAt:(id)sender |
| 140 |
{ |
| 141 |
NSLog(@"hogehogegasdfga"); |
| 142 |
if ([[_uncompressCreateAtMatrix cellAtRow:4 column:0] state] == NSOnState) { |
| 143 |
NSOpenPanel* openPanel = [NSOpenPanel openPanel]; |
| 144 |
[openPanel setTitle:NSLocalizedString(@"DialogCompressChooseArchiveTitle",nil)]; |
| 145 |
[openPanel setMessage:NSLocalizedString(@"DialogCompressChooseArchiveMessage",nil)]; |
| 146 |
[openPanel setPrompt:NSLocalizedString(@"DialogChooseFolderButtonTitle",nil)]; |
| 147 |
[openPanel setCanChooseDirectories:YES]; |
| 148 |
[openPanel beginSheetForDirectory:NSHomeDirectory() file:nil types:nil modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(chooseUncompressAtDidEnd:returnCode:contextInfo:) contextInfo:NULL]; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
- (void)chooseUncompressAtDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo |
| 153 |
{ |
| 154 |
if (returnCode == NSOKButton) { |
| 155 |
[_uncompressCreateAtField setEnabled:YES]; |
| 156 |
[_uncompressCreateAtField setStringValue:[sheet filename]]; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
- (IBAction)chooseUncompressAtOther:(id)sender |
| 161 |
{ |
| 162 |
[_uncompressCreateAtField setEnabled:NO]; |
| 163 |
} |
| 164 |
|
| 165 |
@end |