Page 2 of 2

Re: API call help

Posted: Sat Nov 09, 2013 12:25 pm
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

Re: API call help

Posted: Sat Nov 09, 2013 1:44 pm
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?

Re: API call help

Posted: Sun Nov 10, 2013 9:52 pm
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)

Re: API call help

Posted: Tue Dec 10, 2013 1:21 pm
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

Re: API call help

Posted: Thu Dec 12, 2013 10:37 pm
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...

Re: API call help

Posted: Thu Dec 12, 2013 11:43 pm
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. :)