Add code to support selection of inspector on object load and when selected with the PopUp button

This commit is contained in:
Gregory John Casamento 2023-01-18 08:06:12 -05:00
parent 31f974643a
commit c582a05679
4 changed files with 43 additions and 0 deletions

View file

@ -1,7 +1,14 @@
{
"## Comment" = "Do NOT change this file, Gorm maintains it";
FirstResponder = {
Actions = (
"selectInspector:"
);
Super = NSObject;
};
GormBindingsInspector = {
Actions = (
"selectInspector:"
);
Outlets = (
"_containerView",

View file

@ -38,9 +38,14 @@
IBOutlet NSPopUpButton *_bindingsPopUp;
IBOutlet NSBox *_containerView;
IBInspector *_inspectorObject;
NSMutableArray *_bindingsArray;
NSUInteger _selectedInspectorIndex;
}
- (IBAction) selectInspector: (id)sender;
@end
#endif // INCLUDED_GormBindingsInspector_h

View file

@ -56,6 +56,7 @@
// Initialize the array that holds the inspector names...
_bindingsArray = [[NSMutableArray alloc] initWithCapacity: 10];
_selectedInspectorIndex = 0;
}
return self;
}
@ -85,10 +86,32 @@
return title;
}
- (void) _loadInspector
{
NSString *inspectorName = [_bindingsArray objectAtIndex: _selectedInspectorIndex];
Class cls = NSClassFromString(inspectorName);
_inspectorObject = [[cls alloc] init];
if (_inspectorObject != nil)
{
if (![NSBundle loadNibNamed: inspectorName owner: _inspectorObject])
{
NSLog(@"Could not load inspector for binding %@", inspectorName);
return;
}
}
else
{
NSLog(@"Could not instantiate class for %@", inspectorName);
}
}
- (void) _populatePopUp: (NSArray *)array
{
[_bindingsPopUp removeAllItems];
[_bindingsArray removeAllObjects];
_selectedInspectorIndex = 0;
if ([array count] == 0 || array == nil)
{
@ -108,6 +131,8 @@
[_bindingsArray addObject: inspector];
}
}
[self _loadInspector];
}
- (void) setObject: (id)obj
@ -131,4 +156,10 @@
[super revert: sender];
}
- (IBAction) selectInspector: (id)sender
{
_selectedInspectorIndex = [sender indexOfSelectedItem];
[self _loadInspector];
}
@end