add media to the command line.

This commit is contained in:
Kelvin Sherlock 2020-08-25 20:13:37 -04:00
parent 259b5f31a7
commit dc7b14d28d
4 changed files with 59 additions and 8 deletions

View File

@ -91,7 +91,8 @@ static NSString *kMyContext = @"kMyContext";
[self addObserver: self forKeyPath: @"mameNoThrottle" options:0 context: (__bridge void * _Nullable)(kMyContext)];
[_slotController addObserver: self forKeyPath: @"args" options: 0 context: (__bridge void * _Nullable)(kMyContext)];
[_mediaController addObserver: self forKeyPath: @"args" options: 0 context: (__bridge void * _Nullable)(kMyContext)];
[_mediaController bind: @"media" toObject: _slotController withKeyPath: @"media" options: 0];
[self buildCommandLine];
@ -225,11 +226,17 @@ static NSString * JoinArguments(NSArray *argv) {
}
NSArray *args = [_slotController args];
NSArray *args;
args = [_slotController args];
if ([args count]) {
[argv addObjectsFromArray: args];
}
args = [_mediaController args];
if ([args count]) {
[argv addObjectsFromArray: args];
}
if (_mameNoThrottle) [argv addObject: @"-nothrottle"];

View File

@ -63,10 +63,10 @@
<rect key="frame" x="1" y="21" width="304" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField identifier="CategoryView" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Pep-mX-LHY">
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Pep-mX-LHY">
<rect key="frame" x="0.0" y="0.0" width="304" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" identifier="CategoryView" title="Table View Cell" id="Rrg-wr-8eL">
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="Rrg-wr-8eL">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@ -87,6 +87,9 @@
<pathCell key="cell" controlSize="small" selectable="YES" editable="YES" focusRingType="none" alignment="left" pathStyle="popUp" id="dcz-8y-tKb">
<font key="font" metaFont="smallSystem"/>
</pathCell>
<connections>
<action selector="pathAction:" target="-2" id="4oX-bW-ANp"/>
</connections>
</pathControl>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zNo-ij-mUl">
<rect key="frame" x="256" y="5" width="23" height="18"/>
@ -96,7 +99,7 @@
<font key="font" metaFont="smallSystem"/>
</buttonCell>
<connections>
<action selector="buttonDelete:" target="-2" id="f30-YS-1UK"/>
<action selector="deleteAction:" target="-2" id="XAl-eQ-nUj"/>
</connections>
</button>
</subviews>

View File

@ -14,7 +14,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (weak) IBOutlet NSOutlineView *outlineView;
@property (nonatomic) NSDictionary *media;
- (IBAction)buttonDelete:(id)sender;
@property NSArray *args;
- (IBAction)deleteAction:(id)sender;
- (IBAction)pathAction:(id)sender;
//-(void)setMedia: (NSDictionary *)media;

View File

@ -233,6 +233,36 @@ enum {
kIndexCassette
};
-(void)rebuildArgs {
static char* prefix[] = {
"flop", "flop", "hard", "cdrm", "cass"
};
NSMutableArray *args = [NSMutableArray new];
unsigned counts[5] = { 0, 0, 0, 0, 0 };
for (unsigned j = 0; j < 5; ++j) {
MediaCategory *cat = _data[j];
NSInteger valid = [cat validCount];
for (NSInteger i = 0; i < valid; ++i) {
counts[j]++;
MediaItem *item = [cat objectAtIndex: i];
NSURL *url = [item url];
if (!url) continue;
[args addObject: [NSString stringWithFormat: @"-%s%u", prefix[j], counts[j]]];
NSString *s = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
[args addObject: s];
}
if (j == 0) counts[1] = counts[0]; // 3.5/5.25
}
[self setArgs: args];
}
-(void)rebuildRoot {
NSMutableArray *tmp = [NSMutableArray new];
for (unsigned j = 0 ; j < 5; ++j) {
@ -274,7 +304,10 @@ enum {
}
if (delta) [self rebuildRoot];
if (delta) {
[self rebuildRoot];
[self rebuildArgs];
}
}
- (void)viewDidLoad {
@ -371,7 +404,7 @@ enum {
#pragma mark - IBActions
- (IBAction)buttonDelete:(id)sender {
- (IBAction)deleteAction:(id)sender {
NSInteger row = [_outlineView rowForView: sender];
if (row < 0) return;
@ -386,5 +419,10 @@ enum {
MediaCategory *cat = [_outlineView parentForItem: item];
if ([cat pruneChildren]) [self rebuildRoot];
}
[self rebuildArgs];
}
- (IBAction)pathAction:(id)sender {
[self rebuildArgs];
}
@end