Hi,
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.
For details have a look at: http://developer.apple.com/documentation/Cocoa/Conceptual/AppFileMgmt/ Articles/ManagingAccessoryViews.html
E.g.:
tm_dialog -f
invokes a normal cocoa-based file select dialog.
tm_dialog -f myextension.nib
invokes a normal cocoa-based file select dialog and appends myextension.nib as an Accessory View.
tm_dialog -f -p THEPLIST
to set the current dir, which files are allowed to select, multiple file select yes/no, dialog title, etc.
The result is a plist containing the filename and, if an Accessory View is specified, the selections of it.
Hans
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.
[...] tm_dialog -f
Just a general thought, not directly related to your request, but IMO tm_dialog is started to get too complex with respect to arguments, and we have already sort of gathered some legacy stuff ;)
Maybe we should rethink the argument format before adding more. E.g. switch to a system like “tm_dialog «action» «arguments»” so the action is the namespace specifier for the arguments.
I’d also like to change the convention related to the plist returned -- returning the full model isn’t useful when binding arguments to the action button. But maybe a better idea is to write a new shell command with a much cleaner API and still just provide tm_dialog as- is for backwards compatibility -- if this is done, it might be one of those things which is best done when making a major version change.
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.
Good to know in beforehand :) Well, I don't know whether I'm the right person to do it but I will think about it. But I believe I will need some help ;)
What do you mean with "... I probably won’t work much on tm_dialog until Leopard"? Will be there a change for tm_dialog in TM 2.0?
[...] tm_dialog -f
Just a general thought, not directly related to your request, but IMO tm_dialog is started to get too complex with respect to arguments, and we have already sort of gathered some legacy stuff ;)
Maybe we should rethink the argument format before adding more. E.g. switch to a system like “tm_dialog «action» «arguments»” so the action is the namespace specifier for the arguments.
I’d also like to change the convention related to the plist returned -- returning the full model isn’t useful when binding arguments to the action button. But maybe a better idea is to write a new shell command with a much cleaner API and still just provide tm_dialog as-is for backwards compatibility -- if this is done, it might be one of those things which is best done when making a major version change.
I see. The OPTIONS -cnmqaltxw are really options for tm_dialog displaying a nib. Then I understood your suggestion in that way:
tm_dialogAPI ShowAlert {paramsAsPLIST:=title, message, style} tm_dialogAPI ShowMenu {paramsAsPLIST:=items} tm_dialogAPI OPTIONS ShowNib {paramsAsPLIST:=nibFile, defaults} if nibFile=OpenPanel then {paramsAsPLIST:=nibFile, defaults, [AccessoryViewNib]}
'OpenPanel' is a dummy for Cocoa's NSOpenPanel. Maybe one could also add SavePanel, PrintPanel, ColorPanel, FontPanel, DatePicker, ... ;)
Hans
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
On 26. Jul 2007, at 10:01, Hans-Jörg Bibiko wrote:
[...] What do you mean with "... I probably won’t work much on tm_dialog until Leopard"? Will be there a change for tm_dialog in TM 2.0?
Well, Leopard has a spiffy new interface builder and lots of Cocoa improvements, so it would be strange if it did not at least receive an update :)
[...] tm_dialog -f
Just a general thought, not directly related to your request, but IMO tm_dialog is started to get too complex with respect to arguments, and we have already sort of gathered some legacy stuff ;)
Maybe we should rethink the argument format before adding more. E.g. switch to a system like “tm_dialog «action» «arguments»” so the action is the namespace specifier for the arguments.
I’d also like to change the convention related to the plist returned -- returning the full model isn’t useful when binding arguments to the action button. But maybe a better idea is to write a new shell command with a much cleaner API and still just provide tm_dialog as-is for backwards compatibility -- if this is done, it might be one of those things which is best done when making a major version change.
I see. The OPTIONS -cnmqaltxw are really options for tm_dialog displaying a nib. Then I understood your suggestion in that way:
tm_dialogAPI ShowAlert {paramsAsPLIST:=title, message, style} tm_dialogAPI ShowMenu {paramsAsPLIST:=items} tm_dialogAPI OPTIONS ShowNib {paramsAsPLIST:=nibFile, defaults} if nibFile=OpenPanel then {paramsAsPLIST:=nibFile, defaults, [AccessoryViewNib]}
'OpenPanel' is a dummy for Cocoa's NSOpenPanel. Maybe one could also add SavePanel, PrintPanel, ColorPanel, FontPanel, DatePicker, ... ;)
Yes, something along those lines.
On 27. Jul 2007, at 16:51, Hans-Jörg Bibiko wrote:
[...] But now I need some help with the accessory view:
- How should such a nib look like? Can someone write such one?
Go to the “Cocoa-Containers” part in the palette. Then drag a “CustomView” to the “Instances” part of your nib.
You can then work with just this view, i.e. add controls to it.
- How can I load such a nib and how can I have access to it within
the showFileSelect method?
You will load it just as a regular nib, but where we presently iterate the top-level nib objects to find one of type NSWindow, you will need to find one of NSView, and then use that.
On 28.07.2007, at 05:40, Allan Odgaard wrote:
On 27. Jul 2007, at 16:51, Hans-Jörg Bibiko wrote:
[...] But now I need some help with the accessory view: 2) How can I load such a nib and how can I have access to it within the showFileSelect method?
You will load it just as a regular nib, but where we presently iterate the top-level nib objects to find one of type NSWindow, you will need to find one of NSView, and then use that.
Thanks for the hint. It works ;)
I will rewrite the code now and post a diff against the latest tm_dialog release.
To invoke such a panel: tm_dialog -I open tm_dialog -I save accessory.nib ... -I stands for --internal-panel
One question: Which panels (NSOpenPanel, NSSavePanel, NSFontPanel, etc.) would make sense to include?
Hans
BTW I like tm_dialog ;)
On Jul 30, 2007, at 10:15 AM, Hans-Jörg Bibiko wrote:
One question: Which panels (NSOpenPanel, NSSavePanel, NSFontPanel, etc.) would make sense to include?
If you can actually get the color and font info from tm_dialog. Please do! Awesome!
thomas Aylott — subtleGradient — CrazyEgg — sixteenColors
On 30. Jul 2007, at 16:15, Hans-Jörg Bibiko wrote:
[...] One question: Which panels (NSOpenPanel, NSSavePanel, NSFontPanel, etc.) would make sense to include?
A color picker would be nice to have as tm_dialog since what we presently use (AppleScript) is slooow and blocks the entire application.
On 30 Jul 2007, at 17:14, Thomas Aylott (subtleGradient) wrote:
If you can actually get the color and font info from tm_dialog. Please do!
Well, to handle a ColorPanel and Fontpanel is a bit tricky. If I try to run runModalForWindow:aColorPanel it works but TM hangs and one have to force quit it.
I also tried several other things like beginModalSession etc. but I didn't find a solution.
On other approach is to create a normal nib for it. (see attachment)
If one invoke it via "$DIALOG" -m ColourChooser.nib one will see a NSColorWell. Press on it and one can choose a color. Finally press 'Insert'. The bad thing is that tm_dialog is not able able to handle a NSColor. The output is
tm_dialog: Property list invalid for format { color = NSDeviceCMYKColorSpace 0 0 0.643153 0 1; returnButton = Insert; returnCode = 1; }
or
tm_dialog: Property list invalid for format { color = NSCalibratedRGBColorSpace 0.8 0.4 0.4 1; returnButton = Insert; returnCode = 1; }
On other issue is that the NSColorPanel is still visible even I closed the dialog.
Discussion: I don't know which approach would be the easiest one. I believe to use an external nib for that would be fine, but I don't know where I can train tm_dialog to handle NSColor objects.
Furthermore it would be the best to include in such a nib the desired output format like:
For RGB <key>red</key> <integer>233</integer> ...
or
For CMYK <key>Cyan</key> <integer >3</integer> ...
or
For Hex RGB <key>color</key> <string>FFDD01</string>
Any hints, comments on that?
Hans
On 31. Jul 2007, at 14:54, Hans-Joerg Bibiko wrote:
On 30 Jul 2007, at 17:14, Thomas Aylott (subtleGradient) wrote:
If you can actually get the color and font info from tm_dialog. Please do!
Well, to handle a ColorPanel and Fontpanel is a bit tricky. If I try to run runModalForWindow:aColorPanel it works but TM hangs and one have to force quit it. [...]
I assume it hangs only because it is running the tm_dialog command synchronously -- running that asynchronously should work (and using ⌃C or ⌘. should break it more gracefully than force quit).
That said, I just remembered that font and color panels are autonomous entities which signal the first responder when they see a change. So they do not follow the “request a font/color” model, rather you open the panel, and someone just listens to changes, and that someone can change, while the panel is up. So I don’t think this would really work with tm_dialog.
Hi,
so far I did the following:
Usage (internal panel): tm_dialog [-cdp] -I open|save|color {custom_view_nib_file}
Internal Panel Options: -I, --internal-panel aPanel <plist> <nib_file> Show internal panel. aPanel: open, save, color [:= Open File, Save File, Color Picker Dialog] open - Parameters: windowTitle, startDir, button1, message, allowMultipleSelection fileType [string or array], canChooseDir, file save - Parameters: windowTitle, startDir, button1, message, allowOtherFileTypes fileType [string or array], label, file color - Parameters: windowTitle, message, color [string of #RRGGBB notation] -- a custom view is not supported nib_file: contains a customm view with control elements which will be shown at the bottom of the open/save dialog
Returned plist: open/save: <dict> <key>buttonClick</key> <integer>1</integer> <key>result</key> <dict> <key>URL</key> <string>file://localhost/usr/share/doc/bash/article.pdf</string> <key>absoluteFileName</key> <string>/usr/share/doc/bash/article.pdf</string> <key>directory</key> <string>/usr/share/doc/bash</string> <key>pathExtension</key> <string>pdf</string> </dict> </dict>
open with parameter allowMultipleSelection: <dict> <key>buttonClick</key> <integer>1</integer> <key>result</key> <dict> <key>absoluteFileNames</key> <array> <string>/Users/Bibiko/DialogPlugin.zip</string> <string>/Users/Bibiko/fehlerrate.pdf</string> </array> </dict> </dict>
open/save with a custom view with a checkbox - selection key = 'Check': <dict> <key>buttonClick</key> <integer>1</integer> <key>result</key> <dict> <key>URL</key> <string>file://localhost/usr/share/doc/bash/article.pdf</string> <key>absoluteFileName</key> <string>/usr/share/doc/bash/article.pdf</string> <key>directory</key> <string>/usr/share/doc/bash</string> <key>pathExtension</key> <string>pdf</string> <key>Check</key> <integer>1</integer> </dict> </dict>
color: <dict> <key>color</key> <string>#00C960</string> <key>result</key> <dict> <key>returnArgument</key> <string>#00C960</string> </dict> </dict>
Notes:
The parameters allowMultipleSelection, canChooseDir, and allowOtherFileTypes are boolean in such a way that if one write them in a plist they'll be set to YES automatically regardingless what value the key has! E.g. {canChooseDir;} == {canChooseDir="1";} == {canChooseDir=0;} === YES That also means that these parameters are set to NO as default.
The default of the parameter 'startDir' is, if not set, $HOME. You can set - startDir="nil"; - to set it automatically to the last path which was chosen.
The parameter 'fileType' can be a single string like fileType="txt"; or an array fileType=("txt","tab"); .
The Color Picker is realized by a nib file which is stored in $TM_SUPPORT_PATH/nibs. If one invoke it a dialog with a ColorWell appears and the ColorPanel pops up automatically. If one press OK/ Cancel the ColorPanel will also closed.
If one want to preset a file in open/save you can use the parameters 'startDir' and 'file'. 'file' is only the file name without the path!
A humble screenshot of a customized Open File Dialog can be seen at http://email.eva.mpg.de/~bibiko/dt/open.jpg .
########
My question for now is whether I should change something before I post the code to Alan?
Hans
PS I found my fault with the value transformer. Now it works perfectly ;)