/*
Copyright (C) 2002-2003, Jeffrey D. Argast.
The authors make NO WARRANTY or representation, either express or implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy.
Permission is hereby granted to use, copy, modify, and distribute this
software or portions thereof for any purpose, without fee, subject to these
conditions:
(1) If any part of the source code is distributed, then this
statement must be included, with this copyright and no-warranty notice
unaltered.
(2) Permission for use of this software is granted only if the user accepts
full responsibility for any undesirable consequences; the authors accept
NO LIABILITY for damages of any kind.
*/
#import "AppDefaults.h"
#import <Cocoa/Cocoa.h>
#import "MessageDefs.h"
#import "AppUtils.h"
#import "AppEnvironment.h"
#import "PerforceConfigurationsList.h"
#import "PerforceConfiguration.h"
#import "PerforceAction.h"
static NSString* kDiffAppKey = @"Diff App";
static NSString* kEditAppKey = @"Edit App";
static NSString* kMergeAppKey = @"Merge App";
static NSString* kShowEntireDepotKey = @"Show Entire Depot";
static NSString* kShowDeletedFilesKey = @"Show Deleted Files";
static NSString* kNumChangesKey = @"Num Changes To Fetch";
static NSString* kConfigurationsKey = @"Perforce Configurations";
@implementation AppDefaults
+ (void) initialize
{
NSString* envValue;
NSMutableDictionary* defaultValues = [NSMutableDictionary dictionary];
// extract the current environment variables and set those as the
// standard defaults
envValue = [AppEnvironment perforceDiff];
[defaultValues setObject:[NSString stringWithString:envValue] forKey:kDiffAppKey];
envValue = [AppEnvironment perforceEditor];
[defaultValues setObject:[NSString stringWithString:envValue] forKey:kEditAppKey];
envValue = [AppEnvironment perforceMerge];
[defaultValues setObject:[NSString stringWithString:envValue] forKey:kMergeAppKey];
[defaultValues setObject:[NSNumber numberWithBool:NO] forKey:kShowEntireDepotKey];
[defaultValues setObject:[NSNumber numberWithBool:NO] forKey:kShowDeletedFilesKey];
[defaultValues setObject:[NSString stringWithString:@"1500"] forKey:kNumChangesKey];
PerforceConfigurationsList* theList = [[[PerforceConfigurationsList alloc] init] autorelease];
PerforceConfiguration* defaultConfig =
[[[PerforceConfiguration alloc] initWithName:@"Default"
perforcePort:[AppEnvironment perforcePort]
perforceHost:[AppEnvironment perforceHost]
perforceUser:[AppEnvironment perforceUser]
perforceClient:[AppEnvironment perforceClient]
perforcePasswd:[AppEnvironment perforcePasswd]] autorelease];
[theList addConfiguration:defaultConfig];
[theList setActiveConfiguration:0];
NSData* listData = [NSArchiver archivedDataWithRootObject:theList];
[defaultValues setObject:listData forKey:kConfigurationsKey];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
}
+ (AppDefaults*) defaultAppDefaults
{
static AppDefaults* gAppDefaults = nil;
if ( !gAppDefaults )
{
gAppDefaults = [[AppDefaults alloc] init];
}
return gAppDefaults;
}
- (id) init
{
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
self = [super init];
fDiffApp = [[userDefaults objectForKey:kDiffAppKey] retain];
fEditApp = [[userDefaults objectForKey:kEditAppKey] retain];
fMergeApp = [[userDefaults objectForKey:kMergeAppKey] retain];
fShowEntireDepot = [userDefaults boolForKey:kShowEntireDepotKey];
fShowDeletedFiles = [userDefaults boolForKey:kShowDeletedFilesKey];
fNumChanges = [[userDefaults objectForKey:kNumChangesKey] retain];
NSData* configData = [userDefaults dataForKey:kConfigurationsKey];
fConfigurations = [[NSUnarchiver unarchiveObjectWithData:configData] retain];
return self;
}
- (void) dealloc
{
[fDiffApp release];
[fEditApp release];
[fMergeApp release];
[fNumChanges release];
[fConfigurations release];
[super dealloc];
}
- (void) setEnvVars
{
// set these so that the p4api can use them
PerforceConfiguration* config = [fConfigurations activeConfiguration];
[AppEnvironment setPerforcePort:[config perforcePort]];
[AppEnvironment setPerforceHost:[config perforceHost]];
[AppEnvironment setPerforceUser:[config perforceUser]];
[AppEnvironment setPerforceClient:[config perforceClient]];
[AppEnvironment setPerforcePasswd:[config perforcePasswd]];
[AppEnvironment setPerforceDiff:fDiffApp];
[AppEnvironment setPerforceEditor:fEditApp];
[AppEnvironment setPerforceMerge:fMergeApp];
}
- (NSString*) getPerforcePort
{
PerforceConfiguration* config = [fConfigurations activeConfiguration];
return [config perforcePort];
}
- (NSString*) getPerforceUser
{
PerforceConfiguration* config = [fConfigurations activeConfiguration];
return [config perforceUser];
}
- (NSString*) getPerforceClient
{
PerforceConfiguration* config = [fConfigurations activeConfiguration];
return [config perforceClient];
}
- (NSString*) getDiffApp
{
return fDiffApp;
}
- (NSString*) getEditApp
{
return fEditApp;
}
- (NSString*) getMergeApp
{
return fMergeApp;
}
- (BOOL) getShowEntireDepot
{
return fShowEntireDepot;
}
- (BOOL) getShowDeletedFiles
{
return fShowDeletedFiles;
}
- (NSString*) getNumChangesToFetch
{
return fNumChanges;
}
- (PerforceConfigurationsList*) getConfigurations
{
return fConfigurations;
}
//
//
//
- (void) setConfigurations
{
[PerforceAction abortAllActions];
[self setEnvVars];
NSData* listData = [NSArchiver archivedDataWithRootObject:fConfigurations];
[[NSUserDefaults standardUserDefaults] setObject:listData forKey:kConfigurationsKey];
SendNotification (kDefaultsConfigurationsChanged);
}
- (void) setPerforcePort: (NSString*) perforcePort
{
PerforceConfiguration* config = [fConfigurations activeConfiguration];
if ( ![perforcePort isEqualTo:[config perforcePort]] )
{
[config setPerforcePort:perforcePort];
[AppEnvironment setPerforcePort:perforcePort];
[self setConfigurations];
}
}
- (void) setPerforceUser: (NSString*) perforceUser
{
PerforceConfiguration* config = [fConfigurations activeConfiguration];
if ( ![perforceUser isEqualTo:[config perforceUser]] )
{
[config setPerforceUser:perforceUser];
[AppEnvironment setPerforceUser:perforceUser];
[self setConfigurations];
}
}
- (void) setPerforceClient: (NSString*) perforceClient
{
PerforceConfiguration* config = [fConfigurations activeConfiguration];
if ( ![perforceClient isEqualTo:[config perforceClient]] )
{
[config setPerforceClient:perforceClient];
[AppEnvironment setPerforceClient:perforceClient];
[self setConfigurations];
}
}
- (void) setDiffApp: (NSString*) diffApp
{
if ( ![diffApp isEqualTo:fDiffApp] )
{
[fDiffApp release];
fDiffApp = [diffApp retain];
[AppEnvironment setPerforceDiff:fDiffApp];
[[NSUserDefaults standardUserDefaults] setObject:fDiffApp forKey:kDiffAppKey];
}
}
- (void) setEditApp: (NSString*) editApp
{
if ( ![editApp isEqualTo:fEditApp] )
{
[fEditApp release];
fEditApp = [editApp retain];
[AppEnvironment setPerforceEditor:fEditApp];
[[NSUserDefaults standardUserDefaults] setObject:fEditApp forKey:kEditAppKey];
}
}
- (void) setMergeApp: (NSString*) mergeApp
{
if ( ![mergeApp isEqualTo:fMergeApp] )
{
[fMergeApp release];
fMergeApp = [mergeApp retain];
[AppEnvironment setPerforceMerge:fMergeApp];
[[NSUserDefaults standardUserDefaults] setObject:fMergeApp forKey:kMergeAppKey];
}
}
- (void) setShowEntireDepot: (BOOL) showEntireDepot
{
if ( showEntireDepot != fShowEntireDepot )
{
fShowEntireDepot = showEntireDepot;
[[NSUserDefaults standardUserDefaults] setBool:fShowEntireDepot forKey:kShowEntireDepotKey];
SendNotification (kDefaultsShowEntireDepotChanged);
}
}
- (void) setShowDeletedFiles: (BOOL) showDeletedFiles
{
if ( showDeletedFiles != fShowDeletedFiles )
{
fShowDeletedFiles = showDeletedFiles;
[[NSUserDefaults standardUserDefaults] setBool:fShowDeletedFiles forKey:kShowDeletedFilesKey];
SendNotification (kDefaultsShowDeletedFilesChanged);
}
}
- (void) setNumChangesToFetch: (NSString*) numChanges
{
if ( ![numChanges isEqualTo:fNumChanges] )
{
[fNumChanges release];
fNumChanges = [numChanges retain];
[[NSUserDefaults standardUserDefaults] setObject:fNumChanges forKey:kNumChangesKey];
SendNotification (kDefaultsNumChangesToFetchChanged);
}
}
- (void) setConfigurations: (PerforceConfigurationsList*) newConfigurations
{
[fConfigurations release];
fConfigurations = [newConfigurations copy];
[self setConfigurations];
}
- (void) setActiveConfiguration: (NSString*) configName
{
int index = [fConfigurations indexOfConfigurationNamed:configName];
int activeIndex = [fConfigurations indexOfActiveConfiguration];
if ( (index > -1) && (index != activeIndex) )
{
[fConfigurations setActiveConfiguration:index];
[self setConfigurations];
}
}
@end
# |
Change |
User |
Description |
Committed |
|
#1
|
3176 |
paolo_resmini |
initial branch for Paolo Resmini |
|
|
//guest/jeff_argast/P4Cocoa/source/Defaults/AppDefaults.m |
#1
|
2732 |
Jeff Argast |
Initial submission of P4Cocoa |
|
|