Last active
May 16, 2016 15:06
-
-
Save hmasato/64427eb43ad89742b811 to your computer and use it in GitHub Desktop.
[Maya, mel] _scriptEditor_replaceSelected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//hmasato | |
//https://gist.github.com/hmasato/64427eb43ad89742b811 | |
// | |
//_scriptEditor_replaceSelected | |
// | |
proc _scriptEditor_replaceSelected(string $src, string $dst) | |
{ | |
global string $gLastFocusedCommandExecuter; | |
string $ce = $gLastFocusedCommandExecuter; | |
if(! `cmdScrollFieldExecuter -q -hasSelection $ce`) return; | |
string $str = `cmdScrollFieldExecuter -q -selectedText $ce`; | |
string $ret = substituteAllString($str, $src, $dst); | |
if($ret == $str) return; | |
cmdScrollFieldExecuter -e -insertText $ret $ce; | |
} | |
//----------------- | |
//sample: command | |
//----------------- | |
// | |
//----- 1. "C:\Temp\test.txt" => "C:/Temp/test.txt" | |
//_scriptEditor_replaceSelected("\\", "/"); | |
//----- 2. "C:/Temp/test.txt" => "C:\Temp\test.txt" | |
//_scriptEditor_replaceSelected("/", "\\"); | |
//----- 3. "C:\Temp\test.txt" => "C:\\Temp\\test.txt" | |
//_scriptEditor_replaceSelected("\\", "\\\\"); | |
//----- 4. "C:/Temp/test.txt" => "C:\\Temp\\test.txt" | |
//_scriptEditor_replaceSelected("/", "\\\\"); | |
//----------------- | |
//sample: add to scriptEditor's menu | |
//----------------- | |
/* | |
global proc OT_scriptEditor_bs2s() { _scriptEditor_replaceSelected("\\", "/"); } | |
global proc OT_scriptEditor_s2bs() { _scriptEditor_replaceSelected("/", "\\"); } | |
global proc OT_scriptEditor_bs2dbs() { _scriptEditor_replaceSelected("\\", "\\\\"); } | |
global proc OT_scriptEditor_s2dbs() { _scriptEditor_replaceSelected("/", "\\\\"); } | |
global proc OT_scriptEditor_dbs2bs() { _scriptEditor_replaceSelected("\\\\", "\\"); } | |
proc _scriptEditor_addEditMenu() | |
{ | |
string $panel = `scriptedPanel -q -control "scriptEditorPanel1"`; | |
string $parentMenu = ""; | |
string $items[] = {}; | |
$items = `menuBarLayout -q -menuArray $panel`; | |
for($m in $items){ | |
$m = $panel + "|" + $m; | |
if("Edit" != `menu -q -l $m`) continue; | |
$parentMenu = $m; | |
break; | |
} | |
if($parentMenu == "") return; | |
int $i = 0; | |
$items = `menu -q -itemArray $parentMenu`; | |
for($m in $items) | |
{ | |
$i ++; | |
string $l = `menuItem -q -l $m`; | |
if($l != "Paste") continue; | |
$l = `menuItem -q -l $items[$i]`; | |
if(match("^[\[]", $l) != "") continue; | |
$m = `menuItem -p $parentMenu -insertAfter $m -l ("[ \\ -> / ]") -c ("OT_scriptEditor_bs2s();")`; | |
$m = `menuItem -p $parentMenu -insertAfter $m -l ("[ / -> \\ ]") -c ("OT_scriptEditor_s2bs();")`; | |
// $m = `menuItem -p $parentMenu -insertAfter $m -l ("[ \\ -> \\\\ ]") -c ("OT_scriptEditor_bs2dbs();")`; | |
// $m = `menuItem -p $parentMenu -insertAfter $m -l ("[ / -> \\\\ ]") -c ("OT_scriptEditor_s2dbs();")`; | |
// $m = `menuItem -p $parentMenu -insertAfter $m -l ("[ \\\\ -> \\ ]") -c ("OT_scriptEditor_dbs2bs();")`; | |
break; | |
} | |
} | |
_scriptEditor_addEditMenu(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment