// =========================================================================== // 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: Oct 1999 // // // // // // // validateShelfName (string $newName) // // // int : 1 if the name is valid, 0 otherwise // // // This script is called to make verify that a potential name // for a shelf tab is valid. // // // string $newName Potential shelf name to check. // // // validateShelfName "123isNotValid"; // // global proc int validateShelfName (string $newName) { int $isOkay = true; string $regex = "[^0-9a-zA-Z_]"; string $firstCharRegex = "[0-9]"; string $match = match( $regex, $newName ); int $fileExists = false; string $shelfDirs = `internalVar -userShelfDir`; string $shelfArray[]; string $PATH_SEPARATOR = `about -win`? ";" : ":"; tokenize($shelfDirs, $PATH_SEPARATOR, $shelfArray); for( $i = 0; $i < size($shelfArray); $i++ ) { string $fileName = ($shelfArray[$i] + "shelf_" + $newName + ".mel"); if (`file -q -exists $fileName`) { $fileExists = true; break; } } // // test for zero length // string $confirmMsg = (uiRes("m_validateShelfName.kNameNotUnique")); string $title = (uiRes("m_validateShelfName.kAlert")); string $ok = (uiRes("m_validateShelfName.kOk")); if (size($newName) == 0) { confirmDialog -title $title -button $ok -defaultButton $ok -message (uiRes("m_validateShelfName.kNameEmpty")); $isOkay = false; // // test for bad characters // } else if ($match != "") { confirmDialog -title $title -button $ok -defaultButton $ok -message (uiRes("m_validateShelfName.kNameHasIllegalcharacters")); $isOkay = false; // // test for bad first character // } else if ("" != match($firstCharRegex, `substring $newName 1 1`)) { confirmDialog -title $title -button $ok -defaultButton $ok -message (uiRes("m_validateShelfName.kNameCantBeginWithNumerals")); $isOkay = false; // // test for existing saved shelves // } else if ($fileExists) { confirmDialog -title $title -button $ok -defaultButton $ok -message $confirmMsg; $isOkay = false; } else { // // test for existing shelves in optionVars // string $shelfName; $nShelves = `optionVar -q numShelves`; for ($i = 1; $i <= $nShelves; $i++) { $varName = ("shelfName" + $i); $shelfName = `optionVar -q $varName`; if ($shelfName == $newName) { $isOkay = false; break; } } if (!$isOkay) { confirmDialog -title $title -button $ok -defaultButton $ok -message $confirmMsg; } } return $isOkay; }