[futurebasic] Re: [FB] OSPanel - allowedFileTypes

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2017 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Fri, 21 Apr 2017 10:55:10 -0700
> On Apr 21, 2017, at 9:23 AM, Bernie <bernie.fblist@...> wrote:
> 
> 
> Brian wrote:
> 
>> Bernie wrote:
>> 
>>> A couple options to avoid creating an array.
>>> 
>>> [1] When only one UTI type is required:
>>> 	OSPanelOpen( 0, @“Open plain text file", kUTTypePlainText )
>>> 
>>> [2] UTI internal names can be strung together, separated by semicolons:
>>> 	OSPanelOpen( 0, @"Choose a plain text or pdf file", @"public.plain-text;com.adobe.pdf" )
>> 
>> Thanks for posting Bernie. Those are good options. The ponderous( compared to Cocoa ) CF array handling makes it seem worse.
>> Loading an array with constants is fine. Being able to pass constants in the same manner as the strings in #2 would be more economical but we have all we need.
>> 
>> Use of Objective-C's literal syntax might simplify the array syntax a little.
>> 
>> Unfortunately the new literal syntax doesn't really handle constants( wants real objects ) if you code:
>> NSArray *array = @[kUTTypePDF,kUTTypePlainText];
>> 
>> Coercing might satisfy the compiler but not sure if it runs correctly:
>> NSArray *array = @[(NSString*)kUTTypePDF,(NSString*)kUTTypePlainText];
>> 
> 
> Confirmed. Casting to NSString works fine.
> 
> If there’s one function I wish we had in FB, it’s ArrayWithObjects.
> 
> // ---------------
> include "NSLog.incl"
> include "Tlbx UTCoreTypes.incl”
> 
> local fn ArrayWithObjects( obj as CFTypeRef, ... ) as CFArrayRef
> '~'1
> BeginCCode
> va_list ap;
> va_start( ap, obj );
> NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
> while ( obj ) {
>     [array addObject:obj];
>     obj = va_arg( ap, id );
> }
> va_end( ap );
> return (CFArrayRef)array;
> EndC
> end fn = NULL
> 
> 
> OSPanelOpen( 0, @"Choose a plain text or pdf file", fn ArrayWithObjects( kUTTypePDF, kUTTypePlainText, NULL ) )

Yep, had a similar idea and your implementation looks good. Only minor potential issue ( which occurs elsewhere in OSPanel ) is FBer must retain the ArrayWithObjects returned value if it isn't being used immediately ( as it is shown embedded inside OSPanelOpen ).