save/restore/autoload default support.

This commit is contained in:
Kelvin Sherlock 2021-06-12 14:02:11 -04:00
parent 46fe931103
commit c4c2defc01
2 changed files with 62 additions and 6 deletions

View File

@ -406,7 +406,19 @@
<menuItem title="Manage Bookmarks…" id="isI-q6-b1V"> <menuItem title="Manage Bookmarks…" id="isI-q6-b1V">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
</menuItem> </menuItem>
<menuItem title="Set Default" id="vbR-vS-lqO">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="defaultSave:" target="-1" id="FP9-EX-OKP"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="gWR-Yl-mg6"/> <menuItem isSeparatorItem="YES" id="gWR-Yl-mg6"/>
<menuItem title="Default" id="mXC-Lp-gem">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="defaultLoad:" target="-1" id="ErS-k6-azP"/>
</connections>
</menuItem>
</items> </items>
</menu> </menu>
</menuItem> </menuItem>

View File

@ -42,6 +42,8 @@ static NSString *kContextMachine = @"kContextMachine";
@property NSArray *args; @property NSArray *args;
@property NSString *machine; @property NSString *machine;
//@property NSString *machineName;
@property BOOL mameDebug; @property BOOL mameDebug;
@property BOOL mameSquarePixels; @property BOOL mameSquarePixels;
@property BOOL mameMouse; @property BOOL mameMouse;
@ -90,6 +92,8 @@ static NSString *kContextMachine = @"kContextMachine";
-(IBAction)addBookmark:(id)sender; -(IBAction)addBookmark:(id)sender;
-(IBAction)defaultLoad:(id)sender;
@end @end
#define SIZEOF(x) (sizeof(x) / sizeof(x[0])) #define SIZEOF(x) (sizeof(x) / sizeof(x[0]))
@ -162,17 +166,24 @@ static int EffectsIndex(NSString *str) {
-(void)windowWillLoad { -(void)windowWillLoad {
// if this calls [self window], it will recurse. that is bad.
//[self defaultLoad: nil];
[self reset]; [self reset];
} }
static void AddSubview(NSView *parent, NSView *child) { static void AddSubview(NSView *parent, NSView *child) {
[child setFrame: [parent bounds]]; [child setFrame: [parent bounds]];
[parent addSubview: child]; [parent addSubview: child];
} }
- (void)windowDidLoad { - (void)windowDidLoad {
[super windowDidLoad]; [super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
AddSubview(_slotView, [_slotController view]); AddSubview(_slotView, [_slotController view]);
@ -180,6 +191,10 @@ static void AddSubview(NSView *parent, NSView *child) {
AddSubview(_machineView, [_machineViewController view]); AddSubview(_machineView, [_machineViewController view]);
// can't be done until above views are set up.
[self defaultLoad: nil];
NSArray *keys = @[ NSArray *keys = @[
//@"mameMachine", // - handled //@"mameMachine", // - handled
@"mameSquarePixels", @"mameWindowMode", @"mameSquarePixels", @"mameWindowMode",
@ -244,11 +259,15 @@ static void AddSubview(NSView *parent, NSView *child) {
_machine = machine; _machine = machine;
_machineDescription = MameMachine(machine); _machineDescription = MameMachine(machine);
#if 0
[self setMachineName: [_machineDescription objectForKey: @"description"]];
#else
NSString *title = _machineDescription NSString *title = _machineDescription
? [NSString stringWithFormat: @"Ample %@", [_machineDescription objectForKey: @"description"]] ? [NSString stringWithFormat: @"Ample %@", [_machineDescription objectForKey: @"description"]]
: @"Ample"; : @"Ample";
[[self window] setTitle: title]; [[self window] setTitle: title];
#endif
} }
static NSString * JoinArguments(NSArray *argv, NSString *argv0) { static NSString * JoinArguments(NSArray *argv, NSString *argv0) {
@ -646,6 +665,27 @@ static NSString *ShellQuote(NSString *s) {
@implementation LaunchWindowController (Bookmark) @implementation LaunchWindowController (Bookmark)
-(IBAction)defaultSave:(id)sender {
BookmarkManager *bm = [BookmarkManager sharedManager];
NSDictionary *d = [self makeBookmark];
[bm saveDefault: d];
}
-(IBAction)defaultLoad:(id)sender {
BookmarkManager *bm = [BookmarkManager sharedManager];
NSDictionary *d = [bm loadDefault];
if (!d) {
[self reset: sender];
return;
}
[self loadBookmark: d];
}
-(IBAction)addBookmark:(id)sender { -(IBAction)addBookmark:(id)sender {
if (!_machine) return; if (!_machine) return;
@ -679,10 +719,7 @@ static NSString *ShellQuote(NSString *s) {
return; return;
} }
//NSLog(@"%@", _bookmarkName);
NSDictionary *d = [self makeBookmark]; NSDictionary *d = [self makeBookmark];
//NSLog(@"%@", d);
[bm saveBookmark: d name: _bookmarkName]; [bm saveBookmark: d name: _bookmarkName];
@ -694,15 +731,21 @@ static NSString *ShellQuote(NSString *s) {
-(IBAction)bookmarkMenu:(id)sender { -(IBAction)bookmarkMenu:(id)sender {
Class StringClass = [NSString class];
Class NumberClass = [NSNumber class];
NSURL *url = [sender representedObject]; NSURL *url = [sender representedObject];
if (!url) return; if (!url) return;
NSDictionary *d = [NSDictionary dictionaryWithContentsOfURL: url]; NSDictionary *d = [NSDictionary dictionaryWithContentsOfURL: url];
if (!d) return; // oops... if (!d) return; // oops...
[self loadBookmark: d];
}
-(void)loadBookmark: (NSDictionary *)d {
Class StringClass = [NSString class];
Class NumberClass = [NSNumber class];
NSString *machine = [d objectForKey: @"machine"]; NSString *machine = [d objectForKey: @"machine"];
if (!machine) return; if (!machine) return;
@ -731,6 +774,7 @@ static NSString *ShellQuote(NSString *s) {
// Boolean values. // Boolean values.
NSNumber *n; NSNumber *n;
#undef _
#define _(a,b) n = [d objectForKey: a]; if ([n isKindOfClass: NumberClass]) [self b : [n boolValue]] #define _(a,b) n = [d objectForKey: a]; if ([n isKindOfClass: NumberClass]) [self b : [n boolValue]]
_(@"debug", setMameDebug); _(@"debug", setMameDebug);