4 Replies Latest reply on Aug 13, 2009 7:38 AM by Bob Stucky

    [ScriptUI] Position of Window (dialog)?


      Even when I think it's not possible I'm curious if I'm right:

      Is there a way to set the location of a new window depending on the current selection?



      ... I want to spread the zoom to the page and want to make sure the dialog never hides the selection.



        • 1. Re: [ScriptUI] Position of Window (dialog)?
          Bob Stucky Adobe Employee

          var p = new Window( "palette", "Show Me" );

          p.add( "statictext", undefined, "How to move a window" );


          // frameLocation is set by an array [ x, y ]

          p.frameLocation = [ 250, 100 ];




          That'll set the window location. Now to figure out where it goes, you'll need to look at window.bounds and selection[ index ].geometricBounds to figure out how not to cover the selection.



          • 2. Re: [ScriptUI] Position of Window (dialog)?
            Steven.. Level 3

            While its possible to figure that the top left corner shouldn't cover the text, its not possible to figure what the width and height of the dialog is going to be after Adobe's layout engine lays out dialog. because the layout is only complete when window is shown, and when dialog is shown it's modal not giving the scripter the opportunity to move it.

            Tell me if I'm wrong, but this was the result of my testing.


            • 3. Re: [ScriptUI] Position of Window (dialog)?
              Bob Stucky Adobe Employee

              Check the Window.onShow() callback. While I don't have the time to test it at the moment, I believe the full geometry is ready during that callback, and you can make modifications to the layout and position.


              I'll check it tomorrow; but, I'm fairly certain about this.

              • 4. Re: [ScriptUI] Position of Window (dialog)?
                Bob Stucky Adobe Employee

                Here's a sample. Note that the window is created with the layout manager and is centered just prior to being shown.


                The onShow handler moves it near the top left corner, and makes it bigger.



                makeDialog = function() {

                var d = new Window( "dialog", "Wow" );

                d.add( "statictext", undefined, "Some text" );

                var g = d.add( "group" );

                g.alignChildren = ["right", "bottom" ];

                d.okBtn = g.add( "button", undefined, "OK" );

                d.canBtn = g.add( "button", undefined, "Cancel" );

                d.okBtn.onClick = function() {

                this.window.close( 1 );


                d.canBtn.onClick = function() {

                this.window.close( 2 );


                d.onShow = function() {

                $.writeln( "frameSize: " + this.frameSize );

                this.frameLocation = [100,100];

                this.size = [300, 200];