// =========================================================================== // 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 proc saveCurrentWorkspaceLayoutAs() { global string $gMainWindow; global string $gMainWindowMenu; string $savePath = ""; string $text = localizedFactoryWorkspaceLabel(`workspaceLayoutManager -q -current`) ; string $newWorkspaceName = ""; string $workspace, $workspaceArray[]; string $OK = (uiRes("m_workspaceHelperProcs.kOk")); string $cancel = (uiRes("m_workspaceHelperProcs.kCancel")); string $result = `promptDialog -title (uiRes("m_workspaceHelperProcs.kSaveWorkspace")) -message (uiRes("m_workspaceHelperProcs.kEnterName")) -text $text -button $OK -button $cancel -defaultButton $OK -cancelButton $cancel -dismissString $cancel -parent $gMainWindow`; // // If the result was "OK", then proceed // if ( $result == $OK ) { string $compareStringLeft; string $compareStringRight; $newWorkspaceName = `promptDialog -query`; $newWorkspaceName = substituteAllString($newWorkspaceName, "_", " "); $compareStringLeft = `tolower $newWorkspaceName`; // Check if the name is unique. // $workspaceNameArray = `workspaceLayoutManager -listLayouts`; for ($name in $workspaceNameArray) { string $workspaceName = $name; $compareStringRight = `tolower $workspaceName`; if ($compareStringLeft == $compareStringRight) { // Check if the name is from a factory layout string $layoutType = `workspaceLayoutManager -type $workspaceName`; int $layoutIsUser = ($layoutType == "USER"); if ($layoutIsUser) { // Confirm overwrite string $str = (uiRes("m_workspaceHelperProcs.kOverwriteConfirmDlgMsg")); string $msg = `format -s $workspaceName $str`; string $yes = (uiRes("m_workspaceHelperProcs.kYesSave")); string $no = (uiRes("m_workspaceHelperProcs.kNoSave")); string $overwrite = `confirmDialog -title (uiRes("m_workspaceHelperProcs.kWarning")) -message $msg -button $yes -button $no -defaultButton $yes -cancelButton $no -dismissString $no -parent $gMainWindow`; if ($overwrite == $no) { return; } } else { // Saving as factory layout is not allowed: invalid name. string $str = (uiRes("m_workspaceHelperProcs.kFactoryOverwriteMsg")); string $msg = `format -s $workspaceName $str`; string $factoryOK = (uiRes("m_workspaceHelperProcs.kFactoryOK")); string $overwrite = `confirmDialog -title (uiRes("m_workspaceHelperProcs.kFactoryOverwriteWarning")) -message $msg -button $factoryOK -defaultButton $factoryOK -dismissString $factoryOK -parent $gMainWindow`; return; } } } evalEcho("workspaceLayoutManager -sa " + "\"" + $newWorkspaceName + "\""); buildViewMenu($gMainWindowMenu); } } global proc deleteCurrentWorkspaceLayout() { global string $gMainWindow; global string $gMainWindowMenu; string $workspaceName = `workspaceLayoutManager -q -current`; string $localizedWsName = localizedFactoryWorkspaceLabel($workspaceName) ; string $str = (uiRes("m_workspaceHelperProcs.kDeleteConfirmDlgMsg")); string $msg = `format -s $localizedWsName $str`; string $yes = (uiRes("m_workspaceHelperProcs.kYesDelete")); string $no = (uiRes("m_workspaceHelperProcs.kNoDelete")); string $result = `confirmDialog -title (uiRes("m_workspaceHelperProcs.kDeleteWorkspace")) -message $msg -button $yes -button $no -defaultButton $no -cancelButton $no -dismissString $no -parent $gMainWindow`; // // If the result was "Yes", then proceed // if ( $result == $yes ) { evalEcho("workspaceLayoutManager -delete " + "\"" + $workspaceName + "\""); } } global proc importWorkspaceFiles() { global string $gMainWindow; global string $gMainWindowMenu; int $workspaceListModified = false; string $importTitle = (uiRes("m_workspaceHelperProcs.kImportTitle")); $pathArray = `fileDialog2 -caption $importTitle -okCaption $importTitle -fileMode 4 -fileFilter "*.json"`; $workspaceArray = `workspaceLayoutManager -listLayouts`; for ($path in $pathArray) { int $importConfirmed = true; if (`fileExtension $path` == "json"){ string $fileName = basename($path, ".json" ); $fileName = substituteAllString($fileName, "_", " "); string $fileNameLower = `tolower $fileName`; for ($workspace in $workspaceArray){ string $workspaceName = $workspace; string $workspaceNameLower = `tolower $workspaceName`; if ($fileNameLower == $workspaceNameLower){ //ask for overwrite confirmation string $str = (uiRes("m_workspaceHelperProcs.kImportConfirmDlgMsg")); string $msg = `format -s $workspaceName $str`; string $yes = (uiRes("m_workspaceHelperProcs.kYesImport")); string $no = (uiRes("m_workspaceHelperProcs.kNoImport")); string $overwrite = `confirmDialog -title (uiRes("m_workspaceHelperProcs.kWarningImport")) -message $msg -button $yes -button $no -defaultButton $yes -cancelButton $no -dismissString $no -parent $gMainWindow`; if ($overwrite == $no) { $importConfirmed = false; break; } } } //import layout if ($importConfirmed) { evalEcho("workspaceLayoutManager -import " + "\"" + $path + "\""); $workspaceListModified = true; } } } if ($workspaceListModified) { buildViewMenu($gMainWindowMenu); } } global proc string getWorkspaceLayoutOption(string $checkBoxName, string $optionMenuName) // // Description: // If the checkbox "checkBoxName" is checked, returns the selection of the corresponding option menu, else returns a void string. // { string $varValue = ""; if(`checkBoxGrp -q -v1 $checkBoxName`) $varValue = `optionMenuGrp -q -v $optionMenuName`; return $varValue; } global proc updateVP2Preset(string $vp2PresetValue) { if($vp2PresetValue != "") { if ($vp2PresetValue == "Default Settings") { string $sel[] = `ls -sl`; string $node = "hardwareRenderingGlobals"; string $type = `nodeType $node`; string $default = `createNode $type`; copyNode $default $node; delete $default; select -noExpand $sel; createObjectTypeFilters(0); resetObjFilterToDefault(); optionVar -remove ("mayaHardware2" + "hardwareRenderingGlobals" + "PreferredPreset"); } else { nodePreset -load "hardwareRenderingGlobals" $vp2PresetValue; updateObjTypeFilterToCheckBox(); optionVar -stringValue ("mayaHardware2" + "hardwareRenderingGlobals" + "PreferredPreset") $vp2PresetValue; } } } global proc updateMenuModeAndHotkeyMenus(string $workspaceName) // // Description: // Update the menuMode menu and hotkey Set menu corresponding to workspace options. // { string $menuSetValue = getWorkspaceLayoutOption("workspaceLinkMenuSet", "menuSets"); string $hotkeySetValue = getWorkspaceLayoutOption("workspaceLinkHotKeySet", "hotKeySets"); string $vp2PresetValue = getWorkspaceLayoutOption("workspaceLinkVP2Preset", "vp2Presets"); if($menuSetValue != "") { workingMode(findMenuSetFromLabel($menuSetValue)); optionMenu -e -v $menuSetValue menuMode; } if($hotkeySetValue != "") { // We first have to store the backup option var (backupWorkspaceLinkHotKeySetValue) // if exists because next instruction will erase it. // Note : The backup option var is used to restore the original hotkey set which was the current one just // before because the new linked hotkey set has to be temporary and limited to the current workspace. string $bakHotkeySetValue = `optionVar -exists backupWorkspaceLinkHotKeySetValue` ? `optionVar -q backupWorkspaceLinkHotKeySetValue` :`hotkeySet -q -current`; hotkeySet -e -current $hotkeySetValue; // Restore backup option var optionVar -sv backupWorkspaceLinkHotKeySetValue $bakHotkeySetValue; } if($vp2PresetValue != "") { updateVP2Preset($vp2PresetValue); } } global proc applyWorkspaceChanges() // // Description: // This is a Callback which is called when the user clicks on the "Apply" or "Apply/Switch to" button in the workspace options window. // { string $workspaceName = `workspaceLayoutManager -q -current`; optionVar -iv workspaceLinkMenuSetEnabled `checkBoxGrp -q -v1 workspaceLinkMenuSet`; optionVar -iv workspaceLinkHotKeySetEnabled `checkBoxGrp -q -v1 workspaceLinkHotKeySet`; optionVar -iv workspaceLinkVP2PresetEnabled `checkBoxGrp -q -v1 workspaceLinkVP2Preset`; optionVar -sv workspaceLinkMenuSetValue (findMenuSetFromLabel(`optionMenuGrp -q -v menuSets`)); optionVar -sv workspaceLinkHotKeySetValue `optionMenuGrp -q -v hotKeySets`; optionVar -sv workspaceLinkVP2PresetValue `optionMenuGrp -q -v vp2Presets`; workspaceLayoutManager -saveAs $workspaceName; updateMenuModeAndHotkeyMenus($workspaceName); button -e -enable false (getOptionBoxApplyBtn()); } global proc workspaceLayoutOptions(string $workspaceName, string $menuName) { global string $gOptionBoxEditMenuSaveItem; global string $gOptionBoxEditMenuResetItem; global string $gFactoryWorkspaces[]; string $localizedWsName = localizedFactoryWorkspaceLabel($workspaceName) ; workspaceLayoutManager -setCurrent $workspaceName; string $userLayouts[] = `workspaceLayoutManager -listUserLayouts`; string $layoutList[] = stringArrayCatenate($userLayouts, $gFactoryWorkspaces); int $layoutIndex = stringArrayFind($workspaceName, 0, $layoutList); menuItem -e -radioButton 1 ("WorkspaceMenuID_" + $layoutIndex); string $menuSet, $hotkeySet; string $menuSetNames[], $hotkeySetNames[]; string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; columnLayout; int $linkMenuSetEnabled = `optionVar -q "workspaceLinkMenuSetEnabled"`; checkBoxGrp -label1 (uiRes("m_workspaceHelperProcs.kWorkspaceLinkMenuSet")) -v1 $linkMenuSetEnabled workspaceLinkMenuSet; optionMenuGrp -label (uiRes("m_workspaceHelperProcs.kWorkspaceChooseMenuSet")) -enable $linkMenuSetEnabled menuSets; updateDropDownMenu2("menuSets", true, false); if($linkMenuSetEnabled == true) { string $optionVarValue = `optionVar -q workspaceLinkMenuSetValue`; optionMenuGrp -e -value `menuSet -q -label $optionVarValue` menuSets; } int $linkHotKeySetEnabled = `optionVar -q "workspaceLinkHotKeySetEnabled"`; checkBoxGrp -label1 (uiRes("m_workspaceHelperProcs.kWorkspaceLinkHotkeySet")) -v1 $linkHotKeySetEnabled workspaceLinkHotKeySet; optionMenuGrp -label (uiRes("m_workspaceHelperProcs.kWorkspaceChooseHotkeySet")) -enable `checkBoxGrp -q -value1 workspaceLinkHotKeySet` hotKeySets; $hotkeySetNames = `hotkeySet -q -hotkeySetArray`; for ($hotkeySet in $hotkeySetNames) { menuItem -label $hotkeySet; } if($linkHotKeySetEnabled) optionMenuGrp -e -value `optionVar -q workspaceLinkHotKeySetValue` hotKeySets; int $linkVP2SetEnabled = `optionVar -q "workspaceLinkVP2PresetEnabled"`; checkBoxGrp -label1 (uiRes("m_workspaceHelperProcs.kWorkspaceLinkVPPreset")) -v1 $linkVP2SetEnabled workspaceLinkVP2Preset; optionMenuGrp -label (uiRes("m_workspaceHelperProcs.kWorkspaceChooseVPPreset")) -enable `checkBoxGrp -q -value1 workspaceLinkVP2Preset` vp2Presets; menuItem -label (uiRes("m_workspaceHelperProcs.kDefaultSettings")); string $vp2PresetNames[] = `nodePreset -list "hardwareRenderingGlobals"`; for ($vp2Preset in $vp2PresetNames) { menuItem -label $vp2Preset; } if($linkVP2SetEnabled) { string $preferredPresetName; string $preferredPresetOptVar = ("mayaHardware2" + "hardwareRenderingGlobals" + "PreferredPreset"); if (`optionVar -exists $preferredPresetOptVar`) { $preferredPresetName = `optionVar -query $preferredPresetOptVar`; optionMenuGrp -e -value $preferredPresetName vp2Presets; } else { optionMenuGrp -e -value "Default Settings" vp2Presets; } } separator -useTemplate "NONE"; checkBoxGrp -label1 (uiRes("m_workspaceHelperProcs.kWorkspaceAutoSave")) -value1 `optionVar -q "workspacesAutoSave"` -changeCommand "updateWorkspaceAutoSave(!`optionVar -q \"workspacesAutoSave\"`);button -e -enable true (getOptionBoxApplyBtn());" workspacesAutoSaveCheckBox; setUITemplate -popTemplate; //Buttons string $switchToCommandString = "applyWorkspaceChanges; hideOptionBox;"; string $applyAndCloseBtn = getOptionBoxApplyAndCloseBtn(); button -edit -command $switchToCommandString $applyAndCloseBtn; string $applyBtn = getOptionBoxApplyBtn(); button -edit -enable false -command "applyWorkspaceChanges" $applyBtn; string $checkBoxMenuChangecommand = "optionMenuGrp -e -enable `checkBoxGrp -q -value1 workspaceLinkMenuSet` menuSets;" + "button -e -enable true (getOptionBoxApplyBtn())"; string $checkBoxhotkeyChangecommand = "optionMenuGrp -e -enable `checkBoxGrp -q -value1 workspaceLinkHotKeySet` hotKeySets;" + "button -e -enable true (getOptionBoxApplyBtn())"; string $checkBoxVP2PresetChangecommand = "optionMenuGrp -e -enable `checkBoxGrp -q -value1 workspaceLinkVP2Preset` vp2Presets;" + "button -e -enable true (getOptionBoxApplyBtn())"; checkBoxGrp -e -changeCommand $checkBoxMenuChangecommand workspaceLinkMenuSet; checkBoxGrp -e -changeCommand $checkBoxhotkeyChangecommand workspaceLinkHotKeySet; checkBoxGrp -e -changeCommand $checkBoxVP2PresetChangecommand workspaceLinkVP2Preset; optionMenuGrp -e -changeCommand "button -e -enable true (getOptionBoxApplyBtn())" menuSets; optionMenuGrp -e -changeCommand "button -e -enable true (getOptionBoxApplyBtn())" hotKeySets; optionMenuGrp -e -changeCommand "button -e -enable true (getOptionBoxApplyBtn())" vp2Presets; string $saveBtn = getOptionBoxSaveBtn(); button -edit -enable false $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -edit -enable false $resetBtn; //Menu items menuItem -edit -enable false $gOptionBoxEditMenuSaveItem; menuItem -edit -enable false $gOptionBoxEditMenuResetItem; string $str = (uiRes("m_workspaceHelperProcs.kWorkspaceOptions")); string $title = `format -s $localizedWsName $str`; setOptionBoxTitle( $title ); setOptionBoxHelpTag( "WorkspaceOptions" ); showOptionBox(); } global proc updateWorkspaceDocking(int $lock) { optionVar -iv workspacesLockDocking $lock; if(`symbolCheckBox -exists lockDockingButton`) symbolCheckBox -e -value $lock lockDockingButton; } global proc updateWorkspaceAutoSave(int $save) { optionVar -iv workspacesAutoSave $save; }