// =========================================================================== // 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. // =========================================================================== proc scriptEditorPredefines() // // Predefinitions such as: // Tagging for labels which are used multiple times. We can call uiRes() for the specified // labels later in the file. // { global string $gScriptEditorMenuBarPrefix = "scriptEditor"; // Options Menu Item suffixes global string $gShowLineNumbersMenuItemSuffix = "ShowLineNumbersMenuItem"; global string $gUseTabsForIndentMenuItemSuffix = "UseTabsForIndentMenuItem"; global string $gAutoCloseBracesMenuItemSuffix = "AutoCloseBracesMenuItem"; global string $gCommandCompletionMenuItemSuffix = "CommandCompletionMenuItem"; global string $gPathCompletionMenuItemSuffix = "PathCompletionMenuItem"; global string $gToolTipHelpMenuItemSuffix = "ToolTipHelpMenuItem"; global string $gShowQuickHelpMenuItemSuffix = "QuickHelpMenuItem"; global string $gBatchRenderMsgsMenuItemSuffix = "BatchRenderMessagesMenuItem"; global string $gEchoAllCmdsMenuItemSuffix = "EchoAllCmdsMenuItem"; global string $gErrorLineNumsMenuItemSuffix = "ErrorLineNumberMenuItem"; global string $gStackTraceMenuItemSuffix = "StackTraceMenuItem"; global string $gSuppressResultsMenuItemSuffix = "SuppressResultsMenuItem"; global string $gSuppressInfoMenuItemSuffix = "SuppressInfoMenuItem"; global string $gSuppressWarningsMenuItemSuffix = "SuppressWarningsMenuItem"; global string $gSuppressErrorsMenuItemSuffix = "SuppressErrorsMenuItem"; global string $gSuppressDupVarMessagesMenuItemSuffix = "SuppressDupVarMessagesMenuItem"; global string $gSuppressStackTraceMenuItemSuffix = "SuppressStackTraceMenuItem"; global string $gHistoryFilterNoneMenuItemSuffix = "FilterNoneMenuItem"; global string $gHistoryFilterMELMenuItemSuffix = "FilterMELMenuItem"; global string $gHistoryFilterPythonMenuItemSuffix = "FilterPythonMenuItem"; global string $gExecuterBackupFileName = "commandExecuter"; global string $gLastUsedDir; // Tagging string $cancel = (uiRes("m_scriptEditorPanel.kCancel")); // * menus string $file = (uiRes("m_scriptEditorPanel.kFile")); string $edit = (uiRes("m_scriptEditorPanel.kEdit")); string $history = (uiRes("m_scriptEditorPanel.kHistory")); string $command = (uiRes("m_scriptEditorPanel.kCommand")); string $help = (uiRes("m_scriptEditorPanel.kHelp")); // file string $load = (uiRes("m_scriptEditorPanel.kLoadScript")); string $source = (uiRes("m_scriptEditorPanel.kSourceScript")); string $save = (uiRes("m_scriptEditorPanel.kSaveScript")); string $saveToShelf = (uiRes("m_scriptEditorPanel.kSaveScriptToShelf")); // edit string $undo = (uiRes("m_scriptEditorPanel.kUndo")); string $redo = (uiRes("m_scriptEditorPanel.kRedo")); string $cut = (uiRes("m_scriptEditorPanel.kCut")); string $copy = (uiRes("m_scriptEditorPanel.kCopy")); string $paste = (uiRes("m_scriptEditorPanel.kPaste")); string $selectAll = (uiRes("m_scriptEditorPanel.kSelectAll")); string $clearHistory = (uiRes("m_scriptEditorPanel.kClearHistory")); string $clearInput = (uiRes("m_scriptEditorPanel.kClearInput")); string $clearAll = (uiRes("m_scriptEditorPanel.kClearAll")); string $goto = (uiRes("m_scriptEditorPanel.kGoto")); string $indentSel = (uiRes("m_scriptEditorPanel.kIndentSelection")); string $unindentSel = (uiRes("m_scriptEditorPanel.kUnindentSelection")); // show string $showHistory = (uiRes("m_scriptEditorPanel.kShowHistory")); string $showInput = (uiRes("m_scriptEditorPanel.kShowInput")); string $showBoth = (uiRes("m_scriptEditorPanel.kShowBoth")); string $searchAndReplace = (uiRes("m_scriptEditorPanel.kSearchAndReplace")); // history string $batchRenderMessages = (uiRes("m_scriptEditorPanel.kBatchRenderMessages")); string $echoAllCommands = (uiRes("m_scriptEditorPanel.kEchoAllCommands")); string $showErrorLineNumbers = (uiRes("m_scriptEditorPanel.kLineNumbersInErrors")); string $showStackTrace = (uiRes("m_scriptEditorPanel.kShowStackTrace")); string $suppressCommandResults = (uiRes("m_scriptEditorPanel.kSuppressCommandResults")); string $suppressInfoMessages = (uiRes("m_scriptEditorPanel.kSuppressInfoMessages")); string $suppressWarningMessages = (uiRes("m_scriptEditorPanel.kSuppressWarningMessages")); string $suppressErrorMessages = (uiRes("m_scriptEditorPanel.kSuppressErrorMessages")); string $suppressDupVarMessages = (uiRes("m_scriptEditorPanel.kSuppressDupVarMessages")); string $suppressStackWindow = (uiRes("m_scriptEditorPanel.kSuppressStackWindow")); string $filterOutput = (uiRes("m_scriptEditorPanel.kFilterOutput")); // command string $showLineNumbers = (uiRes("m_scriptEditorPanel.kShowLineNumbers")); string $useTabsForIndent = (uiRes("m_scriptEditorPanel.kUseTabsForIndent")); string $autoCloseBraces = (uiRes("m_scriptEditorPanel.kAutoCloseBraces")); string $showQuickHelp = (uiRes("m_scriptEditorPanel.kShowQuickHelp")); string $commandCompletion = (uiRes("m_scriptEditorPanel.kCommandCompletion")); string $pathCompletion = (uiRes("m_scriptEditorPanel.kPathCompletion")); string $toolTipHelp = (uiRes("m_scriptEditorPanel.kToolTipHelp")); string $showCommandHelp = (uiRes("m_scriptEditorPanel.kShowCommandHelp")); string $execute = (uiRes("m_scriptEditorPanel.kExecute")); string $executeAll = (uiRes("m_scriptEditorPanel.kExecuteAll")); // tabs string $tabName = (uiRes("m_scriptEditorPanel.kTabName")); string $tabNameWarning = (uiRes("m_scriptEditorPanel.kInvalidTabNameWarning")); string $addTab = (uiRes("m_scriptEditorPanel.kAddTab")); string $rename = (uiRes("m_scriptEditorPanel.kRename")); // string $searchError = (uiRes("m_scriptEditorPanel.kSearchFailed")); } global proc buildScriptEditorContextHelpItems(string $nameRoot, string $menuParent) // // Description: // Build context sensitive menu items for the script editor. // // Input Arguments: // $nameRoot - name to use as the root of all item names // $menuParent - the name of the parent of this menu // // Return Value: // None // { menuItem -label (uiRes("m_scriptEditorPanel.kHelpOnMEL")) -annotation (uiRes("m_scriptEditorPanel.kHelpOnMELAnn")) -enableCommandRepeat false -command "showHelp MEL"; if (`exists python`) { menuItem -label (uiRes("m_scriptEditorPanel.kHelpOnPython")) -annotation (uiRes("m_scriptEditorPanel.kHelpOnPythonAnn")) -enableCommandRepeat false -command "showHelp Python"; } menuItem -label (uiRes("m_scriptEditorPanel.kHelpOnSelCmd")) -annotation (uiRes("m_scriptEditorPanel.kHelpOnSelCmdAnn")) -enableCommandRepeat false -command "handleScriptEditorAction showSelectedCmdHelp"; menuItem -label (uiRes("m_scriptEditorPanel.kHelpOnScriptEditor")) -annotation (uiRes("m_scriptEditorPanel.kHelpOnScriptEditorAnn")) -enableCommandRepeat false -command "showHelp ScriptEditor"; } global proc handleScriptEditorAction(string $action) // // Delegation function for possible actions on the script editor. // { global string $gCommandLayout; global string $gCommandExecuterTabsPane; global string $gCommandReporter; global string $gLastFocusedCommandExecuter; // global string $gBatchRenderMsgsMenuItemSuffix; global string $gEchoAllCmdsMenuItemSuffix; global string $gErrorLineNumsMenuItemSuffix; global string $gStackTraceMenuItemSuffix; global string $gSuppressResultsMenuItemSuffix; global string $gSuppressInfoMenuItemSuffix; global string $gSuppressWarningsMenuItemSuffix; global string $gSuppressErrorsMenuItemSuffix; global string $gSuppressDupVarMessagesMenuItemSuffix; global string $gSuppressStackTraceMenuItemSuffix; // switch ($action) { // file menu actions case "load": { loadFileInNewTab(); } break; case "source": delegateCommandToFocusedExecuterWindow "-e -source" 0; break; case "save": { // If the executer tab contains a previously loaded file, then just save it. string $filename = getCurrentExecuterFilename(); if (size($filename) > 0) { delegateCommandToFocusedExecuterWindow("-e -saveFile \"" + $filename + "\"", 0); } else { // find the current tab label and use that as the default file name // append the file extension to the name so that the save dialog knows the correct file type string $tabName = `getCurrentExecuterTabLabel`; string $fileExt = `getCurrentExecuterTabType`; string $tabExt = `fileExtension($tabName)`; if (size($tabExt) > 0) { delegateCommandToFocusedWindow ("-e -saveSelection \"" + $tabName + "\""); } else { delegateCommandToFocusedWindow ("-e -saveSelection \"" + $tabName + $fileExt + "\""); } // Get the filename (if we saved entire contents) and rename the tab. string $filename = getCurrentExecuterFilename(); if (size($filename) > 0) { renameCurrentExecuterTab($filename, 0); // Also connect this executer to the modificationChanged & fileChanged commands. delegateCommandToFocusedExecuterWindow "-e -modificationChangedCommand executerTabModificationChanged" 0; delegateCommandToFocusedExecuterWindow "-e -fileChangedCommand executerTabFileChanged" 0; syncScriptEditorPanelToolbarAndMenu(); } } } break; case "saveToShelf": delegateCommandToFocusedWindow "-e -saveSelectionToShelf"; break; // edit menu actions case "undo": delegateCommandToFocusedExecuterWindow "-e -undo" 0; break; case "redo": delegateCommandToFocusedExecuterWindow "-e -redo" 0; break; case "cut": delegateCommandToFocusedWindow "-e -cutSelection"; break; case "copy": delegateCommandToFocusedWindow "-e -copySelection"; break; case "paste": delegateCommandToFocusedExecuterWindow "-e -pasteSelection" 0; break; case "selectAll": delegateCommandToFocusedWindow "-e -selectAll"; break; case "clearHistory": if ($gCommandReporter != "") { evalDeferred("cmdScrollFieldReporter -e -clear $gCommandReporter"); } break; case "clearInput": delegateCommandToFocusedExecuterWindow "-e -clear" 0; break; case "clearAll": // can't seem to recursively call this handler function, so manually clear both input and history if ($gCommandReporter != "") { evalDeferred("cmdScrollFieldReporter -e -clear $gCommandReporter"); } delegateCommandToFocusedExecuterWindow "-e -clear" 0; break; case "searchAndReplace": createSearchAndReplaceWindow; break; case "gotoLine": gotoLinePrompt; break; case "indentSelection": delegateCommandToFocusedExecuterWindow "-e -indentSelection" 0; break; case "unindentSelection": delegateCommandToFocusedExecuterWindow "-e -unindentSelection" 0; break; // show actions case "maximizeInput": paneLayout -e -setPane $gCommandExecuterTabsPane 1 $gCommandLayout; paneLayout -e -configuration "single" $gCommandLayout; selectCurrentExecuterControl; break; case "maximizeHistory": paneLayout -e -setPane $gCommandReporter 1 $gCommandLayout; paneLayout -e -configuration "single" $gCommandLayout; setFocus $gCommandReporter; break; case "maximizeBoth": paneLayout -e -setPane $gCommandReporter 1 $gCommandLayout; paneLayout -e -setPane $gCommandExecuterTabsPane 2 $gCommandLayout; paneLayout -e -configuration "horizontal2" $gCommandLayout; selectCurrentExecuterControl; break; // history menu actions case "batchRenderMsgs": int $newBatch = 0; if (`optionVar -q batchRenderMessagesVerbosity`) { // is on, turn off batchRender -v 1; }else { // is off, turn on batchRender -v 3; $newBatch = 1; } // set optionvar optionVar -iv batchRenderMessagesVerbosity $newBatch; // synchronize history option synchronizeScriptEditorOption($newBatch, $gBatchRenderMsgsMenuItemSuffix); break; case "echoAllCommands": toggleCommandReporterOption("-echoAllCommands", $gEchoAllCmdsMenuItemSuffix); { // toggle echo all commands icon state iconTextCheckBox -e -v (`optionVar -q echoAllLines`) echoAllCommandsButton; } break; case "showErrorLineNumbers": toggleCommandReporterOption("-lineNumbers", $gErrorLineNumsMenuItemSuffix); break; case "showStackTrace": toggleCommandReporterOption("-stackTrace", $gStackTraceMenuItemSuffix); break; case "toggleSuppressResults": toggleCommandReporterOption("-suppressResults", $gSuppressResultsMenuItemSuffix); break; case "toggleSuppressInfos": toggleCommandReporterOption("-suppressInfo", $gSuppressInfoMenuItemSuffix); break; case "toggleSuppressWarnings": toggleCommandReporterOption("-suppressWarnings", $gSuppressWarningsMenuItemSuffix); break; case "toggleSuppressErrors": toggleCommandReporterOption("-suppressErrors", $gSuppressErrorsMenuItemSuffix); break; case "toggleSuppressDupVarMessages": int $newState = !`melOptions -q -duplicateVariableWarnings`; melOptions -duplicateVariableWarnings $newState; optionVar -iv melDuplicateVariableWarnings $newState; // The melOption is an enable while the UI check is a suppress, // so we need to invert the state for the UI. synchronizeScriptEditorOption(!$newState, $gSuppressDupVarMessagesMenuItemSuffix); break; case "toggleSuppressStackWindow": toggleCommandReporterOption("-suppressStackTrace", $gSuppressStackTraceMenuItemSuffix); break; case "filterOutHistoryNone": setCommandReporterFilter(""); break; case "filterOutHistoryMEL": setCommandReporterFilter("mel"); break; case "filterOutHistoryPython": setCommandReporterFilter("python"); break; // command menu actions case "showLineNumbers": toggleCommandExecuterShowLineNumbers; break; case "tabsForIndent": toggleCommandExecuterTabsForIndent; break; case "autoCloseBraces": toggleCommandExecuterAutoCloseBraces; break; case "commandCompletion": toggleCommandExecuterCommandCompletion; break; case "pathCompletion": toggleCommandExecuterPathCompletion; break; case "toolTipHelp": toggleCommandExecuterToolTipHelp; break; case "showQuickHelp": toggleCmdQuickHelp(-1, 0); break; case "execute": { string $filename = getCurrentExecuterFilename(); if (size($filename) > 0) { delegateCommandToFocusedExecuterWindow "-e -executeAll" 1; } else { delegateCommandToFocusedExecuterWindow "-e -execute" 1; } } break; case "executeAll": delegateCommandToFocusedExecuterWindow "-e -executeAll" 1; break; // tab operations case "addExecuterTab": addNewExecuterTab("", 0); break; case "addMELExecuterTab": addNewExecuterTab("mel", 1); break; case "addPythonExecuterTab": addNewExecuterTab("python", 1); break; case "renameCurrentExecuterTab": // Don't allow renaming a tab which contains a file. string $filename = getCurrentExecuterFilename(); if (size($filename) == 0) { renameCurrentExecuterTab("", 0); } break; case "removeOtherExecuterTabs": removeOtherExecuterTabs; break; case "removeCurrentExecuterTab": // NOTE: MUST eval deferred as one can innocuously remove their current tab if they type // this command in the current executer (not a problem if done through menu items) evalDeferred("removeCurrentExecuterTab"); break; case "selectPreviousExecuterTab": selectExecuterTabOffset(-1); break; case "selectNextExecuterTab": selectExecuterTabOffset(1); break; // help operations case "showSelectedCmdHelp": showSelectedCmdHelp(false); break; case "showSelectedCmdQuickHelp": showSelectedCmdHelp(true); break; // last case suppress options for scriptEditorInfo cmd workaround/hack, not to be used // externally case "suppressResults": setCommandReporterOption("-suppressResults", $gSuppressResultsMenuItemSuffix, true); break; case "unsuppressResults": setCommandReporterOption("-suppressResults", $gSuppressResultsMenuItemSuffix, false); break; case "suppressInfos": setCommandReporterOption("-suppressInfo", $gSuppressInfoMenuItemSuffix, true); break; case "unsuppressInfos": setCommandReporterOption("-suppressInfo", $gSuppressInfoMenuItemSuffix, false); break; case "suppressWarnings": setCommandReporterOption("-suppressWarnings", $gSuppressWarningsMenuItemSuffix, true); break; case "unsuppressWarnings": setCommandReporterOption("-suppressWarnings", $gSuppressWarningsMenuItemSuffix, false); break; case "suppressErrors": setCommandReporterOption("-suppressErrors", $gSuppressErrorsMenuItemSuffix, true); break; case "unsuppressErrors": setCommandReporterOption("-suppressErrors", $gSuppressErrorsMenuItemSuffix, false); break; case "suppressStackWindow": setCommandReporterOption("-suppressStackTrace", $gSuppressStackTraceMenuItemSuffix, true); break; case "unsuppressStackWindow": setCommandReporterOption("-suppressStackTrace", $gSuppressStackTraceMenuItemSuffix, false); break; default: { // internal assertion, never expected to show warning ("Invalid action specified (" + $action + ")\n"); } break; } } global proc string shortObjectName(string $longObjectName) // // Given a long ui name path, return the short object name. // { // string $buffer[]; $numTokens = `tokenize $longObjectName "|" $buffer`; if ($numTokens > 0) { return $buffer[size($buffer)-1]; }else { return ""; } } global proc buildScriptEditorCondensedPopupMenus(string $parent, int $isHistoryPopup) // // Builds all the necessary menus under the specified menubar/popup // { // build the default marking menus menuItem -radialPosition "N" -parent $parent -label (uiRes("m_scriptEditorPanel.kNewExecuterTab")) -command "handleScriptEditorAction \"addExecuterTab\""; menuItem -radialPosition "W" -parent $parent -label (uiRes("m_scriptEditorPanel.kSelectPreviousTab")) -command "handleScriptEditorAction \"selectPreviousExecuterTab\""; menuItem -radialPosition "E" -parent $parent -label (uiRes("m_scriptEditorPanel.kSelectNextTab")) -command "handleScriptEditorAction \"selectNextExecuterTab\""; $deleteSM = `menuItem -radialPosition "SE" -parent $parent -subMenu true -label (uiRes("m_scriptEditorPanel.kCloseMMLabel"))`; menuItem -parent $deleteSM -radialPosition "E" -label (uiRes("m_scriptEditorPanel.kCloseCurrentMMLabel")) -command "handleScriptEditorAction \"removeCurrentExecuterTab\""; menuItem -parent $deleteSM -radialPosition "W" -label (uiRes("m_scriptEditorPanel.kCloseOthersMMLabel")) -command "handleScriptEditorAction \"removeOtherExecuterTabs\""; setParent -m ..; if (!$isHistoryPopup) { // build the default short rmb menus menuItem -label (uiRes("m_scriptEditorPanel.kExecute")) -parent $parent -command "handleScriptEditorAction \"execute\""; menuItem -label (uiRes("m_scriptEditorPanel.kQuickHelp")) -parent $parent -command "handleScriptEditorAction \"showSelectedCmdQuickHelp\""; menuItem -label (uiRes("m_scriptEditorPanel.kShowCommandHelp")) -parent $parent -command "handleScriptEditorAction showSelectedCmdHelp"; menuItem -divider on; menuItem -label (uiRes("m_scriptEditorPanel.kUndo")) -parent $parent -command "handleScriptEditorAction \"undo\""; menuItem -label (uiRes("m_scriptEditorPanel.kRedo")) -parent $parent -command "handleScriptEditorAction \"redo\""; menuItem -divider on; menuItem -label (uiRes("m_scriptEditorPanel.kCut")) -parent $parent -command "handleScriptEditorAction \"cut\""; menuItem -label (uiRes("m_scriptEditorPanel.kCopy")) -parent $parent -command "handleScriptEditorAction \"copy\""; menuItem -label (uiRes("m_scriptEditorPanel.kPaste")) -parent $parent -command "handleScriptEditorAction \"paste\""; menuItem -divider on; menuItem -label (uiRes("m_scriptEditorPanel.kSelectAll")) -parent $parent -command "handleScriptEditorAction \"selectAll\""; menuItem -divider on; menuItem -label (uiRes("m_scriptEditorPanel.kClearInput")) -parent $parent -command "handleScriptEditorAction \"clearInput\""; menuItem -label (uiRes("m_scriptEditorPanel.kClearAll")) -parent $parent -command "handleScriptEditorAction \"clearAll\""; }else { menuItem -label (uiRes("m_scriptEditorPanel.kCopy")) -parent $parent -command "handleScriptEditorAction \"copy\""; menuItem -label (uiRes("m_scriptEditorPanel.kSelectAll")) -parent $parent -command "handleScriptEditorAction \"selectAll\""; menuItem -divider on; menuItem -label (uiRes("m_scriptEditorPanel.kClearHistory")) -parent $parent -command "handleScriptEditorAction \"clearHistory\""; menuItem -label (uiRes("m_scriptEditorPanel.kClearAll")) -parent $parent -command "handleScriptEditorAction \"clearAll\""; } } global proc buildScriptEditorMenus(string $parent, string $prefix, int $isPopupParent, int $isHistoryPopup) // // Builds all the necessary menus under the specified menubar/popup // { global int $gScriptEditorMenuBarVisible; // scoped vars string $fileMenu, $editMenu; string $historyMenu, $commandMenu; if ($isPopupParent) { // check if we are creating the full menu bar popup (only done if the menu bar is not visible) $fileMenu = `menuItem -parent $parent -label (uiRes("m_scriptEditorPanel.kFile")) -allowOptionBoxes true -subMenu true`; $editMenu = `menuItem -parent $parent -label (uiRes("m_scriptEditorPanel.kEdit")) -allowOptionBoxes true -subMenu true`; menuItem -parent $parent -divider on; $historyMenu = `menuItem -parent $parent -label (uiRes("m_scriptEditorPanel.kHistory")) -allowOptionBoxes true -subMenu true`; $commandMenu = `menuItem -parent $parent -label (uiRes("m_scriptEditorPanel.kCommand")) -allowOptionBoxes true -subMenu true`; // build popup help menus menuItem -parent $parent -divider on; $helpMenu = `menuItem -parent $parent -label (uiRes("m_scriptEditorPanel.kHelp")) -subMenu true`; buildScriptEditorContextHelpItems($parent, $parent); // post menu commands menuItem -e -postMenuCommand ("buildScriptEditorFileMenu " + $fileMenu) $fileMenu; menuItem -e -postMenuCommand ("buildScriptEditorEditMenu(\"" + $editMenu + "\", 1, " + $isHistoryPopup + ")") $editMenu; menuItem -e -postMenuCommand ("buildScriptEditorHistoryMenu(\"" + $historyMenu + "\", \"" + $prefix + "\")") $historyMenu; menuItem -e -postMenuCommand ("buildScriptEditorCommandMenu(\"" + $commandMenu + "\", \"" + $prefix + "\", 1)") $commandMenu; }else { $fileMenu = `menu -parent $parent -label (uiRes("m_scriptEditorPanel.kFile")) -allowOptionBoxes true -tearOff true`; $editMenu = `menu -parent $parent -label (uiRes("m_scriptEditorPanel.kEdit")) -allowOptionBoxes true -tearOff true`; $historyMenu = `menu -parent $parent -label (uiRes("m_scriptEditorPanel.kHistory")) -allowOptionBoxes true -tearOff true`; $commandMenu = `menu -parent $parent -label (uiRes("m_scriptEditorPanel.kCommand")) -allowOptionBoxes true -tearOff true`; // post menu commands menu -e -postMenuCommand ("buildScriptEditorFileMenu " + $fileMenu) $fileMenu; menu -e -postMenuCommand ("buildScriptEditorEditMenu(\"" + $editMenu + "\", 0, 0)") $editMenu; menu -e -postMenuCommand ("buildScriptEditorHistoryMenu(\"" + $historyMenu + "\", \"" + $prefix + "\")") $historyMenu; menu -e -postMenuCommand ("buildScriptEditorCommandMenu(\"" + $commandMenu + "\", \"" + $prefix + "\", 0)") $commandMenu; } } global proc buildScriptEditorFileMenu(string $parentMenu) // // Builds the file menu items under the specified menu // { setParent -menu $parentMenu; if (`menu -query -numberOfItems $parentMenu` != 0) { return; } string $loadMenu, $saveMenu; // create the menus $loadMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kLoadScript")) -annotation (uiRes("m_scriptEditorPanel.kLoadAnnot")) -c "handleScriptEditorAction \"load\""`; menuItem -l (uiRes("m_scriptEditorPanel.kSourceScript")) -annotation (uiRes("m_scriptEditorPanel.kSourceAnnot")) -c "handleScriptEditorAction \"source\""; $saveMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kSaveScript")) -annotation (uiRes("m_scriptEditorPanel.kSaveAnnot")) -c "handleScriptEditorAction \"save\""`; menuItem -l (uiRes("m_scriptEditorPanel.kSaveScriptToShelf")) -annotation (uiRes("m_scriptEditorPanel.kSaveToShelfAnnot")) -c "handleScriptEditorAction \"saveToShelf\""; } global proc buildScriptEditorEditMenu(string $parentMenu, int $filterCondensedMenus, int $historyPopup) // // Builds the edit menu items under the specified menu // { setParent -menu $parentMenu; if (`menu -query -numberOfItems $parentMenu` != 0) { return; } int $isLinux = `about -linux`, $isWin = `about -win`, $isMac = `about -mac`; string $undoMenu, $redoMenu; string $cutMenu, $copyMenu, $pasteMenu, $selectAllMenu; string $indentSelMenu, $unindentSelMenu, $gotoMenu, $searchAndReplaceMenu; // create the menus if (!$filterCondensedMenus || $historyPopup) { $undoMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kUndo")) -annotation (uiRes("m_scriptEditorPanel.kUedoAnnot")) -c "handleScriptEditorAction \"undo\""`; $redoMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kRedo")) -annotation (uiRes("m_scriptEditorPanel.kRedoAnnot")) -c "handleScriptEditorAction \"redo\""`; } if (!$filterCondensedMenus || $historyPopup) { menuItem -divider on; $cutMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kCut")) -annotation (uiRes("m_scriptEditorPanel.kCutAnnot")) -c "handleScriptEditorAction \"cut\""`; } if (!$filterCondensedMenus) { $copyMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kCopy")) -annotation (uiRes("m_scriptEditorPanel.kCopyAnnot")) -c "handleScriptEditorAction \"copy\""`; } if (!$filterCondensedMenus || $historyPopup) { $pasteMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kPaste")) -annotation (uiRes("m_scriptEditorPanel.kPasteAnnot")) -c "handleScriptEditorAction \"paste\""`; $selectAllMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kSelectAll")) -annotation (uiRes("m_scriptEditorPanel.kSelectAllAnnot")) -c "handleScriptEditorAction \"selectAll\""`; menuItem -divider on; } $gotoMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kGoto")) -annotation (uiRes("m_scriptEditorPanel.kGotoLineAnnot")) -c "handleScriptEditorAction \"gotoLine\""`; $searchAndReplaceMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kSearchAndReplace")) -annotation (uiRes("m_scriptEditorPanel.kSearchAndReplaceAnnot")) -c "handleScriptEditorAction \"searchAndReplace\""`; menuItem -divider on; // currently, there's an issue with the indent on linux? $indentSelMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kIndentSelection")) -annotation (uiRes("m_scriptEditorPanel.kIndentSelectionAnnot")) -c "handleScriptEditorAction \"indentSelection\""`; $unindentSelMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kUnindentSelection")) -annotation (uiRes("m_scriptEditorPanel.kUnindentSelectionAnnot")) -c "handleScriptEditorAction \"unindentSelection\""`; menuItem -divider on; if (!$filterCondensedMenus || !$historyPopup) { menuItem -l (uiRes("m_scriptEditorPanel.kClearHistory")) -annotation (uiRes("m_scriptEditorPanel.kClearHistoryAnnot")) -c "handleScriptEditorAction \"clearHistory\""; } if (!$filterCondensedMenus || $historyPopup) { menuItem -l (uiRes("m_scriptEditorPanel.kClearInput")) -annotation (uiRes("m_scriptEditorPanel.kClearInputAnnot")) -c "handleScriptEditorAction \"clearInput\""; } if (!$filterCondensedMenus) { menuItem -l (uiRes("m_scriptEditorPanel.kClearAll")) -annotation (uiRes("m_scriptEditorPanel.kClearAllAnnot")) -c "handleScriptEditorAction \"clearAll\""; } } global proc buildScriptEditorHistoryMenu(string $parentMenu, string $prefix) // // Builds the history menu items under the specified menu // { // global string $gBatchRenderMsgsMenuItemSuffix; global string $gEchoAllCmdsMenuItemSuffix; global string $gErrorLineNumsMenuItemSuffix; global string $gStackTraceMenuItemSuffix; global string $gSuppressResultsMenuItemSuffix; global string $gSuppressInfoMenuItemSuffix; global string $gSuppressWarningsMenuItemSuffix; global string $gSuppressErrorsMenuItemSuffix; global string $gSuppressDupVarMessagesMenuItemSuffix; global string $gSuppressStackTraceMenuItemSuffix; global string $gHistoryFilterNoneMenuItemSuffix; global string $gHistoryFilterMELMenuItemSuffix; global string $gHistoryFilterPythonMenuItemSuffix; // string $filter = `optionVar -q commandReporterSourceTypeFilter`; $filter = `tolower $filter`; setParent -menu $parentMenu; if (`menu -query -numberOfItems $parentMenu` != 0) { string $itemName; $itemName = ($prefix + $gSuppressDupVarMessagesMenuItemSuffix); if (`menuItem -q -exists $itemName`) { menuItem -e -checkBox (!`melOptions -q -duplicateVariableWarnings`) $itemName; } // update the no-filter menu item $itemName = ($prefix + $gHistoryFilterNoneMenuItemSuffix); if (`menuItem -q -exists $itemName`) { menuItem -e -radioButton ($filter == "") $itemName; } // update the mel-filter menu item $itemName = ($prefix + $gHistoryFilterMELMenuItemSuffix); if (`menuItem -q -exists $itemName`) { menuItem -e -radioButton ($filter == "python") $itemName; } // update the python-filter menu item $itemName = ($prefix + $gHistoryFilterPythonMenuItemSuffix); if (`menuItem -q -exists $itemName`) { menuItem -e -radioButton ($filter == "mel") $itemName; } return; } // global string $gCommandReporter; // create the menus menuItem -l (uiRes("m_scriptEditorPanel.kBatchRenderMessages")) -checkBox `optionVar -q batchRenderMessagesVerbosity` -annotation (uiRes("m_scriptEditorPanel.kShowBatchRenderMessagesAnnot")) -c "handleScriptEditorAction \"batchRenderMsgs\"" ($prefix + $gBatchRenderMsgsMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kEchoAllCommands")) -checkBox `cmdScrollFieldReporter -q -echoAllCommands $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kEchoAllCommmandsAnnot")) -c "handleScriptEditorAction \"echoAllCommands\"" ($prefix + $gEchoAllCmdsMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kLineNumbersInErrors")) -checkBox `cmdScrollFieldReporter -q -lineNumbers $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kShowLineNumInErrorsAnnot")) -c "handleScriptEditorAction \"showErrorLineNumbers\"" ($prefix + $gErrorLineNumsMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kShowStackTrace")) -checkBox `cmdScrollFieldReporter -q -stackTrace $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kShowStackTraceAnnot")) -c "handleScriptEditorAction \"showStackTrace\"" ($prefix + $gStackTraceMenuItemSuffix); menuItem -divider on; menuItem -subMenu true -tearOff true -l (uiRes("m_scriptEditorPanel.kFilterOutput")); radioMenuItemCollection; menuItem -label (uiRes("m_scriptEditorPanel.kFilterNone")) -radioButton ($filter == "") -annotation (uiRes("m_scriptEditorPanel.kFilterNoneAnnot")) -command "handleScriptEditorAction \"filterOutHistoryNone\"" ($prefix + $gHistoryFilterNoneMenuItemSuffix); menuItem -label (uiRes("m_scriptEditorPanel.kFilterMEL")) -radioButton ($filter == "python") -annotation (uiRes("m_scriptEditorPanel.kFilterMELAnnot")) -command "handleScriptEditorAction \"filterOutHistoryPython\"" ($prefix + $gHistoryFilterMELMenuItemSuffix); menuItem -label (uiRes("m_scriptEditorPanel.kFilterPython")) -radioButton ($filter == "mel") -annotation (uiRes("m_scriptEditorPanel.kFilterPythonAnnot")) -command "handleScriptEditorAction \"filterOutHistoryMEL\"" ($prefix + $gHistoryFilterPythonMenuItemSuffix); setParent -m ..; menuItem -divider on; menuItem -l (uiRes("m_scriptEditorPanel.kSuppressCommandResults")) -checkBox `cmdScrollFieldReporter -q -suppressResults $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kSuppressResultsAnnot")) -c "handleScriptEditorAction \"toggleSuppressResults\"" ($prefix + $gSuppressResultsMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kSuppressInfoMessages")) -checkBox `cmdScrollFieldReporter -q -suppressInfo $gCommandReporter` -c "handleScriptEditorAction \"toggleSuppressInfos\"" -annotation (uiRes("m_scriptEditorPanel.kSuppressInfoMsgsAnnot")) ($prefix + $gSuppressInfoMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kSuppressWarningMessages")) -checkBox `cmdScrollFieldReporter -q -suppressWarnings $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kSuppressWarningMsgsAnnot")) -c "handleScriptEditorAction \"toggleSuppressWarnings\"" ($prefix + $gSuppressWarningsMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kSuppressErrorMessages")) -checkBox `cmdScrollFieldReporter -q -suppressErrors $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kSuppressErrorMsgsAnnot")) -c "handleScriptEditorAction \"toggleSuppressErrors\"" ($prefix + $gSuppressErrorsMenuItemSuffix); menuItem -version 2016 -l (uiRes("m_scriptEditorPanel.kSuppressDupVarMessages")) -checkBox (!`melOptions -q -duplicateVariableWarnings`) -annotation (uiRes("m_scriptEditorPanel.kSuppressDupVarMsgsAnnot")) -c "handleScriptEditorAction \"toggleSuppressDupVarMessages\"" ($prefix + $gSuppressDupVarMessagesMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kSuppressStackWindow")) -checkBox `cmdScrollFieldReporter -q -suppressStackTrace $gCommandReporter` -annotation (uiRes("m_scriptEditorPanel.kSuppressStackWindowAnnot")) -c "handleScriptEditorAction \"toggleSuppressStackWindow\"" ($prefix + $gSuppressStackTraceMenuItemSuffix); } global proc buildScriptEditorCommandMenu(string $parentMenu, string $prefix, int $filterCondensedMenus) // // Builds the command menu items under the specified menu // { // global string $gShowLineNumbersMenuItemSuffix; global string $gUseTabsForIndentMenuItemSuffix; global string $gAutoCloseBracesMenuItemSuffix; global string $gCommandCompletionMenuItemSuffix; global string $gPathCompletionMenuItemSuffix; global string $gToolTipHelpMenuItemSuffix; global string $gShowQuickHelpMenuItemSuffix; global int $gCommandExecuterShowQuickHelp; // setParent -menu $parentMenu; // string $curExecuter = `getCurrentExecuterControl`; string $newTabMenu, $closeTabMenu, $selectNextTabMenu, $selectPreviousTabMenu; // executer tabs control if (!(`menuItem -query -exists seNewTabMenu`)) { $newTabMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kNewExecuterTab")) -annotation (uiRes("m_scriptEditorPanel.kNewTabAnnot")) -c "handleScriptEditorAction \"addExecuterTab\"" seNewTabMenu`; menuItem -l (uiRes("m_scriptEditorPanel.kRenameCurrentTab")) -annotation (uiRes("m_scriptEditorPanel.kRenameTabAnnot")) -c "handleScriptEditorAction \"renameCurrentExecuterTab\"" seRenameTabMenu; menuItem -subMenu true -label (uiRes("m_scriptEditorPanel.kSelectTab")) seSelectTabMenu; $selectPreviousTabMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kSelectPreviousTab")) -annotation (uiRes("m_scriptEditorPanel.kSelectPreviousTabAnnot")) -c "handleScriptEditorAction \"selectPreviousExecuterTab\""`; $selectNextTabMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kSelectNextTab")) -annotation (uiRes("m_scriptEditorPanel.kSelectNextTabAnnot")) -c "handleScriptEditorAction \"selectNextExecuterTab\""`; setParent -menu $parentMenu; $closeTabMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kCloseCurrentTab")) -annotation (uiRes("m_scriptEditorPanel.kCloseCurrentTabAnnot")) -c "handleScriptEditorAction \"removeCurrentExecuterTab\"" seCloseTabMenu`; } // executer options if (!(`menuItem -query -exists ($prefix + $gShowLineNumbersMenuItemSuffix)`)) { menuItem -divider on; menuItem -l (uiRes("m_scriptEditorPanel.kShowLineNumbers")) -checkBox `cmdScrollFieldExecuter -q -showLineNumbers $curExecuter` -annotation (uiRes("m_scriptEditorPanel.kShowLineNumberAnnot")) -c "handleScriptEditorAction \"showLineNumbers\"" ($prefix + $gShowLineNumbersMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kUseTabsForIndent")) -checkBox `cmdScrollFieldExecuter -q -tabsForIndent $curExecuter` -annotation (uiRes("m_scriptEditorPanel.kUseTabsForIndentAnnot")) -c "handleScriptEditorAction \"tabsForIndent\"" ($prefix + $gUseTabsForIndentMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kAutoCloseBraces")) -checkBox `cmdScrollFieldExecuter -q -autoCloseBraces $curExecuter` -annotation (uiRes("m_scriptEditorPanel.kAutoCloseBracesAnnot")) -c "handleScriptEditorAction \"autoCloseBraces\"" ($prefix + $gAutoCloseBracesMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kCommandCompletion")) -checkBox `cmdScrollFieldExecuter -q -commandCompletion $curExecuter` -annotation (uiRes("m_scriptEditorPanel.kCommandCompletionAnnot")) -c "handleScriptEditorAction \"commandCompletion\"" ($prefix + $gCommandCompletionMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kPathCompletion")) -checkBox `cmdScrollFieldExecuter -q -objectPathCompletion $curExecuter` -annotation (uiRes("m_scriptEditorPanel.kPathCompletionAnnot")) -c "handleScriptEditorAction \"pathCompletion\"" ($prefix + $gPathCompletionMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kToolTipHelp")) -checkBox `cmdScrollFieldExecuter -q -showTooltipHelp $curExecuter` -annotation (uiRes("m_scriptEditorPanel.kToolTipHelpAnnot")) -c "handleScriptEditorAction \"toolTipHelp\"" ($prefix + $gToolTipHelpMenuItemSuffix); menuItem -l (uiRes("m_scriptEditorPanel.kShowQuickHelp")) -checkBox $gCommandExecuterShowQuickHelp -annotation (uiRes("m_scriptEditorPanel.kQuickHelpNumberAnnot")) -c "handleScriptEditorAction \"showQuickHelp\"" ($prefix + $gShowQuickHelpMenuItemSuffix); } if (!$filterCondensedMenus) { if (! (`menuItem -query -exists seExecuteMenu`)) { menuItem -divider on; string $executeMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kExecute")) -annotation (uiRes("m_scriptEditorPanel.kExecuteAnnot")) -c "handleScriptEditorAction \"execute\"" seExecuteMenu`; } } // if the plug-in's loaded, add it to the command menu int $profilerPluginLoaded = `pluginInfo -q -loaded "melProfiler"`; if ($profilerPluginLoaded) { if (!(`menuItem -query -exists seMELProfilerMenuItem`)) { string $melProfileMenuString = (uiRes("m_scriptEditorPanel.kLaunchMELProfiler")); string $executeMenu = `menuItem -l (uiRes("m_scriptEditorPanel.kLaunchMELProfiler")) -annotation (uiRes("m_scriptEditorPanel.kExecuteMELAnnot")) -c "melProfilerWindow" seMELProfilerMenuItem`; } } else { if ((`menuItem -query -exists seMELProfilerMenuItem`)) { catchQuiet(`deleteUI -menuItem seMELProfilerMenuItem`); } } } global proc synchronizeScriptEditorOption(int $newVal, string $menuItemSuffix) // // Synchronizes the various option menu items on the given value for the given menu item. // Also affects the respective main menu bar menu item. // { // toggle all the reporter menu items global string $gCommandReporter; string $objName = `shortObjectName $gCommandReporter`; string $menuName = ($objName + $menuItemSuffix); if (`menuItem -q -exists $menuName`) { menuItem -e -cb $newVal $menuName; } // toggle all the executer reporter menu items global string $gCommandExecuter[]; string $menu; for ($menu in $gCommandExecuter) { $objName = `shortObjectName $menu`; $menuName = ($objName + $menuItemSuffix); if (`menuItem -q -exists $menuName`) { menuItem -e -cb $newVal $menuName; } } // toggle the main menubar menu item global string $gScriptEditorMenuBarPrefix; $menuName = ($gScriptEditorMenuBarPrefix + $menuItemSuffix); if (`menuItem -q -exists $menuName`) { menuItem -e -cb $newVal $menuName; } } global proc setCommandReporterOption( string $optionFlag, string $menuItemSuffix, int $newVal ) // // Sets instead of toggles // { global string $gLastFocusedCommandReporter; if ($gLastFocusedCommandReporter != "") { // get the old value and swap it int $curVal = `cmdScrollFieldReporter -q $optionFlag $gLastFocusedCommandReporter`; if ($newVal != $curVal) { // set the new value eval("cmdScrollFieldReporter -e " + $optionFlag + " " + $newVal + " " + $gLastFocusedCommandReporter); saveCommandReporterOptionVars($gLastFocusedCommandReporter); synchronizeScriptEditorOption($newVal, $menuItemSuffix); } } } global proc toggleCommandReporterOption( string $optionFlag, string $menuItemSuffix ) // // Toggles an cmdScrollFieldReporter option. // { global string $gLastFocusedCommandReporter; if ($gLastFocusedCommandReporter != "") { // get the old value and swap it int $curVal = `cmdScrollFieldReporter -q $optionFlag $gLastFocusedCommandReporter`; int $newVal = abs($curVal-1); // set the new value eval("cmdScrollFieldReporter -e " + $optionFlag + " " + $newVal + " " + $gLastFocusedCommandReporter); saveCommandReporterOptionVars($gLastFocusedCommandReporter); synchronizeScriptEditorOption($newVal, $menuItemSuffix); } } global proc toggleCommandExecuterShowLineNumbers() // // Specifically toggles whether to show line numbers in the command executers or not. // { global string $gShowLineNumbersMenuItemSuffix; global string $gCommandExecuter[]; // get the old value and swap it int $curVal = `cmdScrollFieldExecuter -q -showLineNumbers $gCommandExecuter[0]`; int $newVal = abs($curVal-1); // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -showLineNumbers " + $newVal + " " + $executer); } iconTextCheckBox -e -v $newVal showLineNumbersButton; optionVar -iv commandExecuterShowLineNumbers $newVal; synchronizeScriptEditorOption($newVal, $gShowLineNumbersMenuItemSuffix); } global proc toggleCommandExecuterTabsForIndent() // // Toggles whether tabs are inserted in the executer { global string $gUseTabsForIndentMenuItemSuffix; global string $gCommandExecuter[]; // get the old value and swap it int $curVal = `cmdScrollFieldExecuter -q -tabsForIndent $gCommandExecuter[0]`; int $newVal = abs($curVal-1); // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -tabsForIndent " + $newVal + " " + $executer); } optionVar -iv commandExecuterTabsForIndent $newVal; synchronizeScriptEditorOption($newVal, $gUseTabsForIndentMenuItemSuffix); } global proc toggleCommandExecuterAutoCloseBraces() // // Toggles whether closing braces are automatically added { global string $gAutoCloseBracesMenuItemSuffix; global string $gCommandExecuter[]; // get the old value and swap it int $curVal = `cmdScrollFieldExecuter -q -autoCloseBraces $gCommandExecuter[0]`; int $newVal = abs($curVal-1); // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -autoCloseBraces " + $newVal + " " + $executer); } optionVar -iv commandExecuterAutoCloseBraces $newVal; synchronizeScriptEditorOption($newVal, $gAutoCloseBracesMenuItemSuffix); } global proc setCommandExecuterSpacesPerTab(int $newVal) // // Sets the number of spaces which are equivalent to one tab stop { global string $gCommandExecuter[]; // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -spacesPerTab " + $newVal + " " + $executer); } optionVar -iv commandExecuterSpacesPerTab $newVal; } global proc toggleCommandExecuterCommandCompletion() // // Toggles command completion // { global string $gCommandCompletionMenuItemSuffix; global string $gCommandExecuter[]; // get the old value and swap it int $curVal = `cmdScrollFieldExecuter -q -commandCompletion $gCommandExecuter[0]`; int $newVal = abs($curVal-1); // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -commandCompletion " + $newVal + " " + $executer); } optionVar -iv commandExecuterCommandCompletion $newVal; synchronizeScriptEditorOption($newVal, $gCommandCompletionMenuItemSuffix); } global proc toggleCommandExecuterPathCompletion() // // Toggles dag path completion // { global string $gPathCompletionMenuItemSuffix; global string $gCommandExecuter[]; // get the old value and swap it int $curVal = `cmdScrollFieldExecuter -q -objectPathCompletion $gCommandExecuter[0]`; int $newVal = abs($curVal-1); // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -objectPathCompletion " + $newVal + " " + $executer); } optionVar -iv commandExecuterPathCompletion $newVal; synchronizeScriptEditorOption($newVal, $gPathCompletionMenuItemSuffix); } global proc toggleCommandExecuterToolTipHelp() // // Toggles dag path completion // { global string $gToolTipHelpMenuItemSuffix; global string $gCommandExecuter[]; // get the old value and swap it int $curVal = `cmdScrollFieldExecuter -q -showTooltipHelp $gCommandExecuter[0]`; int $newVal = abs($curVal-1); // set the new value string $executer; for ($executer in $gCommandExecuter) { eval("cmdScrollFieldExecuter -e -showTooltipHelp " + $newVal + " " + $executer); } optionVar -iv commandExecuterToolTipHelp $newVal; synchronizeScriptEditorOption($newVal, $gToolTipHelpMenuItemSuffix); } global proc delegateCommandToFocusedExecuterWindow( string $cmd, int $deferred) // // Delegates a command to the last focused executer control. // Parameter deferred means use evalDeferred instead of eval, this is important to avoid // instability because the MEL scanner is not reentrant. { global string $gLastFocusedCommandExecuter; if ($gLastFocusedCommandExecuter != "") { string $evalCmd = "cmdScrollFieldExecuter " + $cmd + " " + $gLastFocusedCommandExecuter; if ($deferred == 1) { evalDeferred($evalCmd); } else { eval($evalCmd); } } } global proc delegateCommandToFocusedReporterWindow( string $cmd ) // // Delegates a command to the last focused reporter control. // { global string $gLastFocusedCommandReporter; if ($gLastFocusedCommandReporter != "") { eval("cmdScrollFieldReporter " + $cmd + " " + $gLastFocusedCommandReporter); } } global proc delegateCommandToFocusedWindow( string $cmd ) // // Delegates a command to the currently focused control. // { global string $gLastFocusedCommandReporter; global string $gLastFocusedCommandExecuter; global string $gLastFocusedCommandControl; if ($gLastFocusedCommandControl == $gLastFocusedCommandReporter) { eval("cmdScrollFieldReporter " + $cmd + " " + $gLastFocusedCommandControl); }else if ($gLastFocusedCommandControl == $gLastFocusedCommandExecuter) { eval("cmdScrollFieldExecuter " + $cmd + " " + $gLastFocusedCommandControl); } } global proc string getCurrentExecuterControl() // // Returns the current executer control. // { global string $gCommandExecuterTabs; // get tab array string $array[] = `tabLayout -q -ca $gCommandExecuterTabs`; // get selected tab index int $selTabIdx = `tabLayout -q -selectTabIndex $gCommandExecuterTabs` - 1; // get the tab at the index string $curFormLayout = $array[$selTabIdx]; // get the formLayout children in this tab (according to how we built it) string $tabChldrn[] = `formLayout -q -ca $curFormLayout`; // get the formLayout's first child which should be the cmdScrollFieldExecuter string $curExecuter = $tabChldrn[0]; return $curExecuter; } global proc setLastFocusedCommandExecuter(string $controlName) { global string $gLastFocusedCommandExecuter; global string $gLastFocusedCommandControl; $gLastFocusedCommandExecuter = $controlName; $gLastFocusedCommandControl = $controlName; } global proc setLastFocusedCommandReporter(string $controlName) { global string $gLastFocusedCommandReporter; global string $gLastFocusedCommandControl; $gLastFocusedCommandReporter = $controlName; $gLastFocusedCommandControl = $controlName; } global proc selectCurrentExecuterControl() { string $curExecuter = `getCurrentExecuterControl`; setLastFocusedCommandExecuter $curExecuter; setFocus $curExecuter; syncExecuterTabState(); syncScriptEditorPanelToolbarAndMenu(); } global proc int selectExecuterTabByName(string $name) { global string $gCommandExecuter[]; global string $gCommandExecuterName[]; global string $gCommandExecuterTabs; if (size($name) > 0) { // Look thru all our executers to see if any match the input. // Note: this can be a simple tabname or the file associated with tab. int $i; for ($i = 0; $i < size($gCommandExecuter); $i++) { if ($gCommandExecuterName[$i] == $name) { tabLayout -e -selectTabIndex ($i+1) $gCommandExecuterTabs; selectCurrentExecuterControl(); return 1; } } } return 0; } // // Almost the same as selectCurrentExecuterControl() // The only difference is this procedure won't reset the focus to the current executer. // global proc selectCurrentExecuterControlWithoutFocus() { string $curExecuter = `getCurrentExecuterControl`; setLastFocusedCommandExecuter $curExecuter; syncExecuterTabState(); } global proc setCommandReporterFilter(string $filter) // // Updates the command reporter filter to filter the specified source from showing. // { global string $gScriptEditorMenuBarPrefix; global string $gCommandReporter; // set the filter for the only command reporter cmdScrollFieldReporter -e -filterSourceType $filter $gCommandReporter; // set the global option var optionVar -sv commandReporterSourceTypeFilter $filter; } global proc loadCommandReporterOptionVars(string $reporter) // // Updates the command reporter with the saved preferences. // { // load command reporter options string $buffer[]; $numTokens = `tokenize $reporter "|" $buffer`; if (size($buffer) == 0) return; string $optionVarKey = "commandReporter" + $buffer[size($buffer)-1]; if (!`optionVar -exists commandReporterSourceTypeFilter`) { optionVar -sv commandReporterSourceTypeFilter ""; } cmdScrollFieldReporter -e -lineNumbers `optionVar -q "showLineNumbersIsOn"` -stackTrace `optionVar -q "stackTraceIsOn"` -echoAllCommands `optionVar -q "echoAllLines"` -suppressResults `optionVar -q ($optionVarKey + "SuppressResults")` -suppressInfo `optionVar -q ($optionVarKey + "SuppressInfo")` -suppressWarnings `optionVar -q ($optionVarKey + "SuppressWarnings")` -suppressErrors `optionVar -q ($optionVarKey + "SuppressErrors")` -suppressStackTrace `optionVar -q ($optionVarKey + "SuppressStackTrace")` -filterSourceType `optionVar -q commandReporterSourceTypeFilter` $reporter; } global proc saveCommandReporterOptionVars(string $reporter) // // Save preferences with the command reporter's options state. // { // save command reporter options. // first, we need to get the short reoprter name string $buffer[]; $numTokens = `tokenize $reporter "|" $buffer`; if (size($buffer) == 0) return; string $optionVarKey = "commandReporter" + $buffer[size($buffer)-1]; optionVar -iv "showLineNumbersIsOn" `cmdScrollFieldReporter -q -lineNumbers $reporter`; optionVar -iv "stackTraceIsOn" `cmdScrollFieldReporter -q -stackTrace $reporter`; optionVar -iv "echoAllLines" `cmdScrollFieldReporter -q -echoAllCommands $reporter`; optionVar -iv ($optionVarKey + "SuppressResults") `cmdScrollFieldReporter -q -suppressResults $reporter`; optionVar -iv ($optionVarKey + "SuppressInfo") `cmdScrollFieldReporter -q -suppressInfo $reporter`; optionVar -iv ($optionVarKey + "SuppressWarnings") `cmdScrollFieldReporter -q -suppressWarnings $reporter`; optionVar -iv ($optionVarKey + "SuppressErrors") `cmdScrollFieldReporter -q -suppressErrors $reporter`; optionVar -iv ($optionVarKey + "SuppressStackTrace") `cmdScrollFieldReporter -q -suppressStackTrace $reporter`; } global proc verifyCommandPopupMenus() // // On RMB, we check if the state of the menubar has changed from before, if so, then we need // to delete the old popup menus and rebuild a new set (either condensed or full) // { global int $gScriptEditorMenuBarVisible; global string $gCommandPopupMenus[]; global string $gCommandReporter; global string $gCommandExecuter[]; int $menuBarVisible = `scriptedPanel -q -menuBarVisible scriptEditorPanel1`; if ($menuBarVisible != $gScriptEditorMenuBarVisible) { // delete all the sub menus for each popup menu // handle the reporters first int $index = 0; int $i = 0, $j; if (size($gCommandPopupMenus) > 0) { // delete the history sub menus // history only has 5 default menu items (including dividers) string $menuItems[] = `popupMenu -q -itemArray $gCommandPopupMenus[0]`; if (size($menuItems) > 5) { int $end = size($menuItems); for ($i = 5; $i < $end; $i++) { deleteUI $menuItems[$i]; } } int $j = 1; // delete executer sub menus // executer only has 13 default menu items (including dividers) for (; $j < size($gCommandPopupMenus); $j++) { string $menu = $gCommandPopupMenus[$j]; string $menuItems[] = `popupMenu -q -itemArray $menu`; if (size($menuItems) > 13) { int $end = size($menuItems); for ($i = 13; $i < $end; $i++) { deleteUI $menuItems[$i]; } } } } // set new state $gScriptEditorMenuBarVisible = $menuBarVisible; // rebuild sub menus again if necessary if (!$gScriptEditorMenuBarVisible) { // then build the sub menus under the condensed menus // assert - size($gCommandPopupMenus) == size($gCommandReporters) + size($gCommandExecuters) $index = 0; menuItem -parent $gCommandPopupMenus[$index] -divider on; // fill history sub menus buildScriptEditorMenus($gCommandPopupMenus[$index], `shortObjectName $gCommandReporter`, true, true); $index++; // fill the executer sub menus for ($control in $gCommandExecuter) { menuItem -parent $gCommandPopupMenus[$index] -divider on; buildScriptEditorMenus($gCommandPopupMenus[$index], `shortObjectName $control`, true, false); $index++; } } } } global proc doubleClickCmdQuickHelp() // // Handles a double click in the cmd quick help results // { global string $gCommandExecuterSideBarHelpField; global string $gCommandExecuterSideBarHelpResults; string $curExec = `getCurrentExecuterControl`; string $sels[] = `textScrollList -q -selectItem $gCommandExecuterSideBarHelpResults`; string $cmd = `textField -q -text $gCommandExecuterSideBarHelpField`; $cmd = `strip $cmd`; if (size($sels) == 0) { return; } // otherwise, go through the list and add the selected flags into the script editor // mapping the types as we go along? string $sel; string $line; // we replace the selection with the command if there is one (usually from the // command -> quick help menu/ shortcut). // TODO: reconsider if we can move the cursor past the selection and the first space // OR: just find the next space and replace that? if (`cmdScrollFieldExecuter -q -hasSelection $curExec`) { $line = $cmd; } for ($sel in $sels) { // we know that it is in the format of -shortFlag/-longFlag ... // for now, we only want to append the long flag on string $buffer[]; $numTokens = `tokenize $sel "/" $buffer`; // append line if ($numTokens > 1) { $line += (" " + $buffer[1]); } } // replace certain keywords (the values) with some defaults $line = `substituteAllString $line " on|off" " false"`; // default boolean to false $line = `substituteAllString $line " UnsignedInt" " 0"`; // default uint to 0 $line = `substituteAllString $line " Int" " 0"`; // default int to 0 $line = `substituteAllString $line " Float" " 1.0"`; // default float to 0.0 // insert the text into the current executer cmdScrollFieldExecuter -e -insertText $line $curExec; } global proc toggleCmdQuickHelp(int $show, int $forceToggle) // // Toggles the visibility of the sidebar panel. // $show -> -1 = toggle, 0 = hide, 1 = show // { global string $gCommandExecuterSideBar; global string $gCommandExecuterTabs; global string $gCommandExecuterTabsPane; global int $gCommandExecuterShowQuickHelp; global string $gShowQuickHelpMenuItemSuffix; // toggle int $curVis = `tabLayout -q -visible $gCommandExecuterSideBar`; if ($show < 0) { $show = abs($curVis-1); } // return if already in that state if (($show == $curVis) && !$forceToggle) { return; } if ($show) { // show form tabLayout -e -visible true -width 120 $gCommandExecuterSideBar; // Ensure that pane is displayed // Note: since the panel is set to keep a static width when the window is resized, // setting the tabLayout visible will keep the pane minimized on the right. // however, if we put it a size (here 1% for the width), it will display it at its // minimal size (here 120 pixels) paneLayout -e -ps 2 1 100 $gCommandExecuterTabsPane; // if showing, then set the field global string $gCommandExecuterSideBarHelpField; setFocus $gCommandExecuterSideBarHelpField; }else { // hide form tabLayout -e -visible false $gCommandExecuterSideBar; } // save optionVar $gCommandExecuterShowQuickHelp = $show; synchronizeScriptEditorOption($show, $gShowQuickHelpMenuItemSuffix); } global proc string commandHelpExists(string $cmd) // // Returns whether quick help for the specified command exists, and if so, // the command name for which it exists under. // { $cmd = `strip $cmd`; if (size($cmd) > 0) { // take the first word if multple are selected string $buffer[]; int $numTokens = tokenize($cmd, $buffer); string $helpExists[] = `help -list $buffer[0]`; // if help exists if (size($helpExists) > 0) { return $helpExists[0]; }else { // if none found, then show help result help $cmd; } } // return empty string return ""; } global proc showFieldCmdDocumentation() // // Loads the detailed docs for the field command if it exists. // { global string $gCommandExecuterSideBarHelpField; string $cmd = `textField -q -text $gCommandExecuterSideBarHelpField`; $cmd = `strip $cmd`; $cmd = `commandHelpExists($cmd)`; // help exists? then load docs if (size($cmd) > 0) { help -doc $cmd; } } global proc showFieldCmdQuickHelp() // // Shows the list of flags in the sidebar given that the sidebar field already contains the cmd name. // { global string $gCommandExecuterSideBarHelpForm; global string $gCommandExecuterSideBarHelpField; global string $gCommandExecuterSideBarHelpResults; // clear results first textScrollList -e -removeAll $gCommandExecuterSideBarHelpResults; string $cmd = `textField -q -text $gCommandExecuterSideBarHelpField`; $cmd = `strip $cmd`; string $res = `help $cmd`; int $cmdFlagsFound = false; string $flags[]; $numTokens = `tokenize $res "\r\n" $flags`; string $flag; for ($flag in $flags) { string $flagArgs[]; $numTokens = `tokenize $flag $flagArgs`; if ($numTokens >= 2) { if (startsWith( $flagArgs[0], "-") && startsWith( $flagArgs[1], "-")) { $cmdFlagsFound = true; // then build string string $line = ($flagArgs[0] + "/" + $flagArgs[1]); int $i = 2; // skip last arg if it is the multi use descriptor if ($flagArgs[size($flagArgs)-1] == "(multi-use)") { --$numTokens; } // build line while ($i < $numTokens) { $line += (" " + $flagArgs[$i]); ++$i; } // and add to the results textScrollList -e -append $line $gCommandExecuterSideBarHelpResults; } } } // if none found, then show help result if (!$cmdFlagsFound) { print $res; } setFocus `getCurrentExecuterControl`; } global proc showSelectedCmdHelp(int $quickHelp) // // Shows either the quick or detailed help for the selected command text. // { // get the current executer string $curExec = `getCurrentExecuterControl`; // show warning if we want quick help and there is no selection if ($quickHelp && !(`cmdScrollFieldExecuter -q -hasSelection $curExec`)) { warning (uiRes("m_scriptEditorPanel.kNoSelectionForHelp")); return; } // get the selected text from the executer control string $cmd = `cmdScrollFieldExecuter -q -selectedText $curExec`; $cmd = `commandHelpExists($cmd)`; // help exists if (size($cmd) > 0) { if (!$quickHelp) { // Want to show either the Mel or the Python docs. string $curExecuter = `getCurrentExecuterControl`; string $scriptLang = `cmdScrollFieldExecuter -query -sourceType $curExecuter`; help -language $scriptLang -doc $cmd; }else { // set the field and update side bar quick help global string $gCommandExecuterSideBarHelpField; textField -e -text $cmd $gCommandExecuterSideBarHelpField; showFieldCmdQuickHelp; // show side bar if not visible toggleCmdQuickHelp(1, 0); } } } global proc addToSearchAndSelectHistory(string $query) { // check if we already have this line number in the history global string $gCommandExecuterSearch[]; int $found = `stringArrayContains $query $gCommandExecuterSearch`; int $len = size($gCommandExecuterSearch); // if not, then append to history if (!$found) { if ($len == 4) { // shift history up by one and append this last for ($i = 1; $i < 4; ++$i) { $gCommandExecuterSearch[$i-1] = $i; } --$len; } // add to end $gCommandExecuterSearch[$len++] = $query; } } global proc searchAndSelectToolbarPopupUpdate() // // // { global string $gCommandExecuterSearch[]; popupMenu -e -deleteAllItems scriptEditorToolbarSearchFieldPopupMenu; // create the new menu items int $i = size($gCommandExecuterSearch) - 1; while ($i >= 0) { string $val = $gCommandExecuterSearch[$i]; menuItem -parent scriptEditorToolbarSearchFieldPopupMenu -label $val -command ("textField -e -text \"" + $val + "\" scriptEditorToolbarSearchField; setFocus scriptEditorToolbarSearchField;"); --$i; } } global proc searchAndSelectToolbarCmd(int $down) // // Runs search and select with the text in the toolbar search field. // { string $text = `textField -q -text scriptEditorToolbarSearchField`; if (size($text) > 0) { $curExecuter = `getCurrentExecuterControl`; cmdScrollFieldExecuter -e -searchDown $down -searchMatchCase false -searchWraps false -searchString $text $curExecuter; int $res = `cmdScrollFieldExecuter -q -searchAndSelect $curExecuter`; if (!$res) { warning (uiRes("m_scriptEditorPanel.kSearchFailed")); } addToSearchAndSelectHistory($text); // Using the version that doesn't reset the focus to the current Excuter. // Because in the new design, unlike the return/enter key in the mainkeyboard, // user press enter key in the numerical pad // won't release the focus in the search and select field. selectCurrentExecuterControlWithoutFocus; } } global proc updateSearchOptions(string $executer) { if (size($executer) == 0) $executer = `getCurrentExecuterControl`; cmdScrollFieldExecuter -e -searchDown `checkBoxGrp -q -value1 commandSearchOptions` -searchMatchCase `checkBoxGrp -q -value2 commandSearchOptions` -searchWraps `checkBoxGrp -q -value3 commandSearchOptions` -searchString `textField -q -text commandSearchField` $executer; } global proc searchAndSelect() { string $curExecuter = `getCurrentExecuterControl`; updateSearchOptions($curExecuter); int $res = `cmdScrollFieldExecuter -q -searchAndSelect $curExecuter`; if (!$res) { warning (uiRes("m_scriptEditorPanel.kSearchFailed")); } addToSearchAndSelectHistory(`textField -q -text commandSearchField`); } global proc searchAndReplace() { string $curExecuter = `getCurrentExecuterControl`; updateSearchOptions($curExecuter); string $sel = `cmdScrollFieldExecuter -q -selectedText $curExecuter`; string $searchText = `textField -q -text commandSearchField`; string $replaceText = `textField -q -text commandReplaceField`; // either we are starting from a previous find, and the text is already selected, in which case // we will replace then move on ... if ($sel == $searchText) { cmdScrollFieldExecuter -e -insertText $replaceText $curExecuter; cmdScrollFieldExecuter -q -searchAndSelect $curExecuter; // or we are starting out without a selection, so find the next string, and replace. // the next iteration will be for case 1 above }else { $res = `cmdScrollFieldExecuter -q -searchAndSelect $curExecuter`; if ($res) { cmdScrollFieldExecuter -e -insertText $replaceText $curExecuter; // search again for next spot to replace cmdScrollFieldExecuter -q -searchAndSelect $curExecuter; }else { warning (uiRes("m_scriptEditorPanel.kSearchReplaceFailed")); } } } global proc searchAndReplaceAll() { string $curExecuter = `getCurrentExecuterControl`; updateSearchOptions($curExecuter); string $searchText = `textField -q -text commandSearchField`; string $replaceText = `textField -q -text commandReplaceField`; cmdScrollFieldExecuter -e -replaceAll $searchText $replaceText $curExecuter; setFocus $curExecuter; } global proc destroySearchAndReplaceWindow() { if (`window -q -exists commandSearchAndReplaceWnd`) { updateSearchOptions(""); deleteUI -window commandSearchAndReplaceWnd; string $curExecuter = `getCurrentExecuterControl`; setFocus $curExecuter; } } global proc createSearchAndReplaceWindow() { if (`window -q -exists commandSearchAndReplaceWnd`) { // update the search field with the selected text string $executer = `getCurrentExecuterControl`; string $selText = `cmdScrollFieldExecuter -q -selectedText $executer`; if (size($selText) > 0) { textField -e -text $selText commandSearchField; }else { textField -e -text `cmdScrollFieldExecuter -q -searchString $executer` commandSearchField; } showWindow commandSearchAndReplaceWnd; return; }else { string $curExecuter = `getCurrentExecuterControl`; window -title (uiRes("m_scriptEditorPanel.kSearchAndReplaceWndTitle")) -sizeable false -minimizeButton false -maximizeButton false -toolbox true -width 440 -height 160 commandSearchAndReplaceWnd; $fl = `formLayout`; string $fwl = `text -width 80 -label (uiRes("m_scriptEditorPanel.kFindWhatLabel")) -align "right"`; string $fwtf = `textField -width 120 -enterCommand "searchAndSelect" -alwaysInvokeEnterCommandOnReturn true commandSearchField`; string $sb = `button -width 80 -label (uiRes("m_scriptEditorPanel.kSearch")) -command "searchAndSelect"`; string $rwl = `text -width 80 -label (uiRes("m_scriptEditorPanel.kReplaceWithLabel")) -align "right"`; string $rwtf = `textField -width 120 -enterCommand "searchAndReplace" -alwaysInvokeEnterCommandOnReturn true commandReplaceField`; string $rb = `button -width 80 -label (uiRes("m_scriptEditorPanel.kReplace")) -command "searchAndReplace"`; string $rab = `button -width 80 -label (uiRes("m_scriptEditorPanel.kReplaceAll")) -command "searchAndReplaceAll"`; string $cwb = `button -width 80 -label (uiRes("m_scriptEditorPanel.kClose")) -command "destroySearchAndReplaceWindow"`; string $execc = `getCurrentExecuterControl`; // update the text field texts if (`cmdScrollFieldExecuter -q -hasSelection $execc`) { string $selectedText = `cmdScrollFieldExecuter -q -selectedText $execc`; textField -e -text $selectedText $fwtf; textField -e -text $selectedText $rwtf; }else { string $prevSearchString = `cmdScrollFieldExecuter -q -searchString $execc`; textField -e -text $prevSearchString $fwtf; textField -e -text $prevSearchString $rwtf; } string $sol = `text -width 80 -label (uiRes("m_scriptEditorPanel.kSAROptions")) -align "right"`; string $so = `checkBoxGrp -numberOfCheckBoxes 3 -label1 (uiRes("m_scriptEditorPanel.kSAROptionsSearchDown")) -label2 (uiRes("m_scriptEditorPanel.kSAROptionsMatchCase")) -label3 (uiRes("m_scriptEditorPanel.kSAROptionsWrap")) -valueArray3 true false true -vertical commandSearchOptions`; if (size($curExecuter) > 0) { int $isSearchDown = `cmdScrollFieldExecuter -q -searchDown $curExecuter`; int $isMatchCase = `cmdScrollFieldExecuter -q -searchMatchCase $curExecuter`; int $isWraps = `cmdScrollFieldExecuter -q -searchWraps $curExecuter`; checkBoxGrp -e -valueArray3 $isSearchDown $isMatchCase $isWraps commandSearchOptions; } // we'll build the search form from right to left int $formMargin = 5; int $controlMargin = 5; formLayout -e -attachNone $cwb "top" -attachForm $cwb "bottom" $formMargin -attachForm $cwb "right" $formMargin -attachNone $cwb "left" -attachForm $sb "top" $formMargin -attachForm $sb "right" $formMargin -attachNone $sb "bottom" -attachNone $sb "left" -attachControl $rb "top" $controlMargin $sb -attachForm $rb "right" $formMargin -attachNone $rb "bottom" -attachNone $rb "left" -attachControl $rab "top" $controlMargin $rb -attachForm $rab "right" $formMargin -attachNone $rab "bottom" -attachNone $rab "left" -attachForm $fwl "top" $formMargin -attachNone $fwl "right" -attachNone $fwl "bottom" -attachForm $fwl "left" $formMargin -attachControl $rwl "top" $controlMargin $fwtf -attachNone $rwl "right" -attachNone $rwl "bottom" -attachForm $rwl "left" $formMargin -attachForm $fwtf "top" $formMargin -attachControl $fwtf "right" $controlMargin $sb -attachNone $fwtf "bottom" -attachControl $fwtf "left" $controlMargin $fwl -attachControl $rwtf "top" $controlMargin $fwtf -attachControl $rwtf "right" $controlMargin $rb -attachNone $rwtf "bottom" -attachControl $rwtf "left" $controlMargin $rwl -attachControl $sol "top" $controlMargin $rwtf -attachNone $sol "right" -attachNone $sol "bottom" -attachForm $sol "left" $formMargin -attachControl $so "top" $controlMargin $rwtf -attachControl $so "right" $controlMargin $rab -attachForm $so "bottom" $formMargin -attachControl $so "left" $controlMargin $sol $fl; showWindow; // set focus setFocus commandSearchField; } } global proc loadFileInNewTab() { global string $gCommandExecuterTabs; global string $gLastFocusedCommandExecuter; global string $gLastUsedDir; // First prompt for the file to load. string $dir = (size($gLastUsedDir) > 0) ? $gLastUsedDir : `internalVar -usd`; string $loadFile = commandScrollFieldPromptForFile((uiRes("m_scriptEditorPanel.kLoadScriptTitle")), $dir, 0, "all"); if (size($loadFile) > 0) { // Remember this directory for the next time. $gLastUsedDir = dirname($loadFile); // If we already have this file opened in another tab, just make that tab // active instead of loading the file again. if (selectExecuterTabByName($loadFile)) { return; } // Create a new tab and load the file in it. int $sel = 1; string $ext = fileExtension($loadFile); switch($ext) { case "py": buildNewExecuterTab(-1, "Python", "python", 0); break; case "mel": buildNewExecuterTab(-1, "MEL", "mel", 0); break; default: $sel = 0; addNewExecuterTab("", 0); break; } if ($sel) { // select the last tab created tabLayout -e -selectTabIndex `tabLayout -q -numberOfChildren $gCommandExecuterTabs` $gCommandExecuterTabs; selectCurrentExecuterControl(); } // Then load the file contents into the new field delegateCommandToFocusedExecuterWindow("-e -loadFile \"" + $loadFile + "\"", 0); // Get the filename and rename the tab. string $filename = `cmdScrollFieldExecuter -query -filename $gLastFocusedCommandExecuter`; if (size($filename) > 0) { renameCurrentExecuterTab($filename, 0); delegateCommandToFocusedExecuterWindow "-e -modificationChangedCommand executerTabModificationChanged" 0; delegateCommandToFocusedExecuterWindow "-e -fileChangedCommand executerTabFileChanged" 0; } } } global proc addNewExecuterTab( string $sourceType, int $promptRename) { int $commitChange = false; string $line; int $hasPython = `exists python`; if (!$hasPython) { $sourceType = "mel"; // go ahead and build tab if we aren't prompting rename, otherwise, // check that first if (!$promptRename) { $commitChange = true; $line = "MEL"; } } string $cancel = (uiRes("m_scriptEditorPanel.kCancel")); if ($hasPython && (size($sourceType) == 0)) { // if the input source type if not given (empty), then prompt user for type to add // "Python" and "MEL" are not localized because they are used in the logic $sourceType = `confirmDialog -title (uiRes("m_scriptEditorPanel.kSourceTypeTitle")) -message (uiRes("m_scriptEditorPanel.kSourceTypeChoiceMsg")) -button "MEL" -button "Python" -button $cancel -defaultButton "MEL" -dismissString $cancel`; // if user canceled then skip if ($sourceType == $cancel) { return; }else { // go ahead and build tab if we aren't prompting rename, otherwise, // check that first if (!$promptRename) { $commitChange = true; $line = $sourceType; } } } if ($promptRename) { // prompt the user for the name of the new tab string $add = (uiRes("m_scriptEditorPanel.kAddTab")); string $namePrompt = `promptDialog -title (uiRes("m_scriptEditorPanel.kNewTab")) -text $sourceType -message (uiRes("m_scriptEditorPanel.kTabName")) -button $add -cancelButton $cancel`; if ($namePrompt == $add) { $line = `promptDialog -q -text`; if (size($line) > 0) { $commitChange = true; }else { warning (uiRes("m_scriptEditorPanel.kInvalidTabNameWarning")); } } } // commit to building new tab if ($commitChange) { $sourceType = `tolower $sourceType`; if ($sourceType != "python") { // default to mel if not python $sourceType = "mel"; } buildNewExecuterTab(-1, $line, $sourceType, 1); // select the last tab created global string $gCommandExecuterTabs; tabLayout -e -selectTabIndex `tabLayout -q -numberOfChildren $gCommandExecuterTabs` $gCommandExecuterTabs; selectCurrentExecuterControl; } syncExecuterTabState(); } global proc renameCurrentExecuterTab( string $newName, int $dirty ) { if (size($newName) == 0) { // prompt the user for a name to rename to, must not be empty string $rename = (uiRes("m_scriptEditorPanel.kRename")); string $namePrompt = `promptDialog -title (uiRes("m_scriptEditorPanel.kRenameTab")) -message (uiRes("m_scriptEditorPanel.kTabName")) -button $rename`; if ($namePrompt == $rename) { $newName = `promptDialog -q -text`; } } if (size($newName) > 0) { // get the current tab, then rename it global string $gCommandExecuterTabs; global string $gCommandExecuterName[]; // get selected tab index (1 based) int $selTabIdx = `tabLayout -q -selectTabIndex $gCommandExecuterTabs`; string $tabName = $newName; // Is the new name a full (writable) filename? int $isWritable = isFullPathToScriptFile($newName, "-w"); int $isReadable = isFullPathToScriptFile($newName, "-r"); if ($isWritable || $isReadable) { $tabName = basename($newName, ""); // Set the tab tooltip to the full filename path string $tooltip = $newName; if (! $isWritable) { string $readOnly = (uiRes("m_scriptEditorPanel.kReadOnly")); $tabName += $readOnly; $tooltip += $readOnly; } tabLayout -e -tabTooltipIndex $selTabIdx $tooltip $gCommandExecuterTabs; } if ($dirty) { $tabName += " *"; } // set the new tab name tabLayout -e -tabLabelIndex $selTabIdx $tabName $gCommandExecuterTabs; // update the global array (if name is a filename, we save that) $gCommandExecuterName[$selTabIdx-1] = $newName; } else { warning (uiRes("m_scriptEditorPanel.kInvalidTabNameWarning")); } syncExecuterTabState(); } global proc string getCurrentExecuterTabLabel() { global string $gCommandExecuterTabs; // get selected tab index (0 based) int $selTabIdx = `tabLayout -q -selectTabIndex $gCommandExecuterTabs` - 1; // get tab label array string $tabLabels[] = `tabLayout -q -tabLabel $gCommandExecuterTabs`; if (size($tabLabels) > 0) { // Remove the 'dirty' flag from any tab labels which might have it. string $lbl = $tabLabels[$selTabIdx]; if (endsWith($lbl, " *")) { $lbl = startString($lbl, size($lbl)-2); // Remove " *" } return $lbl; }else { return ""; } } global proc string getCurrentExecuterFilename() { string $curExecuter = `getCurrentExecuterControl`; string $filename = `cmdScrollFieldExecuter -query -filename $curExecuter`; return $filename; } global proc string getCurrentExecuterTabType() { // get selected tab string $curExecuter = `getCurrentExecuterControl`; // get tab's source type string $executerTabType = `cmdScrollFieldExecuter -q -sourceType $curExecuter`; if ($executerTabType == "python") { return ".py"; }else if ($executerTabType == "mel") { return ".mel"; }else { return ""; } } global proc removeOtherExecuterTabs() { global string $gCommandExecuterTabs; // go through every other tab, and prompt user to remove (all, yes, no, cancel), build array of answers int $numTabs = `tabLayout -q -numberOfChildren $gCommandExecuterTabs`; int $curTab = `tabLayout -q -selectTabIndex $gCommandExecuterTabs` - 1; // 0 based value int $remTab[]; // get the controls string $array[] = `tabLayout -q -childArray $gCommandExecuterTabs`; string $execs[]; // if there is only one tab left, then do not delete! if ($numTabs <= 1) { warning (uiRes("m_scriptEditorPanel.kLastExecuterTabWarning")); return; } // for all other tabs int $i; string $all = (uiRes("m_scriptEditorPanel.kAll")); string $cancel = (uiRes("m_scriptEditorPanel.kCancel")); string $yes = (uiRes("m_scriptEditorPanel.kYes")); string $no = (uiRes("m_scriptEditorPanel.kNo")); // save the executers first for ($i = 0; $i < $numTabs; ++$i) { if ($i != $curTab) { // get current executer -- // get the tab at the index string $curFormLayout = $array[$i]; // get the formLayout children in this tab (according to how we built it) string $tabChldrn[] = `formLayout -q -childArray $curFormLayout`; // get the formLayout's first child which should be the cmdScrollFieldExecuter string $curExecuter = $tabChldrn[0]; // save for use below $execs[$i] = $curExecuter; } } // now go through and prompt (exec stored above as we may skip iterations here yet still need it later) for ($i = 0; $i < $numTabs; ++$i) { if ($i != $curTab) { // automatically remove if there is no text if (`cmdScrollFieldExecuter -q -textLength $execs[$i]` > 0) { // select tabLayout -e -selectTabIndex ($i+1) $gCommandExecuterTabs; // prompt to remove string $confirmRemove = `confirmDialog -title (uiRes("m_scriptEditorPanel.kRemoveExecuterTabTitle")) -message (uiRes("m_scriptEditorPanel.kRemoveExecuterTabPromptMsg")) -button $all -button $yes -button $no -button $cancel -cancelButton $cancel -defaultButton $yes -dismissString $cancel`; // if user canceled then skip if ($confirmRemove == $cancel) { return; }else if ($confirmRemove == $all) { // set everything afterwards to yes while ($i < $numTabs) { $remTab[$i] = 1; ++$i; } break; }else if ($confirmRemove == $yes) { $remTab[$i] = 1; }else if ($confirmRemove == $no) { $remTab[$i] = 0; } }else { $remTab[$i] = 1; } } } // select the old tab tabLayout -e -selectTabIndex ($curTab+1) $gCommandExecuterTabs; selectCurrentExecuterControl; // rebuild all the global arrays string $newExecuter[], $newExecuterLayout[], $newExecuterName[]; string $newExecuterType[], $newPopupMenus[]; global string $gCommandExecuter[]; global string $gCommandExecuterLayout[]; global string $gCommandExecuterName[]; global string $gCommandExecuterType[]; global string $gCommandPopupMenus[]; // now go through array and remove the ones which are to be removed. for ($i = 0; $i < $numTabs; ++$i) { if ( ($remTab[$i] == 0) || ($i == $curTab) ) { // copy array value if not to delete $newExecuter[size($newExecuter)] = $gCommandExecuter[$i]; $newExecuterLayout[size($newExecuterLayout)] = $gCommandExecuterLayout[$i]; $newExecuterName[size($newExecuterName)] = $gCommandExecuterName[$i]; $newExecuterType[size($newExecuterType)] = $gCommandExecuterType[$i]; $newPopupMenus[size($newPopupMenus)] = $gCommandPopupMenus[$i]; }else { // otherwise, we remove the tab // delete the actual control deleteUI $array[$i]; } } // save the new global arrays $gCommandExecuter = $newExecuter; $gCommandExecuterLayout = $newExecuterLayout; $gCommandExecuterName = $newExecuterName; $gCommandExecuterType = $newExecuterType; $gCommandPopupMenus = $newPopupMenus; syncExecuterTabState(); } global proc removeCurrentExecuterTab() { // Original method which to remove a tab, prompting user first. removeCurrentExecuterTab2(0); } // Added June 2016 - New method which takes a force param, which when true just // forcefully removes the tab without prompting. global proc removeCurrentExecuterTab2(int $force) { global string $gCommandExecuter[]; global string $gCommandExecuterLayout[]; global string $gCommandExecuterName[]; global string $gCommandExecuterType[]; global string $gCommandPopupMenus[]; global string $gCommandExecuterTabs; // if there is only one tab left, then do not delete! if (`tabLayout -q -numberOfChildren $gCommandExecuterTabs` <= 1) { warning (uiRes("m_scriptEditorPanel.kLastExecuterTabWarning")); return; } // If the tab is associated to a file and it has been modified prompt the // user if they want to save. string $curExecuter = `getCurrentExecuterControl`; saveCommandExecuterIfDirty($curExecuter); // prompt the user to see if they actually want to remove (only if there is text in this tab) if (!$force && (`cmdScrollFieldExecuter -q -textLength $curExecuter` > 0)) { string $cancel = (uiRes("m_scriptEditorPanel.kCancel")); string $confirmRemove = `confirmDialog -title (uiRes("m_scriptEditorPanel.kRemoveExecuterTabTitle")) -message (uiRes("m_scriptEditorPanel.kRemoveExecuterTabPromptMsg")) -button (uiRes("m_scriptEditorPanel.kYes")) -button $cancel -cancelButton $cancel -defaultButton $cancel -dismissString $cancel`; // if user canceled then skip if ($confirmRemove == $cancel) return; } // tab controls array string $array[] = `tabLayout -q -childArray $gCommandExecuterTabs`; // get selected tab index (now zero based) int $selTabIdx = `tabLayout -q -selectTabIndex $gCommandExecuterTabs` - 1; // the executer form to delete string $executerFormToDelete = $array[$selTabIdx]; // rebuild all the global arrays string $newExecuter[], $newExecuterLayout[], $newExecuterName[]; string $newExecuterType[], $newPopupMenus[]; int $i, $len = size($gCommandExecuter); for ($i = 0; $i < $len; ++$i) { if ($i != $selTabIdx) { // copy array value if not the one to delete $newExecuter[size($newExecuter)] = $gCommandExecuter[$i]; $newExecuterLayout[size($newExecuterLayout)] = $gCommandExecuterLayout[$i]; $newExecuterName[size($newExecuterName)] = $gCommandExecuterName[$i]; $newExecuterType[size($newExecuterType)] = $gCommandExecuterType[$i]; $newPopupMenus[size($newPopupMenus)] = $gCommandPopupMenus[$i]; } } // save the new global arrays $gCommandExecuter = $newExecuter; $gCommandExecuterLayout = $newExecuterLayout; $gCommandExecuterName = $newExecuterName; $gCommandExecuterType = $newExecuterType; $gCommandPopupMenus = $newPopupMenus; // actually delete the ui element deleteUI $executerFormToDelete; // assert; -numChildren < size($array) // select new tab, make it focused int $numChildren = `tabLayout -q -numberOfChildren $gCommandExecuterTabs`; int $newIdx = `min ($selTabIdx+1) $numChildren`; tabLayout -e -selectTabIndex $newIdx $gCommandExecuterTabs; selectCurrentExecuterControl; syncExecuterTabState(); } global proc buildNewExecuterTab(int $index, string $name, string $sourceType, int $userRequested) { global int $gScriptEditorMenuBarVisible; global string $gCommandExecuterTabs; // tabLayout global string $gCommandExecuter[]; // cmdScrollFieldExecuter of each tab global string $gCommandExecuterLayout[]; // formLayout of each tab global string $gCommandExecuterName[]; // tabname of each tab global string $gCommandExecuterType[]; // type (mel/python) of each tab global string $gCommandPopupMenus[]; // popupMenu of each cmdScrollFieldReporter/cmdScrollFieldExecuter global string $gExecuterBackupFileName; int $hasPython = `exists python`; if (!$hasPython && ($sourceType == "python")) { $sourceType = "mel"; } // if $index is out of bounds, we append to the current executer list if ( ($index < 0) || ($index > size($gCommandExecuter)) ){ $index = size($gCommandExecuter); } $gCommandExecuterType[$index] = $sourceType; $gCommandExecuterName[$index] = $name; // If name is a filepath, we save that string $tabName = basename($name, ""); // and for tab we want just the filename. // set tab layout as parent setParent $gCommandExecuterTabs; $gCommandExecuterLayout[$index] = `formLayout`; $gCommandExecuter[$index] = `eval("cmdScrollFieldExecuter -sourceType " + $sourceType + " ")`; cmdScrollFieldExecuter -e -showLineNumbers `optionVar -q commandExecuterShowLineNumbers` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -commandCompletion `optionVar -q commandExecuterCommandCompletion` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -objectPathCompletion `optionVar -q commandExecuterPathCompletion` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -showTooltipHelp `optionVar -q commandExecuterToolTipHelp` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -tabsForIndent `optionVar -q commandExecuterTabsForIndent` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -autoCloseBraces `optionVar -q commandExecuterAutoCloseBraces` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -spacesPerTab `optionVar -q commandExecuterSpacesPerTab` $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -searchWraps true $gCommandExecuter[$index]; int $curPopupIdx = size($gCommandPopupMenus); $gCommandPopupMenus[$curPopupIdx] = `popupMenu -markingMenu true -postMenuCommand "verifyCommandPopupMenus"`; buildScriptEditorCondensedPopupMenus($gCommandPopupMenus[$curPopupIdx], false); // fix form layout for executer formLayout -e -attachForm $gCommandExecuter[$index] "left" 0 -attachForm $gCommandExecuter[$index] "right" 0 -attachForm $gCommandExecuter[$index] "top" 0 -attachForm $gCommandExecuter[$index] "bottom" 2 $gCommandExecuterLayout[$index]; // rename the tab labels tabLayout -edit -tabLabel $gCommandExecuterLayout[$index] $tabName $gCommandExecuterTabs; cmdScrollFieldExecuter -e -receiveFocusCommand ("setLastFocusedCommandExecuter " + $gCommandExecuter[$index]) $gCommandExecuter[$index]; // Set the tab tooltip (if one). if ($tabName != $name) { tabLayout -edit -tabTooltip $gCommandExecuterLayout[$index] $name $gCommandExecuterTabs; } // Load contents if it is not a new pane created by the user. // No need to error check as -loadContents does not throw errors to screen. if($userRequested == 0) { // If the input name is a full path to a filename (that exists) then let's // load it directly instead of the backup. if (isFullPathToScriptFile($name, "-r")) { cmdScrollFieldExecuter -e -loadFile $name $gCommandExecuter[$index]; // Also connect this executer to the modificationChanged & fileChanged commands. cmdScrollFieldExecuter -e -modificationChangedCommand executerTabModificationChanged $gCommandExecuter[$index]; cmdScrollFieldExecuter -e -fileChangedCommand executerTabFileChanged $gCommandExecuter[$index]; } else { // Set up file name of executer tab contents string $currentExecuterBackupFileName = $gExecuterBackupFileName; int $fileIndex; if ($index > 0){ $fileIndex = $index - 1; $currentExecuterBackupFileName += ("-"+$fileIndex); } cmdScrollFieldExecuter -e -loadContents $currentExecuterBackupFileName $gCommandExecuter[$index]; } } cmdScrollFieldExecuter -e -select 0 0 $gCommandExecuter[$index]; // reset the current menubar visibility state, as the new tab assumes menu bar visible, // and is built only with condensed menus $gScriptEditorMenuBarVisible = 1; } global proc selectExecuterTabOffset(int $offset) // // Selected the executer tab with the offset from the current index. // ie. (0) -> current tab, (-1) -> previous tab, etc. // indices are modulated, and remain within the bounds of the number of tabs visible // { global string $gCommandExecuterTabs; int $numTabs = `tabLayout -q -numberOfChildren $gCommandExecuterTabs`; // return if there are no tabs if ($numTabs == 0) return; // get selected tab index, and from that, the new index (now zero based) int $selTabIdx = `tabLayout -q -selectTabIndex $gCommandExecuterTabs` - 1; int $newTabIdx = $selTabIdx + $offset; // modulate so within bounds while ($newTabIdx < 0) $newTabIdx += $numTabs; while ($newTabIdx >= $numTabs) $newTabIdx -= $numTabs; // assertion: 0 <= $newTabIdx < $numTabs // select the new tab (now one based) tabLayout -e -selectTabIndex ($newTabIdx + 1) $gCommandExecuterTabs; selectCurrentExecuterControl; } global proc syncExecuterTabState(){ global string $gCommandExecuterName[]; global string $gCommandExecuterType[]; global string $gCommandExecuterTabs; //sync the currently selected tab index optionVar -iv ScriptEditorExecuterTabIndex `tabLayout -q -selectTabIndex $gCommandExecuterTabs`; //sync the rest of the tab info int $i; if (`optionVar -exists ScriptEditorExecuterLabelArray`) { optionVar -clearArray ScriptEditorExecuterLabelArray; optionVar -clearArray ScriptEditorExecuterTypeArray; } for ($i = 0; $i < size($gCommandExecuterName); $i++){ optionVar -stringValueAppend ScriptEditorExecuterLabelArray $gCommandExecuterName[$i]; optionVar -stringValueAppend ScriptEditorExecuterTypeArray $gCommandExecuterType[$i]; } } global proc syncScriptEditorPanelToolbarAndMenu() { // When we have a filename: // - disable the 'execute' button (which is the one that clears the script after executing). // - disable the rename tab menu item. string $filename = getCurrentExecuterFilename(); if (size($filename) > 0) { iconTextButton -e -enable 1 executeAllButton; iconTextButton -e -enable 0 executeButton; if (`menuItem -exists seRenameTabMenu`) menuItem -e -enable 0 seRenameTabMenu; } else { iconTextButton -e -enable 1 executeAllButton; iconTextButton -e -enable 1 executeButton; if (`menuItem -exists seRenameTabMenu`) menuItem -e -enable 1 seRenameTabMenu; } } global proc saveCommandExecuterIfDirty(string $commandExecuter) { string $filename = `cmdScrollFieldExecuter -query -filename $commandExecuter`; if (size($filename) > 0) { // If the tab is associated to a file and it has been modified // prompt the user if they want to save. if (`cmdScrollFieldExecuter -q -modified $commandExecuter`) { string $save; string $yes = (uiRes("m_scriptEditorPanel.kYes")); string $no = (uiRes("m_scriptEditorPanel.kNo")); string $dialogDisabled = `getenv "MAYA_IGNORE_DIALOGS"`; if ((size($dialogDisabled) > 0) && ($dialogDisabled == "1")) { // If the ignore dialogs env var is set, then auto-save. $save = $yes; } else { // Prompt to save. string $saveMsg = `format -s $filename (uiRes("m_scriptEditorPanel.kSaveModified"))`; $save = `confirmDialog -title (uiRes("m_scriptEditorPanel.kModifiedTitle")) -message $saveMsg -icon "question" -button $yes -button $no -defaultButton $yes -cancelButton $no -dismissString $no`; } if ($save == $yes) { cmdScrollFieldExecuter -e -saveFile ("" + $filename + "") $commandExecuter; } } } } global proc syncExecuterBackupFiles() { global string $gCommandExecuter[]; global string $gExecuterBackupFileName; global string $gCommandExecuterName[]; if(`optionVar -q saveActionsScriptEditor`) { // clear the script editor temp dir first before writing temp files string $scriptEditorTempDir = (`internalVar -userPrefDir` + "scriptEditorTemp/"); string $tempFiles[] = `getFileList -folder $scriptEditorTempDir -filespec ($gExecuterBackupFileName+"*")`; string $file; for ($file in $tempFiles) { sysFile -delete ($scriptEditorTempDir + $file); } // save all the executer control text to files string $currentExecuterBackupFileName; int $fileIndex; int $i = 0; for($i = 0; $i < size($gCommandExecuter); $i++) { // Set up file name of executer tab contents $currentExecuterBackupFileName = $gExecuterBackupFileName; if ($i > 0) { $fileIndex = $i - 1; $currentExecuterBackupFileName += ("-" + $fileIndex); } // Auto-save all the scratch-pad tabs. if (!isFullPathToScriptFile($gCommandExecuterName[$i], "-w")) { cmdScrollFieldExecuter -e -storeContents $currentExecuterBackupFileName $gCommandExecuter[$i]; } else { // If the tab is associated to a file and it has been modified // prompt the user if they want to save. saveCommandExecuterIfDirty($gCommandExecuter[$i]); } } } } global proc gotoLine(string $line) // // Parses and goes to the specified line. // { string $validLine = `match "^[0-9]+$" $line`; int $numLine; if (size($validLine) > 0) { $numLine = int($validLine); selectCurrentExecuterControl; delegateCommandToFocusedExecuterWindow ("-e -currentLine " + $numLine, 0); // check if we already have this line number in the history global int $gCommandExecuterGoto[]; int $found = false; int $len = size($gCommandExecuterGoto); int $i; for ($i in $gCommandExecuterGoto) { if ($i == $numLine) { $found = true; } } // if not, then append to history if (!$found) { if ($len == 4) { // shift history up by one and append this last for ($i = 1; $i < 4; ++$i) { $gCommandExecuterGoto[$i-1] = $i; } --$len; } // add to end $gCommandExecuterGoto[$len++] = $validLine; } // select the executer selectCurrentExecuterControl; }else { warning (uiRes("m_scriptEditorPanel.kInvalidLineNumWarning")); } } global proc gotoLineToolbarCmd() // // // { string $line = `textField -q -text scriptEditorToolbarGotoField`; gotoLine($line); } global proc gotoLineToolbarPopupUpdate() // // Updates the RMB popups for the toolbar goto line field. // { global int $gCommandExecuterGoto[]; popupMenu -e -deleteAllItems scriptEditorToolbarGotoFieldPopupMenu; // create the new menu items int $i = size($gCommandExecuterGoto) - 1; while ($i >= 0) { int $val = $gCommandExecuterGoto[$i]; menuItem -parent scriptEditorToolbarGotoFieldPopupMenu -label ("" + $val) -command ("gotoLine(" + $val + ")"); --$i; } } global proc gotoLinePrompt() // // Prompts the user for the line to move the cursor to in the current command executer. // { string $goStr = (uiRes("m_scriptEditorPanel.kGo")); string $prompt = `promptDialog -title (uiRes("m_scriptEditorPanel.kLineNumber")) -message (uiRes("m_scriptEditorPanel.kLineNumMessage")) -button $goStr`; if ($prompt == $goStr) { string $line = `promptDialog -q -text`; gotoLine($line); } } global proc addScriptEditorPanel (string $whichPanel) // // Description: // Add the panel to a layout. // Parent the editors to that layout and create any other // controls required. // { // Predefines scriptEditorPredefines; // global int $gScriptEditorMenuBarVisible; global string $gCommandPopupMenus[]; global string $gCommandLayout; global string $gCommandReporter; global string $gCommandExecuter[]; global string $gCommandExecuterLayout[]; global string $gCommandExecuterName[]; global string $gCommandExecuterType[]; global string $gLastFocusedCommandExecuter; global string $gLastFocusedCommandReporter; global string $gLastFocusedCommandControl; $gScriptEditorMenuBarVisible = 1; $gLastFocusedCommandControl = ""; $gLastFocusedCommandReporter = ""; $gLastFocusedCommandExecuter = ""; $gCommandExecuterLayout = {}; $gCommandExecuter = {}; $gCommandPopupMenus = {}; global string $gCommandExecuterTabs; global string $gCommandExecuterTabsPane; string $editorControl = ($whichPanel + "EditorControl"); int $hasPython = `exists python`; // Make sure that there is no template active setUITemplate -pushTemplate NONE; // clear the option vars from before first; if (size($gCommandExecuter) == 0) { // on the first instance of the script editor, we load the arrays from the option vars if (`optionVar -exists ScriptEditorExecuterTypeArray`) { // We first load them into temporary arrays and then make sure that we // don't have any that are file's which are duplicated in array. string $tempCommandExecuterName[] = `optionVar -q ScriptEditorExecuterLabelArray`; string $tempCommandExecuterType[] = `optionVar -q ScriptEditorExecuterTypeArray`; clear($gCommandExecuterName); clear($gCommandExecuterType); int $len = size($tempCommandExecuterName); int $i; int $index; for ($i = 0; $i < $len; ++$i) { // If this item points to a file, make sure we don't already have it. // If this item points to a scratch tab, just add it. if (isFullPathToScriptFile($tempCommandExecuterName[$i], "-r")) { if (0 == stringArrayContains($tempCommandExecuterName[$i], $gCommandExecuterName)) { $gCommandExecuterName[$index] = $tempCommandExecuterName[$i]; $gCommandExecuterType[$index] = $tempCommandExecuterType[$i]; $index++; } } else { $gCommandExecuterName[$index] = $tempCommandExecuterName[$i]; $gCommandExecuterType[$index] = $tempCommandExecuterType[$i]; $index++; } } } }else { if (`optionVar -exists ScriptEditorExecuterTypeArray`) { optionVar -clearArray ScriptEditorExecuterLabelArray; optionVar -clearArray ScriptEditorExecuterTypeArray; } } // Define the standard panel // string $widgetList[]; $widgetList[2] = `scriptedPanel -query -control $whichPanel`; $widgetList[0] = `formLayout`; $widgetList[3] = `frameLayout -visible true -borderVisible false -labelVisible false -collapsable false -collapse true`; $widgetList[4] = `formLayout -visible true`; $widgetList[5] = `flowLayout -columnSpacing 4`; setParent $widgetList[0]; $widgetList[6] = `formLayout -visible true`; formLayout -edit -attachForm $widgetList[3] top 0 -attachForm $widgetList[3] right 0 -attachForm $widgetList[3] left 0 -attachControl $widgetList[6] top 0 $widgetList[3] -attachForm $widgetList[6] bottom 0 -attachForm $widgetList[6] right 0 -attachForm $widgetList[6] left 0 $widgetList[0]; setParent $widgetList[0]; // Add tools to the tool layout // int $iconSize = 23; setParent $widgetList[5]; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kLoadScript")) -image "openScript.png" -command "handleScriptEditorAction \"load\"" openScriptButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kSourceScript")) -image "sourceScript.png" -command "handleScriptEditorAction \"source\"" sourceScriptButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kSaveScript")) -image "save.png" -command "handleScriptEditorAction \"save\"" saveScriptButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kSaveScriptToShelf")) -image "saveToShelf.png" -command "handleScriptEditorAction \"saveToShelf\"" saveScriptToShelfButton; separator -height $iconSize -horizontal false -style single fileSeperator; iconTextButton -width $iconSize -height$iconSize -annotation (uiRes("m_scriptEditorPanel.kClearHistory")) -image "clearHistory.png" -command "handleScriptEditorAction \"clearHistory\"" clearHistoryButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kClearInput")) -image "clearInput.png" -command "handleScriptEditorAction \"clearInput\"" clearInputButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kClearAll")) -image "clearAll.png" -command "handleScriptEditorAction \"clearAll\"" clearAllButton; separator -height $iconSize -horizontal false -style single clearSeperator; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kShowHistory")) -image "showHistory.png" -command "handleScriptEditorAction \"maximizeHistory\"" showHistoryButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kShowInput")) -image "showInput.png" -command "handleScriptEditorAction \"maximizeInput\"" showInputButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kShowBoth")) -image "showBoth.png" -command "handleScriptEditorAction \"maximizeBoth\"" showBothButton; separator -height $iconSize -horizontal false -style single showSeperator; iconTextCheckBox -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kEchoAllCommands")) -image "echoCommands.png" -changeCommand "handleScriptEditorAction \"echoAllCommands\"" echoAllCommandsButton; // echo all commands initial icon state if (`optionVar -exists echoAllLines`) { iconTextCheckBox -e -v (`optionVar -q echoAllLines`) echoAllCommandsButton; } iconTextCheckBox -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kShowLineNumbers")) -image "showLineNumbers.png" -changeCommand "handleScriptEditorAction \"showLineNumbers\"" showLineNumbersButton; // show line numbers initial icon state if (`optionVar -exists commandExecuterShowLineNumbers`) { iconTextCheckBox -e -v (`optionVar -q commandExecuterShowLineNumbers`) showLineNumbersButton; } separator -height $iconSize -horizontal false -style single optionsSeperator; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kExecuteAll")) -image "executeAll.png" -command "handleScriptEditorAction \"executeAll\"" executeAllButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kExecute")) -image "execute.png" -command "handleScriptEditorAction \"execute\"" executeButton; separator -height $iconSize -horizontal false -style single executeSeperator; textField -width 120 -height 20 -annotation (uiRes("m_scriptEditorPanel.kSASToolbarField")) -enterCommand "searchAndSelectToolbarCmd(true)" -alwaysInvokeEnterCommandOnReturn true scriptEditorToolbarSearchField; popupMenu -postMenuCommand "searchAndSelectToolbarPopupUpdate" scriptEditorToolbarSearchFieldPopupMenu; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kSASToolbarDownButton")) -image "searchDown.png" -command "searchAndSelectToolbarCmd(true)" scriptEditorToolbarSearchDownButton; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kSASToolbarUpButton")) -image "searchUp.png" -command "searchAndSelectToolbarCmd(false)" scriptEditorToolbarSearchDownUp; separator -height $iconSize -horizontal false -style single searchSeperator; textField -width 30 -height 20 -annotation (uiRes("m_scriptEditorPanel.kGotoLineToolbarField")) -enterCommand "gotoLineToolbarCmd" -alwaysInvokeEnterCommandOnReturn true scriptEditorToolbarGotoField; popupMenu -postMenuCommand "gotoLineToolbarPopupUpdate" scriptEditorToolbarGotoFieldPopupMenu; iconTextButton -width $iconSize -height $iconSize -annotation (uiRes("m_scriptEditorPanel.kGotoLineToolbarButton")) -image "gotoLine.png" -command "gotoLineToolbarCmd" scriptEditorToolbarGotoLineButton; int $formMargin = 2; // Layout the toolbar // setParent $widgetList[4]; formLayout -edit -attachForm $widgetList[5] "left" $formMargin -attachForm $widgetList[5] "top" $formMargin -attachForm $widgetList[5] "bottom" $formMargin -attachForm $widgetList[5] "right" 0 $widgetList[4]; // Parent the editors to the editor layout // setParent $widgetList[6]; { // build the panels first $gCommandLayout = `paneLayout -configuration "horizontal2"`; $gCommandReporter = `cmdScrollFieldReporter -width 20 -height 20`; cmdScrollFieldReporter -e -receiveFocusCommand ("setLastFocusedCommandReporter " + $gCommandReporter) $gCommandReporter; $gCommandPopupMenus[size($gCommandPopupMenus)] = `popupMenu -markingMenu true -postMenuCommand "verifyCommandPopupMenus"`; buildScriptEditorCondensedPopupMenus($gCommandPopupMenus[size($gCommandPopupMenus)-1], true); loadCommandReporterOptionVars($gCommandReporter); setLastFocusedCommandReporter $gCommandReporter; $gCommandExecuterTabsPane = `paneLayout -configuration "vertical2" -staticWidthPane 2`; $gCommandExecuterTabs = `tabLayout -selectCommand "selectCurrentExecuterControl" -showNewTab true -newTabCommand "handleScriptEditorAction \"addExecuterTab\"" -borderStyle "none"`; if (size($gCommandExecuterName) == 0) { // build all new buildNewExecuterTab(-1, "MEL", "mel", 0); if ($hasPython) { buildNewExecuterTab(-1, "Python", "python", 0); } }else { // don't need to update name, just build with the other info int $len = size($gCommandExecuterName); int $i; for ($i = 0; $i < $len; ++$i) { buildNewExecuterTab($i, $gCommandExecuterName[$i], $gCommandExecuterType[$i], 0); } } if (size($gCommandExecuterName) > 0) setLastFocusedCommandExecuter $gCommandExecuter[0]; // help sidebar setParent $gCommandExecuterTabsPane; global string $gCommandExecuterSideBar; global string $gCommandExecuterSideBarHelpForm; global string $gCommandExecuterSideBarHelpField; global string $gCommandExecuterSideBarHelpResults; global int $gCommandExecuterShowQuickHelp; $gCommandExecuterSideBar = `tabLayout`; $gCommandExecuterSideBarHelpForm = `formLayout -width 120`; $gCommandExecuterSideBarHelpField = `textField -height 24 -enterCommand "showFieldCmdQuickHelp" -alwaysInvokeEnterCommandOnReturn true`; $gCommandExecuterSideBarHelpResults = `textScrollList -doubleClickCommand "doubleClickCmdQuickHelp" -allowMultiSelection on`; // popup menu to hide quick help popupMenu; menuItem -radialPosition "N" -label (uiRes("m_scriptEditorPanel.kShowDetailedHelp")) -command "showFieldCmdDocumentation"; menuItem -radialPosition "S" -label (uiRes("m_scriptEditorPanel.kHideQuickHelp")) -command "toggleCmdQuickHelp(0, 0)"; tabLayout -e -tabLabel $gCommandExecuterSideBarHelpForm (uiRes("m_scriptEditorPanel.kQuickHelp")) $gCommandExecuterSideBar; formLayout -e -attachForm $gCommandExecuterSideBarHelpField top 0 -attachForm $gCommandExecuterSideBarHelpField left 0 -attachForm $gCommandExecuterSideBarHelpField right 0 -attachNone $gCommandExecuterSideBarHelpField bottom -attachControl $gCommandExecuterSideBarHelpResults top 2 $gCommandExecuterSideBarHelpField -attachForm $gCommandExecuterSideBarHelpResults left 0 -attachForm $gCommandExecuterSideBarHelpResults right 0 -attachForm $gCommandExecuterSideBarHelpResults bottom 0 $gCommandExecuterSideBarHelpForm; // show and attach forms accordingly // NOTE: move formLayout attachments out of func if we add new side bars! toggleCmdQuickHelp($gCommandExecuterShowQuickHelp, 1); formLayout -e -attachForm $gCommandLayout left 0 -attachForm $gCommandLayout right 0 -attachForm $gCommandLayout top 0 -attachForm $gCommandLayout bottom 0 $widgetList[6]; } // menuBarLayout is turned on for this editor - // create the top level menus // setParent $widgetList[2]; // build the menus { global string $gScriptEditorMenuBarPrefix; buildScriptEditorMenus($widgetList[2], $gScriptEditorMenuBarPrefix, false, false); addContextHelpProc $whichPanel "buildScriptEditorContextHelpItems"; doHelpMenu $whichPanel $whichPanel; } // select the previous executer tab (if one was saved) // if (`optionVar -exists ScriptEditorExecuterTabIndex`) { int $prevIdx = `optionVar -q ScriptEditorExecuterTabIndex`; if ( (0 < $prevIdx) && ($prevIdx <= `tabLayout -q -numberOfChildren $gCommandExecuterTabs`) ) { tabLayout -e -selectTabIndex $prevIdx $gCommandExecuterTabs; } } setUITemplate -popTemplate; selectCurrentExecuterControl; scriptJob -parent $whichPanel -event "quitApplication" ("removeScriptEditorPanel " + $whichPanel); } global proc removeScriptEditorPanel (string $whichPanel) // // Description: // Remove the panel from a layout. // Delete controls. // { string $editorControl = ($whichPanel + "EditorControl"); global string $gCommandExecuterTabs; global string $gCommandReporter; global string $gCommandExecuter[]; global string $gCommandExecuterName[]; global string $gCommandExecuterType[]; global string $gLastFocusedCommandExecuter; global string $gLastFocusedCommandReporter; global string $gLastFocusedCommandControl; // save reporter options saveCommandReporterOptionVars($gCommandReporter); // save out the tab index optionVar -iv ScriptEditorExecuterTabIndex `tabLayout -q -selectTabIndex $gCommandExecuterTabs`; // store contents of script editor tabs into backup files syncExecuterBackupFiles(); // update the optionvar keeping the the arrays if (`optionVar -exists ScriptEditorExecuterLabelArray`) { optionVar -clearArray ScriptEditorExecuterLabelArray; optionVar -clearArray ScriptEditorExecuterTypeArray; } for ($i = 0; $i < size($gCommandExecuter); ++$i) { optionVar -stringValueAppend ScriptEditorExecuterLabelArray $gCommandExecuterName[$i]; optionVar -stringValueAppend ScriptEditorExecuterTypeArray $gCommandExecuterType[$i]; } // no controls are showing, so we clear all the focused control vars $gLastFocusedCommandExecuter = ""; $gLastFocusedCommandReporter = ""; $gLastFocusedCommandControl = ""; destroySearchAndReplaceWindow; } global proc createScriptEditorPanel (string $whichPanel) // // Description: // Define the editors that are used in this panel. // No controls are created at this point. // { // create unique names for editors based on panel name // string $editorControl = ($whichPanel + "EditorControl"); } global proc deleteScriptEditorPanel (string $whichPanel) // // Description: // This proc will delete the contents of the panel, but not // the panel itself. // // Note: // We only need to delete editors here. Other UI will be taken care of // by the remove proc. // { string $editorControl = ($whichPanel + "EditorControl"); } global proc string saveStateScriptEditorPanel (string $whichPanel) // // Description: // This proc returns a string that when executed will restore the // current state of the panel elements. // { string $editorControl = ($whichPanel + "EditorControl"); return (""); } global proc showScriptEditorPanel () // // Description: // This proc replaces the currently focused panel with script editor panel // if it's not among visible panels. { global string $gScriptEditorPanel; string $panels[] = `getPanel -visiblePanels`; if(stringArrayCount("scriptEditorPanel1", $panels) == 0) { string $currentPanel = `getPanel -withFocus`; if(stringArrayCount($currentPanel, $panels) == 0) { $currentPanel = $panels[0]; } scriptedPanel -edit -replacePanel $currentPanel "scriptEditorPanel1"; } } global proc executerTabModificationChanged(int $m) { string $filename = getCurrentExecuterFilename(); if (size($filename) > 0) { renameCurrentExecuterTab($filename, $m); } } global proc executerTabFileChanged(string $file) { string $yes = (uiRes("m_scriptEditorPanel.kYes")); string $no = (uiRes("m_scriptEditorPanel.kNo")); string $dialogDisabled = `getenv "MAYA_IGNORE_DIALOGS"`; string $doAction; int $fileExists = isFullPathToScriptFile($file, "-r"); if ((size($dialogDisabled) > 0) && ($dialogDisabled == "1")) { // If the ignore dialogs env var is set, then auto-reload the file. $doAction = $yes; } else { // Prompt to either reload file or keep non existing file. string $parent; if (`scriptedPanel -q -exists scriptEditorPanel1`) { $parent = "scriptEditorPanel1Window"; } if ($fileExists) { string $reloadMsg = `format -s $file (uiRes("m_scriptEditorPanel.kReloadFile"))`; $doAction = `confirmDialog -title (uiRes("m_scriptEditorPanel.kReloadTitle")) -message $reloadMsg -icon "question" -button $yes -button $no -defaultButton $yes -cancelButton $no -dismissString $no -parent $parent`; } else { string $keepMsg = `format -s $file (uiRes("m_scriptEditorPanel.kKeepFile"))`; $doAction = `confirmDialog -title (uiRes("m_scriptEditorPanel.kKeepTitle")) -message $keepMsg -icon "question" -button $yes -button $no -defaultButton $no -cancelButton $yes -dismissString $yes -parent $parent`; } } // First switch to the tab which contains this file. if (selectExecuterTabByName($file)) { if ($fileExists && ($doAction == $yes)) { // Then reload the file contents into the field. delegateCommandToFocusedExecuterWindow("-e -loadFile \"" + $file + "\"", 0); } else if (!$fileExists && ($doAction == $no)) { // Then remove this current tab (which contains this file). removeCurrentExecuterTab2(true); } } } global proc int isFullPathToScriptFile(string $f, string $test) { // In order to be a full path, we must have a directory. string $dir = dirname($f); return( size($dir) && `filetest $test $f` ); }