Skip to main content
July 28, 2009
Question

does "resource specifications" work?

  • July 28, 2009
  • 1 reply
  • 1206 views

As you know, "resource specifications" is a great way to create UIs--it avoids a heck of a lot of brute-force calls that create objects in specific x,y locations within a dialog box.

Here's an example one I wrote.

var win= new Window (
            """dialog {
            info: Panel {
                orientation: "column",
                text: "Go to Folder",
                path: Group {
                orientation: "row",
                s: StaticText { text: "Path:" },
                pathText: EditText {
                    characters: 60,
                    text: doc.thumbnail.path
                }
                },
            },
            buttons: Group {
                orientation: "row",
                browseBtn: Button { text: "Browse" },
                cancelBtn: Button { text: "Cancel", properties: { name: "cancel" } },
                okBtn: Button { text: "OK", properties: { name: "ok" } }                   
            }
            }"""
        );

The dialog comes up great. the problem is, you can't add event handlers for the buttons at all. Here's how you're supposed to do it (according to the doc).

       win.buttons.browseBtn.onClick = function() {
            $.writeln("Browse Pressed.");
            var f = Folder.selectDialog ( "Navigate to Folder" );
            win.info.dirText.text = f.fsName;
        }
        win.info.path.pathText.onChange = win.buttons.okBtn.onClick = function() {
            win.close();
            var f = new Folder (win.info.path.pathText.text);
            $.writeln("OK pressed: " + f.fsName);
            if (! f.exists) alert ( f.fsName + ": doesn't exist");
            else {
            alert("Going to " + f.fsName);
            app.document.thumbnail = new Thumbnail(f.fsName);
            // What's the Error if we can't browse there? (permissions, etc.)
            }
        }
        win.buttons.cancelBtn.onClick = function() { win.close(); }

Doesn't work.  However, if you create the exact same buttons using the brute-force method of using the "add()" function for the Panel object, you can add the event handlers using precisely the same code and they work. Example:

    win.btnPanel.searchBtn = win.btnPanel.add("button", [225, 65, 315, 85], "Search");
    // Register event listeners that define the button behavior
    win.btnPanel.searchBtn.onClick = function() {
        $.writeln("Search pressed");
    }

My assumption is that "resource specifications" has a bug.

I can upload the full demo scripts that demonstrate each if needed.

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
July 28, 2009

Works for me, there were a few typos that stopped it working.

var win= new Window (
            """dialog {
            info: Panel {
                orientation: "column",
                text: "Go to Folder",
                path1: Group {
                orientation: "row",
                s: StaticText { text: "Path:" },
                pathText: EditText {
                    characters: 60,
                    text: "doc.thumbnail.path"
                }
                },
            },
            buttons: Group {
                orientation: "row",
                browseBtn: Button { text: "Browse" },
                cancelBtn: Button { text: "Cancel", properties: { name: "cancel" } },
                okBtn: Button { text: "OK", properties: { name: "ok" } }                   
            }
            }"""
        );

       win.buttons.browseBtn.onClick = function() {
            $.writeln("Browse Pressed.");
            var f = Folder.selectDialog ( "Navigate to Folder" );
            win.info.path1.pathText.text = f.fsName;
        }
        win.info.path1.pathText.onChange = win.buttons.okBtn.onClick = function() {
            win.close();
            var f = new Folder (win.info.path1.pathText.text);
            $.writeln("OK pressed: " + f.fsName);
            if (! f.exists) alert ( f.fsName + ": doesn't exist");
            else {
            alert("Going to " + f.fsName);
            app.document.thumbnail = new Thumbnail(f.fsName);
            }
        }
  win.show();