Add preferences window.

This commit is contained in:
Kelvin Sherlock 2020-08-29 14:40:34 -04:00
parent 3634890100
commit fe94158187
6 changed files with 123 additions and 6 deletions

View File

@ -63,6 +63,8 @@
B6BA258224E99BEB005FB8FF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B6BA258124E99BEB005FB8FF /* Assets.xcassets */; };
B6BA258524E99BEB005FB8FF /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = B6BA258324E99BEB005FB8FF /* MainMenu.xib */; };
B6BA258824E99BEB005FB8FF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B6BA258724E99BEB005FB8FF /* main.m */; };
B6D6DE3924FAC8B500661A5F /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = B6D6DE3724FAC8B500661A5F /* Preferences.xib */; };
B6D6DE3B24FACF4F00661A5F /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = B6D6DE3A24FACF4F00661A5F /* Defaults.plist */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -133,6 +135,8 @@
B6BA258624E99BEB005FB8FF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B6BA258724E99BEB005FB8FF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
B6BA258924E99BEB005FB8FF /* MA2ME.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MA2ME.entitlements; sourceTree = "<group>"; };
B6D6DE3824FAC8B500661A5F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Preferences.xib; sourceTree = "<group>"; };
B6D6DE3A24FACF4F00661A5F /* Defaults.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Defaults.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -242,9 +246,11 @@
B64E15AB24EA1FD400E8AD3D /* SlotBrowserDelegate.m */,
B64E15AF24EA365E00E8AD3D /* Resources */,
B6BA258624E99BEB005FB8FF /* Info.plist */,
B6D6DE3A24FACF4F00661A5F /* Defaults.plist */,
B6BA258724E99BEB005FB8FF /* main.m */,
B6BA258924E99BEB005FB8FF /* MA2ME.entitlements */,
B6BA258324E99BEB005FB8FF /* MainMenu.xib */,
B6D6DE3724FAC8B500661A5F /* Preferences.xib */,
B61099E524F5F230005CB652 /* MediaView.xib */,
B61099E324F5F230005CB652 /* SlotView.xib */,
);
@ -343,6 +349,7 @@
B6109A4324F5F377005CB652 /* agat7.plist in Resources */,
B6109A2B24F5F377005CB652 /* elppa.plist in Resources */,
B6109A3B24F5F377005CB652 /* apple2gsr1.plist in Resources */,
B6D6DE3B24FACF4F00661A5F /* Defaults.plist in Resources */,
B6109A2224F5F377005CB652 /* models.plist in Resources */,
B6109A4024F5F377005CB652 /* craft2p.plist in Resources */,
B6109A1B24F5F377005CB652 /* uniap2pt.plist in Resources */,
@ -352,6 +359,7 @@
B6109A2A24F5F377005CB652 /* apple3.plist in Resources */,
B6109A2124F5F377005CB652 /* apple2ee.plist in Resources */,
B6109A3624F5F377005CB652 /* dodo.plist in Resources */,
B6D6DE3924FAC8B500661A5F /* Preferences.xib in Resources */,
B61099E724F5F231005CB652 /* SlotView.xib in Resources */,
B6109A2924F5F377005CB652 /* apple2gs.plist in Resources */,
B6109A1F24F5F377005CB652 /* apple2jp.plist in Resources */,
@ -404,6 +412,14 @@
name = MainMenu.xib;
sourceTree = "<group>";
};
B6D6DE3724FAC8B500661A5F /* Preferences.xib */ = {
isa = PBXVariantGroup;
children = (
B6D6DE3824FAC8B500661A5F /* Base */,
);
name = Preferences.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */

View File

@ -10,6 +10,7 @@
@interface AppDelegate : NSObject <NSApplicationDelegate, NSBrowserDelegate>
- (IBAction)displayPreferences:(id)sender;
@end

View File

@ -34,18 +34,34 @@
@property NSArray *browserItems;
@end
@implementation AppDelegate
@implementation AppDelegate {
NSWindowController *_prefs;
}
static NSString *kMyContext = @"kMyContext";
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSBundle *bundle = [NSBundle mainBundle];
NSString *path;
NSDictionary *dict;
path = [bundle pathForResource: @"Defaults" ofType: @"plist"];
dict = [NSDictionary dictionaryWithContentsOfFile: path];
if (dict)
{
[[NSUserDefaults standardUserDefaults] registerDefaults: dict];
}
/* My Copy of XCode/Interface Builder barfs on NSBrowser. */
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource: @"models" ofType: @"plist"];
path = [bundle pathForResource: @"models" ofType: @"plist"];
_browserItems = [NSArray arrayWithContentsOfFile: path];
NSView *view = [_window contentView];
@ -332,8 +348,13 @@ static NSString * JoinArguments(NSArray *argv) {
- (IBAction)launchAction:(id)sender {
if (![_args count]) return;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *path = [defaults stringForKey: @"MamePath"];
if (![path length]) path = @"/usr/local/bin/mame";
NSError *error = nil;
NSURL *url = [NSURL fileURLWithPath: @"/usr/local/bin/mame"];
NSURL *url = [NSURL fileURLWithPath: path];
NSTask *task = [NSTask launchedTaskWithExecutableURL: url
arguments: _args
@ -347,6 +368,12 @@ static NSString * JoinArguments(NSArray *argv) {
if (error) NSLog(@"launchAction: %@", error);
}
- (IBAction)displayPreferences:(id)sender {
if (!_prefs) {
_prefs = [[NSWindowController alloc] initWithWindowNibName: @"Preferences"];
}
[_prefs showWindow: sender];
}
@end

View File

@ -37,7 +37,11 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<action selector="displayPreferences:" target="Voe-Tx-rLC" id="Hsm-pX-sUc"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
<menuItem title="Services" id="NMo-om-nkz">
<modifierMask key="keyEquivalentModifierMask"/>
@ -774,6 +778,14 @@
<rect key="frame" x="392" y="169" width="306" height="570"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
</customView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XMQ-jr-w2i">
<rect key="frame" x="261" y="102" width="67" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="No Blur" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Xxl-Eu-ziO">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
</view>
<point key="canvasLocation" x="769" y="196.5"/>
@ -782,6 +794,6 @@
<viewController title="Media View" nibName="MediaView" id="kiU-IX-LTW" customClass="MediaViewController"/>
</objects>
<resources>
<image name="NSAppleMenuImage" width="128" height="128"/>
<image name="NSAppleMenuImage" width="11" height="14"/>
</resources>
</document>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSWindowController">
<connections>
<outlet property="window" destination="QvC-M9-y7g" id="SHw-b5-d6g"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Oz5-Xb-btk">
<rect key="frame" x="98" y="229" width="362" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="vDR-2V-qxd">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="yvB-HG-64y" name="value" keyPath="values.MamePath" id="H3O-1l-peo"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qmb-Ag-Xyr">
<rect key="frame" x="18" y="234" width="74" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="MAME Path" id="Xcq-4g-Wlw">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
<point key="canvasLocation" x="140" y="147"/>
</window>
<userDefaultsController id="KVS-Ag-1un"/>
<userDefaultsController representsSharedInstance="YES" id="yvB-HG-64y"/>
</objects>
</document>

8
MA2ME/Defaults.plist Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MamePath</key>
<string>/usr/local/bin/mame</string>
</dict>
</plist>