// =========================================================================== // 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. // =========================================================================== // // // Creation Date: 1995 // // Description: // This implements the group of controls that represents the // shelf. The shelf can either be part of a window // or in a window of its own. // // Input Arguments: // The name of the layout that the shelf should add itself // to. If empty, then this script will create a window. // // Return Value: // The name of the top level layout control. // (Used for embedding within another window) // global proc buildShelfMenu( string $parent ) // // Create the popup menu that allows users to switch between // shelf tabs. This is created each time it is selected to // keep it in sync. // { global string $gShelfTopLevel; global string $gShelfCollection = ""; setParent -m $parent; menu -e -dai $parent; $gShelfCollection = `radioMenuItemCollection`; // Shelf tab listing string $curShelf = `tabLayout -q -selectTab $gShelfTopLevel`; string $shelfArray[] = `shelfTabLayout -q -childArray $gShelfTopLevel`; int $numShelves = size($shelfArray); if(!`exists shelfLabel_melToUI` ){ source "shelfLabel.mel"; } for ($i=0; $i<$numShelves; ++$i) { string $cmd = "shelfTabLayout -edit -selectTabIndex "+($i+1)+" "+$gShelfTopLevel+"; " +"shelfTabChange();"; int $enabled = ($shelfArray[$i] == $curShelf); menuItem -ecr false -radioButton $enabled -cl $gShelfCollection -label `shelfLabel_melToUI( $shelfArray[$i] )` -c $cmd; } } global proc loadShelf(int $index) { // Check if the shelf buttons have been created for the new tab. // If no shelf buttons have been created for the new tab, create them. string $varName = "shelfName" + $index; string $shelfName = `optionVar -q $varName`; if ( `shelfLayout -exists $shelfName` && `shelfLayout -query -numberOfChildren $shelfName` == 0 ) { string $shelfFileNum = "shelfFile" + $index; string $shelfFile = `optionVar -q $shelfFileNum`; if ($shelfFile != 0) { int $isFile = `exists $shelfFile`; if ($isFile != 0) { // If we use evalContinue then we aren't notified if there are any errors // evalContinue $shelfFile; setParent $shelfName; string $shelfVersion = ""; if (catch($shelfVersion = eval($shelfFile))) { string $returnStr; string $msg = (uiRes("m_shelf.kShelfItemsCantBeRead")); string $shelfLabel = `shelfLabel_melToUI $shelfName`; $msg = `format -s $shelfLabel $msg`; warning -noContext $msg; } // Now that shelf has been loaded adjust optionVar accordingly optionVar -intValue ("shelfLoad"+$index) true; // Store the version where the shelf was introduced as well. if( $shelfVersion != "" ) { optionVar -stringValue ("shelfVersion"+$index) $shelfVersion; // If the shelf already exists add the version information if(`shelfLayout -exists $shelfName`) { shelfLayout -edit -version $shelfVersion $shelfName; } } } } } } global proc shelfTabRefresh() // // Description: // This procedure is called when we want to refresh the current // active shelf tab button. Mac only // { global string $gShelfTopLevel; if( `about -macOS`) { int $activeShelfTab = `shelfTabLayout -query -selectTabIndex $gShelfTopLevel`; tabLayout -edit -selectTabIndex $activeShelfTab $gShelfTopLevel; } // Refresh shelf button size/positon considering DPI scaling setShelfStyle `optionVar -query shelfItemStyle` `optionVar -query shelfItemSize`; } global proc shelfTabChange() // // Description: // This procedure is called whenever the user selects a new // active shelf tab. // // Update the active shelf preference. // { global string $gShelfTopLevel; setParent $gShelfTopLevel; int $activeShelfTab; $activeShelfTab = `shelfTabLayout -query -selectTabIndex $gShelfTopLevel`; optionVar -intValue "selectedShelf" $activeShelfTab; loadShelf($activeShelfTab); tabLayout -edit -selectTabIndex $activeShelfTab $gShelfTopLevel; setShelfStyle `optionVar -query shelfItemStyle` `optionVar -query shelfItemSize`; } global proc toggleShelfTabs() { global string $gShelfTopLevel; // Set optionVar to the opposite of the current state int $newState = !`optionVar -q shelfTabsVisible`; optionVar -intValue "shelfTabsVisible" $newState; shelfTabLayout -e -tv $newState $gShelfTopLevel; setShelfStyle `optionVar -query shelfItemStyle` `optionVar -query shelfItemSize`; refresh; string $shelfWorkspaceControl = getUIComponentToolBar("Shelf", false); evalDeferred("updateShelfInitialSize(\"" + $shelfWorkspaceControl + "\" )" ); } global proc buildShelves() { global string $gShelfTopLevel; setParent $gShelfTopLevel; // Define a template for shelf layouts. // if (!`uiTemplate -exists shelfLayoutTemplate`) { uiTemplate shelfLayoutTemplate; shelfLayout -dt shelfLayoutTemplate -h 36 -cwh 36 36; } // Activate the shelf layout template. // setUITemplate -pushTemplate shelfLayoutTemplate; string $varName, $cmd, $shelfName, $shelfVersion; int $i, $nShelves; if(!`exists shelfLabel_melToUI` ){ source "shelfLabel.mel"; } $nShelves = `optionVar -q numShelves`; for ($i = 1; $i <= $nShelves; $i++) { $varName = ("shelfName" + $i); $shelfName = `optionVar -q $varName`; $varName = ("shelfVersion" + $i); $shelfVersion = `optionVar -q $varName`; if(`shelfLayout -exists $shelfName`) { string $warningMsg = (uiRes("m_shelf.kShelfExists")); string $shelfLabel = `shelfLabel_melToUI $shelfName`; warning(`format -s $shelfLabel $warningMsg`); continue; } $cmd = ("shelfLayout " + $shelfName); eval( $cmd ); // If the shelf version was specified then set it if( $shelfVersion != "0" ) { shelfLayout -edit -version $shelfVersion $shelfName; } string $align = "left"; if ( `optionVar -ex ("shelfAlign" + $i)` ) $align = `optionVar -q ("shelfAlign" + $i)`; shelfLayout -e -aln $align $shelfName; //Editing the shelf labels // shelfTabLayout -edit -tabLabel $shelfName (shelfLabel_melToUI($shelfName)) $gShelfTopLevel; setParent ..; } // Deactivate the shelf layout template. // setUITemplate -popTemplate; // Define the default active shelf to 'Polygons' if a preference does not // exist yet. // if (!`optionVar -exists "selectedShelf"`) { optionVar -intValue "selectedShelf" -1; for ($i = 1; $i <= $nShelves; $i++) { $varName = ("shelfName" + $i); $shelfName = `optionVar -q $varName`; if ($shelfName == "Polygons") { optionVar -intValue "selectedShelf" $i; break; } } } // Get the selected tab preference and make that shelf tab active. // int $activeTab = `optionVar -query "selectedShelf"`; // Make sure the tab preference is valid given the number of // tabs in the shelf, ie. it should be a number ranging from // 1 to the number of tabs in the shelf. // if ($activeTab < 1 || $activeTab > `tabLayout -query -numberOfChildren $gShelfTopLevel`) { // // The active tab preference is not valid given the number // of tabs in the Shelf. // // Reset the preference to the first shelf tab. // $activeTab = 1; optionVar -intValue "selectedShelf" $activeTab; } tabLayout -edit -selectTabIndex $activeTab $gShelfTopLevel; loadShelf($activeTab); // Set the display style for the buttons on the Shelf. // setShelfStyle `optionVar -query shelfItemStyle` `optionVar -query shelfItemSize`; } global proc updateShelfLayoutDirection(int $shelfIsHorz) { global string $gShelfForm; global string $gShelfLayout; global string $gShelfTopLevel; global string $gShelfOptionsLayout; global string $gShelfShelvesButton; global string $gShelfOptionsButton; global string $gShelfOptions; global int $gPanelHandleOffset; // For improving the alignment of shelves buttons. // if ($shelfIsHorz) { formLayout -edit -attachPosition $gShelfShelvesButton "top" 0 12 -attachForm $gShelfShelvesButton "left" 0 -attachNone $gShelfShelvesButton "bottom" -attachForm $gShelfShelvesButton "right" 0 -attachNone $gShelfOptionsButton "top" -attachForm $gShelfOptionsButton "left" 0 -attachPosition $gShelfOptionsButton "bottom" 0 88 -attachForm $gShelfOptionsButton "right" 0 $gShelfOptionsLayout; } else { formLayout -edit -attachForm $gShelfShelvesButton "top" 0 -attachPosition $gShelfShelvesButton "left" 0 12 -attachForm $gShelfShelvesButton "bottom" 0 -attachNone $gShelfShelvesButton "right" -attachForm $gShelfOptionsButton "top" 0 -attachNone $gShelfOptionsButton "left" -attachForm $gShelfOptionsButton "bottom" 0 -attachPosition $gShelfOptionsButton "right" 0 88 $gShelfOptionsLayout; } // Layout Shelf. // if ($shelfIsHorz) { formLayout -edit -attachForm $gShelfOptions "top" 0 -attachForm $gShelfOptions "left" 2 -attachForm $gShelfOptions "bottom" 1 -attachNone $gShelfOptions "right" -attachForm $gShelfTopLevel "top" 0 -attachControl $gShelfTopLevel "left" 2 $gShelfOptions -attachForm $gShelfTopLevel "bottom" 0 -attachForm $gShelfTopLevel "right" 0 $gShelfLayout; } else { formLayout -edit -attachForm $gShelfOptions "top" 2 -attachForm $gShelfOptions "left" 0 -attachNone $gShelfOptions "bottom" -attachForm $gShelfOptions "right" 1 -attachControl $gShelfTopLevel "top" 2 $gShelfOptions -attachForm $gShelfTopLevel "left" 0 -attachForm $gShelfTopLevel "bottom" 0 -attachForm $gShelfTopLevel "right" 0 $gShelfLayout; } // Attach Shelf to parent. // if ($shelfIsHorz) { formLayout -edit -attachForm $gShelfLayout "top" 0 -attachForm $gShelfLayout "left" $gPanelHandleOffset -attachForm $gShelfLayout "bottom" 0 -attachForm $gShelfLayout "right" 0 $gShelfForm; } else { formLayout -edit -attachForm $gShelfLayout "top" $gPanelHandleOffset -attachForm $gShelfLayout "left" 0 -attachForm $gShelfLayout "bottom" 0 -attachForm $gShelfLayout "right" 0 $gShelfForm; } // Set the Shelf tab position. // if ($shelfIsHorz) { shelfTabLayout -e -tabPosition "north" ShelfLayout; } else { shelfTabLayout -e -tabPosition "east" ShelfLayout; } // Set the orientation of the shelf control. // string $shelfWorkspaceControl = getUIComponentToolBar("Shelf", false); workspaceControl -e -horizontal $shelfIsHorz $shelfWorkspaceControl; // Set the Shelf button alignment and horz/vert layout. // string $shelfTabs[] = `shelfTabLayout -q -ca ShelfLayout`; string $shelf; string $align = "left"; if (!$shelfIsHorz) $align = "top"; for ($shelf in $shelfTabs) { shelfLayout -e -alignment $align -horizontal $shelfIsHorz $shelf; } } ////////////////////////////////////////////////////////////////////////// // // This is the main code executed when this file is source'd. // ////////////////////////////////////////////////////////////////////////// { global string $gShelfForm; global string $gShelfLayout; global string $gShelfTopLevel; global string $gShelfOptionsLayout; global string $gShelfShelvesButton; global string $gShelfOptionsButton; global string $gShelfOptions; // Create a layout appropriate for the Shelf. // $gShelfLayout = `formLayout -parent $gShelfForm`; ////////////////////////////////////////////////////////////////////// // // Create the Menu and Options area. // ////////////////////////////////////////////////////////////////////// setParent $gShelfLayout; $gShelfOptions = `frameLayout -parent $gShelfLayout -borderVisible false -labelVisible false -collapse false -collapsable false`; $gShelfOptionsLayout = `formLayout // Color - #363636 -backgroundColor 0.21176 0.21176 0.21176`; $gShelfShelvesButton = `iconTextButton -image1 "shelfTab.png" -annotation (uiRes("m_shelf.kChangeShelfTab")) -height 15 -width 20`; $gShelfOptionsButton = `iconTextButton -image1 "shelfOptions.png" -annotation (uiRes("m_shelf.kModifyShelf")) -height 16 -width 20`; setParent ..; // Get the tab visible state. // if (!`optionVar -exists "shelfTabsVisible"`) { optionVar -intValue "shelfTabsVisible" true; } int $tabVis = `optionVar -q shelfTabsVisible`; // Create the tab-switching menu // string $menu = `popupMenu -button 1 -parent $gShelfShelvesButton`; menu -edit -postMenuCommand ( "buildShelfMenu " + $menu ) $menu; // Create the options menu // $menu = `popupMenu -button 1 -parent $gShelfOptionsButton`; menuItem -ecr false -cb $tabVis -c "toggleShelfTabs" -label (uiRes("m_shelf.kShelfTabs")); menuItem -d true; menuItem -ecr false -label (uiRes("m_shelf.kShelfEditor")) -c "ShelfPreferencesWindow"; menuItem -d true; menuItem -subMenu true -label (uiRes("m_shelf.kNavigateShelfMenu")) -tearOff true; menuItem -ecr true -label (uiRes("m_shelf.kPrevShelf")) -c "incrementSelectedShelf(-1)" -echoCommand true; menuItem -ecr true -label (uiRes("m_shelf.kNextShelf")) -c "incrementSelectedShelf(1)" -echoCommand true; menuItem -divider true; menuItem -ecr true -label (uiRes("m_shelf.kJumpToShelf")) -c "jumpToNamedShelf(\"\")" -echoCommand true; setParent -menu ..; menuItem -d true; menuItem -ecr false -label (uiRes("m_shelf.kNewShelf")) -c "createNewShelf"; string $cmd = "deleteShelfTab(`tabLayout -q -selectTab $gShelfTopLevel`);"; menuItem -ecr false -label (uiRes("m_shelf.kDeleteShelf")) -c $cmd; menuItem -d true; menuItem -ecr false -label (uiRes("m_shelf.kLoadShelf")) -c "loadNewShelf \"\""; menuItem -d true; menuItem -ecr false -label (uiRes("m_shelf.kSaveShelf")) -c "saveAllShelves $gShelfTopLevel"; ////////////////////////////////////////////////////////////////////// // // Create the Shelf. // ////////////////////////////////////////////////////////////////////// $gShelfTopLevel = `shelfTabLayout -parent $gShelfLayout -tabsVisible $tabVis -borderStyle "none" -changeCommand ("shelfTabChange") ShelfLayout`; // By default the Shelf is horizontal. updateShelfLayoutDirection(true); } global proc loadNamedShelf(string $shelfName) { global string $gShelfTopLevel; string $shelfArray[] = `shelfTabLayout -q -childArray $gShelfTopLevel`; int $numShelves = size($shelfArray); for ($i=0; $i<$numShelves; ++$i) { if( $shelfArray[$i] == $shelfName ){ loadShelf( ($i+1) ); break; } } } global proc jumpToNamedShelf(string $name) // // Description: // Change the selected shelf to the one specified by name. // Error if unable to find that shelf name. // // Parameters: // $name string name of shelf. If "", then display a dialog to choose // // Examples: // jumpToShelf("Polygons"); // jumpToShelf("Animation"); // { global string $gShelfTopLevel; // Display dialog to choose name if "" if ($name == "") { string $ok = (uiRes("m_shelf.kOK")); string $cancel = (uiRes("m_shelf.kCancel")); string $result = `promptDialog -title (uiRes("m_shelf.kJumpToShelfTitle")) -message (uiRes("m_shelf.kShelfNameMsg")) -button $ok -button $cancel -defaultButton $ok -cancelButton $cancel -dismissString $cancel`; if ($result == $ok) { $name = `promptDialog -query -text`; } else { return; // Do nothing since "Cancel" was pressed } } // Find the shelf index matching the specified shelf name string $tabLabels[] = `shelfTabLayout -q -tabLabel $gShelfTopLevel`; int $i; int $tabIndex = -1; for ($i=0; $i < size($tabLabels); $i++) { if ($tabLabels[$i] == $name) { $tabIndex = $i +1; // Note: index for -selectTabIndex is +1 of the string array index break; } } // Change to shelf if found a match if ($tabIndex != -1) { shelfTabLayout -e -selectTabIndex $tabIndex $gShelfTopLevel; shelfTabChange(); } else { error (((uiRes("m_shelf.kCannotFindShelf"))+$name)); } } global proc incrementSelectedShelf(int $increment) // // Description: // Increment or decrement the selected shelf index by the specified value. // A negative number decrements the index while a positive number increments it. // The resulting index is automatically capped by the first and last shelf indices. // Examples: // incrementShelfIndex(1); // select the next shelf // incrementShelfIndex(-1); // select the previous shelf // incrementShelfIndex(2); // select the 2nd shelf past the current selection // incrementShelfIndex(100); // go to the last shelf // incrementShelfIndex(-100); // go to the first shelf { global string $gShelfTopLevel; int $numberOfShelves = `shelfTabLayout -q -numberOfChildren $gShelfTopLevel`; int $tabIndex = `shelfTabLayout -q -selectTabIndex $gShelfTopLevel`; $tabIndex += $increment; if ($tabIndex < 1) { $tabIndex = 1; } if ($tabIndex > $numberOfShelves) { $tabIndex = $numberOfShelves; } shelfTabLayout -e -selectTabIndex $tabIndex $gShelfTopLevel; shelfTabChange(); } global proc addShelfSeparator() { // The actual shelf separator will be drawn as 2px (any scaling factor) wide line. // It will have 5px (at 100%) padding on each side. // Shelf icons are normally 32x32 (at 100%). separator -width 12 -height 35 -style "shelf" -hr false; }