// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== global string $gEditorNamespaceTreeViewName; // //Global string for current selected namespaces, //Multinamespaces are seperated by "|" // global string $gCurrentSelectedNamespaces; // //Global flag which decides if update $gCurrentSelectedNamespaces from treeView or not, // global int $gInManuallySelectStatusSetting = 0; global proc beginManuallySetSelect() { global int $gInManuallySelectStatusSetting; $gInManuallySelectStatusSetting = 1; } global proc endManuallySetSelect() { global int $gInManuallySelectStatusSetting; $gInManuallySelectStatusSetting = 0; } global proc int inManuallySelectSetting() { global int $gInManuallySelectStatusSetting; return $gInManuallySelectStatusSetting; } global proc string getCurrentSelectedNamaespaces() { global string $gCurrentSelectedNamespaces; return $gCurrentSelectedNamespaces; } global proc setCurrentSelectedNamespaces(string $toSet) { global string $gCurrentSelectedNamespaces; $gCurrentSelectedNamespaces = $toSet; } global proc string getCurrentSelectedNamespacesFromArray(string $selectedArray[]) { string $retVal ; int $size = size($selectedArray); int $i = 0; while($i < $size) { $retVal = $retVal + "|" + $selectedArray[$i]; $i++; } return $retVal; } global proc selectNamespaceTreeViewItem(string $treeViewControl, string $itemNames[]) // Description: // Selecte tree view item and update $gCurrentSelectedNamespaces // ALWAYS USE THIS PROC TO SELECTED NAMESPACE TREEVIEW IN SCRICPT { int $foundValidNS = 0; if( size($itemNames) > 0 ) { //Set select status, if none is selected, select the root // string $selectingItemNames; int $size = size($itemNames); int $i = 0; while($i < $size) { if(`treeView -q -itemExists $itemNames[$i] $treeViewControl`) { //If the itemNames has valid names, clear select status and $gCurrentSelectedNamespaces if($foundValidNS == 0) { treeView -e -clearSelection $treeViewControl; setCurrentSelectedNamespaces(""); $foundValidNS = 1; beginManuallySetSelect(); } treeView -e -selectItem $itemNames[$i] true $treeViewControl; $selectingItemNames = $selectingItemNames + "|" + $itemNames[$i]; } $i++; } if($foundValidNS) { setCurrentSelectedNamespaces($selectingItemNames); endManuallySetSelect(); } } } // Procedure Name: // updateNamespaceEditor // // Description: // Updates the namespaceEditor when called. When the namespaceEditor is created // it creates a scriptJob that is tied to it that cals this when the selection // changes. This is also called from namespaceEditCmd. // // Input Arguments: // None. // // Return Value: // None. // global proc updateNamespaceEditor( ) { global string $gEditorNamespaceTreeViewName; //fill the treeView according to current namespace info namespaceTreeView_update($gEditorNamespaceTreeViewName, "postUpdateTreeView"); //For bug377815, set root selected if nothing is selected string $selectedNamespace[] = namespaceTreeView_getSelectedItems($gEditorNamespaceTreeViewName); int $sizeOfSelect = size($selectedNamespace); if($sizeOfSelect <=0) { string $selects[]; $selects[0] = ":"; selectNamespaceTreeViewItem($gEditorNamespaceTreeViewName, $selects); } //update enable status of button such as "set current button" treeViewChangeSelectCallback(); } // Procedure Name: // buildNamespaceEditorContextHelpItems // // Description: // Creates the help menu and items for the namespaceEditor. // // Input Arguments: // $nameRoot - name to use as the root of all item names // $menuParent - the name of the parent of this menu // // Return Value: // None // global proc buildNamespaceEditorContextHelpItems(string $nameRoot, string $menuParent) { menuItem -label (uiRes("m_namespaceEditor.kHelpOnNamespaceEditor")) -enableCommandRepeat false -command "showHelp namespaceEditor"; } // Procedure Name: // namespaceEditor // // Description: // Creates the namespaceEditor for editting namespaces. // // Input Arguments: // None. // // Return Value: // None. // global proc namespaceEditor( ) { if( `window -exists namespaceEditor` ) { deleteUI -window namespaceEditor; } // GG: don't hardcode the HEIGHT! It doesn't work X-platform window -title (uiRes("m_namespaceEditor.kNamespaceEditor")) -menuBar true -w 250 -s true namespaceEditor; // Options Menu string $optionsMenu = `menu -label (uiRes("m_namespaceEditor.kOptions")) optionMenu`; menu -e -pmc ("buildNamespaceEditorOptionsMenu "+$optionsMenu) $optionsMenu; addContextHelpProc "namespaceEditor" "buildNamespaceEditorContextHelpItems"; doHelpMenu("namespaceEditor", "namespaceEditor"); formLayout namespaceEditorForm; global string $gEditorNamespaceTreeViewName; $gEditorNamespaceTreeViewName = namespaceTreeView(1, "editorRenameTreeViewItem", "treeViewChangeSelectCallback"); separator scrollButtonsSeparator; int $buttonHeight = 26; int $buttoneWidth = 127; columnLayout namespaceEditorButtonLayout; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorNew")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorNewAnnot")) -enable true -c ("namespaceEditCmd new "+ $gEditorNamespaceTreeViewName) newButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorDelete")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorDeleteAnnot")) -c ("namespaceEditCmd delete " + $gEditorNamespaceTreeViewName) -enable true deleteButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorSelectContents")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorSelectContentsAnnot")) -c ("namespaceEditCmd select " + $gEditorNamespaceTreeViewName) -enable true selectButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorListContents")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorListContentsAnnot")) -c ("namespaceEditCmd list " + $gEditorNamespaceTreeViewName) -enable true listButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorAdd")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorAddAnnot")) -c ("namespaceEditCmd add " + $gEditorNamespaceTreeViewName) -enable true addButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorSelectAllEmpty")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorSelectAllEmptyAnnot")) -c ("namespaceEditCmd selectEmpty " + $gEditorNamespaceTreeViewName) -enable true selectEmptyButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorCollapse")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorCollapseAnnot")) -c ("namespaceEditCmd collapse " + $gEditorNamespaceTreeViewName) -enable true collapseButton; button -h $buttonHeight -w $buttoneWidth -label (uiRes("m_namespaceEditor.kNamespaceEditorSetCurrent")) -annotation (uiRes("m_namespaceEditor.kNamespaceEditorSetCurrentAnnot")) -enable false -c ("setCurrentNamespace " + $gEditorNamespaceTreeViewName) setCurrentNamespaceButton; setParent ..; button -h 26 -w 107 -label (uiRes("m_namespaceEditor.kNamespaceEditorUpdate")) -c "updateNamespaceEditor" updateButton; button -h 26 -w 107 -label (uiRes("m_namespaceEditor.kNamespaceEditorClose")) -c "evalDeferred (\"deleteUI -window namespaceEditor\")" closeButton; setParent ..; formLayout -e -af $gEditorNamespaceTreeViewName top 5 -ac $gEditorNamespaceTreeViewName right 5 namespaceEditorButtonLayout -af $gEditorNamespaceTreeViewName left 5 -ac $gEditorNamespaceTreeViewName bottom 5 scrollButtonsSeparator -af namespaceEditorButtonLayout top 5 -af namespaceEditorButtonLayout right 5 -an namespaceEditorButtonLayout left -an namespaceEditorButtonLayout bottom -af scrollButtonsSeparator left 0 -af scrollButtonsSeparator right 0 -ac scrollButtonsSeparator bottom 5 updateButton -an scrollButtonsSeparator top -af updateButton left 5 -af updateButton bottom 5 -ap updateButton right 3 50 -an updateButton top -ap closeButton left 2 50 -af closeButton bottom 5 -af closeButton right 5 -an closeButton top namespaceEditorForm; // Create script jobs to keep the uv set editor up to date // when the selection changes // scriptJob -parent "namespaceEditor" -event "SelectionChanged" "updateNamespaceEditor" -compressUndo true; scriptJob -parent "namespaceEditor" -event "Undo" "updateNamespaceEditor" -compressUndo true; scriptJob -parent "namespaceEditor" -event "Redo" "updateNamespaceEditor" -compressUndo true; scriptJob -parent "namespaceEditor" -event "SceneOpened" "updateNamespaceEditor" -compressUndo true; showWindow namespaceEditor; updateNamespaceEditor; } global proc setCurrentNamespace(string $control) // Description // Set selected item to be current namespace // Do the "set current" logic in namespaceTreeView_update // for we need update the treeView item's status // { string $selSets[] = `treeView -q -si $control`; string $currentNStoSet = ""; if(size($selSets)) { //If multi selected, use the first one $currentNStoSet = $selSets[0]; } namespace -set $currentNStoSet; namespaceTreeView_update($control, ""); string $selSet[]; $selSet[0] = $currentNStoSet; selectNamespaceTreeViewItem($control, $selSet); } global proc editorRenameTreeViewItem(string $itemName) // // Description: // Called after item label be edited. { string $ok = (uiRes("m_namespaceEditor.kRenameOK")) ; string $cancel = (uiRes("m_namespaceEditor.kRenameCancel")); string $result = `promptDialog -title (uiRes("m_namespaceEditor.kRenameTitle")) -message (uiRes("m_namespaceEditor.kRenameImplication")) -button $ok -button $cancel -text $itemName -defaultButton $ok -cancelButton $cancel -dismissString $cancel`; // If the result was "OK", then proceed // if ( $result == $ok ) { global string $gEditorNamespaceTreeViewName; string $shortName = `promptDialog -query -text`; string $ret = namespaceTreeView_rename( $itemName, $shortName, $gEditorNamespaceTreeViewName, "updateNamespaceEditor"); } } global proc setRelativeNamespaceFromUI(string $checkBoxMenuItem) // // Description: // Set relative namespace from editor's setRelativeNamespace Check box . // Params: // $checkBoxMenuItem the control name, // { if( `window -exists namespaceEditor`) { int $editorValue = `menuItem -q -checkBox $checkBoxMenuItem`; namespace -relativeNames $editorValue; } } global proc treeViewChangeSelectCallback() // // Description // callback called when the selection changes on the treeView, // used to enable/disable affected controls { global string $gEditorNamespaceTreeViewName; if( `treeView -exists $gEditorNamespaceTreeViewName`) { //Enable or disable buttons depending on current selection in tree view string $selSets[] = namespaceTreeView_getSelectedItems($gEditorNamespaceTreeViewName); int $count = size($selSets); if(size($selSets)>0) { //button "Set Current" //For bug376504 int $singleSelected = ($count == 1); if($singleSelected) { button -e -enable true setCurrentNamespaceButton; } else { button -e -enable false setCurrentNamespaceButton; } //Button "Delete&Collapse to Child" int $rootIncluded = stringArrayContains(":", $selSets); if($rootIncluded) { button -e -enable false deleteButton; } else { button -e -enable true deleteButton; } //Button "Collapse to Child" if($rootIncluded || !$singleSelected) { button -e -enable false collapseButton; } else { button -e -enable true collapseButton; } //Button "Add Selected" string $selects[] = `ls -selection`; if(size($selects)) { button -e -enable $singleSelected addButton; } else { button -e -enable false addButton; } //Button "Select Contents" button -e -enable $singleSelected selectButton; //Button "List Contents" button -e -enable $singleSelected listButton; //Set selected status if the treeView selecting is not from UI // if(!inManuallySelectSetting()) { setCurrentSelectedNamespaces(getCurrentSelectedNamespacesFromArray($selSets)); } } else { button -e -enable false setCurrentNamespaceButton; button -e -enable false collapseButton; button -e -enable false deleteButton; button -e -enable false addButton; button -e -enable false selectButton; button -e -enable false listButton; } } } global proc postUpdateTreeView(string $control) // Description: // The callback function which be called after the treeView is updated (namespaceTreeView_update). { //Set treeView selected status according to $gCurrentSelectedNamespaces // string $selectedNamespaces = getCurrentSelectedNamaespaces(); string $selSets[] = stringToStringArray($selectedNamespaces, "|"); selectNamespaceTreeViewItem($control, $selSets); } // Description: // Build the option menu in namespace editor global proc buildNamespaceEditorOptionsMenu( string $menu ) { setParent -m $menu; if( `menu -query -numberOfItems $menu` > 0){ menu -edit -deleteAllItems $menu; } int $isRelative = `namespace -q -relativeNames`; string $checkBox = `menuItem -label (uiRes("m_namespaceEditor.kNamespaceEditorRelativeNS")) -ann (uiRes("m_namespaceEditor.kNamespaceEditorRelativeNSAnnot")) -cb $isRelative -to false checkBoxRelativeNamespace`; menuItem -e -c ("setRelativeNamespaceFromUI " + $checkBox) $checkBox; }