Re: [hatari-devel] Hatari Mac GUI: Selecting IDE image

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

Attached is a second patch that removes the ability to specify file types when specifying an existing file on disk (for example a disk image) in the hopenfile() method, so we don't need to pass in `what:null` in several places.

It does _not_ remove the ability to specify file types when saving something (like a memory snapshot) so it is still possible to cause the user to _save_ a file of the desired type in the hsavefile() method.

I didn't make any changes to the default directories, given Bob's comment that he hopes that Hatari continues to save config files/screenshots in the existing places.

How does the above look?

I'd be happy to make further changes to the Mac UI if needed but I need to confess, once again, that I'm very much out of my comfort zone with Objective C/Cocoa/Xcode so I'll need to see if I can find the time to learn it a bit better. (For example, I promised you Eero that I would attempt to add the ability to select MIDI files in the Mac GUI but didn't manage to finish it at the time... I'd still like to find the time to do that.)

Cheers,
Chris
 


On Sat, 27 Aug 2022 at 00:42, Eero Tamminen <oak@xxxxxxxxxxxxxx> wrote:
Hi,

On 27.8.2022 0.20, Chris Jenkins wrote:
>> * would NSOpenPanel default to all files being selectable i.e. could
>> mutString lines be completely removed?
>>
>
> It looks like it does. I'll remove the what: parameter completely, meaning
> that the Mac GUI will allow any filetype to be specified in any file
> selector. (As far as I understand it, that's what the SDL GUI does: no
> matter what sort of file you are choosing, you can choose a file with any
> extension. Correct me if I'm wrong on that one!)

Yes, SDL GUI allows selecting any file, in any place where file is selected..

(There's even support for select files inside Zip archive files.)


> BTW, mutString will still be needed because that's used to return the path
> of the chosen file.
>
> * does using this "chooseDirectories:NO defaultInitialDir" mean file
>> selector defaulting to application workdir, or to dir of the initial
>> file selection?
>>
>
> I confess I haven't figured this out yet. I will attempt to figure it out
> and report back. I confess that the file selector on the Mac sometimes
> defaults to an unexpected place for me so it'll be good for me to
> understand it better. I guess ultimately we'd want the Mac UI to behave the
> same as the Hatari configuration defaults and/or the SDL UI...?

Otherwise yes, but I guess it's fine to follow OS defaults for things
like application (Hatari) configuration files, maybe also screenshots,
if OS has defaults for such.

(Although I have to admit that I like Hatari saving screenshots on Linux
to working dir instead of my already full ~/Pictures/ folder.)


> I'm busy this weekend but will attempt to create a new patch early next
> week (once it works and I'm confident that I've not screwed up some basic
> Objective C thing) to remove the filetype filters at least.

Great, thanks!


        - Eero


From f89b83d2f44dafa1cbca65b57278af5779b34290 Mon Sep 17 00:00:00 2001
From: Chris Jenkins <cdpjenkins@gmail.com>
Date: Thu, 25 Aug 2022 21:34:30 +0100
Subject: [PATCH] Allow all filetypes in Mac GUI

Previously, when selecting files (hard disk images, midi output etc...),
only certain filetypes were allowed. The Mac fileselector that we use,
NSOpenPanel, has actually deprecated the allowedFileTypes property and
certainly doesn't show the user any indication of the set of types that are
permitted.

Longer term, it might make sense to revamp this code.
---
 src/gui-osx/PrefsController.h |  2 +-
 src/gui-osx/PrefsController.m | 38 ++++++++++++++++++-----------------
 src/gui-osx/SDLMain.m         |  6 +++---
 src/gui-osx/Shared.h          | 10 ++-------
 src/gui-osx/Shared.m          | 10 ++++-----
 5 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/src/gui-osx/PrefsController.h b/src/gui-osx/PrefsController.h
index ee88737a..56a30a8a 100644
--- a/src/gui-osx/PrefsController.h
+++ b/src/gui-osx/PrefsController.h
@@ -191,7 +191,7 @@
 - (void)saveAllControls;
 - (void)insertFloppyImageIntoDrive:(int)drive forTextField:(NSTextField*)floppyTextField  realPath:(NSMutableString *)realPath ;
 - (BOOL)choosePathForControl:(NSTextField*)textField chooseDirectories:(BOOL)chooseDirectories defaultInitialDir:(NSString*)defaultInitialDir 
-																					mutString:(NSMutableString *)mutString what:(NSArray *)what ;
+																					mutString:(NSMutableString *)mutString ;
 - (void)initKeysDropDown:(NSPopUpButton*)dropDown;
 - (void)setJoystickControls;
 - (void)saveJoystickControls;
diff --git a/src/gui-osx/PrefsController.m b/src/gui-osx/PrefsController.m
index bc3b4cb0..e6c90e84 100644
--- a/src/gui-osx/PrefsController.m
+++ b/src/gui-osx/PrefsController.m
@@ -235,7 +235,7 @@ char szPath[FILENAME_MAX];
 /*  Returns: TRUE is the user selected a path, FALSE if he/she aborted   */
 /*-----------------------------------------------------------------------*/
 - (BOOL)choosePathForControl:(NSTextField*)textField chooseDirectories:(BOOL)chooseDirectories defaultInitialDir:(NSString*)defaultInitialDir 
-    mutString:(NSMutableString *)mutString what:(NSArray *)what
+    mutString:(NSMutableString *)mutString
 {
 	NSString *directoryToOpen ;
 	NSString *fileToPreselect ;
@@ -248,8 +248,9 @@ char szPath[FILENAME_MAX];
 	 {	directoryToOpen = defaultInitialDir.stringByExpandingTildeInPath ;	// no path: use user's directory
 		fileToPreselect = nil; } ;
 
-	newPath = [NSApp hopenfile:chooseDirectories defoDir:directoryToOpen
-                      defoFile:fileToPreselect types:what];
+	newPath = [NSApp hopenfile:chooseDirectories
+					   defoDir:directoryToOpen
+                      defoFile:fileToPreselect];
 	if (newPath.length != 0)												// user canceled if empty
 	{
 		[mutString setString:[NSString stringWithString:newPath]] ;			// save this path
@@ -269,9 +270,10 @@ char szPath[FILENAME_MAX];
 - (void)insertFloppyImageIntoDrive:(int)drive forTextField:(NSTextField*)floppyTextField
                           realPath:(NSMutableString *)realPath
 {
-	if ([self choosePathForControl:floppyTextField  chooseDirectories:NO
+	if ([self choosePathForControl:floppyTextField
+				 chooseDirectories:NO
                  defaultInitialDir:imgeDir
-                         mutString:realPath  what:@[allF]])
+                         mutString:realPath])
 		
 		Floppy_SetDiskFileName(drive, [realPath cStringUsingEncoding:NSASCIIStringEncoding], NULL);
 		// Insert the floppy image at this path  ????
@@ -281,7 +283,7 @@ char szPath[FILENAME_MAX];
 //-----------------------------------------------------------------------------
 - (NSString *)initial:(NSString *)route
 {
-BOOL flag1, flag2;
+	BOOL flag1, flag2;
 
 	if ((route==nil) || (route.length == 0))  return @"~" ;
 	flag1 = [[NSFileManager defaultManager] fileExistsAtPath:route isDirectory:&flag2] ;
@@ -296,14 +298,14 @@ BOOL flag1, flag2;
 - (IBAction)chooseCartridgeImage:(id)sender;
 {
     [self choosePathForControl: cartridgeImage chooseDirectories:NO defaultInitialDir:[self initial:cartridge]  // cartridge
-        mutString:cartridge  what:@[allC]];
+        mutString:cartridge];
 }
 
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseDefaultImagesLocation:(id)sender
 {
 	[self choosePathForControl: defaultImagesLocation chooseDirectories:YES defaultInitialDir:[self initial:imgeDir]                                // images location
-        mutString:imgeDir  what:nil];
+        mutString:imgeDir];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseFloppyImageA:(id)sender
@@ -319,62 +321,62 @@ BOOL flag1, flag2;
 - (IBAction)chooseGemdosImage:(id)sender																// directory for Gemdos
 {
 	[self choosePathForControl: gemdosImage chooseDirectories:YES defaultInitialDir:INITIAL_DIR(gemdos)	// gemdos
-                mutString:gemdos  what:nil] ;
+                mutString:gemdos] ;
 	if (gemdos.length >2 ) [gemdosImage setStringValue:[NSApp pathUser:gemdos]] ;
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseHdImage:(id)sender
 {
 	[self choosePathForControl: hdImage chooseDirectories:NO defaultInitialDir:[self initial:hrdDisk]	// HD image ?
-            mutString:hrdDisk  what:@[@"img",@"hdv"]] ;
+            mutString:hrdDisk] ;
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseIdeMasterHdImage:(id)sender
 {
 	[self choosePathForControl: ideMasterHdImage chooseDirectories:NO defaultInitialDir:[self initial:masterIDE]		// IDE master
-            mutString:masterIDE  what:@[@"hdv"]];
+            mutString:masterIDE];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseIdeSlaveHdImage:(id)sender
 {
 	[self choosePathForControl: ideSlaveHdImage chooseDirectories:NO defaultInitialDir:[self initial:slaveIDE]			// IDE slave
-            mutString:slaveIDE  what:@[@"hdv"]];
+            mutString:slaveIDE];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseKeyboardMappingFile:(id)sender
 {
 	[self choosePathForControl: keyboardMappingFile chooseDirectories:NO defaultInitialDir:[self initial:keyboard]		// keyboard mapping
-            mutString:keyboard  what:@[@"txt",@"map"]];
+            mutString:keyboard];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseMidiOutputFile:(id)sender
 {
 	[self choosePathForControl: writeMidiToFile chooseDirectories:NO defaultInitialDir:[self initial:midiOut]			// midi output 
-            mutString:midiOut  what:@[@"mid"]];
+            mutString:midiOut];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)choosePrintToFile:(id)sender
 {
 	[self choosePathForControl: printToFile chooseDirectories:NO defaultInitialDir:[self initial:printit]				// print to file
-            mutString:printit  what:@[@"prn"]];
+            mutString:printit];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseRS232InputFile:(id)sender
 {
 	[self choosePathForControl: readRS232FromFile chooseDirectories:NO defaultInitialDir:[self initial:rs232In]			// RS232 input
-        mutString:rs232In  what:nil];
+        mutString:rs232In];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseRS232OutputFile:(id)sender
 {
 	[self choosePathForControl: writeRS232ToFile chooseDirectories:NO defaultInitialDir:[self initial:rs232Out]			// RS232 output
-        mutString:rs232Out  what:nil];
+        mutString:rs232Out];
 }
 /*----------------------------------------------------------------------*/
 - (IBAction)chooseTosImage:(id)sender;
 {
 	[self choosePathForControl: tosImage chooseDirectories:NO defaultInitialDir:[self initial:TOS]						// TOS image
-        mutString:TOS  what:@[allT]];
+        mutString:TOS];
 }
 
 
diff --git a/src/gui-osx/SDLMain.m b/src/gui-osx/SDLMain.m
index a8bbc090..a65e0064 100644
--- a/src/gui-osx/SDLMain.m
+++ b/src/gui-osx/SDLMain.m
@@ -192,7 +192,7 @@ char szPath[FILENAME_MAX] ;											// for general use
 {
 	NSString	*aDisk ;
 
-	aDisk = [NSApp hopenfile:NO defoDir:nil defoFile:@"" types:@[allF]] ;
+	aDisk = [NSApp hopenfile:NO defoDir:nil defoFile:@""] ;
 	if (aDisk.length == 0) return ;                 		// user canceled
 
 	[aDisk getCString:szPath maxLength:FILENAME_MAX-1 encoding:NSASCIIStringEncoding] ;
@@ -355,7 +355,7 @@ char szPath[FILENAME_MAX] ;											// for general use
 	 {	directoryToOpen = @"~".stringByExpandingTildeInPath ;			// Currently no path: we use user's directory
 		fileToPreselect = nil; } ;
 
-	newPath = [NSApp hopenfile:NO defoDir:directoryToOpen defoFile:fileToPreselect types:@[@"sav"] ] ;
+	newPath = [NSApp hopenfile:NO defoDir:directoryToOpen defoFile:fileToPreselect] ;
 	if (newPath.length != 0)											// Perform the memory snapshot load
 		MemorySnapShot_Restore([newPath cStringUsingEncoding:NSASCIIStringEncoding], TRUE);
 
@@ -428,7 +428,7 @@ char szPath[FILENAME_MAX] ;											// for general use
 
 	GuiOsx_Pause(true);
 
-	newCfg = [NSApp hopenfile:NO defoDir:nil defoFile:ConfigFile types:@[@"cfg"] ] ;
+	newCfg = [NSApp hopenfile:NO defoDir:nil defoFile:ConfigFile] ;
 
 	if (newCfg.length != 0)
 	{
diff --git a/src/gui-osx/Shared.h b/src/gui-osx/Shared.h
index c6068da4..e6654766 100644
--- a/src/gui-osx/Shared.h
+++ b/src/gui-osx/Shared.h
@@ -14,12 +14,6 @@
 
 // disk extensions allowed in open box
 #define allF	@"st",@"msa",@"dim",@"gz",@"zip",@"stx",@"ipf",@"raw",@"ctr"
-// cartridge extensions
-#define allC	@"img",@"rom",@"bin",@"cart"
-// TOS extensions
-#define allT	@"img",@"rom",@"bin"
-
-
 
 // Wrapper to run an NSWindow modally
 @protocol NSWindowDelegate;
@@ -48,8 +42,8 @@ void GuiOsx_Resume(void);
 
 // Some useful tools
 // choose file to open
-- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types ;
-- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types titre:(NSString *)titre ;
+- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile ;
+- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile titre:(NSString *)titre ;
 
 // choose file to save
 - (NSString *)hsavefile:(BOOL)creatDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types ;
diff --git a/src/gui-osx/Shared.m b/src/gui-osx/Shared.m
index 2b611bf4..afc48571 100644
--- a/src/gui-osx/Shared.m
+++ b/src/gui-osx/Shared.m
@@ -90,13 +90,13 @@ void GuiOsx_Resume(void)
 
 // Open file or directory
 //
-- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types
+- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile 
 {
-	return [self hopenfile:chooseDir defoDir:defoDir defoFile:defoFile types:types titre:nil] ;
+	return [self hopenfile:chooseDir defoDir:defoDir defoFile:defoFile titre:nil] ;
 }
 
 /*----------------------------------------------------------------------*/
-- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types titre:(NSString *)titre
+- (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile titre:(NSString *)titre
 {
 NSOpenPanel *openPanel ;
 	NSArray     *lesURLs = nil ;
@@ -106,9 +106,7 @@ NSOpenPanel *openPanel ;
 	openPanel.canChooseDirectories = chooseDir ;
 	openPanel.canChooseFiles = !chooseDir;
 	openPanel.allowsMultipleSelection = NO ;
-	if (types != nil) 
-	 {	openPanel.allowedFileTypes = types ;
-		openPanel.allowsOtherFileTypes = YES ;  } ;
+
 	if (titre != nil) openPanel.title = titre ;
 
 //	if ([openPanel respondsToSelector:@selector(setDirectoryURL:)])
-- 
2.34.1



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/