From f90f5a6bf32aa061dc3ae7aeedf0bfdf9301f3e1 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 25 Sep 2020 20:46:25 -0400 Subject: [PATCH] window restoration support. only applies if you option quit (quit and save windows) or quit unexpectedly. --- Ample.xcodeproj/project.pbxproj | 36 ++++++++++++++++++------------ Ample/AppDelegate.m | 11 +++++---- Ample/Defaults.plist | 2 ++ Ample/DiskImagesWindowController.h | 4 +++- Ample/DiskImagesWindowController.m | 19 ++++++++++++++++ Ample/DownloadWindowController.h | 5 ++++- Ample/DownloadWindowController.m | 27 ++++++++++++++++++++++ 7 files changed, 84 insertions(+), 20 deletions(-) diff --git a/Ample.xcodeproj/project.pbxproj b/Ample.xcodeproj/project.pbxproj index bebcd7e..acb95cc 100644 --- a/Ample.xcodeproj/project.pbxproj +++ b/Ample.xcodeproj/project.pbxproj @@ -465,18 +465,14 @@ B6BA257D24E99BE9005FB8FF /* Ample */ = { isa = PBXGroup; children = ( - B64AF1F4250ED5E400A09B9B /* TableCellView.h */, - B64AF1F5250ED5E400A09B9B /* TableCellView.m */, - B6E9A17E25088B1B005E7525 /* NewSlotViewController.h */, - B6E9A17F25088B1B005E7525 /* NewSlotViewController.m */, - B63C1B9125008A2700511A71 /* DownloadWindowController.h */, - B63C1B9225008A2700511A71 /* DownloadWindowController.m */, B6BA257E24E99BE9005FB8FF /* AppDelegate.h */, B6BA257F24E99BE9005FB8FF /* AppDelegate.m */, B63C1B8924FF4B7100511A71 /* Ample.h */, B63C1B8A24FF4BF700511A71 /* Ample.m */, - B6D6DE3F24FADFAC00661A5F /* LaunchWindowController.h */, - B6D6DE4024FADFAC00661A5F /* LaunchWindowController.m */, + B64AF1F4250ED5E400A09B9B /* TableCellView.h */, + B64AF1F5250ED5E400A09B9B /* TableCellView.m */, + B6E9A17E25088B1B005E7525 /* NewSlotViewController.h */, + B6E9A17F25088B1B005E7525 /* NewSlotViewController.m */, B65593B024ECB61800722E0C /* SlotViewController.m */, B65593AF24ECB61800722E0C /* SlotViewController.h */, B64979C024EF6703008ABD20 /* MediaViewController.h */, @@ -487,14 +483,9 @@ B60A6E1224EE0AE2004B7EEF /* FlippedView.h */, B608E17D2502FE0C00D53465 /* TransparentScroller.h */, B608E17E2502FE0C00D53465 /* TransparentScroller.m */, - B6004DED24FB05D600D38596 /* LogWindowController.h */, - B6004DEE24FB05D600D38596 /* LogWindowController.m */, - B66236A724FD9A34006CABD7 /* PreferencesWindowController.h */, - B66236A824FD9A34006CABD7 /* PreferencesWindowController.m */, + B6BA563A251685DA00B0C47D /* Window Controllers */, B6B9EA652506A5550080E70D /* EjectButton.h */, B6B9EA642506A5550080E70D /* EjectButton.m */, - B64AF1F0250ECB2E00A09B9B /* DiskImagesWindowController.h */, - B64AF1F1250ECB2E00A09B9B /* DiskImagesWindowController.m */, B64AF1F8250EF6A500A09B9B /* Transformers.h */, B64AF1F9250EF6A500A09B9B /* Transformers.m */, B6BA258124E99BEB005FB8FF /* Assets.xcassets */, @@ -509,6 +500,23 @@ path = Ample; sourceTree = ""; }; + B6BA563A251685DA00B0C47D /* Window Controllers */ = { + isa = PBXGroup; + children = ( + B64AF1F0250ECB2E00A09B9B /* DiskImagesWindowController.h */, + B64AF1F1250ECB2E00A09B9B /* DiskImagesWindowController.m */, + B63C1B9125008A2700511A71 /* DownloadWindowController.h */, + B63C1B9225008A2700511A71 /* DownloadWindowController.m */, + B6D6DE3F24FADFAC00661A5F /* LaunchWindowController.h */, + B6D6DE4024FADFAC00661A5F /* LaunchWindowController.m */, + B6004DED24FB05D600D38596 /* LogWindowController.h */, + B6004DEE24FB05D600D38596 /* LogWindowController.m */, + B66236A724FD9A34006CABD7 /* PreferencesWindowController.h */, + B66236A824FD9A34006CABD7 /* PreferencesWindowController.m */, + ); + name = "Window Controllers"; + sourceTree = ""; + }; B6D6DE4224FAEE8900661A5F /* Nibs */ = { isa = PBXGroup; children = ( diff --git a/Ample/AppDelegate.m b/Ample/AppDelegate.m index 3a2344c..0f502a8 100644 --- a/Ample/AppDelegate.m +++ b/Ample/AppDelegate.m @@ -46,12 +46,13 @@ + _diskImages = [DiskImagesWindowController sharedInstance]; //[DiskImagesWindowController new]; + if ([self installMameComponents]) { + [self displayLaunchWindow]; } - _diskImages = [DiskImagesWindowController new]; - } -(void)displayLaunchWindow { @@ -119,6 +120,7 @@ } [win close]; [self displayLaunchWindow]; + [self displayROMS: nil]; }); }]; @@ -152,15 +154,16 @@ - (IBAction)displayROMS:(id)sender { if (!_downloader) { - _downloader = [DownloadWindowController new]; + _downloader = [DownloadWindowController sharedInstance]; } [_downloader showWindow: sender]; } - (IBAction)displayRecentDiskImages:(id)sender { if (!_diskImages) { - _diskImages = [DiskImagesWindowController new]; + _diskImages = [DiskImagesWindowController sharedInstance]; } [_diskImages showWindow: sender]; } + @end diff --git a/Ample/Defaults.plist b/Ample/Defaults.plist index 3a4e96d..4414f9d 100644 --- a/Ample/Defaults.plist +++ b/Ample/Defaults.plist @@ -10,5 +10,7 @@ MamePath /usr/local/bin/mame + NSQuitAlwaysKeepsWindows + diff --git a/Ample/DiskImagesWindowController.h b/Ample/DiskImagesWindowController.h index b792240..37562cd 100644 --- a/Ample/DiskImagesWindowController.h +++ b/Ample/DiskImagesWindowController.h @@ -10,7 +10,9 @@ NS_ASSUME_NONNULL_BEGIN -@interface DiskImagesWindowController : NSWindowController +@interface DiskImagesWindowController : NSWindowController + ++(instancetype)sharedInstance; @end diff --git a/Ample/DiskImagesWindowController.m b/Ample/DiskImagesWindowController.m index 5c15939..9ef7d98 100644 --- a/Ample/DiskImagesWindowController.m +++ b/Ample/DiskImagesWindowController.m @@ -24,6 +24,21 @@ } ++(instancetype)sharedInstance { + static DiskImagesWindowController *me; + if (!me) { + me = [self new]; + } + return me; +} + ++ (void)restoreWindowWithIdentifier:(NSUserInterfaceItemIdentifier)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler { + NSLog(@"restore disk images window"); + NSWindowController *controller = [self sharedInstance]; + NSWindow *w = [controller window]; + [w restoreStateWithCoder: state]; + completionHandler(w, nil); +} -(instancetype)init { @@ -48,6 +63,10 @@ [self setContent: [NSMutableArray new]]; [super windowDidLoad]; + NSWindow *window = [self window]; + [window setRestorable: YES]; + [window setRestorationClass: [self class]]; + [_tableView registerForDraggedTypes: @[NSPasteboardTypeFileURL]]; [_tableView setDraggingSourceOperationMask: NSDragOperationCopy forLocal: NO]; // enable drag/drop to othr apps. diff --git a/Ample/DownloadWindowController.h b/Ample/DownloadWindowController.h index 80c1ec3..65103e1 100644 --- a/Ample/DownloadWindowController.h +++ b/Ample/DownloadWindowController.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface DownloadWindowController : NSWindowController +@interface DownloadWindowController : NSWindowController @property NSString *currentROM; @property NSInteger currentCount; @@ -18,6 +18,9 @@ NS_ASSUME_NONNULL_BEGIN @property NSInteger errorCount; @property BOOL active; ++(instancetype)sharedInstance; + + @end @interface DownloadWindowController (URL) diff --git a/Ample/DownloadWindowController.m b/Ample/DownloadWindowController.m index 956e008..ecc6a63 100644 --- a/Ample/DownloadWindowController.m +++ b/Ample/DownloadWindowController.m @@ -52,12 +52,38 @@ enum { NSMutableDictionary *_taskIndex; } ++(instancetype)sharedInstance { + static DownloadWindowController *me = nil; + if (!me) { + me = [self new]; + } + return me; +} + ++ (void)restoreWindowWithIdentifier:(nonnull NSUserInterfaceItemIdentifier)identifier state:(nonnull NSCoder *)state completionHandler:(nonnull void (^)(NSWindow * _Nullable, NSError * _Nullable))completionHandler { + NSLog(@"restore rom manager window"); + + NSWindowController *controller = [DownloadWindowController sharedInstance]; + NSWindow *w = [controller window]; + [w restoreStateWithCoder: state]; + completionHandler(w, nil); +} + +#if 0 +- (void)encodeWithCoder:(nonnull NSCoder *)coder { + +} +#endif + -(NSString *)windowNibName { return @"DownloadWindow"; } - (void)windowDidLoad { [super windowDidLoad]; + NSWindow *window = [self window]; + [window setRestorable: YES]; + [window setRestorationClass: [self class]]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. @@ -303,6 +329,7 @@ enum { */ NSLog(@"%@", src); } + @end @implementation DownloadWindowController (Table)