[TxMt] tm_dialog: add FileSelect + Appending Accessory Views
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Fri Jul 27 14:51:07 UTC 2007
On 26.07.2007, at 00:33, Allan Odgaard wrote:
> On 25. Jul 2007, at 15:08, Hans-Joerg Bibiko wrote:
>
>> I wonder if it possible 'easily' to enhance tm_dialog in a way
>> that one can also use it as FileSelect dialog, like CocoaDialog it
>> does, in conjunction with an user-defined nib-file to append a
>> CustomView to the predefined NSOpenPanel.
>> [...]
>
> Yeah, that shouldn’t be too hard. Are you asking because you want
> to take a swing at it yourself, or because you’d like to see others
> add it? Personally I probably won’t work much on tm_dialog until
> Leopard.
>
Now I added a fileSelect to tm_dialog. I simply cloned the method for
showAlert and I wrote:
[in Dialog.mm]
- (id)showFileSelect:(NSString*)filePath withParameters:(NSDictionary
*)parameters modal:(BOOL)modal
{
NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease];
NSMutableDictionary* resultDict = [NSMutableDictionary dictionary];
NSString* startDir = [parameters objectForKey:@"startDir"];
BOOL allowsMultSel = ([[parameters objectForKey:@"allowsMultSel"]
isEqualToString:@"YES"]) ? YES : NO;
[openPanel setAllowsMultipleSelection:allowsMultSel];
[openPanel setCanChooseDirectories:([[parameters
objectForKey:@"canChooseDir"] isEqualToString:@"YES"]) ? YES : NO];
[openPanel setCanChooseFiles:YES];
if ([startDir length] == 0) startDir = NSHomeDirectory();
int openPanelResult = [openPanel runModalForDirectory: startDir
file: nil types: [parameters objectForKey:@"fileType"]];
if (openPanelResult)
{
if (allowsMultSel)
[resultDict setObject:[[openPanel filenames] retain]
forKey:@"fileNames"];
else
[resultDict setObject:[[openPanel filename] retain]
forKey:@"fileName"];
}
[resultDict setObject:[NSNumber numberWithUnsignedInt:(unsigned)
openPanelResult] forKey:@"buttonClick"];
return resultDict;
}
OK.
####################
"$DIALOG" -F -p '{fileType=
("txt","log");allowsMultSel="YES";canChooseDir="YES";startDir="~/
Desktop";}'
gives you
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>buttonClick</key>
<integer>1</integer>
<key>fileNames</key>
<array>
<string>/Users/Bibiko/Desktop/tt0.txt</string>
<string>/Users/Bibiko/Desktop/tt1.txt</string>
</array>
</dict>
</plist>
####################
"$DIALOG" -F
gives you
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>buttonClick</key>
<integer>1</integer>
<key>fileName</key>
<string>/Users/Bibiko/Desktop/ntries.db</string>
</dict>
</plist>
####################
and if cancel it:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>buttonClick</key>
<integer>0</integer>
</dict>
</plist>
Fine.
####################
But now I need some help with the accessory view:
1) How should such a nib look like? Can someone write such one?
2) How can I load such a nib and how can I have access to it within
the showFileSelect method?
Any hints?
Thanks,
Hans
More information about the textmate
mailing list