Mac: Implement open recent menu

This commit is contained in:
Michael Buckley 2019-09-03 19:51:25 -07:00
parent 2ce70f130c
commit 5cf1aa0c0e
5 changed files with 42 additions and 132 deletions

BIN
macosx/.DS_Store vendored

Binary file not shown.

View File

@ -17,6 +17,7 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.s9xEngine = [S9xEngine new]; self.s9xEngine = [S9xEngine new];
[self importRecentItems];
} }
@ -24,6 +25,30 @@
// Insert code here to tear down your application // Insert code here to tear down your application
} }
- (void)importRecentItems
{
const NSInteger maxRecents = 20;
for (NSInteger i = maxRecents - 1; i >= 0; --i)
{
NSString *key = [NSString stringWithFormat:@"RecentItem_%02tu", i];
NSString *recentItem = [NSUserDefaults.standardUserDefaults objectForKey:key];
if (recentItem != nil)
{
[NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:[NSURL fileURLWithPath:recentItem]];
[NSUserDefaults.standardUserDefaults removeObjectForKey:key];
}
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
return [self openURL:[NSURL fileURLWithPath:filename]];
}
- (IBAction)openDocument:(id)sender - (IBAction)openDocument:(id)sender
{ {
NSOpenPanel* panel = [NSOpenPanel new]; NSOpenPanel* panel = [NSOpenPanel new];
@ -31,8 +56,19 @@
if ( response == NSModalResponseOK ) if ( response == NSModalResponseOK )
{ {
[self.s9xEngine loadROM:panel.URL]; [self openURL:panel.URL];
} }
} }
- (BOOL)openURL:(NSURL *)url
{
if ([self.s9xEngine loadROM:url])
{
[NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:url];
return YES;
}
return NO;
}
@end @end

View File

@ -168,7 +168,6 @@ extern os_unfair_lock keyLock;
extern NSOpenGLView *s9xView; extern NSOpenGLView *s9xView;
void AddRecentItem (NSURL *);
void AdjustMenus (void); void AdjustMenus (void);
void UpdateMenuCommandStatus (Boolean); void UpdateMenuCommandStatus (Boolean);
void ApplyNSRTHeaderControllers (void); void ApplyNSRTHeaderControllers (void);
@ -183,7 +182,7 @@ uint64 GetMicroseconds(void);
- (void)start; - (void)start;
- (void)loadROM:(NSURL *)fileURL; - (BOOL)loadROM:(NSURL *)fileURL;
@end @end

View File

@ -335,9 +335,6 @@ static ButtonCommand btncmd[] =
static void Initialize (void); static void Initialize (void);
static void Deinitialize (void); static void Deinitialize (void);
static void InitAutofire (void); static void InitAutofire (void);
static void InitRecentItems (void);
static void DeinitRecentItems (void);
static void ClearRecentItems (void);
static void ProcessInput (void); static void ProcessInput (void);
static void ResizeGameWindow (void); static void ResizeGameWindow (void);
static void ChangeAutofireSettings (int, int); static void ChangeAutofireSettings (int, int);
@ -999,125 +996,6 @@ static inline void EmulationLoop (void)
// return (result); // return (result);
//} //}
// //
static void InitRecentItems (void)
{
CFStringRef keyRef, pathRef;
int count;
char key[32];
count = 0;
for (int i = 0; i <= kRecentMenu_MAX; i++)
recentItem[i] = NULL;
for (int i = 0; i < kRecentMenu_MAX; i++)
{
sprintf(key, "RecentItem_%02d", i);
keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
if (keyRef)
{
pathRef = (CFStringRef) CFPreferencesCopyAppValue(keyRef, kCFPreferencesCurrentApplication);
if (pathRef)
{
recentItem[count] = pathRef;
count++;
}
CFRelease(keyRef);
}
}
}
//
static void DeinitRecentItems (void)
{
CFStringRef keyRef;
char key[32];
for (int i = 0; i < kRecentMenu_MAX; i++)
{
sprintf(key, "RecentItem_%02d", i);
keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
if (keyRef)
{
if (recentItem[i])
{
CFPreferencesSetAppValue(keyRef, recentItem[i], kCFPreferencesCurrentApplication);
CFRelease(recentItem[i]);
recentItem[i] = NULL;
}
else
CFPreferencesSetAppValue(keyRef, NULL, kCFPreferencesCurrentApplication);
CFRelease(keyRef);
}
}
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
}
static void ClearRecentItems (void)
{
for (int i = 0; i < kRecentMenu_MAX; i++)
{
if (recentItem[i])
{
CFRelease(recentItem[i]);
recentItem[i] = NULL;
}
}
}
//
void AddRecentItem (NSURL *url)
{
// OSStatus err;
// char path[PATH_MAX + 1];
//
// err = FSRefMakePath(ref, (unsigned char *) path, PATH_MAX);
// if (err == noErr)
// {
// CFStringRef pathRef;
//
// pathRef = CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8);
// if (pathRef)
// {
// int i, j;
//
// for (i = 0; i < kRecentMenu_MAX; i++)
// if (recentItem[i] && (CFStringCompare(pathRef, recentItem[i], 0) == 0))
// break;
//
// if (i == kRecentMenu_MAX)
// {
// for (j = kRecentMenu_MAX - 1; j >= 0; j--)
// recentItem[j + 1] = recentItem[j];
//
// if (recentItem[kRecentMenu_MAX])
// {
// CFRelease(recentItem[kRecentMenu_MAX]);
// recentItem[kRecentMenu_MAX] = NULL;
// }
//
// recentItem[0] = pathRef;
// }
// else
// {
// CFRelease(pathRef);
//
// if (i > 0)
// {
// CFStringRef temp;
//
// temp = recentItem[i];
//
// for (j = i - 1; j >= 0; j--)
// recentItem[j + 1] = recentItem[j];
//
// recentItem[0] = temp;
// }
// }
// }
// }
}
// //
//static void InitRecentMenu (void) //static void InitRecentMenu (void)
//{ //{
@ -2923,8 +2801,6 @@ static void Initialize (void)
InitMacSound(); InitMacSound();
SetUpHID(); SetUpHID();
InitRecentItems();
InitMultiCart(); InitMultiCart();
autofire = (autofireRec[0].buttonMask || autofireRec[1].buttonMask) ? true : false; autofire = (autofireRec[0].buttonMask || autofireRec[1].buttonMask) ? true : false;
@ -2960,7 +2836,6 @@ static void Deinitialize (void)
deviceSetting = deviceSettingMaster; deviceSetting = deviceSettingMaster;
DeinitMultiCart(); DeinitMultiCart();
DeinitRecentItems();
SavePrefs(); SavePrefs();
ReleaseHID(); ReleaseHID();
DeinitCheatFinder(); DeinitCheatFinder();
@ -3283,7 +3158,7 @@ void QuitWithFatalError ( NSString *message)
} }
} }
- (void)loadROM:(NSURL *)fileURL - (BOOL)loadROM:(NSURL *)fileURL
{ {
if ( SNES9X_OpenCart(fileURL) ) if ( SNES9X_OpenCart(fileURL) )
{ {
@ -3291,7 +3166,10 @@ void QuitWithFatalError ( NSString *message)
s9xView.window.title = fileURL.lastPathComponent.stringByDeletingPathExtension; s9xView.window.title = fileURL.lastPathComponent.stringByDeletingPathExtension;
[s9xView.window makeKeyAndOrderFront:nil]; [s9xView.window makeKeyAndOrderFront:nil];
[self start]; [self start];
return YES;
} }
return NO;
} }
@end @end

View File

@ -106,9 +106,6 @@ bool8 SNES9X_OpenCart (NSURL *inRef)
ChangeTypeAndCreator(filename, 'CART', '~9X~'); ChangeTypeAndCreator(filename, 'CART', '~9X~');
AddRecentItem(cartRef);
//BuildRecentMenu();
ApplyNSRTHeaderControllers(); ApplyNSRTHeaderControllers();
for (int a = 0; a < MAC_MAX_PLAYERS; a++) for (int a = 0; a < MAC_MAX_PLAYERS; a++)