window restoration support.

only applies if you option quit (quit and save windows) or quit unexpectedly.
This commit is contained in:
Kelvin Sherlock 2020-09-25 20:46:25 -04:00
parent ecfd5fb7a8
commit f90f5a6bf3
7 changed files with 84 additions and 20 deletions

View File

@ -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 = "<group>";
};
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 = "<group>";
};
B6D6DE4224FAEE8900661A5F /* Nibs */ = {
isa = PBXGroup;
children = (

View File

@ -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

View File

@ -10,5 +10,7 @@
<true/>
<key>MamePath</key>
<string>/usr/local/bin/mame</string>
<key>NSQuitAlwaysKeepsWindows</key>
<true/>
</dict>
</plist>

View File

@ -10,7 +10,9 @@
NS_ASSUME_NONNULL_BEGIN
@interface DiskImagesWindowController : NSWindowController
@interface DiskImagesWindowController : NSWindowController <NSWindowRestoration>
+(instancetype)sharedInstance;
@end

View File

@ -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.

View File

@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface DownloadWindowController : NSWindowController
@interface DownloadWindowController : NSWindowController <NSWindowRestoration>
@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) <NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate>

View File

@ -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)