Ensure that stack frames are loaded when the array controller selection changes.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 24 Oct 2015 05:49:16 +0000 (01:49 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 24 Oct 2015 05:49:16 +0000 (01:49 -0400)
This also makes the array controller not attempt to preserve the selection.

English.lproj/Debugger.xib
Source/DebuggerController.m

index 1d2a263cb5ecfe1e7b93bf99e521037166cdf4b3..617567664091ada654c2b60eaa1bb59db959311b 100644 (file)
                 <outlet property="delegate" destination="-2" id="92"/>
             </connections>
         </window>
-        <arrayController objectClassName="StackFrame" automaticallyPreparesContent="YES" automaticallyRearrangesObjects="YES" id="36" userLabel="StackController">
+        <arrayController objectClassName="StackFrame" automaticallyPreparesContent="YES" preservesSelection="NO" automaticallyRearrangesObjects="YES" id="36" userLabel="StackController">
             <declaredKeys>
                 <string>filename</string>
                 <string>index</string>
index c15befd459aa6418289b6cd0ef2c4d4b60a082ca..9de546678461e3f1153981420dd175384e226878 100644 (file)
   [[self window] setExcludedFromWindowsMenu:YES];
   [[self window] setTitle:[NSString stringWithFormat:@"MacGDBp @ %d", [connection port]]];
   [sourceViewer setDelegate:self];
-  [stackArrayController setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES] autorelease]]];
+  [stackArrayController setSortDescriptors:@[ [[[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES] autorelease] ]];
+  [stackArrayController addObserver:self
+                         forKeyPath:@"selectedObjects"
+                            options:NSKeyValueObservingOptionNew
+                            context:nil];
   self.connection.autoAttach = [attachedCheckbox_ state] == NSOnState;
 }
 
+/**
+ * Key-value observation routine.
+ */
+- (void)observeValueForKeyPath:(NSString*)keyPath
+                      ofObject:(id)object
+                        change:(NSDictionary<NSString*,id>*)change
+                       context:(void*)context {
+  if (object == stackArrayController && [keyPath isEqualToString:@"selectedObjects"]) {
+    for (StackFrame* frame in stackArrayController.selectedObjects)
+      [connection loadStackFrame:frame];
+  } else {
+    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+  }
+}
+
 /**
  * Validates the menu items for the "Debugger" menu
  */