From 48cdd702be72fd49d5c699757a1f7b91da213dd5 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 12 Mar 2021 19:58:12 -0500 Subject: [PATCH] pop up for child slots. --- Ample/Base.lproj/MediaView.xib | 3 +- Ample/Base.lproj/NewSlotView.xib | 31 ++++++++++-------- Ample/MediaViewController.m | 4 +++ Ample/NewSlotViewController.m | 55 +++++++++++++++++++++++++++++--- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/Ample/Base.lproj/MediaView.xib b/Ample/Base.lproj/MediaView.xib index e02ae57..c6f808a 100644 --- a/Ample/Base.lproj/MediaView.xib +++ b/Ample/Base.lproj/MediaView.xib @@ -20,7 +20,7 @@ - + @@ -38,6 +38,7 @@ + diff --git a/Ample/Base.lproj/NewSlotView.xib b/Ample/Base.lproj/NewSlotView.xib index 8cc6743..8151e9a 100644 --- a/Ample/Base.lproj/NewSlotView.xib +++ b/Ample/Base.lproj/NewSlotView.xib @@ -9,6 +9,7 @@ + @@ -22,7 +23,7 @@ - + @@ -40,6 +41,7 @@ + @@ -127,35 +129,38 @@ - + - - + + - + - - + + - + @@ -166,14 +171,14 @@ - + - + - + @@ -199,7 +204,7 @@ - + diff --git a/Ample/MediaViewController.m b/Ample/MediaViewController.m index 4a11d26..318b10f 100644 --- a/Ample/MediaViewController.m +++ b/Ample/MediaViewController.m @@ -80,6 +80,8 @@ } -(void)prepareView: (NSTableCellView *)view { + + [view setObjectValue: self]; [[view textField] setStringValue: _title]; } @@ -209,6 +211,8 @@ NSValueTransformer *t; NSDictionary *options; + [view setObjectValue: self]; + NSPathControl *pc = [view pathControl]; NSButton *button = [view ejectButton]; diff --git a/Ample/NewSlotViewController.m b/Ample/NewSlotViewController.m index 54e9af3..96b474b 100644 --- a/Ample/NewSlotViewController.m +++ b/Ample/NewSlotViewController.m @@ -6,12 +6,16 @@ // Copyright © 2020 Kelvin Sherlock. All rights reserved. // + #import "Ample.h" #import "NewSlotViewController.h" #import "Menu.h" #import "Slot.h" #import "Media.h" + +#import + /* number of slot types. bitmask used so should be < sizeof(unsigned *8) */ #define SLOT_COUNT 21 static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); @@ -19,10 +23,12 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); #define SIZEOF(x) (sizeof(x) / sizeof(x[0])) +static unsigned RootKey = 0; @interface NewSlotViewController () @property (weak) IBOutlet NSOutlineView *outlineView; +@property (weak) IBOutlet NSOutlineView *childOutlineView; @end @@ -50,12 +56,17 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); // Do view setup here. _root = @[]; + objc_setAssociatedObject(_outlineView, &RootKey, _root, OBJC_ASSOCIATION_RETAIN); + + //[_outlineView setIndentationPerLevel: 2.0]; } -(void)resetMachine { _root = @[]; + objc_setAssociatedObject(_outlineView, &RootKey, _root, OBJC_ASSOCIATION_RETAIN); + [_outlineView reloadData]; _slots_valid = 0; @@ -111,6 +122,7 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); extern NSArray *BuildSlots(NSString *name, NSDictionary *data); _root = BuildSlots(_machine, d); + objc_setAssociatedObject(_outlineView, &RootKey, _root, OBJC_ASSOCIATION_RETAIN); for (Slot *item in _root) { NSInteger index = [item index]; @@ -214,22 +226,41 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); } // needs to reload children if expanded. +#ifdef SLOT_TREE if (direct) { BOOL rc = ([_outlineView isItemExpanded: item]); [_outlineView reloadItem: item reloadChildren: rc]; } +#endif [self rebuildArgs]; } - (IBAction)hamburger:(id)sender { -#if 1 +#if 0 if ([_popover isShown]) { [_popover close]; } #endif + + NSInteger index = [sender tag]; + if (index < 0 || index >= SLOT_COUNT) return; + + Slot *item = _slot_object[index]; + + NSArray *children = [item selectedChildren]; + objc_setAssociatedObject(_childOutlineView, &RootKey, children, OBJC_ASSOCIATION_RETAIN); + if (!children) return; + + [_childOutlineView reloadData]; + NSSize size = [_popover contentSize]; + if (size.width < 200) size.width = 250; + size = [_childOutlineView sizeThatFits: size]; + size.height += 40; + [_popover setContentSize: size]; + [_popover showRelativeToRect: [sender bounds] ofView: sender - preferredEdge: NSRectEdgeMaxX]; + preferredEdge: NSRectEdgeMaxY]; } -(IBAction)resetSlots:(id)sender { @@ -247,7 +278,9 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); _slot_media[index] = [item selectedMedia]; } +#ifdef SLOT_TREE [_outlineView reloadData]; +#endif [self rebuildMedia]; [self rebuildArgs]; } @@ -260,25 +293,37 @@ static_assert(SLOT_COUNT <= sizeof(unsigned) * 8, "too many slot types"); - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { - if (!item) return [_root count]; + NSArray *root = objc_getAssociatedObject(outlineView, &RootKey); + if (!item) return [root count]; +#ifdef SLOT_TREE NSArray *tmp = [(Slot *)item selectedChildren]; return [tmp count]; -// return 0; +#endif + return 0; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { - if (!item) return [_root objectAtIndex: index]; + NSArray *root = objc_getAssociatedObject(outlineView, &RootKey); + + if (!item) return [root objectAtIndex: index]; +#ifdef SLOT_TREE NSArray *tmp = [(Slot *)item selectedChildren]; return [tmp objectAtIndex: index]; +#endif return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { + +#ifdef SLOT_TREE if (!item) return NO; NSArray *tmp = [(Slot *)item selectedChildren]; return [tmp count] > 0; +#else + return NO; +#endif }