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
I forgot to mention why I need this new method.
The GetBundle script works with different repositories. I want to be able to select a repo in order to display that one. Furthermore if one selects a bundle in the table, I want to be able to interrupt the update process for the descriptions in order to avoid the destroying of my selection; and I want to be able to display more info about that bundle, meaning author, revision, etc. which will be downloaded only if the user selected one.
--Hans
On 9 Jul 2008, at 10:42, Hans-Joerg Bibiko wrote:
[...] 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.
So are you polling? I.e. how do you learn _when_ the user changes the pop-up?
I would suggest that we instead make this an extension of wait or a new monitor command.
So one would call: "$DIALOG" window monitor «property 1» [.. «property n»] «token»
This command then returns if «property i» changes, and returns a dictionary with the changed properties.
This would be implemented by using key/value observing. Two problems though, 1) what if the property is changed while no-one is observing it, but later the user calls the command (this could be solved by storing a copy of the initial parameters and reference + update these, each time the user monitors a property, and 2) monitor doesn’t imply waiting for actions, but for all practical purposes, this would be desired.
Based on the above, it might be better with:
"$DIALOG" window observe «property» «token»
This will immediately return the value of «property» _and_ setup KVO for this, which makes "$DIALOG" window wait «token» return, if that property is changed.
This solves both #1 and #2.
On 4 Aug 2008, at 11:44, Allan Odgaard wrote:
On 9 Jul 2008, at 10:42, Hans-Joerg Bibiko wrote:
[...] 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.
I would suggest that we instead make this an extension of wait or a new monitor command.
So one would call: "$DIALOG" window monitor «property 1» [.. «property n»] «token»
This command then returns if «property i» changes, and returns a dictionary with the changed properties.
This would be implemented by using key/value observing. Two problems though, 1) what if the property is changed while no-one is observing it, but later the user calls the command (this could be solved by storing a copy of the initial parameters and reference + update these, each time the user monitors a property, and 2) monitor doesn’t imply waiting for actions, but for all practical purposes, this would be desired.
Based on the above, it might be better with:
"$DIALOG" window observe «property» «token»
This will immediately return the value of «property» _and_ setup KVO for this, which makes "$DIALOG" window wait «token» return, if that property is changed.
This solves both #1 and #2.
Thanks. I agree. This would be a very nice enhancement ;)
--Hans