2
  • Binding a popup menu to an array controller with the path selection.type works fine.
  • Binding a popup menu to a document controller with the path currentDocument.arrayController.selection.type works one way only (changes in selection are not propagated to the popup menu).

How can one achieve inspector-window-like functionality by binding a popup menu to the appropriate array controller depending on the document in focus?

andyvn22
  • 14,696
  • 1
  • 52
  • 74

2 Answers2

0

Are they the same array controller, or is the Inspector window using a separate array controller that happens to be fed by the same array?

Two separate array controllers will have two separate selections. To fix that, give the same object that owns the ultimate array a second property for an NSIndexSet for the selection, and bind both array controllers' selectedIndexes to that property.

It may seem slightly silly to use an NSIndexSet for a pop-up menu's single (not multiple) selection, but array controllers are generic like that.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • There's only one array controller. (Well. There are as many as there are open documents.) The question is why binding directly to it (thus needing to put the inspector window in the document nib, meh) works, whereas binding to it through a document controller and `currentDocument` doesn't. – andyvn22 Oct 23 '10 at 15:11
0

Here's an (ugly) workaround for anyone struggling with this: subclass NSArrayController so that its selection always returns all its contents, keep track of the selected items yourself in an NSMutableSet, and bind the array controller's content set to that. (For some reason, binding the content set of an array controller works across the nibs, though binding the selection indices of a popup menu doesn't.)

andyvn22
  • 14,696
  • 1
  • 52
  • 74