## PPG.PPGLayout

### Introduced

v4.0

### Description

Returns the PPGLayout for the currently inspected object. By changing the PPGLayout's contents, it is possible to dynamically change the UI from within logic code. After changes are complete use PPG.Refresh to redraw the user interface.

### Examples

#### JScript Example

    // JScript Custom Property example demonstrating how to
    // build a simple Script viewer by using the
    // siControlFolder, siControlCombo and multi-line string
    // control.
    //
    // Note: This example could be extended: for example by adding a
    // "Save" and "New" button.
    Main()
    function Main()
    {
            var oCustomProperty = ActiveSceneRoot.AddProperty(
                                      "CustomProperty", false,
                                      "Script View" ) ;
            oCustomProperty.AddParameter3( "Dir", siString ) ;
            oCustomProperty.AddParameter3( "Scripts", siString ) ;
            oCustomProperty.AddParameter3( "File", siString ) ;
            var oLayout = oCustomProperty.PPGLayout
            oLayout.AddGroup( "Script Directory" ) ;
            var oItem = oLayout.AddItem( "Dir", "Directory", "Folder" ) ;
            oItem.SetAttribute( "NoLabel", true ) ;
            oLayout.EndGroup() ;
            oLayout.AddGroup( "Script File" ) ;
            var oItem = oLayout.AddEnumControl( "Scripts", Array(),
                                 "", siControlCombo ) ;
            oItem.SetAttribute( "NoLabel", true ) ;
            oLayout.EndGroup();
            oLayout.AddGroup( "File Contents" ) ;
            var oItem = oLayout.AddString( "File", "", true, 200 ) ;
            oItem.SetAttribute( "NoLabel", true ) ;
            oLayout.EndGroup() ;
            oLayout.Language = "Jscript" ;
            oLayout.Logic = OnInit.toString() +
                                 PopulateCombo.toString() +
                                 Dir_OnChanged.toString() +
                                 Scripts_OnChanged.toString();
            strDefaultDir = Application.InstallationPath( siUserPath ) +
                                 "/Data/Scripts" ;
            oCustomProperty.Dir = strDefaultDir ;
            InspectObj( oCustomProperty );
    }
    //
    // The remaining code is event code which
    // is injected into the PPG layout.
    //
    function OnInit()
    {
            PopulateCombo() ;
    }
    function Dir_OnChanged()
    {
            PopulateCombo() ;
            PPG.File.Value = "" ;
    }
    function Scripts_OnChanged()
    {
            strDir = PPG.Dir.Value
            strScript = PPG.Scripts.Value
            if ( strDir == "" || strScript == "" )
            {
                    PPG.File.Value = "" ;
                    return ;
            }
            try
            {
                    var oFSO = new ActiveXObject( "Scripting.FileSystemObject" ) ;
                    var oFile = oFSO.OpenTextFile( strDir + "/" + strScript ) ;
                    PPG.File.Value = oFile.ReadAll() ;
            }
            catch( e )
            {
                    PPG.File.Value = "" ;
                    Application.LogMessage ( "Error reading file " +
                                 strDir + "/" + strScript +
                                 "(" + e.Description + ")" ) ;
            }
    }
    function PopulateCombo()
    {
            strDir = PPG.Dir.Value ;
            strOldValue = PPG.Scripts.Value ;
            // Get access to the PPGLayout object
    var oLayout = PPG.PPGLayout ;
            // The Combo box definition is part of the layout.
            // We look it up based on the script name of the associated
            // parameter
            var oCombo = PPG.PPGLayout.Item( "Scripts" ) ;
            if ( strDir == "" )
            {
                    //Flush any contents
                    oCombo.UIItems = null ;
                    PPG.Scripts.Value = "" ;
            }
            else
            {
                    var oFSO = new ActiveXObject( "Scripting.FileSystemObject" ) ;
                    var oItems = new Array() ;
                    try
                    {
                            bFoundOldValue = false ;
                            var oFolder = oFSO.GetFolder( strDir ) ;
                       fc = new Enumerator(oFolder.files);
                       for (; !fc.atEnd(); fc.moveNext())
                       {
                                    var oFile = fc.item() ;
                                    if ( -1 != oFile.Name.indexOf( ".vbs" ) ||
                                              -1 != oFile.Name.indexOf( ".js" ) ||
                                              -1 != oFile.Name.indexOf( ".pys" ) ||
                                              -1 != oFile.Name.indexOf( ".pls" ) )
                                    {
                                            // Both label and value will be the string name
                                            oItems.push( oFile.Name ) ;
                                            oItems.push( oFile.Name ) ;
                                            if ( strOldValue == oFile.Name )
                                            {
                                                    bFoundOldValue = true ;
                                            }
                                    }
                       }
                            oCombo.UIItems = oItems ;
                            if ( bFoundOldValue )
                            {
                                    // This is the case when you close and reopen the
                                    // property page - we want to restore the original
                                    // setting if possible.
                                    PPG.Scripts.Value = strOldValue ;
                            }
                            else
                            {
                                    // We leave the value empty
                                    // so that the user actually
                                    // picks a script file
                                    // before we load anything
                                    PPG.Scripts.Value = "" ;
                            }
                    }
                    catch( e )
                    {
                            Application.LogMessage( "Error finding script files" +
                               " in specified directory: " + e.Description );
                    }
            }
            // Necessary to make sure the updated Combo is drawn
            PPG.Refresh() ;
    }

### See Also

ProjectItem.PPGLayout InspectObj