Add "Open Memory Stick" to File menu on Mac

This commit is contained in:
Henrik Rydgård 2023-04-26 10:18:04 +02:00
parent c24f7eb084
commit eeaeb8b7cc
3 changed files with 26 additions and 12 deletions

View File

@ -41,7 +41,7 @@ variableName.state = [self controlStateForBool: ConfigurationValueName];
@interface BarItemsManager : NSObject <NSMenuDelegate> @interface BarItemsManager : NSObject <NSMenuDelegate>
+(instancetype)sharedInstance; +(instancetype)sharedInstance;
-(void)setupAppBarItems; -(void)setupAppBarItems;
@property (assign) NSMenu *openMenu; @property (assign) NSMenu *fileMenu;
@property (assign) std::shared_ptr<I18NCategory> mainSettingsLocalization; @property (assign) std::shared_ptr<I18NCategory> mainSettingsLocalization;
@property (assign) std::shared_ptr<I18NCategory> graphicsLocalization; @property (assign) std::shared_ptr<I18NCategory> graphicsLocalization;
@end @end
@ -65,9 +65,9 @@ void initializeOSXExtras() {
-(void)setupAppBarItems { -(void)setupAppBarItems {
NSMenuItem *openMenuItem = [[NSMenuItem alloc] init]; NSMenuItem *fileMenuItem = [[NSMenuItem alloc] init];
openMenuItem.submenu = [self makeOpenSubmenu]; fileMenuItem.submenu = [self makeFileSubmenu];
openMenuItem.submenu.delegate = self; fileMenuItem.submenu.delegate = self;
NSMenuItem *graphicsMenuItem = [[NSMenuItem alloc] init]; NSMenuItem *graphicsMenuItem = [[NSMenuItem alloc] init];
graphicsMenuItem.submenu = [self makeGraphicsMenu]; graphicsMenuItem.submenu = [self makeGraphicsMenu];
@ -80,7 +80,7 @@ void initializeOSXExtras() {
NSMenuItem *helpMenuItem = [[NSMenuItem alloc] init]; NSMenuItem *helpMenuItem = [[NSMenuItem alloc] init];
helpMenuItem.submenu = [self makeHelpMenu]; helpMenuItem.submenu = [self makeHelpMenu];
[NSApplication.sharedApplication.menu addItem:openMenuItem]; [NSApplication.sharedApplication.menu addItem:fileMenuItem];
[NSApplication.sharedApplication.menu addItem:graphicsMenuItem]; [NSApplication.sharedApplication.menu addItem:graphicsMenuItem];
[NSApplication.sharedApplication.menu addItem:debugMenuItem]; [NSApplication.sharedApplication.menu addItem:debugMenuItem];
[NSApplication.sharedApplication.menu addItem:helpMenuItem]; [NSApplication.sharedApplication.menu addItem:helpMenuItem];
@ -206,16 +206,23 @@ void initializeOSXExtras() {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://discord.gg/5NJB6dD"]]; [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://discord.gg/5NJB6dD"]];
} }
-(NSMenu *)makeOpenSubmenu { -(NSMenu *)makeFileSubmenu {
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"File"]; NSMenu *menu = [[NSMenu alloc] initWithTitle:@"File"];
NSMenuItem *openWithSystemFolderBrowserItem = [[NSMenuItem alloc] initWithTitle:@"Open..." action:@selector(openSystemFileBrowser) keyEquivalent:@"o"]; NSMenuItem *openWithSystemFolderBrowserItem = [[NSMenuItem alloc] initWithTitle:@"Open..." action:@selector(openSystemFileBrowser) keyEquivalent:@"o"];
openWithSystemFolderBrowserItem.keyEquivalentModifierMask = NSEventModifierFlagCommand; openWithSystemFolderBrowserItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
openWithSystemFolderBrowserItem.enabled = YES; openWithSystemFolderBrowserItem.enabled = YES;
openWithSystemFolderBrowserItem.target = self; openWithSystemFolderBrowserItem.target = self;
[menu addItem:openWithSystemFolderBrowserItem]; [menu addItem:openWithSystemFolderBrowserItem];
self.openMenu = menu; self.fileMenu = menu;
[self addOpenRecentlyItem]; [self addOpenRecentlyItem];
[self.fileMenu addItem:[NSMenuItem separatorItem]];
NSMenuItem *openMemstickFolderItem = [[NSMenuItem alloc] initWithTitle:@"Open Memory Stick" action:@selector(openMemstickFolder) keyEquivalent:@""];
openMemstickFolderItem.enabled = YES;
openMemstickFolderItem.target = self;
[self.fileMenu addItem:openMemstickFolderItem];
return menu; return menu;
} }
@ -504,7 +511,7 @@ TOGGLE_METHOD(ShowDebugStats, g_Config.bShowDebugStats, NativeMessageReceived("c
} }
openRecent.submenu = recentsMenu; openRecent.submenu = recentsMenu;
[self.openMenu addItem:openRecent]; [self.fileMenu addItem:openRecent];
} }
-(void)openRecentItem: (NSMenuItem *)item { -(void)openRecentItem: (NSMenuItem *)item {
@ -522,6 +529,12 @@ TOGGLE_METHOD(ShowDebugStats, g_Config.bShowDebugStats, NativeMessageReceived("c
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true); services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true);
} }
-(void)openMemstickFolder {
NSString *script = [NSString stringWithFormat:@"tell application \"Finder\"\nactivate\nopen folder (\"%s\" as POSIX file)\nend tell\n", g_Config.memStickDirectory.c_str()];
NSAppleScript *openScript = [[NSAppleScript alloc] initWithSource: script];
[openScript executeAndReturnError:nil];
}
- (void)dealloc { - (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self]; [NSNotificationCenter.defaultCenter removeObserver:self];
} }

View File

@ -1183,6 +1183,7 @@ int main(int argc, char *argv[]) {
NativeKey(key); NativeKey(key);
break; break;
} }
// TODO: Should we even keep the "non-precise" events?
if (event.wheel.y > 0) { if (event.wheel.y > 0) {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
mouseWheelMovedUpFrames = 5; mouseWheelMovedUpFrames = 5;

View File

@ -454,7 +454,7 @@ namespace MainWindow {
break; break;
case ID_FILE_MEMSTICK: case ID_FILE_MEMSTICK:
ShellExecute(NULL, L"open", g_Config.memStickDirectory.ToWString().c_str(), 0, 0, SW_SHOW); ShellExecute(NULL, L"open", g_Config.memStickDirectory.ToWString().c_str(), 0, 0, SW_SHOWNORMAL);
break; break;
case ID_TOGGLE_BREAK: case ID_TOGGLE_BREAK: