From 3bd6d16afd6b068de6b061a87cba955f5ca3ff88 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Sun, 4 Dec 2011 06:09:59 +0000 Subject: Made it so that opening a memory card on PCSXR for the Mac allows you to set which slot you want to put it in. Just ignore the "Could not open file" warning for now: It's wrong. Added a class method to ConfigurationController that will set a memory card based on a path passed to it. Also made ConfigurationController listen for when a memory card is changed. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@72844 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/ConfigurationController.h | 1 + macosx/ConfigurationController.m | 41 +- macosx/English.lproj/PcsxrMemCardDocument.xib | 723 ++++++++++++++++++++++++++ macosx/Info.plist | 2 + macosx/Pcsxr.xcodeproj/project.pbxproj | 19 + macosx/PcsxrMemCardDocument.h | 19 + macosx/PcsxrMemCardDocument.m | 100 ++++ 7 files changed, 893 insertions(+), 12 deletions(-) create mode 100644 macosx/English.lproj/PcsxrMemCardDocument.xib create mode 100644 macosx/PcsxrMemCardDocument.h create mode 100644 macosx/PcsxrMemCardDocument.m diff --git a/macosx/ConfigurationController.h b/macosx/ConfigurationController.h index 964e4eda..d6ef4491 100644 --- a/macosx/ConfigurationController.h +++ b/macosx/ConfigurationController.h @@ -45,5 +45,6 @@ - (BOOL)memoryCardWindowIsVisible; - (NSString *)keyForSender:(id)sender; ++ (void)setMemoryCard:(int)theCard toPath:(NSString *)theFile; @end diff --git a/macosx/ConfigurationController.m b/macosx/ConfigurationController.m index 0faccc89..ab3dc22c 100644 --- a/macosx/ConfigurationController.m +++ b/macosx/ConfigurationController.m @@ -6,8 +6,24 @@ #include "psxcommon.h" #include "plugins.h" +NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier"; + + @implementation ConfigurationController ++ (void)setMemoryCard:(int)theCard toPath:(NSString *)theFile +{ + if (theCard == 1) { + [[NSUserDefaults standardUserDefaults] setObject:theFile forKey:@"Mcd1"]; + strcpy(Config.Mcd1, [theFile fileSystemRepresentation] ); + } else { + [[NSUserDefaults standardUserDefaults] setObject:theFile forKey:@"Mcd2"]; + strcpy(Config.Mcd2, [theFile fileSystemRepresentation] ); + } + + [[NSNotificationCenter defaultCenter] postNotificationName:memChangeNotifier object:nil]; +} + - (IBAction)setCheckbox:(id)sender { if ([sender isKindOfClass:[NSMatrix class]]) { @@ -58,14 +74,9 @@ if ([openDlg runModal] == NSFileHandlingPanelOKButton) { NSArray* urls = [openDlg URLs]; NSString *mcdPath = [[urls objectAtIndex:0] path]; - strcpy(mcd, (const char *)[mcdPath fileSystemRepresentation]); + [ConfigurationController setMemoryCard:tag toPath:mcdPath]; [label setTitleWithMnemonic:mcdPath]; - - if (tag == 1) - [[NSUserDefaults standardUserDefaults] setObject:mcdPath forKey:@"Mcd1"]; - else - [[NSUserDefaults standardUserDefaults] setObject:mcdPath forKey:@"Mcd2"]; } [openDlg release]; } @@ -90,15 +101,10 @@ if ([openDlg runModal] == NSFileHandlingPanelOKButton) { NSString *mcdPath = [[openDlg URL] path]; - strcpy(mcd, (const char *)[mcdPath fileSystemRepresentation]); + [ConfigurationController setMemoryCard:tag toPath:mcdPath]; [label setTitleWithMnemonic:mcdPath]; - if (tag == 1) - [[NSUserDefaults standardUserDefaults] setObject:mcdPath forKey:@"Mcd1"]; - else - [[NSUserDefaults standardUserDefaults] setObject:mcdPath forKey:@"Mcd2"]; - CreateMcd(mcd); } [openDlg release]; @@ -129,12 +135,22 @@ } } +- (void)memoryCardDidChangeNotification:(NSNotification *)aNote +{ + NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:Config.Mcd1 length:strlen(Config.Mcd1)]; + [mcd1Label setTitleWithMnemonic:path]; + path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:Config.Mcd2 length:strlen(Config.Mcd2)]; + [mcd2Label setTitleWithMnemonic:path]; +} + - (void)awakeFromNib { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [[self window] center]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryCardDidChangeNotification:) name:memChangeNotifier object:nil]; + // setup checkboxes checkBoxDefaults = [[NSMutableDictionary alloc] init]; @@ -201,6 +217,7 @@ - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; [checkBoxDefaults release]; if (memCardEdit) { [memCardEdit release]; diff --git a/macosx/English.lproj/PcsxrMemCardDocument.xib b/macosx/English.lproj/PcsxrMemCardDocument.xib new file mode 100644 index 00000000..f19add63 --- /dev/null +++ b/macosx/English.lproj/PcsxrMemCardDocument.xib @@ -0,0 +1,723 @@ + + + + 1060 + 11C74 + 1938 + 1138.23 + 567.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 1938 + + + YES + NSTextField + NSView + NSWindowTemplate + NSTextFieldCell + NSImageCell + NSButtonCell + NSImageView + NSButton + NSCustomObject + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + PcsxrMemCardDocument + + + FirstResponder + + + 1 + 2 + {{133, 235}, {416, 155}} + 1886912512 + Memory Card + NSWindow + View + + {94, 86} + + + 256 + + YES + + + 289 + {{129, 19}, {90, 34}} + + + + 2 + YES + + 67239424 + 134217728 + Cancel + + LucidaGrande + 13 + 1558 + + + -2038284033 + 1 + + Helvetica + 13 + 16 + + + Gw + 200 + 25 + + + + + 289 + {{222, 19}, {90, 34}} + + + + 2 + 1 + YES + + 67239424 + 134217728 + Slot 1 + + + -2035924737 + 1 + + + + DQ + + 200 + 25 + + + + + 268 + + YES + + YES + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + + NSFilenamesPboardType + + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT TIFF v4.0 pasteboard type + + NeXT filename pasteboard type + + + + {{20, 70}, {64, 64}} + + + + 2 + YES + + 130560 + 33554432 + + NSImage + pcsxrmemcard + + 0 + 1 + 0 + NO + + NO + + + + 266 + {{100, 118}, {290, 17}} + + + + 2 + YES + + 67239424 + 0 + Memory Card Selection + + LucidaGrande-Bold + 13 + 2072 + + + + 6 + System + controlBackgroundColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + + 266 + {{100, 51}, {290, 34}} + + + + 2 + YES + + 69336577 + 0 + Select which memory card slot you want to put this card in. + + LucidaGrande + 11 + 3100 + + + + 6 + System + controlColor + + + + + + + + 268 + {{100, 93}, {290, 17}} + + + + _NS:3944 + YES + + 68288064 + 272630784 + Label + + LucidaGrande + 13 + 1044 + + _NS:3944 + + + + + + + + 289 + {{312, 19}, {90, 34}} + + + + 2 + 2 + YES + + 67239424 + 134217728 + Slot 2 + + + -2035924737 + 1 + + + + 200 + 25 + + + + {416, 155} + + + + + {{0, 0}, {1680, 1028}} + {94, 108} + {10000000000000, 10000000000000} + YES + + + NSApplication + + + + + YES + + + window + + + + 18 + + + + setMemCard: + + + + 100039 + + + + setMemCard: + + + + 100040 + + + + cardPath + + + + 100042 + + + + changeMemCardSheet + + + + 100043 + + + + setMemCard: + + + + 100044 + + + + delegate + + + + 17 + + + + nextKeyView + + + + 100033 + + + + nextKeyView + + + + 100038 + + + + + YES + + 0 + + YES + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + 5 + + + YES + + + + Window + + + 6 + + + YES + + + + + + + + + + + + -3 + + + Application + + + 100021 + + + YES + + + + + + 100022 + + + YES + + + + + + 100023 + + + YES + + + + + + 100024 + + + YES + + + + + + 100025 + + + YES + + + + + + 100028 + + + + + 100029 + + + + + 100030 + + + + + 100031 + + + + + 100032 + + + + + 100034 + + + YES + + + + + + 100035 + + + + + 100036 + + + YES + + + + + + 100037 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 100021.IBPluginDependency + 100022.IBPluginDependency + 100023.IBPluginDependency + 100024.IBPluginDependency + 100025.IBPluginDependency + 100028.IBPluginDependency + 100029.IBPluginDependency + 100030.IBPluginDependency + 100031.IBPluginDependency + 100032.IBPluginDependency + 100034.IBPluginDependency + 100035.IBPluginDependency + 100036.IBPluginDependency + 100037.IBPluginDependency + 5.IBPluginDependency + 5.IBWindowTemplateEditedContentRect + 6.IBPluginDependency + + + YES + 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 + 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 + {{133, 170}, {507, 413}} + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 100044 + + + + YES + + NSDocument + + YES + + YES + printDocument: + revertDocumentToSaved: + runPageLayout: + saveDocument: + saveDocumentAs: + saveDocumentTo: + + + YES + id + id + id + id + id + id + + + + YES + + YES + printDocument: + revertDocumentToSaved: + runPageLayout: + saveDocument: + saveDocumentAs: + saveDocumentTo: + + + YES + + printDocument: + id + + + revertDocumentToSaved: + id + + + runPageLayout: + id + + + saveDocument: + id + + + saveDocumentAs: + id + + + saveDocumentTo: + id + + + + + IBProjectSource + ./Classes/NSDocument.h + + + + PcsxrMemCardDocument + NSDocument + + setMemCard: + id + + + setMemCard: + + setMemCard: + id + + + + YES + + YES + cardPath + changeMemCardSheet + + + YES + NSTextField + NSWindow + + + + YES + + YES + cardPath + changeMemCardSheet + + + YES + + cardPath + NSTextField + + + changeMemCardSheet + NSWindow + + + + + IBProjectSource + ./Classes/PcsxrMemCardDocument.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + pcsxrmemcard + {128, 128} + + + diff --git a/macosx/Info.plist b/macosx/Info.plist index e960fad4..c098366e 100644 --- a/macosx/Info.plist +++ b/macosx/Info.plist @@ -75,6 +75,8 @@ LSTypeIsPackage + NSDocumentClass + PcsxrMemCardDocument CFBundleTypeExtensions diff --git a/macosx/Pcsxr.xcodeproj/project.pbxproj b/macosx/Pcsxr.xcodeproj/project.pbxproj index 0c1122a0..5aff9eaf 100644 --- a/macosx/Pcsxr.xcodeproj/project.pbxproj +++ b/macosx/Pcsxr.xcodeproj/project.pbxproj @@ -42,6 +42,8 @@ 55A90220147D7C380037E18F /* PcsxrMemCardController.m in Sources */ = {isa = PBXBuildFile; fileRef = 55A9021F147D7C380037E18F /* PcsxrMemCardController.m */; }; 55A90223147D7C7A0037E18F /* MemCardManager.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55A90221147D7C7A0037E18F /* MemCardManager.xib */; }; 55A90229147D89380037E18F /* PcsxrMemoryObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 55A90228147D89380037E18F /* PcsxrMemoryObject.m */; }; + 55C7A212148B298F00C22ABC /* PcsxrMemCardDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C7A210148B298F00C22ABC /* PcsxrMemCardDocument.m */; }; + 55C7A214148B2B3800C22ABC /* PcsxrMemCardDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C7A216148B2B3800C22ABC /* PcsxrMemCardDocument.xib */; }; 712FD1E81093096F00575A92 /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 712FD1E51093096F00575A92 /* debug.c */; }; 712FD1E91093096F00575A92 /* socket.c in Sources */ = {isa = PBXBuildFile; fileRef = 712FD1E61093096F00575A92 /* socket.c */; }; 713B530E110B75650002F164 /* ppf.c in Sources */ = {isa = PBXBuildFile; fileRef = 713B530C110B75650002F164 /* ppf.c */; }; @@ -270,6 +272,9 @@ 55A90222147D7C7A0037E18F /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = MemCardManager.xib; sourceTree = ""; }; 55A90227147D89380037E18F /* PcsxrMemoryObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PcsxrMemoryObject.h; sourceTree = ""; }; 55A90228147D89380037E18F /* PcsxrMemoryObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PcsxrMemoryObject.m; sourceTree = ""; }; + 55C7A20F148B298F00C22ABC /* PcsxrMemCardDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PcsxrMemCardDocument.h; sourceTree = ""; }; + 55C7A210148B298F00C22ABC /* PcsxrMemCardDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PcsxrMemCardDocument.m; sourceTree = ""; }; + 55C7A215148B2B3800C22ABC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/PcsxrMemCardDocument.xib; sourceTree = ""; }; 712FD1E51093096F00575A92 /* debug.c */ = {isa = PBXFileReference; fileEncoding = 0; lastKnownFileType = sourcecode.c.c; path = debug.c; sourceTree = ""; }; 712FD1E61093096F00575A92 /* socket.c */ = {isa = PBXFileReference; fileEncoding = 0; lastKnownFileType = sourcecode.c.c; path = socket.c; sourceTree = ""; }; 712FD1E71093096F00575A92 /* socket.h */ = {isa = PBXFileReference; fileEncoding = 0; lastKnownFileType = sourcecode.c.h; path = socket.h; sourceTree = ""; }; @@ -414,6 +419,7 @@ 28F0C3C7146521B000A90285 /* PCSXR.xib */, 28F0C3CA146521B700A90285 /* AddPluginSheet.xib */, 55A90221147D7C7A0037E18F /* MemCardManager.xib */, + 55C7A216148B2B3800C22ABC /* PcsxrMemCardDocument.xib */, ); name = Resources; path = English.lproj; @@ -459,6 +465,8 @@ 55A9021F147D7C380037E18F /* PcsxrMemCardController.m */, 55A90227147D89380037E18F /* PcsxrMemoryObject.h */, 55A90228147D89380037E18F /* PcsxrMemoryObject.m */, + 55C7A20F148B298F00C22ABC /* PcsxrMemCardDocument.h */, + 55C7A210148B298F00C22ABC /* PcsxrMemCardDocument.m */, ); name = MacOSX; sourceTree = ""; @@ -753,6 +761,7 @@ 28F0C3CC146521B700A90285 /* AddPluginSheet.xib in Resources */, 559DACEE146C72FF00C5DF71 /* Localizable.strings in Resources */, 55A90223147D7C7A0037E18F /* MemCardManager.xib in Resources */, + 55C7A214148B2B3800C22ABC /* PcsxrMemCardDocument.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -806,6 +815,7 @@ 559366D012B694DF004ACC1E /* ix86_sse.c in Sources */, 55A90220147D7C380037E18F /* PcsxrMemCardController.m in Sources */, 55A90229147D89380037E18F /* PcsxrMemoryObject.m in Sources */, + 55C7A212148B298F00C22ABC /* PcsxrMemCardDocument.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -906,6 +916,15 @@ name = MemCardManager.xib; sourceTree = ""; }; + 55C7A216148B2B3800C22ABC /* PcsxrMemCardDocument.xib */ = { + isa = PBXVariantGroup; + children = ( + 55C7A215148B2B3800C22ABC /* English */, + ); + name = PcsxrMemCardDocument.xib; + path = ..; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ diff --git a/macosx/PcsxrMemCardDocument.h b/macosx/PcsxrMemCardDocument.h new file mode 100644 index 00000000..b0466bbb --- /dev/null +++ b/macosx/PcsxrMemCardDocument.h @@ -0,0 +1,19 @@ +// +// PcsxrMemCardDocument.h +// Pcsxr +// +// Created by Charles Betts on 12/3/11. +// Copyright (c) 2011 __MyCompanyName__. All rights reserved. +// + +#import + +@interface PcsxrMemCardDocument : NSDocument { + IBOutlet NSWindow *changeMemCardSheet; + IBOutlet NSTextField *cardPath; + int memChosen; +} + +- (IBAction)setMemCard:(id)sender; + +@end diff --git a/macosx/PcsxrMemCardDocument.m b/macosx/PcsxrMemCardDocument.m new file mode 100644 index 00000000..aa130378 --- /dev/null +++ b/macosx/PcsxrMemCardDocument.m @@ -0,0 +1,100 @@ +// +// PcsxrMemCardDocument.m +// Pcsxr +// +// Created by Charles Betts on 12/3/11. +// Copyright (c) 2011 __MyCompanyName__. All rights reserved. +// + +#import "PcsxrMemCardDocument.h" +#import "ConfigurationController.h" + +@implementation PcsxrMemCardDocument + +- (int)showMemoryCardChooserForFile:(NSString *)theFile +{ + if (!changeMemCardSheet) { + [NSBundle loadNibNamed:[self windowNibName] owner:self]; + } + [cardPath setObjectValue:theFile]; + + [NSApp runModalForWindow:changeMemCardSheet]; + + [NSApp endSheet:changeMemCardSheet]; + [changeMemCardSheet orderOut:self]; + + return memChosen; +} + +- (id)init +{ + self = [super init]; + if (self) { + memChosen = 0; + } + return self; +} + +- (NSString *)windowNibName +{ + // Override returning the nib file name of the document + // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. + return @"PcsxrMemCardDocument"; +} + +- (void)windowControllerDidLoadNib:(NSWindowController *)aController +{ + [super windowControllerDidLoadNib:aController]; + // Add any code here that needs to be executed once the windowController has loaded the document's window. +} + +#if 0 +- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError +{ + /* + Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil. + You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead. + */ + if (outError) { + *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; + } + return nil; +} + +- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError +{ + /* + Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO. + You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. + If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded. + */ + if (outError) { + *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; + } + return YES; +} +#endif + +- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError +{ + int chosen = [self showMemoryCardChooserForFile:[fileWrapper filename]]; + if (chosen == 0) { + if (outError) { + *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:nil]; + } + return NO; + } else { + [ConfigurationController setMemoryCard:chosen toPath:[[self fileURL] path]]; + //TODO: make this return YES so that "File Can't be Opened" dialog box doesn't pop up, but the window itself doesn't stay on the screen. + return NO; + } +} + +- (IBAction)setMemCard:(id)sender +{ + memChosen = [sender tag]; + + [NSApp stopModal]; +} + +@end -- cgit v1.2.3