From d37fb49781f1d01c38059fee9371addbb53faccd Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 9 Mar 2021 22:58:01 -0500 Subject: [PATCH] display slot submenus. i don't particularly like the UI so it will probably change soon. --- Ample/NewSlotViewController.m | 34 ++++++++++++++++++---- Ample/Slot.h | 4 +-- Ample/Slot.m | 53 +++++++++++------------------------ 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/Ample/NewSlotViewController.m b/Ample/NewSlotViewController.m index 0629820..678eef5 100644 --- a/Ample/NewSlotViewController.m +++ b/Ample/NewSlotViewController.m @@ -49,6 +49,7 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); // Do view setup here. _root = @[]; + [_outlineView setIndentationPerLevel: 2.0]; } -(void)resetMachine { @@ -179,8 +180,16 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); - (IBAction)menuChanged:(NSPopUpButton *)sender { + BOOL direct = YES; NSInteger index = [sender tag]; if (index < 0) return; // + + if (index >= 0 && index < SLOT_COUNT) { + direct = YES; + } else { + direct = NO; + index &= ~0x10000; + } if (index >= SLOT_COUNT) return; // unsigned mask = 1 << index; @@ -190,9 +199,11 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); SlotOption *o = [[sender selectedItem] representedObject]; Slot *item = _slot_object[index]; - _slots_explicit |= mask; - _slot_value[index] = [o value]; - //_slots_default &= ~mask; + if (direct) { + _slots_explicit |= mask; + _slot_value[index] = [o value]; + //_slots_default &= ~mask; + } Media media = [item selectedMedia]; if (!MediaEqual(&media, &_slot_media[index])) { @@ -201,6 +212,11 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); } + // needs to reload children if expanded. + if (direct) { + BOOL rc = ([_outlineView isItemExpanded: item]); + [_outlineView reloadItem: item reloadChildren: rc]; + } [self rebuildArgs]; } -(IBAction)resetSlots:(id)sender { @@ -217,8 +233,8 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); if (index < 0) continue; _slot_media[index] = [item selectedMedia]; } - //[_outlineView reloadData]; // will need to reload if changing the default makes children disappear. + [_outlineView reloadData]; [self rebuildMedia]; [self rebuildArgs]; } @@ -233,17 +249,23 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); if (!item) return [_root count]; - return 0; + NSArray *tmp = [(Slot *)item selectedChildren]; + return [tmp count]; +// return 0; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { if (!item) return [_root objectAtIndex: index]; + NSArray *tmp = [(Slot *)item selectedChildren]; + return [tmp objectAtIndex: index]; return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { - return NO; + if (!item) return NO; + NSArray *tmp = [(Slot *)item selectedChildren]; + return [tmp count] > 0; } diff --git a/Ample/Slot.h b/Ample/Slot.h index d1a3383..b1cd403 100644 --- a/Ample/Slot.h +++ b/Ample/Slot.h @@ -30,14 +30,12 @@ -(void)reset; -(void)prepareView: (SlotTableCellView *)view; -//-(void)loadDeviceSlots: (NSDictionary *)devices; -(void)selectValue: (NSString *)value; -(SlotOption *)selectedItem; -(Media)selectedMedia; -//-(instancetype)initWithName: (NSString *)name title: (NSString *)title data: (NSArray *)data; - +-(NSArray *)selectedChildren; @end diff --git a/Ample/Slot.m b/Ample/Slot.m index 5a220d4..7042c6a 100644 --- a/Ample/Slot.m +++ b/Ample/Slot.m @@ -41,7 +41,7 @@ static NSArray *DeepCopyArray(NSArray *src) { @end @interface SlotOption() { - NSArray *_children; + //NSArray *_children; //NSDictionary *_media; Media _media; NSString *_keyPath; @@ -49,6 +49,8 @@ static NSArray *DeepCopyArray(NSArray *src) { BOOL _default; } +@property (readonly) NSArray *children; + -(instancetype)initWithDictionary: (NSDictionary *)dictionary devices: (NSDictionary *)devices; -(NSMenuItem *)menuItem; @@ -155,6 +157,12 @@ static NSDictionary *IndexMap = nil; } +-(NSArray *)selectedChildren { + if (_selectedIndex < 0) return nil; + return [[_options objectAtIndex: _selectedIndex] children]; +} + + -(id)copyWithZone:(NSZone *)zone { Slot *child = [Slot new]; @@ -222,7 +230,13 @@ static NSDictionary *IndexMap = nil; _defaultIndex = index; } ++index; - if (topLevel) [o setKeyPath: _name]; + if (topLevel) { + [o setKeyPath: _name]; + NSArray *tmp = [o children]; + for (Slot *x in tmp) { + [x setIndex: _index | 0x10000]; + } + } [options addObject: o]; } _options = options; @@ -498,42 +512,7 @@ NSDictionary *BuildDevices(NSArray *array) { NSArray *BuildSlots(NSString *name, NSDictionary *data) { static NSCache *cache = nil; - - typedef struct SlotInfo { - NSString *key; - NSString *flag; - NSString *title; - } SlotInfo; - static SlotInfo Slots[] = { - { @"ram", @"-ramsize", @"RAM:" }, - { @"sl0", @"-sl0", @"Slot 0:" }, - { @"sl1", @"-sl1", @"Slot 1:" }, - { @"sl2", @"-sl2", @"Slot 2:" }, - { @"sl3", @"-sl3", @"Slot 3:" }, - { @"sl4", @"-sl4", @"Slot 4:" }, - { @"sl5", @"-sl5", @"Slot 5:" }, - { @"sl6", @"-sl6", @"Slot 6:" }, - { @"sl7", @"-sl7", @"Slot 7:" }, - { @"exp", @"-exp", @"Expansion:" }, - { @"aux", @"-aux", @"Auxiliary:" }, - { @"rs232", @"-rs232", @"RS232:" }, - { @"gameio", @"-gameio", @"Game I/O:" }, - { @"modem", @"-modem", @"Modem:" }, - { @"printer", @"-printer", @"Printer:" }, - - // nubus mac - { @"nb9", @"-nb9", @"Slot 9:" }, - { @"nba", @"-nba", @"Slot A:" }, - { @"nbb", @"-nbb", @"Slot B:" }, - { @"nbc", @"-nbc", @"Slot C:" }, - { @"nbd", @"-nbd", @"Slot D:" }, - { @"nbe", @"-nbe", @"Slot E:" }, - }; - - - #define SIZEOF(x) (sizeof(x) / sizeof(x[0])) - if (!cache) { cache = [NSCache new]; }