From ec03001040a634987b658e4b79e377ec4fd2e959 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Thu, 20 Dec 2012 22:42:36 +0000 Subject: Add a recent menu. Ignoring Xcode 4 generated files. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@81905 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/English.lproj/PCSXR.xib | 237 ++++++++++++++++++++++++++++++++- macosx/Pcsxr.xcodeproj/project.pbxproj | 4 + macosx/PcsxrController.h | 4 + macosx/PcsxrController.m | 12 +- macosx/RecentItemsMenu.h | 23 ++++ macosx/RecentItemsMenu.m | 103 ++++++++++++++ 6 files changed, 373 insertions(+), 10 deletions(-) create mode 100644 macosx/RecentItemsMenu.h create mode 100644 macosx/RecentItemsMenu.m diff --git a/macosx/English.lproj/PCSXR.xib b/macosx/English.lproj/PCSXR.xib index 3af0f7cb..6d563890 100644 --- a/macosx/English.lproj/PCSXR.xib +++ b/macosx/English.lproj/PCSXR.xib @@ -231,6 +231,52 @@ + + + Run Recent... + + 2147483647 + + + submenuAction: + + Run Recent... + + YES + + + YES + YES + + + 2147483647 + + + 1 + + + + Clear recent list + + 2147483647 + + + 1 + + + + + + + YES + YES + + + 1048576 + 2147483647 + + + Pause @@ -550,6 +596,28 @@ PcsxrController + + Menu + + 2147483647 + + + submenuAction: + + Menu + + YES + + + Item + + 2147483647 + + + + + + @@ -802,6 +870,30 @@ 323 + + + recentItems + + + + 364 + + + + pcsxr + + + + 365 + + + + clearRecentDocuments: + + + + 368 + @@ -1000,6 +1092,8 @@ + + @@ -1152,6 +1246,9 @@ 308 + + YES + @@ -1204,6 +1301,63 @@ + + 324 + + + + + 329 + + + YES + + + + + + 330 + + + YES + + + + + + + 366 + + + + + 367 + + + + + 369 + + + YES + + + + + + 370 + + + YES + + + + + + 371 + + + @@ -1261,6 +1415,15 @@ 318.IBPluginDependency 320.IBPluginDependency 322.IBPluginDependency + 324.IBPluginDependency + 329.IBPluginDependency + 330.CustomClassName + 330.IBPluginDependency + 366.IBPluginDependency + 367.IBPluginDependency + 369.IBPluginDependency + 370.IBPluginDependency + 371.IBPluginDependency 5.IBPluginDependency 56.IBPluginDependency 57.IBPluginDependency @@ -1324,6 +1487,15 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + RecentItemsMenu + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1343,7 +1515,7 @@ - 323 + 371 @@ -1447,19 +1619,70 @@ - preferenceWindow - NSWindow + YES + + YES + preferenceWindow + recentItems + + + YES + NSWindow + RecentItemsMenu + + + + YES + + YES + preferenceWindow + recentItems + + + YES + + preferenceWindow + NSWindow + + + recentItems + RecentItemsMenu + + + + + IBProjectSource + ./Classes/PcsxrController.h + + + + RecentItemsMenu + NSMenu + + clearRecentDocuments: + id + + + clearRecentDocuments: + + clearRecentDocuments: + id + + + + pcsxr + PcsxrController - preferenceWindow + pcsxr - preferenceWindow - NSWindow + pcsxr + PcsxrController IBProjectSource - ./Classes/PcsxrController.h + ./Classes/RecentItemsMenu.h diff --git a/macosx/Pcsxr.xcodeproj/project.pbxproj b/macosx/Pcsxr.xcodeproj/project.pbxproj index 55ed00f1..0218a19a 100644 --- a/macosx/Pcsxr.xcodeproj/project.pbxproj +++ b/macosx/Pcsxr.xcodeproj/project.pbxproj @@ -260,6 +260,8 @@ 2BBB1792051E113B00B84448 /* EmuThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = EmuThread.m; sourceTree = ""; }; 2BBB17DA051E4D0F00B84448 /* Plugin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Plugin.c; sourceTree = SOURCE_ROOT; }; 2BC4786204C7FD3600CAB520 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; + 5550D2711683C923006C56B5 /* RecentItemsMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RecentItemsMenu.h; sourceTree = ""; }; + 5550D2721683C923006C56B5 /* RecentItemsMenu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RecentItemsMenu.m; sourceTree = ""; }; 559366C012B694DF004ACC1E /* iGte.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iGte.h; sourceTree = ""; }; 559366C112B694DF004ACC1E /* iR3000A-64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "iR3000A-64.c"; sourceTree = ""; }; 559366C212B694DF004ACC1E /* ix86-64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "ix86-64.c"; sourceTree = ""; }; @@ -488,6 +490,8 @@ 0280B7AC16764CC3007B8001 /* HotkeyController.m */, 02717967167884C9004AED62 /* hotkeys.m */, 02717969167884DF004AED62 /* hotkeys.h */, + 5550D2711683C923006C56B5 /* RecentItemsMenu.h */, + 5550D2721683C923006C56B5 /* RecentItemsMenu.m */, ); name = MacOSX; sourceTree = ""; diff --git a/macosx/PcsxrController.h b/macosx/PcsxrController.h index b89587c0..10ae42c0 100644 --- a/macosx/PcsxrController.h +++ b/macosx/PcsxrController.h @@ -3,8 +3,10 @@ #import #import "EmuThread.h" #import "PluginList.h" +#import "RecentItemsMenu.h" @class ConfigurationController; +@class RecentItemsMenu; @interface PcsxrController : NSObject { @@ -12,6 +14,7 @@ PluginList *pluginList; IBOutlet NSWindow *preferenceWindow; + IBOutlet RecentItemsMenu *recentItems; BOOL sleepInBackground; BOOL wasPausedBeforeBGSwitch; @@ -27,6 +30,7 @@ - (IBAction)defrost:(id)sender; - (IBAction)fullscreen:(id)sender; - (IBAction)pauseInBackground:(id)sender; +- (void)runURL:(NSURL*)url; + (void)setConfigFromDefaults; + (void)setDefaultFromConfig:(NSString *)defaultKey; diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m index f23d7dfd..da5de3d3 100644 --- a/macosx/PcsxrController.m +++ b/macosx/PcsxrController.m @@ -195,9 +195,9 @@ static NSString *HandleBinCue(NSString *toHandle) [openDlg setAllowedFileTypes:[PcsxrDiscHandler supportedUTIs]]; if ([openDlg runModal] == NSFileHandlingPanelOKButton) { - NSArray* urls = [openDlg URLs]; - SetIsoFile((const char *)[HandleBinCue([[urls objectAtIndex:0] path]) fileSystemRepresentation]); - [EmuThread run]; + NSURL *url = [[openDlg URLs] objectAtIndex:0]; + [recentItems addRecentItem:url]; + [self runURL:url]; } [openDlg release]; } @@ -208,6 +208,12 @@ static NSString *HandleBinCue(NSString *toHandle) [EmuThread runBios]; } +- (void)runURL:(NSURL*)url +{ + SetIsoFile((const char *)[HandleBinCue([url path]) fileSystemRepresentation]); + [EmuThread run]; +} + - (IBAction)freeze:(id)sender { NSInteger num = [sender tag]; diff --git a/macosx/RecentItemsMenu.h b/macosx/RecentItemsMenu.h new file mode 100644 index 00000000..21c518c8 --- /dev/null +++ b/macosx/RecentItemsMenu.h @@ -0,0 +1,23 @@ +// +// RecentItemsMenu.h +// Pcsxr +// +// Created by Nicolas Pepin-Perreault on 12-12-16. +// +// + +#import +#import "PcsxrController.h" + +@class PcsxrController; +@interface RecentItemsMenu : NSMenu { + IBOutlet PcsxrController *pcsxr; +} + +- (IBAction)clearRecentDocuments:(id)sender; +- (void)addRecentItem:(NSURL*)documentURL; +- (NSMenuItem*)createMenuItem:(NSURL*)documentURL; +- (void)openRecentItem:(NSMenuItem*)sender; +- (void)addMenuItem:(NSMenuItem*)item; + +@end diff --git a/macosx/RecentItemsMenu.m b/macosx/RecentItemsMenu.m new file mode 100644 index 00000000..aaf3f01b --- /dev/null +++ b/macosx/RecentItemsMenu.m @@ -0,0 +1,103 @@ +// +// RecentItemsMenu.m +// Pcsxr +// +// Created by Nicolas Pepin-Perreault on 12-12-16. +// +// + +#import "RecentItemsMenu.h" + +@implementation RecentItemsMenu + +// Initialization +- (void)awakeFromNib +{ + [self setAutoenablesItems:YES]; + + // Populate the menu + NSArray* recentDocuments = [[NSDocumentController sharedDocumentController] recentDocumentURLs]; + NSInteger index = 0; + for(NSURL* url in recentDocuments) { + [self addMenuItem:[self createMenuItem:url] atIndex:index]; + index++; + } +} + +- (void)addRecentItem:(NSURL*)documentURL +{ + [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:documentURL]; + + NSMenuItem* item = [self findMenuItemByURL:documentURL]; + if(item != nil) { + [self removeItem:item]; + [self insertItem:item atIndex:0]; + } + else { + [self addMenuItem:[self createMenuItem:documentURL]]; + } +} + +- (void)addMenuItem:(NSMenuItem*)item +{ + [self addMenuItem:item atIndex:0]; + + // Prevent menu from overflowing; the -2 accounts for the "Clear..." and the separator items + NSInteger maxNumItems = [[NSDocumentController sharedDocumentController] maximumRecentDocumentCount]; + if(([self numberOfItems]-2) > maxNumItems) { + [self removeItemAtIndex:maxNumItems]; + } +} + +- (NSMenuItem*)findMenuItemByURL:(NSURL*)url +{ + for(NSMenuItem* item in [self itemArray]) { + if([[item representedObject] isEqual:url]) { + return item; + } + } + + return nil; +} + +- (void)addMenuItem:(NSMenuItem*)item atIndex:(NSInteger)index +{ + [self insertItem:item atIndex:index]; // insert at the top + [item release]; +} + +- (NSMenuItem*)createMenuItem:(NSURL*)documentURL +{ + NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:[documentURL relativePath] action:@selector(openRecentItem:) keyEquivalent:@""]; + [newItem setRepresentedObject:documentURL]; + [newItem setEnabled:YES]; + [newItem setTarget:self]; + [newItem setTag:0]; + + return newItem; +} + +- (void)openRecentItem:(NSMenuItem*)sender +{ + NSURL* url = [sender representedObject]; + [self addRecentItem:url]; + [pcsxr runURL:url]; +} + +- (IBAction)clearRecentDocuments:(id)sender +{ + [self removeDocumentItems]; + [[NSDocumentController sharedDocumentController] clearRecentDocuments:sender]; +} + +// Document items are menu items with tag 0 +- (void)removeDocumentItems +{ + for(NSMenuItem* item in [self itemArray]) { + if([item tag] == 0) { + [self removeItem:item]; + } + } +} + +@end -- cgit v1.2.3