API call help

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: API call help

Post by Wolfram »

Withe "#returnAbsoluteNames" it woks. I get a Path like this "file://localhost/TEXT.txt" for a file in the root of my HD.

With Wilbert solution I get the same Path.


...And I'm on OS X 10.7.5
macOS Catalina 10.15.7
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: API call help

Post by Wolfram »

Danilo wrote:
Wolfram wrote:but I get an Error if I try to load a File
Object dose not respond to method "fileSystemRepresentation"
Does it work for you with flag '#returnAbsoluteNames'?
In this case you get results like "file:///users/danilo/todo.rtf", but it could
be different URL for Network files.
Withe "#returnAbsoluteNames" it woks. I get a Path like this "file://localhost/TEXT.txt" for a file in the root of my HD.
Can I use this kind of Path or are there any problems with it?
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: API call help

Post by wilbert »

Here's a modified version of my previous post, returning file names in a more common form

Code: Select all

#RequesterTypeOpen = 0
#RequesterTypeSave = 1

Procedure.s FileRequester(RequesterType, Title.s, DefaultFile.s = "", AllowedFileTypes.s = "", Message.s = "", Flags = 0)
  Protected Result.s, Path.s, NSPanel, NSEnumerator, NSURL, NSString
  
  If RequesterType = #RequesterTypeSave
    NSPanel = CocoaMessage(0, 0, "NSSavePanel savePanel")
  Else
    NSPanel = CocoaMessage(0, 0, "NSOpenPanel openPanel")
    If Flags & #PB_Requester_MultiSelection
      CocoaMessage(0, NSPanel, "setAllowsMultipleSelection:", #YES)
    EndIf    
  EndIf
  
  Path = GetPathPart(DefaultFile)
  DefaultFile = GetFilePart(DefaultFile)
  
  CocoaMessage(0, NSPanel, "setTitle:$", @Title)
  CocoaMessage(0, NSPanel, "setMessage:$", @Message)
  CocoaMessage(0, NSPanel, "setAllowedFileTypes:", CocoaMessage(0, CocoaMessage(0, 0, "NSString stringWithString:$", @AllowedFileTypes), "componentsSeparatedByString:$", @"|"))
  CocoaMessage(0, NSPanel, "setDirectoryURL:", CocoaMessage(0, 0, "NSURL fileURLWithPath:$", @Path))
  CocoaMessage(0, NSPanel, "setNameFieldStringValue:$", @DefaultFile)
  
  If CocoaMessage(0, NSPanel, "runModal")
    If RequesterType = #RequesterTypeSave
      Result = PeekS(CocoaMessage(0, CocoaMessage(0, CocoaMessage(0, NSPanel, "URL"), "path"), "fileSystemRepresentation"), -1, #PB_Ascii)
    Else
      NSEnumerator = CocoaMessage(0, CocoaMessage(0, NSPanel, "URLs"), "objectEnumerator")
      NSURL = CocoaMessage(0, NSEnumerator, "nextObject")
      If NSURL
        Result = PeekS(CocoaMessage(0, CocoaMessage(0, NSURL, "path"), "fileSystemRepresentation"), -1, #PB_Ascii)
        NSURL = CocoaMessage(0, NSEnumerator, "nextObject")
        While NSURL
          Result + "|" + PeekS(CocoaMessage(0, CocoaMessage(0, NSURL, "path"), "fileSystemRepresentation"), -1, #PB_Ascii)
          NSURL = CocoaMessage(0, NSEnumerator, "nextObject")
        Wend
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn Result
EndProcedure


Debug FileRequester(#RequesterTypeOpen,
                    "Please choose file to open",
                    "/users/",
                    "pb|pbi|txt",
                    "Optional message",
                    #PB_Requester_MultiSelection)
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: API call help

Post by Wolfram »

Wilbert solution works fine But there is one problem...

on OSX 10.7.5 if I use the search field in the NSOpenPanel I can only search for .txt fils
Example: if I open it with AllowedFileTypes "txt" and search for .txt I find every text file.
If I open it with AllowedFileTypes "ems" and search for .ems I get no result.

on OSX 10.6.8 it works!

Dose anyone have an idee???

Thanx
macOS Catalina 10.15.7
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: API call help

Post by Shardik »

I have tested with a test file "Test.ems" using Wilbert's last example code on both OS X 10.6.8 (Snow Leopard) and OS X 10.7.5 (Lion) and I can't reproduce Wolfram's finding that ems file extensions are not found on Lion. Wilbert's example works without any problems on both Snow Leopard and Lion with the file extension ems...
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: API call help

Post by WilliamL »

I just tried wilbert's example and it works correctly for me. It only lets me choose 'pb' or 'pbi' or 'txt' files.

Oh, I tried '.ems' and it only found files that I changed to .ems. :)
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
Post Reply