From b6f67f981cf8b1ec04223f6ac84b7fe70882a480 Mon Sep 17 00:00:00 2001 From: tudnai Date: Wed, 3 Jun 2020 10:23:55 -0700 Subject: [PATCH] - File Open - Recent Files - Disk Menus moved to File Menu --- A2Mac/AppDelegate.swift | 26 +- A2Mac/Base.lproj/Main.storyboard | 448 ++++++++++++++----------------- A2Mac/ViewController.swift | 35 +++ 3 files changed, 241 insertions(+), 268 deletions(-) diff --git a/A2Mac/AppDelegate.swift b/A2Mac/AppDelegate.swift index 4568353..8555d16 100644 --- a/A2Mac/AppDelegate.swift +++ b/A2Mac/AppDelegate.swift @@ -33,26 +33,18 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } - + @IBAction func selectAnImageFromFile(sender: AnyObject) { - let openPanel = NSOpenPanel() - openPanel.title = "Disk Image" - openPanel.allowsMultipleSelection = false - openPanel.canChooseDirectories = false - openPanel.canCreateDirectories = false - openPanel.canChooseFiles = true - openPanel.allowedFileTypes = ["dsk","do","po","nib", "woz"] - - openPanel.begin { (result) -> Void in - if result == NSApplication.ModalResponse.OK { - print("file:", openPanel.url!.path) - //Do what you will - //If there's only one URL, surely 'openPanel.URL' - //but otherwise a for loop works - woz_loadFile( openPanel.url?.path ) - } + if ( ViewController.current != nil ) { + ViewController.current?.perform(#selector(ViewController.openDiskImage)) } } + + func application(_ sender: NSApplication, openFile filename: String) -> Bool { + woz_loadFile( filename ) + + return true + } } diff --git a/A2Mac/Base.lproj/Main.storyboard b/A2Mac/Base.lproj/Main.storyboard index 1d98002..e94d324 100644 --- a/A2Mac/Base.lproj/Main.storyboard +++ b/A2Mac/Base.lproj/Main.storyboard @@ -83,34 +83,208 @@ - - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - @@ -134,11 +308,6 @@ - - - - - @@ -149,18 +318,6 @@ - - - - - - - - - - - - @@ -176,12 +333,6 @@ - - - - - - @@ -192,7 +343,8 @@ - + + @@ -635,212 +787,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index 0ffe35b..1d9ae93 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -288,6 +288,7 @@ class ViewController: NSViewController { } default: + super.keyDown(with: event) break } } @@ -733,10 +734,13 @@ class ViewController: NSViewController { let upd = RepeatingTimer(timeInterval: 1/Double(fps)) + static var current : NSViewController? = nil override func viewDidLoad() { super.viewDidLoad() + ViewController.current = self + hires.clearScreen(); woz_loadFile( Bundle.main.resourcePath! + "/Apple DOS 3.3 January 1983.woz" ) @@ -854,6 +858,37 @@ class ViewController: NSViewController { diskAccelerator_speed = 0 } } + + + @objc func openDiskImage() { + let openPanel = NSOpenPanel() + openPanel.title = "Disk Image" + openPanel.allowsMultipleSelection = false + openPanel.canChooseDirectories = false + openPanel.canCreateDirectories = false + openPanel.canChooseFiles = true + openPanel.allowedFileTypes = ["dsk","do","po","nib", "woz"] + + openPanel.begin { (result) -> Void in + if result == NSApplication.ModalResponse.OK { + print("file:", openPanel.url!.path) + //Do what you will + //If there's only one URL, surely 'openPanel.URL' + //but otherwise a for loop works + + if let filePath = openPanel.url?.path { + woz_loadFile( filePath ) + NSDocumentController.shared.noteNewRecentDocumentURL(URL(fileURLWithPath: filePath)) + } + } + } + } + + + @IBAction func openDocument(_ sender: Any?) { + openDiskImage() + } + }