add bookmark menu

This commit is contained in:
Kelvin Sherlock 2021-06-03 23:04:37 -04:00
parent 6215a0df12
commit 94aac38af4
4 changed files with 194 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#import "DiskImagesWindowController.h"
#import "CheatSheetWindowController.h"
#import "Transformers.h"
#import "BookmarkManager.h"
#import "LogWindowController.h"
@ -40,6 +41,10 @@
RegisterTransformers();
BookmarkManager *bm = [BookmarkManager sharedManager];
[bm loadBookmarks];
[bm updateMenu];
path = [bundle pathForResource: @"Defaults" ofType: @"plist"];
dict = [NSDictionary dictionaryWithContentsOfFile: path];

View File

@ -8,6 +8,8 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="LaunchWindowController">
<connections>
<outlet property="addBookmarkWindow" destination="yIt-hP-HBq" id="Qhx-WV-cg4"/>
<outlet property="bookmarkTextField" destination="fAl-Vn-x1w" id="GNr-j6-BiQ"/>
<outlet property="machineView" destination="oVt-eD-aaj" id="Q9V-Kr-6GN"/>
<outlet property="machineViewController" destination="RgH-d9-xl8" id="DIa-h0-6y2"/>
<outlet property="mediaController" destination="t7c-zy-czN" id="a7d-HC-TWx"/>
@ -487,6 +489,78 @@ DQ
<viewController title="Media View" nibName="MediaView" id="t7c-zy-czN" customClass="MediaViewController"/>
<viewController title="Slot View" nibName="SlotView" id="lyS-mc-3Tf" customClass="SlotViewController"/>
<customObject id="RgH-d9-xl8" customClass="MachineViewController"/>
<window title="Add Bookmark" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="yIt-hP-HBq">
<windowStyleMask key="styleMask" titled="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="462" height="116"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" wantsLayer="YES" id="WVd-g4-Tbl">
<rect key="frame" x="0.0" y="0.0" width="462" height="116"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Gho-Xy-rn4">
<rect key="frame" x="358" y="13" width="90" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Add" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Vxo-rD-aMe">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="bookmarkSave:" target="-2" id="wLF-LE-5RO"/>
<binding destination="-2" name="enabled" keyPath="bookmarkName" id="U5R-gU-1bE">
<dictionary key="options">
<string key="NSValueTransformerName">StringNotEmptyTransformer</string>
</dictionary>
</binding>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3sv-Kd-Ep5">
<rect key="frame" x="268" y="13" width="90" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="jaa-RY-PAg">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="bookmarkCancel:" target="-2" id="uWM-vs-hz7"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1fO-x7-Gft">
<rect key="frame" x="18" y="80" width="103" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Add Bookmark…" id="AZS-JR-SNt">
<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>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fAl-Vn-x1w">
<rect key="frame" x="20" y="49" width="422" height="23"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="bookmark name" drawsBackground="YES" id="Enq-2z-cle">
<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="-2" name="value" keyPath="bookmarkName" id="84v-el-4Uk">
<dictionary key="options">
<bool key="NSContinuouslyUpdatesValue" value="YES"/>
<string key="NSNullPlaceholder">bookmark name</string>
</dictionary>
</binding>
</connections>
</textField>
</subviews>
</view>
<point key="canvasLocation" x="130" y="70"/>
</window>
</objects>
<resources>
<image name="NSAppleMenuImage" width="11" height="14"/>

View File

@ -19,6 +19,11 @@
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="sJn-ug-xF3" customClass="BookmarkManager">
<connections>
<outlet property="menu" destination="ha0-nx-PIl" id="vTa-TU-DS1"/>
</connections>
</customObject>
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
<menuItem title="Ample" id="1Xt-HY-uBw">
@ -389,6 +394,22 @@
</items>
</menu>
</menuItem>
<menuItem title="Bookmarks" id="vHO-2e-qJc">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Bookmarks" id="ha0-nx-PIl">
<items>
<menuItem title="Add Bookmark…" keyEquivalent="d" id="1JF-xV-zmG">
<connections>
<action selector="addBookmark:" target="-1" id="cqp-ko-BfQ"/>
</connections>
</menuItem>
<menuItem title="Manage Bookmarks…" id="isI-q6-b1V">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="gWR-Yl-mg6"/>
</items>
</menu>
</menuItem>
<menuItem title="Window" id="aUF-d1-5bR">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">

View File

@ -15,6 +15,7 @@
#import "AutocompleteControl.h"
#import "SoftwareList.h"
#import "BookmarkManager.h"
#include <sys/stat.h>
#include <wctype.h>
@ -64,6 +65,12 @@ static NSString *kContextMachine = @"kContextMachine";
@property (weak) IBOutlet AutocompleteControl *softwareListControl;
@property SoftwareSet *softwareSet;
@property Software *software;
@property (strong) IBOutlet NSWindow *addBookmarkWindow;
@property (strong) NSString *bookmarkName;
@property (weak) IBOutlet NSTextField *bookmarkTextField;
@end
@interface LaunchWindowController (SoftwareList)
@ -72,6 +79,13 @@ static NSString *kContextMachine = @"kContextMachine";
@end
@interface LaunchWindowController (Bookmark)
-(IBAction)addBookmark:(id)sender;
@end
static NSString *BackendStrings[] = {
@"",
@"metal",
@ -456,7 +470,12 @@ static NSString *ShellQuote(NSString *s) {
if (cmd == @selector(exportShellScript:)) {
return [_args count] ? YES : NO;
}
return [super validateMenuItem: menuItem];
if (cmd == @selector(addBookmark:)) {
return _mameMachine ? YES : NO;
}
return YES;
//return [super validateMenuItem: menuItem]; // not implemented?
}
# pragma mark - IBActions
@ -548,6 +567,80 @@ static NSString *ShellQuote(NSString *s) {
@implementation LaunchWindowController (Bookmark)
-(IBAction)addBookmark:(id)sender {
if (!_mameMachine) return;
NSString *name = _mameMachine;
if (_software) {
name = [name stringByAppendingFormat: @" - %@", [_software title]];
}
[self setBookmarkName: name];
[_bookmarkTextField selectText: nil];
[[self window] beginSheet: _addBookmarkWindow completionHandler: nil];
}
-(IBAction)bookmarkCancel:(id)sender {
[[self window] endSheet: _addBookmarkWindow];
[_addBookmarkWindow orderOut: nil];
}
-(IBAction)bookmarkSave:(id)sender {
BookmarkManager *bm = [BookmarkManager sharedManager];
if (![bm validateName: _bookmarkName]) {
[_bookmarkTextField selectText: nil];
NSBeep();
return;
}
//NSLog(@"%@", _bookmarkName);
NSDictionary *d = [self makeBookmark];
//NSLog(@"%@", d);
[bm saveBookmark: d name: _bookmarkName];
[[self window] endSheet: _addBookmarkWindow];
[_addBookmarkWindow orderOut: nil];
[self setBookmarkName: nil];
}
-(IBAction)loadBookmark:(id)sender {
NSURL *url = [sender representedObject];
if (!url) return;
NSDictionary *d = [NSDictionary dictionaryWithContentsOfURL: url];
if (!d) return; // oops...
NSString *machine = [d objectForKey: @"machine"];
if (!machine) return;
#if 0
_bookmark = YES;
[_machineViewController willLoadBookmark];
[_slotController willLoadBookmark];
[_mediaController willLoadBookmark];
[self setMameMachine: machine];
[_machineViewController loadBookmark: d];
[_slotController loadBookmark: d];
[_mediaController loadBookmark: d];
_bookmark = NO;
[_machineViewController didLoadBookmark];
[_slotController didLoadBookmark];
[_mediaController didLoadBookmark];
#endif
[self buildCommandLine];
}
-(NSDictionary *)makeBookmark {
[[self window] makeFirstResponder: nil];