From 4ce12c8d0821bba0d306904bba630546a8983aad Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Wed, 14 Oct 2015 11:25:48 +0000 Subject: [PATCH] improve defaults handling git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@39065 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++++++++++ EcProcess.h | 10 +++++----- EcProcess.m | 15 +++++++++++---- EcUserDefaults.h | 5 +++++ EcUserDefaults.m | 17 +++++++++++++++++ 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11ba8fc..d525645 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2015-10-14 Richard Frith-Macdonald + + * EcUserDefaults.h: + * EcUserDefaults.m: + New -revertSettings method to revert all local config settings. + * EcProcess.h: + * EcProcess.m: + Change cmdDefaultDbg to cmdBasicDbg to avoid confusion of the debug + mode with default settings. + Add 'defaults revert' command for Console to use. + 2015-10-09 Richard Frith-Macdonald * EcProcess.h: declare new -launch: method diff --git a/EcProcess.h b/EcProcess.h index 7403cf1..b7f0e1f 100644 --- a/EcProcess.h +++ b/EcProcess.h @@ -601,12 +601,12 @@ extern NSString* cmdVersion(NSString *ver); - (void) cmdDbg: (NSString*)type msg: (NSString*)fmt, ... NS_FORMAT_FUNCTION(2,3); -/** Send a debug message with debug mode 'defaultMode'.
+/** Send a debug message with debug mode 'basicMode'.
* Calls the -cmdDbg:msg:arguments: method. */ - (void) cmdDebug: (NSString*)fmt arguments: (va_list)args; -/** Send a debug message with debug mode 'defaultMode'.
+/** Send a debug message with debug mode 'basicMode'.
* Operates by calling the -cmdDebug:arguments: method. */ - (void) cmdDebug: (NSString*)fmt, ... NS_FORMAT_FUNCTION(1,2); @@ -1045,9 +1045,9 @@ extern NSString* cmdVersion(NSString *ver); extern EcProcess *EcProc; /* Single instance or nil */ -extern NSString* cmdConnectDbg; /* Debug connection attempts. */ -extern NSString* cmdDefaultDbg; /* Debug normal stuff. */ -extern NSString* cmdDetailDbg; /* Debug stuff in more detail. */ +extern NSString *cmdBasicDbg; /* Debug normal stuff. */ +extern NSString *cmdConnectDbg; /* Debug connection attempts. */ +extern NSString *cmdDetailDbg; /* Debug stuff in more detail. */ #endif /* INCLUDED_ECPROCESS_H */ diff --git a/EcProcess.m b/EcProcess.m index 6be02a7..5246125 100644 --- a/EcProcess.m +++ b/EcProcess.m @@ -625,7 +625,7 @@ ecCommandName() } -NSString *cmdDefaultDbg = @"defaultMode"; +NSString *cmdBasicDbg = @"basicMode"; NSString *cmdConnectDbg = @"connectMode"; NSString *cmdDetailDbg = @"detailMode"; @@ -1797,11 +1797,11 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval); [cmdDebugKnown setObject: @"Mode for distributed object connections" forKey: cmdConnectDbg]; [cmdDebugKnown setObject: @"Standard mode for basic debug information" - forKey: cmdDefaultDbg]; + forKey: cmdBasicDbg]; [cmdDebugKnown setObject: @"Detailed but general purpose debugging" forKey: cmdDetailDbg]; - [cmdDebugModes addObject: cmdDefaultDbg]; + [cmdDebugModes addObject: cmdBasicDbg]; [self ecRegisterDefault: @"Memory" withTypeText: @"YES/NO" @@ -2003,7 +2003,7 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval); - (void) cmdDebug: (NSString*)fmt arguments: (va_list)args { - if (nil != [cmdDebugModes member: cmdDefaultDbg]) + if (nil != [cmdDebugModes member: cmdBasicDbg]) { if (nil == debugLogger) { @@ -3023,7 +3023,14 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval); [self cmdPrintf: @"and value, the command sets a default.\n"]; [self cmdPrintf: @"With the 'read' parameter followed by a name,"]; [self cmdPrintf: @"the command is used to show a default.\n"]; + [self cmdPrintf: @"With the 'revert' parameter,"]; + [self cmdPrintf: @"the command is used to revert all defaults.\n"]; } + else if ([msg count] > 1 && [[msg objectAtIndex: 1] isEqual: @"revert"]) + { + [cmdDefs revertSettings]; + [self cmdPrintf: @"All settings are reverted to default.\n"]; + } else if ([msg count] > 2) { NSString *mode = (NSString*)[msg objectAtIndex: 1]; diff --git a/EcUserDefaults.h b/EcUserDefaults.h index ba89314..c6eed21 100644 --- a/EcUserDefaults.h +++ b/EcUserDefaults.h @@ -67,6 +67,11 @@ */ - (NSString*) key: (NSString*)aKey; +/** Removes all settings previously set up using the -setCommand:forKey: + * method. + */ +- (void) revertSettings; + /** Sets a value to take precedence over others (in the volatile domain * reserved for commands issued to the current process by an operator).
* Setting a nil value removes any previously set value so that behavior diff --git a/EcUserDefaults.m b/EcUserDefaults.m index 9645bac..725b798 100644 --- a/EcUserDefaults.m +++ b/EcUserDefaults.m @@ -208,6 +208,11 @@ static NSLock *lock = nil; return [defs removeObjectForKey: [self _getKey: aKey]]; } +- (void) revertSettings +{ + [defs revertSettings]; +} + - (void) setBool: (BOOL)value forKey: (NSString*)aKey { [defs setBool: value forKey: [self key: aKey]]; @@ -301,6 +306,18 @@ static NSLock *lock = nil; return aKey; } +- (void) revertSettings +{ + NSDictionary *old = [self volatileDomainForName: @"EcCommand"]; + + if (nil != old) + { + [self removeVolatileDomainForName: @"EcCommand"]; + [[NSNotificationCenter defaultCenter] postNotificationName: + NSUserDefaultsDidChangeNotification object: self]; + } +} + - (BOOL) setCommand: (id)val forKey: (NSString*)key { NSDictionary *old = [self volatileDomainForName: @"EcCommand"];