// =========================================================================== // 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: Apr 2012 // // Description: Add and delete custom tabs in the preference panel // // // // // // // addCustomPrefsTab (string $tabCreateFn, string $frameCreateFn, string $updateFn, string $holdStateFn, string $setOptVarToDefaultFn, string $title, string $name) // // // This proc registers a user-defined preference tab in the preferences windows of Maya. // // // string $tabCreateFn The callback function to create the tab. // string $frameCreateFn The callback function to create the frame layout of the tab. // string $updateFn The callback function to update UI elements when option vars changed. // string $holdStateFn The callback function to save or restore the preference setting of the tab. // string $setOptVarToDefaultFn The callback function to set option vars to default values. // string $title The title of the tab. // string $name The name of the tab. // // // // // // global proc prefsUpdateExample() // { // global string $gPreferenceWindow; // setParent $gPreferenceWindow; // string $parent = "prefExample"; // // if (`columnLayout -q -numberOfChildren $parent` == 0) { // return; // } // // setParent $parent; // textField -e -text `optionVar -q exampleWords` words; // } // // global proc exampleFieldChanged() // { // global string $gPreferenceWindow; // if (`window -exists $gPreferenceWindow`) { // setParent prefExample; // if (`textField -exists words`) { // optionVar -sv exampleWords `textField -q -text words`; // } // } // } // // global proc prefsHoldCurrentStateExample(string $mode) // { // exampleFieldChanged(); // // if ($mode == "save") { // optionVar -sv "exampleWordsHold" `optionVar -q exampleWords`; // } else if ($mode == "restore") { // optionVar -sv "exampleWords" `optionVar -q exampleWordsHold`; // } else {// "remove" // // Remove the temporary option vars so they don't get saved out // optionVar -remove "exampleWordsHold"; // } // // global string $gPreferenceWindow; // if (`window -exists $gPreferenceWindow`) { // setParent prefExample; // if (`textField -exists words`) { // textField -e -text `optionVar -q exampleWords` words; // } // } // } // // global proc prefsCreateExample() // { // global string $gPreferenceWindow; // setParent $gPreferenceWindow; // string $parent = "prefExample"; // // // Check to see if this has been created already. // // // if (`columnLayout -q -numberOfChildren $parent` > 0) { // return; // } // // Create the UI // // // setParent $parent; // setUITemplate -pushTemplate prefsTemplate; // // // This is used to force the width to fill the window // separator -style "none" -h 1; // // string $textContent = "Hello, world!"; // if (`optionVar -exists exampleWords`) { // $textContent = `optionVar -q exampleWords`; // } // // textField // -text $textContent // -changeCommand exampleFieldChanged // words; // // setUITemplate -popTemplate; // // exampleFieldChanged(); // prefsUpdateExample(); // } // // global proc prefsFrameLayoutCreateExample() // { // frameLayout -labelVisible false -borderVisible false -marginWidth 10 -marginHeight 10; // columnLayout -adj true prefExample; // } // // global proc prefsSetOptVarToDefault() // { // optionVar -sv exampleWords "Hello, world!"; // } // // // register the new tab // addCustomPrefsTab("prefsCreateExample", // "prefsFrameLayoutCreateExample", // "prefsUpdateExample", // "prefsHoldCurrentStateExample", // "prefsSetOptVarToDefault", // "Example Configuration", // " Example"); // // // unregister the tab // deleteCustomPrefsTab("prefsCreateExample"); // // // global string $gPrefsCustomTabCreate[]; global string $gPrefsCustomTabFrameCreate[]; global string $gPrefsCustomTabCtrlUpdate[]; global string $gPrefsCustomTabHoldCurrentState[]; global string $gPrefsCustomTabSetOptVarToDefault[]; global string $gPrefsCustomTabTitles[]; global string $gPrefsCustomTabNames[]; global proc addCustomPrefsTab(string $tabCreateFn, string $frameCreateFn, string $updateFn, string $holdStateFn, string $setOptVarToDefaultFn, string $title, string $name) { global string $gPrefsCustomTabCreate[]; global string $gPrefsCustomTabFrameCreate[]; global string $gPrefsCustomTabCtrlUpdate[]; global string $gPrefsCustomTabHoldCurrentState[]; global string $gPrefsCustomTabSetOptVarToDefault[]; global string $gPrefsCustomTabTitles[]; global string $gPrefsCustomTabNames[]; $gPrefsCustomTabCreate[size($gPrefsCustomTabCreate)] = $tabCreateFn; $gPrefsCustomTabFrameCreate[size($gPrefsCustomTabFrameCreate)] = $frameCreateFn; $gPrefsCustomTabCtrlUpdate[size($gPrefsCustomTabCtrlUpdate)] = $updateFn; $gPrefsCustomTabHoldCurrentState[size($gPrefsCustomTabHoldCurrentState)] = $holdStateFn; $gPrefsCustomTabSetOptVarToDefault[size($gPrefsCustomTabSetOptVarToDefault)] = $setOptVarToDefaultFn; $gPrefsCustomTabTitles[size($gPrefsCustomTabTitles)] = $title; $gPrefsCustomTabNames[size($gPrefsCustomTabNames)] = $name; } global proc deleteCustomPrefsTab(string $createCmd) { global string $gPrefsCustomTabCreate[]; global string $gPrefsCustomTabFrameCreate[]; global string $gPrefsCustomTabCtrlUpdate[]; global string $gPrefsCustomTabHoldCurrentState[]; global string $gPrefsCustomTabSetOptVarToDefault[]; global string $gPrefsCustomTabTitles[]; global string $gPrefsCustomTabNames[]; int $index = stringArrayFind($createCmd, 0, $gPrefsCustomTabCreate); if (-1 != $index) { stringArrayRemoveAtIndex($index, $gPrefsCustomTabCreate); stringArrayRemoveAtIndex($index, $gPrefsCustomTabFrameCreate); stringArrayRemoveAtIndex($index, $gPrefsCustomTabCtrlUpdate); stringArrayRemoveAtIndex($index, $gPrefsCustomTabHoldCurrentState); stringArrayRemoveAtIndex($index, $gPrefsCustomTabSetOptVarToDefault); stringArrayRemoveAtIndex($index, $gPrefsCustomTabTitles); stringArrayRemoveAtIndex($index, $gPrefsCustomTabNames); } }