summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-12-17 19:08:51 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-12-17 19:08:51 +0000
commitb6f15852f36e8d017a275bc3727c5dcab1846d29 (patch)
treed4913175221b0ea3baca8f0b9bc62e86f481f1aa
parentb205e6323f8b10c9dcbfb9fd21e7cb896b3805ef (diff)
downloadpcsxr-b6f15852f36e8d017a275bc3727c5dcab1846d29.tar.gz
Reduce code duplication in -[PcsxrController application:openFile:].
Added a new function to the PcsxrFileHandle protocol that says what types of UTIs it supports. Currently only used when selecting discs or memory cards from an open dialog, and not used in checking if an app can open a file. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@73437 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rw-r--r--macosx/ConfigurationController.m7
-rw-r--r--macosx/PcsxrController.m34
-rw-r--r--macosx/PcsxrDiscHandler.m5
-rw-r--r--macosx/PcsxrFileHandle.h1
-rw-r--r--macosx/PcsxrFreezeStateHandler.m5
-rw-r--r--macosx/PcsxrMemCardHandler.m5
-rw-r--r--macosx/PcsxrPluginHandler.m5
7 files changed, 39 insertions, 23 deletions
diff --git a/macosx/ConfigurationController.m b/macosx/ConfigurationController.m
index 4460e396..71601855 100644
--- a/macosx/ConfigurationController.m
+++ b/macosx/ConfigurationController.m
@@ -3,6 +3,7 @@
#import "PluginList.h"
#import "PcsxrPlugin.h"
#import "PcsxrMemCardController.h"
+#import "PcsxrMemCardHandler.h"
#include "psxcommon.h"
#include "plugins.h"
@@ -63,7 +64,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
- [openDlg setAllowedFileTypes:[NSArray arrayWithObject:@"com.codeplex.pcsxr.memcard"]];
+ [openDlg setAllowedFileTypes:[PcsxrMemCardHandler utisCanHandle]];
path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:mcd length:strlen(mcd)];
@@ -95,7 +96,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
[openDlg setDirectoryURL:[NSURL fileURLWithPath:[path stringByDeletingLastPathComponent]]];
[openDlg setNameFieldStringValue:@"New Memory Card File.mcr"];
- [openDlg setAllowedFileTypes:[NSArray arrayWithObject:@"com.codeplex.pcsxr.memcard"]];
+ [openDlg setAllowedFileTypes:[PcsxrMemCardHandler utisCanHandle]];
if ([openDlg runModal] == NSFileHandlingPanelOKButton) {
NSString *mcdPath = [[openDlg URL] path];
@@ -244,7 +245,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier";
memCardEdit = [[PcsxrMemCardController alloc] init];
}
[[memCardEdit window] center];
- [memCardEdit showWindow:nil];
+ [memCardEdit showWindow:sender];
}
- (BOOL)memoryCardWindowIsVisible
diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m
index ebc4b2d1..72feab3a 100644
--- a/macosx/PcsxrController.m
+++ b/macosx/PcsxrController.m
@@ -55,7 +55,7 @@ static NSString *HandleBinCue(NSString *toHandle)
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
- [openDlg setAllowedFileTypes:[NSArray arrayWithObjects:@"com.alcohol-soft.mdfdisc", @"com.codeplex.pcsxr.cuefile", @"com.apple.disk-image-ndif", @"public.iso-image", nil]];
+ [openDlg setAllowedFileTypes:[PcsxrDiscHandler utisCanHandle]];
if ([openDlg runModal] == NSFileHandlingPanelOKButton) {
NSArray* files = [openDlg URLs];
@@ -135,7 +135,7 @@ static NSString *HandleBinCue(NSString *toHandle)
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
- [openDlg setAllowedFileTypes:[NSArray arrayWithObjects:@"com.alcohol-soft.mdfdisc", @"com.codeplex.pcsxr.cuefile", @"com.apple.disk-image-ndif", @"public.iso-image", nil]];
+ [openDlg setAllowedFileTypes:[PcsxrDiscHandler utisCanHandle]];
if ([openDlg runModal] == NSFileHandlingPanelOKButton) {
NSArray* urls = [openDlg URLs];
@@ -472,29 +472,23 @@ static NSString *HandleBinCue(NSString *toHandle)
NSRunAlertPanel(NSLocalizedString(@"Error opening file",nil), [NSString stringWithFormat:NSLocalizedString(@"Unable to open %@: %@", nil), [filename lastPathComponent], [err localizedFailureReason]], nil, nil, nil);
return NO;
}
+ NSObject<PcsxrFileHandle> *hand = nil;
+ BOOL isHandled = NO;
if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.plugin"), (CFStringRef)utiFile)) {
- PcsxrPluginHandler *hand = [[PcsxrPluginHandler alloc] init];
- BOOL isHandled = [hand handleFile:filename];
- [hand release];
- return isHandled;
+ hand = [[PcsxrPluginHandler alloc] init];
+ isHandled = [hand handleFile:filename];
} else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.memcard"), (CFStringRef)utiFile)) {
- PcsxrMemCardHandler *hand = [[PcsxrMemCardHandler alloc] init];
- BOOL isHandled = [hand handleFile:filename];
- [hand release];
- return isHandled;
+ hand = [[PcsxrMemCardHandler alloc] init];
+ isHandled = [hand handleFile:filename];
} else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.freeze"), (CFStringRef)utiFile)) {
- PcsxrFreezeStateHandler *hand = [[PcsxrFreezeStateHandler alloc] init];
- BOOL isHandled = [hand handleFile:filename];
- [hand release];
- return isHandled;
+ hand = [[PcsxrFreezeStateHandler alloc] init];
+ isHandled = [hand handleFile:filename];
} else if(UTTypeEqual(CFSTR("com.alcohol-soft.mdfdisc"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.apple.disk-image-ndif"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("public.iso-image"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.codeplex.pcsxr.cuefile"), (CFStringRef)utiFile)) {
- PcsxrDiscHandler *hand = [[PcsxrDiscHandler alloc] init];
- BOOL isHandled = [hand handleFile:HandleBinCue(filename)];
- [hand release];
- return isHandled;
- } else {
- return NO;
+ hand = [[PcsxrDiscHandler alloc] init];
+ isHandled = [hand handleFile:HandleBinCue(filename)];
}
+ if (hand) [hand release];
+ return isHandled;
}
@end
diff --git a/macosx/PcsxrDiscHandler.m b/macosx/PcsxrDiscHandler.m
index 16a9582f..9ba27a79 100644
--- a/macosx/PcsxrDiscHandler.m
+++ b/macosx/PcsxrDiscHandler.m
@@ -13,6 +13,11 @@
@implementation PcsxrDiscHandler
++ (NSArray *)utisCanHandle
+{
+ return [NSArray arrayWithObjects:@"com.alcohol-soft.mdfdisc", @"com.codeplex.pcsxr.cuefile", @"com.apple.disk-image-ndif", @"public.iso-image", nil];
+}
+
- (BOOL)handleFile:(NSString *)theFile
{
SetIsoFile([theFile fileSystemRepresentation]);
diff --git a/macosx/PcsxrFileHandle.h b/macosx/PcsxrFileHandle.h
index 3b29bde3..199e8bef 100644
--- a/macosx/PcsxrFileHandle.h
+++ b/macosx/PcsxrFileHandle.h
@@ -10,6 +10,7 @@
@protocol PcsxrFileHandle <NSObject>
++ (NSArray *)utisCanHandle;
- (BOOL)handleFile:(NSString *)theFile;
@end
diff --git a/macosx/PcsxrFreezeStateHandler.m b/macosx/PcsxrFreezeStateHandler.m
index ae236168..5e1e493c 100644
--- a/macosx/PcsxrFreezeStateHandler.m
+++ b/macosx/PcsxrFreezeStateHandler.m
@@ -12,6 +12,11 @@
@implementation PcsxrFreezeStateHandler
++ (NSArray *)utisCanHandle
+{
+ return [NSArray arrayWithObject:@"com.codeplex.pcsxr.freeze"];
+}
+
- (BOOL)handleFile:(NSString *)theFile
{
if (CheckState([theFile fileSystemRepresentation]) != 0) {
diff --git a/macosx/PcsxrMemCardHandler.m b/macosx/PcsxrMemCardHandler.m
index 2d4e1080..7998cdda 100644
--- a/macosx/PcsxrMemCardHandler.m
+++ b/macosx/PcsxrMemCardHandler.m
@@ -11,6 +11,11 @@
@implementation PcsxrMemCardHandler
++ (NSArray *)utisCanHandle
+{
+ return [NSArray arrayWithObject:@"com.codeplex.pcsxr.memcard"];
+}
+
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
diff --git a/macosx/PcsxrPluginHandler.m b/macosx/PcsxrPluginHandler.m
index 7ab00161..b2231577 100644
--- a/macosx/PcsxrPluginHandler.m
+++ b/macosx/PcsxrPluginHandler.m
@@ -10,6 +10,11 @@
@implementation PcsxrPluginHandler
++ (NSArray *)utisCanHandle
+{
+ return [NSArray arrayWithObject:@"com.codeplex.pcsxr.plugin"];
+}
+
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];