[dasher] MacOSX: make the start-handler dropdown box work!



commit 8e2ea88f8f42545289c88282fbbe6a309fa71d87
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Fri Feb 25 11:36:16 2011 +0000

    MacOSX: make the start-handler dropdown box work!
    
    This is a bit hacky, lots of strings need to match up between InterfaceBuilder
    and PreferencesController.mm, and PreferencesController.mm and Parameters.h...

 Src/MacOSX/DasherController.h                      |   22 -------
 Src/MacOSX/DasherController.mm                     |   49 ---------------
 Src/MacOSX/DasherEdit.mm                           |    1 -
 Src/MacOSX/DasherViewAqua.mm                       |    1 -
 Src/MacOSX/DasherViewOpenGL.mm                     |    1 -
 .../English.lproj/Preferences.nib/designable.nib   |   66 +++++++++++++------
 .../English.lproj/Preferences.nib/keyedobjects.nib |  Bin 51984 -> 52212 bytes
 Src/MacOSX/PreferencesController.mm                |   36 ++++++++++-
 8 files changed, 77 insertions(+), 99 deletions(-)
---
diff --git a/Src/MacOSX/DasherEdit.mm b/Src/MacOSX/DasherEdit.mm
index 1ce3343..966ae2a 100644
--- a/Src/MacOSX/DasherEdit.mm
+++ b/Src/MacOSX/DasherEdit.mm
@@ -7,7 +7,6 @@
 //
 
 #import "DasherEdit.h"
-#import "PreferencesController.h"
 #import "UnicharGenerator.h"
 #import "../Common/Common.h"
 #import <Carbon/Carbon.h>
diff --git a/Src/MacOSX/DasherViewAqua.mm b/Src/MacOSX/DasherViewAqua.mm
index 179e683..5df319b 100755
--- a/Src/MacOSX/DasherViewAqua.mm
+++ b/Src/MacOSX/DasherViewAqua.mm
@@ -11,7 +11,6 @@
 #import <Foundation/Foundation.h>
 
 #import "DasherApp.h"
-#import "PreferencesController.h"
 
 #import <sys/time.h>
 
diff --git a/Src/MacOSX/DasherViewOpenGL.mm b/Src/MacOSX/DasherViewOpenGL.mm
index 61708a6..df17a93 100755
--- a/Src/MacOSX/DasherViewOpenGL.mm
+++ b/Src/MacOSX/DasherViewOpenGL.mm
@@ -11,7 +11,6 @@
 #import <Foundation/Foundation.h>
 
 #import "DasherApp.h"
-#import "PreferencesController.h"
 
 #import <sys/time.h>
 
diff --git a/Src/MacOSX/English.lproj/Preferences.nib/designable.nib b/Src/MacOSX/English.lproj/Preferences.nib/designable.nib
index ebf8757..853f949 100644
--- a/Src/MacOSX/English.lproj/Preferences.nib/designable.nib
+++ b/Src/MacOSX/English.lproj/Preferences.nib/designable.nib
@@ -2,17 +2,17 @@
 <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
 	<data>
 		<int key="IBDocument.SystemTarget">1050</int>
-		<string key="IBDocument.SystemVersion">10F569</string>
+		<string key="IBDocument.SystemVersion">10J567</string>
 		<string key="IBDocument.InterfaceBuilderVersion">788</string>
-		<string key="IBDocument.AppKitVersion">1038.29</string>
-		<string key="IBDocument.HIToolboxVersion">461.00</string>
+		<string key="IBDocument.AppKitVersion">1038.35</string>
+		<string key="IBDocument.HIToolboxVersion">462.00</string>
 		<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
 			<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
 			<string key="NS.object.0">788</string>
 		</object>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
-			<integer value="14"/>
+			<integer value="654"/>
 		</object>
 		<object class="NSArray" key="IBDocument.PluginDependencies">
 			<bool key="EncodedWithXMLCoder">YES</bool>
@@ -2044,6 +2044,14 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
 				<bool key="NSClearsFilterPredicateOnInsertion">YES</bool>
 			</object>
 			<object class="NSUserDefaultsController" id="16386636">
+				<object class="NSMutableArray" key="NSDeclaredKeys">
+					<bool key="EncodedWithXMLCoder">YES</bool>
+					<object class="NSMutableString">
+						<characters key="NS.bytes">StartWithMousePosition</characters>
+					</object>
+					<string>StartOnMousePosition</string>
+					<string>StartHandlerIdx</string>
+				</object>
 				<bool key="NSSharedInstance">YES</bool>
 			</object>
 		</object>
@@ -2444,22 +2452,6 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBBindingConnection" key="connection">
-						<string key="label">value: values.StartOnMousePosition</string>
-						<reference key="source" ref="514110910"/>
-						<reference key="destination" ref="16386636"/>
-						<object class="NSNibBindingConnector" key="connector">
-							<reference key="NSSource" ref="514110910"/>
-							<reference key="NSDestination" ref="16386636"/>
-							<string key="NSLabel">value: values.StartOnMousePosition</string>
-							<string key="NSBinding">value</string>
-							<string key="NSKeyPath">values.StartOnMousePosition</string>
-							<int key="NSNibBindingConnectorVersion">2</int>
-						</object>
-					</object>
-					<int key="connectionID">682</int>
-				</object>
-				<object class="IBConnectionRecord">
-					<object class="IBBindingConnection" key="connection">
 						<string key="label">value: values.PauseOutside</string>
 						<reference key="source" ref="631046352"/>
 						<reference key="destination" ref="16386636"/>
@@ -3081,6 +3073,38 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
 					</object>
 					<int key="connectionID">867</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBBindingConnection" key="connection">
+						<string key="label">value: values.StartWithMousePosition</string>
+						<reference key="source" ref="514110910"/>
+						<reference key="destination" ref="16386636"/>
+						<object class="NSNibBindingConnector" key="connector">
+							<reference key="NSSource" ref="514110910"/>
+							<reference key="NSDestination" ref="16386636"/>
+							<string key="NSLabel">value: values.StartWithMousePosition</string>
+							<string key="NSBinding">value</string>
+							<string key="NSKeyPath">values.StartWithMousePosition</string>
+							<int key="NSNibBindingConnectorVersion">2</int>
+						</object>
+					</object>
+					<int key="connectionID">874</int>
+				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBBindingConnection" key="connection">
+						<string key="label">selectedIndex: values.StartHandlerIdx</string>
+						<reference key="source" ref="797062810"/>
+						<reference key="destination" ref="16386636"/>
+						<object class="NSNibBindingConnector" key="connector">
+							<reference key="NSSource" ref="797062810"/>
+							<reference key="NSDestination" ref="16386636"/>
+							<string key="NSLabel">selectedIndex: values.StartHandlerIdx</string>
+							<string key="NSBinding">selectedIndex</string>
+							<string key="NSKeyPath">values.StartHandlerIdx</string>
+							<int key="NSNibBindingConnectorVersion">2</int>
+						</object>
+					</object>
+					<int key="connectionID">876</int>
+				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<object class="NSArray" key="orderedObjects">
@@ -4572,7 +4596,7 @@ AAAAAAAAAAAAAHRleHQAAAAAQ29weXJpZ2h0IEFwcGxlIENvbXB1dGVyLCBJbmMuLCAyMDA1AAAAAA</
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">867</int>
+			<int key="maxID">876</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
diff --git a/Src/MacOSX/English.lproj/Preferences.nib/keyedobjects.nib b/Src/MacOSX/English.lproj/Preferences.nib/keyedobjects.nib
index 5e15696..dbec137 100644
Binary files a/Src/MacOSX/English.lproj/Preferences.nib/keyedobjects.nib and b/Src/MacOSX/English.lproj/Preferences.nib/keyedobjects.nib differ
diff --git a/Src/MacOSX/PreferencesController.mm b/Src/MacOSX/PreferencesController.mm
index f7568e4..7a0cdb8 100644
--- a/Src/MacOSX/PreferencesController.mm
+++ b/Src/MacOSX/PreferencesController.mm
@@ -18,6 +18,18 @@ static PreferencesController *preferencesController = nil;
 }
 @end
 
+//The key which "Start With Mouse Position:" checkbox writes its value to, as specified in InterfaceBuilder
+static const NSString *AnyStartHandlerEnabled = @"values.StartWithMousePosition";
+//The key which the drop-down box (circle/two-box) writes its selected-index to, as specified in InterfaceBuilder
+static const NSString *StartHandlerIndex = @"values.StartHandlerIdx";
+//The names (as written out to persistent settings file) of the bool parameters corresponding to each
+// of the entries in that drop-down box, in the order they appear in the drop-down.
+static const NSString *StartHandlerParamNames[2] = {
+  @"CircleStart", @"StartOnMousePosition"
+};
+#define numStartHandlerParams (sizeof(StartHandlerParamNames)/sizeof(StartHandlerParamNames[0]))
+
+
 @implementation PreferencesController
 
 - (id)defaultsValueForKey:(NSString *)aKey {
@@ -39,10 +51,23 @@ static PreferencesController *preferencesController = nil;
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
-  NSString *key = [keyPath substringFromIndex:[@"values." length]];
-  NSString *value = [self defaultsValueForKey:key];
   
-  [dasherApp setParameterValue:value forKey:key];
+  if ([keyPath isEqualTo:AnyStartHandlerEnabled] || [keyPath isEqualTo:StartHandlerIndex]) {
+    bool bOn[numStartHandlerParams];
+    for (unsigned int i=0; i<numStartHandlerParams; i++) bOn[i]=NO;
+    NSUserDefaultsController *udc = [NSUserDefaultsController sharedUserDefaultsController];
+    if ([[udc valueForKeyPath:AnyStartHandlerEnabled] boolValue]) {
+      int which = [[udc valueForKeyPath:StartHandlerIndex] intValue];
+      if (which>=0 && which<numStartHandlerParams)
+        bOn[ which ]=YES;
+    }
+    for (unsigned int i=0; i<numStartHandlerParams; i++)
+      [dasherApp setParameterValue:[NSNumber numberWithBool:bOn[i]] forKey:StartHandlerParamNames[i]];
+  } else {
+    NSString *key = [keyPath substringFromIndex:[@"values." length]];
+    NSString *value = [self defaultsValueForKey:key];
+    [dasherApp setParameterValue:value forKey:key];
+  }
 }
 
 - (void)observeDefaults {
@@ -51,8 +76,11 @@ static PreferencesController *preferencesController = nil;
   NSUserDefaultsController *udc = [NSUserDefaultsController sharedUserDefaultsController];
   
   while (key = [e nextObject]) {
-    [udc addObserver:self forKeyPath:[NSString stringWithFormat:@"values.%@", key] options:0 context:NULL];
+    if (![key isEqualToString:@"FrameRate"])
+      [udc addObserver:self forKeyPath:[NSString stringWithFormat:@"values.%@", key] options:0 context:NULL];
   }
+  [udc addObserver:self forKeyPath:AnyStartHandlerEnabled options:0 context:NULL];
+  [udc addObserver:self forKeyPath:StartHandlerIndex options:0 context:NULL];
 }
 
 - (void)awakeFromNib {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]