Hi,
I just fiddling with the GetBundle GUI. While doing this I thought that it would be nice to have a asynchronous window created via
"$DIALOG" window create ...
which I can modify while runtime.
A simple example:
Supposing you have a NIB which shows names and last names of persons in a table, and you want to select one person in order to display more information. But I want to be able to display either all male persons or all female persons, and if I selected an item the window shouldn't be closed. What I did is to set up such a NIB with a pop-down menu 'Choose Gender'. Fine. But how can I notify the running script in the background that I changed that pop-down menu?
I didn't find a way to do this. That's why I introduced a new method to '"$DIALOG" window' named 'getparams'. This method is very simple. It write the current NSDictionary 'parameters' of the current nibController to the standard output. Nothing else. But then I was able to ask the async window: Are there any changes? If so, then I changed the content of the parameters accordingly and updated the window's parameters.
Here is a screencast to illustrate this example: http://www.bibiko.de/TM_intact_async_window.mov (1.7MB)
By using the new method 'getparams' it opens ways to do more useful things, I believe. You can hide/show items easier, change the content of data cells, change the title of buttons according to the status of radio buttons or checkboxes, etc.....
Here is the code for "$DIALOG2" > window.mm
... else if([command isEqualToString:@"getparams"]) { if([proxy numberOfArguments] < 4) ErrorAndReturn(@"no window token given"); NSString* token = [proxy argumentAtIndex:3]; TMDNibController* nibController = [TMDNibController controllerForToken:token]; if(nibController) { id params = [[nibController parameters] mutableCopy]; [params removeObjectForKey:@"controller"]; NSString* error = nil; if(NSData* data = [NSPropertyListSerialization dataFromPropertyList:params format:NSPropertyListXMLFormat_v1_0 errorDescription:&error]) { NSString* outpl = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; [proxy writeStringToOutput:outpl]; } else { fprintf(stderr, "%s\n", [error UTF8String] ?: "unknown error serializing returned property list"); fprintf(stderr, "%s\n", [[[nibController parameters] description] UTF8String]); } } else { [proxy writeStringToError:@"There is no window with that token"]; } }
I guess one could improve and simplify the code.
Is this worth to implement this?
Thanks,
--Hans