ample/Ample/LaunchWindowController.m

538 lines
14 KiB
Mathematica
Raw Normal View History

//
// LaunchWindowController.m
2020-08-30 03:24:49 +00:00
// Ample
//
// Created by Kelvin Sherlock on 8/29/2020.
// Copyright © 2020 Kelvin Sherlock. All rights reserved.
//
2020-09-02 03:52:11 +00:00
#import "Ample.h"
#import "LaunchWindowController.h"
#import "MediaViewController.h"
2021-05-30 22:19:51 +00:00
#import "SlotViewController.h"
#import "MachineViewController.h"
#import "LogWindowController.h"
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
#import "AutocompleteControl.h"
#import "SoftwareList.h"
2021-01-30 01:07:44 +00:00
#include <sys/stat.h>
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
#include <wctype.h>
2021-01-30 01:07:44 +00:00
static NSString *kMyContext = @"kMyContext";
static NSString *kContextMachine = @"kContextMachine";
@interface LaunchWindowController ()
@property (strong) IBOutlet MediaViewController *mediaController;
2021-05-30 22:19:51 +00:00
@property (strong) IBOutlet SlotViewController *slotController;
@property (strong) IBOutlet MachineViewController *machineViewController;
@property (weak) IBOutlet NSView *machineView;
@property (weak) IBOutlet NSView *slotView;
@property (weak) IBOutlet NSView *mediaView;
/* kvo */
@property NSString *commandLine;
@property NSArray *args;
@property NSString *mameMachine;
@property BOOL mameDebug;
@property BOOL mameSquarePixels;
@property BOOL mameMouse;
@property BOOL mameSamples;
2020-09-05 15:00:29 +00:00
@property BOOL mameAVI;
@property BOOL mameWAV;
@property BOOL mameVGM;
2020-09-05 15:00:29 +00:00
@property NSString *mameAVIPath;
@property NSString *mameWAVPath;
@property NSString *mameVGMPath;
@property NSString *mameShareDirectory;
2020-09-05 15:00:29 +00:00
@property NSInteger mameSpeed;
@property BOOL mameBGFX;
@property NSInteger mameBackend;
@property NSInteger mameEffects;
@property NSInteger mameWindowMode;
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
@property (weak) IBOutlet AutocompleteControl *softwareListControl;
@property SoftwareSet *softwareSet;
@property Software *software;
@end
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
@interface LaunchWindowController (SoftwareList)
-(void)updateSoftwareList;
@end
@implementation LaunchWindowController
-(NSString *)windowNibName {
return @"LaunchWindow";
}
2020-09-05 15:00:29 +00:00
-(void)windowWillLoad {
[self setMameSpeed: 1];
[self setMameBGFX: YES];
[self setMameMouse: NO];
[self setMameSamples: YES];
2020-09-05 15:00:29 +00:00
}
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
[_slotView addSubview: [_slotController view]];
[_mediaView addSubview: [_mediaController view]];
[_machineView addSubview: [_machineViewController view]];
2020-09-05 15:00:29 +00:00
NSArray *keys = @[
@"mameMachine", @"mameSquarePixels", @"mameWindowMode",
@"mameMouse", @"mameSamples",
2020-09-05 15:00:29 +00:00
@"mameDebug",
@"mameSpeed",
2020-09-05 15:00:29 +00:00
@"mameAVI", @"mameAVIPath",
@"mameWAV", @"mameWAVPath",
@"mameVGM", @"mameVGMPath",
@"mameShareDirectory",
@"mameBGFX", @"mameBackend", @"mameEffects",
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
@"software",
2020-09-05 15:00:29 +00:00
];
for (NSString *key in keys) {
[self addObserver: self forKeyPath: key options:0 context: (__bridge void * _Nullable)(kMyContext)];
}
2020-09-05 15:00:29 +00:00
[_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];
[_machineViewController addObserver: self forKeyPath: @"machine" options: 0 context: (__bridge void * _Nullable)kContextMachine];
2020-09-05 15:00:29 +00:00
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
[_softwareListControl setMinWidth: 250];
[_softwareListControl setHidden: YES];
2020-09-05 15:00:29 +00:00
[self buildCommandLine];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if (context == (__bridge void *)kMyContext) {
[self buildCommandLine];
} else if (context == (__bridge void *)kContextMachine) {
NSString *machine = [_machineViewController machine];
[self setMameMachine: machine];
2020-09-12 22:00:34 +00:00
[_slotController setMachine: machine];
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
[self updateSoftwareList];
[self buildCommandLine];
} else {
[super observeValueForKeyPath: keyPath ofObject: object change: change context: context];
}
}
2021-01-30 01:07:44 +00:00
static NSString * JoinArguments(NSArray *argv, NSString *argv0) {
static NSCharacterSet *safe = nil;
static NSCharacterSet *unsafe = nil;
if (!safe) {
NSString *str =
@"%+-./:=_"
@"0123456789"
@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
safe = [NSCharacterSet characterSetWithCharactersInString: str];
unsafe = [safe invertedSet];
}
NSMutableString *rv = [NSMutableString new];
//unsigned ix = 0;
//[rv appendString: @"mame"];
2021-01-30 01:07:44 +00:00
if (argv0) {
[rv appendString: argv0];
} else {
NSString *path = MamePath();
path = path ? [path lastPathComponent] : @"mame";
[rv appendString: path];
}
for (NSString *s in argv) {
[rv appendString: @" "];
NSUInteger l = [s length];
if (!l) {
[rv appendString: @"''"];
continue;
}
if (!CFStringFindCharacterFromSet((CFStringRef)s, (CFCharacterSetRef)unsafe, CFRangeMake(0, l), 0, NULL)) {
[rv appendString: s];
continue;
}
unichar *buffer = malloc(sizeof(unichar) * l);
[s getCharacters: buffer range: NSMakeRange(0, l)];
[rv appendString: @"'"];
for (NSUInteger i = 0; i < l; ++i) {
unichar c = buffer[i];
switch (c) {
case '\'':
[rv appendString: @"\\'"];
break;
case '\\':
[rv appendString: @"\\\\"];
break;
case 0x7f:
[rv appendString: @"\\177"];
break;
default: {
NSString *cc;
if (c < 0x20) {
cc = [NSString stringWithFormat: @"\\%o", c];
} else {
cc = [NSString stringWithCharacters: &c length: 1];
}
[rv appendString: cc];
break;
}
}
}
[rv appendString: @"'"];
free(buffer);
}
return rv;
}
2021-01-30 01:07:44 +00:00
static NSString *ShellQuote(NSString *s) {
static NSCharacterSet *safe = nil;
static NSCharacterSet *unsafe = nil;
if (!safe) {
NSString *str =
@"%+-./:=_"
@"0123456789"
@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
safe = [NSCharacterSet characterSetWithCharactersInString: str];
unsafe = [safe invertedSet];
}
NSUInteger l = [s length];
if (!l) {
return @"''";
}
if (!CFStringFindCharacterFromSet((CFStringRef)s, (CFCharacterSetRef)unsafe, CFRangeMake(0, l), 0, NULL)) {
return s;
}
NSMutableString *rv = [NSMutableString new];
unichar *buffer = malloc(sizeof(unichar) * l);
[s getCharacters: buffer range: NSMakeRange(0, l)];
[rv appendString: @"'"];
for (NSUInteger i = 0; i < l; ++i) {
unichar c = buffer[i];
switch (c) {
case '\'':
[rv appendString: @"\\'"];
break;
case '\\':
[rv appendString: @"\\\\"];
break;
case 0x7f:
[rv appendString: @"\\177"];
break;
default: {
NSString *cc;
if (c < 0x20) {
cc = [NSString stringWithFormat: @"\\%o", c];
} else {
cc = [NSString stringWithCharacters: &c length: 1];
}
[rv appendString: cc];
break;
}
}
}
[rv appendString: @"'"];
free(buffer);
return rv;
}
-(void)buildCommandLine {
2020-09-05 15:00:29 +00:00
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (!_mameMachine) {
[self setCommandLine: @""];
return;
}
NSMutableArray *argv = [NSMutableArray new];
//[argv addObject: @"mame"];
[argv addObject: _mameMachine];
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
if (_software) {
// todo -- need to include source as well.
NSString *name = [_software name];
if (![_softwareSet nameIsUnique: name])
name = [_software fullName];
[argv addObject: name];
}
// -confirm_quit?
[argv addObject: @"-skip_gameinfo"];
if (_mameMouse)
[argv addObject: @"-mouse"]; // capture the mouse cursor when over the window.
if (!_mameSamples)
[argv addObject: @"-nosamples"];
if (_mameDebug) [argv addObject: @"-debug"];
2020-08-30 02:24:31 +00:00
/*
* -window -nomax uses a 4:3 aspect ratio - ie, height = width * 3 / 4 (since height is always the limiting factor)
* for square pixels, should pass the true size and true aspect ratio.
*/
NSSize screen = [_slotController resolution];
switch(_mameWindowMode) {
case 0: // full screen;
2020-09-08 02:20:26 +00:00
// no uneven stretch doesn't do anything in full-screen mode.
break;
case 1: // 1x
2020-09-08 02:10:37 +00:00
// make the command-line a bit shorter and more pleasant.
if (!_mameSquarePixels) {
[argv addObject: @"-window"];
[argv addObject: @"-nomax"];
break;
}
2020-09-08 02:10:37 +00:00
// drop through.
2020-09-08 02:20:26 +00:00
case 2: // 2x
2020-09-14 23:09:10 +00:00
case 3: // 3x
2020-09-08 02:20:26 +00:00
if (_mameSquarePixels) {
// NSString *aspect = [NSString stringWithFormat: @"%u:%u", (unsigned)screen.width, (unsigned)screen.height];
// [argv addObject: @"-aspect"];
// [argv addObject: aspect];
[argv addObject: @"-nounevenstretch"];
} else {
screen.height = round(screen.width * 3 / 4);
}
[argv addObject: @"-window"];
NSString *res = [NSString stringWithFormat: @"%ux%u",
(unsigned)(_mameWindowMode * screen.width),
(unsigned)(_mameWindowMode * screen.height)
];
[argv addObject: @"-resolution"];
[argv addObject: res];
break;
}
if (_mameBGFX) {
if (_mameBackend) {
static NSString *Names[] = {
@"-",
@"metal",
@"opengl",
};
[argv addObject: @"-bgfx_backend"];
[argv addObject: Names[_mameBackend]];
}
if (_mameEffects) {
static NSString *Names[] = {
@"-",
@"unfiltered",
@"hlsl",
@"crt-geom",
@"crt-geom-deluxe",
2021-03-13 20:44:52 +00:00
@"lcd-grid",
};
[argv addObject: @"-bgfx_screen_chains"];
[argv addObject: Names[_mameEffects]];
}
} else {
[argv addObject: @"-video"];
[argv addObject: @"soft"];
}
// -speed n
// -scale n
NSArray *tmp;
tmp = [_slotController args];
if ([tmp count]) {
[argv addObjectsFromArray: tmp];
}
tmp = [_mediaController args];
if ([tmp count]) {
[argv addObjectsFromArray: tmp];
}
2020-09-05 15:00:29 +00:00
if (_mameSpeed < 0) {
[argv addObject: @"-nothrottle"];
} else if (_mameSpeed > 1) {
[argv addObject: @"-speed"];
[argv addObject: [NSString stringWithFormat: @"%d", (int)_mameSpeed]];
}
2020-09-05 15:00:29 +00:00
// audio video.
if (_mameAVI && [_mameAVIPath length]) {
[argv addObject: @"-aviwrite"];
[argv addObject: _mameAVIPath];
}
if (_mameWAV && [_mameWAVPath length]) {
[argv addObject: @"-wavwrite"];
[argv addObject: _mameWAVPath];
}
// vgm only valid for custom mame.
if (![defaults boolForKey: kUseCustomMame]) {
if (_mameVGM && [_mameVGMPath length]) {
[argv addObject: @"-vgmwrite"];
[argv addObject: _mameVGMPath];
}
}
if (_mameShareDirectory && [_mameShareDirectory length]) {
[argv addObject: @"-share_directory"];
[argv addObject: _mameShareDirectory];
}
2021-01-30 01:07:44 +00:00
[self setCommandLine: JoinArguments(argv, nil)];
[self setArgs: argv];
}
2021-01-30 01:07:44 +00:00
-(BOOL)validateMenuItem:(NSMenuItem *)menuItem {
SEL cmd = [menuItem action];
if (cmd == @selector(exportShellScript:)) {
return [_args count] ? YES : NO;
}
return [super validateMenuItem: menuItem];
}
2021-01-30 01:07:44 +00:00
# pragma mark - IBActions
- (IBAction)launchAction:(id)sender {
if (![_args count]) return;
2020-09-02 03:52:11 +00:00
[LogWindowController controllerForArgs: _args];
2021-01-30 01:07:44 +00:00
}
2021-01-30 01:07:44 +00:00
-(IBAction)exportShellScript: (id)sender {
2021-01-30 01:07:44 +00:00
NSSavePanel *p = [NSSavePanel savePanel];
NSString *defaultName = [_mameMachine stringByAppendingString: @".sh"];
2021-01-30 01:07:44 +00:00
[p setTitle: @"Export Shell Script"];
[p setExtensionHidden: NO];
[p setNameFieldStringValue: defaultName];
2021-01-30 01:07:44 +00:00
//[p setDelegate: self];
NSWindow *w = [self window];
NSMutableString *data = [NSMutableString new];
[data appendString: @"#!/bin/sh\n\n"];
[data appendFormat: @"MAME=%@\n", ShellQuote(MamePath())];
[data appendFormat: @"cd %@\n", ShellQuote(MameWorkingDirectoryPath())];
[data appendString: JoinArguments(_args, @"$MAME")];
[data appendString: @"\n\n"];
[p beginSheetModalForWindow: w completionHandler: ^(NSModalResponse r) {
if (r != NSModalResponseOK) return;
NSURL *url = [p URL];
NSError *error = nil;
[data writeToURL: url atomically: YES encoding: NSUTF8StringEncoding error: &error];
2021-01-30 01:07:44 +00:00
[p orderOut: nil];
if (error) {
[self presentError: error];
return;
}
// chmod 755...
int ok = chmod([url fileSystemRepresentation], 0755);
if (ok < 0) {
// ...
}
}];
}
@end
2021-01-30 01:07:44 +00:00
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
@implementation LaunchWindowController (SoftwareList)
-(void)updateSoftwareList {
_softwareSet = [SoftwareSet softwareSetForMachine: _mameMachine];
[_softwareListControl setAutocompleteDelegate: _softwareSet];
if (_softwareSet) {
[_softwareListControl invalidate];
[_softwareListControl setHidden: NO];
} else {
_software = nil;
[_softwareListControl setHidden: YES];
}
}
- (IBAction)softwareChanged:(id)sender {
id o = [(NSControl *)sender objectValue];
2021-05-28 00:36:24 +00:00
//NSLog(@"%@", o);
Squashed commit of the following: commit 1dd1d6d3eee928d283dafbaf4432b053dff65ac2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Thu May 27 13:30:38 2021 -0400 0.232 rom update commit cfb7f9a4d1647c41fab3328bada0f37bdb041983 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:31:16 2021 -0400 fix resizing to prevent horizontal scrolling commit 5c393ab5a95c9e53c4ef1e0b3f2b77db93e1c29b Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Wed May 26 20:01:48 2021 -0400 esc should close the menu if visible, otherwise clear the text. commit 7da142b64280c39e216584cedb7fb14243d573f0 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:17:10 2021 -0400 show software short name unless it's ambiguous. commit 6f3b3bef5e18e78619959613e28064eb6251ce27 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:47 2021 -0400 cleanup some auto complete rough edges commit 4988d8b266b8b11e519bcb5aab05ad2c3ffe5c23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 23:16:24 2021 -0400 fix commit 6d4bf94fd6b4850564b705ea15e91079b00346c2 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:28 2021 -0400 clean up autocomplete a little... commit 3722271e51d93599903bccc721dc1de61f0aae72 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Tue May 25 19:13:07 2021 -0400 move auto complete logic to SoftwareSet commit 04cc83ecbe9ee4c9100305712c47a11359327734 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:46:39 2021 -0400 software - keep the list name to differentiate in case of name clashes. commit 8e5b5dc7e283f760a16011308298e999110fc052 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 20:45:13 2021 -0400 Autocomplete - limit menu content width to the clip view content width. prevents horizontal scrolling. commit 356048d450447485bb33a4261018f85dac19a134 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:45:42 2021 -0400 add auto complete software list to the launch window. commit 9dc72b702c9b36d490349f291c10b98b56178567 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:44:28 2021 -0400 autocomplete control. commit 40eee83f56d957c64e0f8d927486f13165b9e120 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Mon May 24 18:39:32 2021 -0400 add filters to software list. commit cebfbaa545441f061cffafe8ca93db2377240a06 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun May 23 11:59:00 2021 -0400 add compatibility field for software list filtering.
2021-05-27 23:42:28 +00:00
[self setSoftware: o];
}
@end