As implemented, displayDialog is very limited because it doesn't
provide control of the underlying buttons list. This prevents it from
being used, for example attached to a link in VoodooPad, with an "OK/
Cancel" choice.
Adding (something like) the following to JSTextras.m provides the
desired functionality (in a non-standard syntaxy kind of way - I'm
sure you'll want to re-do this with the proper Cocoa buttons list
eventually, but I'm an old-school C and Assembler programmer, and this
objecty stuff hurts my head - groking enough of the ObjectiveC syntax
to do it right is currently beyond me).
- (NSInteger) displayDialog:(NSString*)msg withTitle:(NSString*)title
withOK:(NSString*)oktxt withNOK:(NSString*)noktxt {
NSAlert *alert = [NSAlert alertWithMessageText:title
defaultButton:oktxt alternateButton:noktxt otherButton:nil
informativeTextWithFormat:msg];
NSInteger button = [alert runModal];
return button;
}
Internal to VoodooPad, this can be used, for example, like so
(assuming that posting this doesn't break the formatting too much...):
# asciiName needs to be set to a unique page name - you probably don't
want the one hardcoded here...
# theHTMLstuff should be appropriately formatted page parts
f = AppKit.NSFont.fontWithName_size_("Monaco", 14);
attrs = {AppKit.NSFontAttributeName: f};
pageToAppendTo = document.createNewPageWithName_("a formatted HTML
page");
theHTMLhead = "<HTML>";
theHTMLcontents = "<table border=2 cellspacing=5
cellpadding=3><tr><td>hello</td><td>world</td></tr><tr><td>goodbye</
td><td>whirled</td></tr></table>";
theHTMLfoot = "</HTML>";
asciiNAME= "index";
theDeleteURL = "<A href=\"javascript:\n \
document = windowController.document();\n \
var VoodooPad = JSTalk.application_('VoodooPad');\n \
var response;\n \
response = VoodooPad.displayDialog_withTitle_withOK_withNOK_('There
is no undo!','Really Delete?','Ok!','Yikes!');\n \
if(response>0) document.deleteItemWithKey_('" + asciiName + "');\n \
else VoodooPad.displayDialog_('oops, I wet myself again');\n \
\">delete item</A>";
theHTML = theHTMLhead + theHTMLcontents + theDeleteURL + theHTMLfoot;
dats = AppKit.NSData.dataWithBytes_length_(theHTML],len(theHTML));
atts, attrs = Foundation.NSMutableAttributedString.alloc
().initWithHTML_documentAttributes_(dats);
pageToAppendTo.setDataAsAttributedString_(atts);
Best of luck,
Will Ray
-gus
> --
> You received this message because you are subscribed to the Google Groups "JSTalk Dev" group.
> To post to this group, send email to jstal...@googlegroups.com.
> To unsubscribe from this group, send email to jstalk-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jstalk-dev?hl=en.
>
--
August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/