// =========================================================================== // 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. // =========================================================================== // // // Window to set and see the user preferences. // // To add a new preference see the file "AddingPreferences.md" // // ADSK_CLR_MGT_BEGIN source "colorManagementUtilities.mel"; // ADSK_CLR_MGT_END global proc revertToSavedPrefs () { // Put the option vars back to what they were when // the window was opened. prefsHoldCurrentState("restore"); // Change any internal states to match the option vars syncPreferencesOptVars("syncCurrentToOpt"); // Update the UI in the Preferences window prefsUpdate(); } global proc revertToFactoryPrefs () // // Restore the preferences back to the shipped settings // { source createPreferencesOptVars.mel; // All other optionVars are reverted to their original values in the Mel script above, // however these don't need initializing there so they will be done only here. python( "from maya.app.prefs.OptionVarManager import OptionVarManager" ); python( "OptionVarManager.revert_to_defaults()" ); // Change any internal states to match the option vars syncPreferencesOptVars("syncCurrentToOpt"); // ADSK_CLR_MGT_BEGIN revertToColorManagementDefaults(); // ADSK_CLR_MGT_END // Update the UI in the Preferences window prefsUpdate(); } global proc int canSavePrefsChanges() { int $canSave = 1; // ADSK_CLR_MGT_BEGIN if (colorManagementPolicyLocked() || policyMismatch() == 0) // No mismatch happens. { $canSave = 1; } else { $canSave = colorManagementPolicyMismatchAction(); } if ($canSave == 0) { // There can be any other module need do such "can save" test, // now this module's (color management) $canSave value is 0, there // is no need to do further test, return 0 directly here. // Notice that any other module should return 0 directly if its $canSave // value is 0. return 0; } // ADSK_CLR_MGT_END // Put other modules' test here. // return $canSave; } global proc savePrefsChanges () { if (canSavePrefsChanges() == 0) { return; } global string $gPreferenceWindow; global int $gPrefWndScriptJob; // Cleanup the temp variables before saving prefsHoldCurrentState("remove"); // Save optionVars to disk savePrefs(); // Close the window, unless this is being called // because the window has already closed. // if (`window -exists $gPreferenceWindow`) { // Kill the script job that saves the preferences when // the window closes so we don't get recursive. scriptJob -force -kill $gPrefWndScriptJob; window -e -vis false $gPreferenceWindow; evalDeferred ("deleteUI "+$gPreferenceWindow); } } global proc cancelPrefsChanges () { global string $gPreferenceWindow; global int $gPrefWndScriptJob; // Put the option vars back to what they were when // the window was opened. prefsHoldCurrentState("restore"); // Change any internal states to match the option vars syncPreferencesOptVars("syncCurrentToOpt"); // Cleanup prefsHoldCurrentState("remove"); // Kill the script job that saves the preferences when // the window closes. scriptJob -force -kill $gPrefWndScriptJob; // Close the window evalDeferred ("deleteUI "+$gPreferenceWindow); } proc prefsSetTabLayout(int $index, string $label) { tabLayout -e -selectTabIndex $index prefTabs; frameLayout -e -label $label prefTitleFrame; } //====================================================================== // // The dual structure of the tabLayout and textScrollList, relies on // index values matching in both. Due to the fact that textScrollList children // cannot be made invisible and tabLayout children cannot be inserted at a // specific location the only way to temporarily disable an element is to // remove it from the textScrollList and make it invisible in the tabLayout. // // This makes the index values of the lists out of sync, so this global list // of disabled elements is maintained (by external agents doing the disabling) // to allow the index values to be put back in sync. global int $gDisabledTabs[]; global proc disableTab(int $whichTab) { global int $gDisabledTabs[]; if( 0 == intArrayContains($whichTab, $gDisabledTabs) ) { $gDisabledTabs[size($gDisabledTabs)] = $whichTab; $gDisabledTabs = sort( $gDisabledTabs ); } } global proc enableTab(int $whichTab) { global int $gDisabledTabs[]; int $itemsToRemove[] = { $whichTab }; $gDisabledTabs = intArrayRemove( $itemsToRemove, $gDisabledTabs ); } proc int mapScrollIndexToTabIndex(int $scrollIndex) { global int $gDisabledTabs[]; int $index = $scrollIndex; // Loop through all disabled tabs, incrementing the location if the disabled // one is after the current index. int $i; for( $i=0; $i