1/******************************************************************************
2	NintendoWare for CTR Maya Plugin
3
4	File:         NW4C_SetFrameExtensionList.mel
5	Description:  set frame extension list to file node
6	Date:         2010/04/28
7
8	Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
9******************************************************************************/
10
11/******************************************************************************
12	frame extension list
13******************************************************************************/
14global proc string nw4cSetFrameExtensionList_Get_FrameExtensionList(string $node)
15{
16	string $val = (`attributeQuery -n $node -ex "nw4cFeList"`) ?
17		(string)`getAttr ($node + ".nw4cFeList")` : "";
18	return $val;
19}
20
21global proc nw4cSetFrameExtensionList_Add_FrameExtensionList(string $node)
22{
23	if (!`attributeQuery -n $node -ex "nw4cFeList"`)
24	{
25		addAttr -ln "nw4cFeList" -dt "string" -h 1 $node;
26	}
27}
28
29global proc nw4cSetFrameExtensionList_Set_FrameExtensionList(string $node, string $val)
30{
31	nw4cSetFrameExtensionList_Add_FrameExtensionList($node);
32	setAttr ($node + ".nw4cFeList") -typ "string" $val;
33}
34
35proc SetJob_FrameExtensionList(string $node)
36{
37	if (!`attributeQuery -n $node -ex "nw4cFeList"`)
38	{
39		return;
40	}
41	scriptJob -p nw4cSetFrameExtensionList_List -rp -ac ($node + ".nw4cFeList")
42		("textFieldGrp -e -tx (`nw4cSetFrameExtensionList_Get_FrameExtensionList "
43			+ $node + "`) nw4cSetFrameExtensionList_List");
44}
45
46global proc nw4cSetFrameExtensionList_ListCB(string $mainNode)
47{
48	string $val = `textFieldGrp -q -tx nw4cSetFrameExtensionList_List`;
49	$val = strip($val);
50	if (match("^-", $val) != "" ||
51		match("-$", $val) != "")
52	{
53		error ("Frame extension list is wrong: " + $val);
54	}
55	if (!`getAttr ($mainNode + ".ufe")`)
56	{
57		error ("Turn on use frame extension attribute: " + $mainNode);
58	}
59	nw4cSetFrameExtensionList_Set_FrameExtensionList($mainNode, $val);
60	SetJob_FrameExtensionList($mainNode);
61}
62
63/******************************************************************************
64	update window
65******************************************************************************/
66global proc nw4cSetFrameExtensionList_UpdateWindow()
67{
68	//-----------------------------------------------------------------------------
69	// get selection
70	string $files[] = `ls -sl -typ file`;
71	if (size($files) == 0)
72	{
73		string $mats[] = `ls -sl -mat`;
74		for ($mat in $mats)
75		{
76			string $hist[] = `listHistory $mat`;
77			for ($node in $hist)
78			{
79				if (`nodeType $node` == "file")
80				{
81					$files[size($files)] = $node;
82					//break;
83				}
84			}
85		}
86	}
87	int $enableFlag = (size($files) == 1);
88
89	//-----------------------------------------------------------------------------
90	// set node name
91	string $nodeName;
92	if ($enableFlag)
93	{
94		$nodeName = $files[0];
95	}
96	else if (size($files) > 1)
97	{
98		$nodeName = "(Multi node is selected)";
99	}
100	else
101	{
102		$nodeName = "(None)";
103	}
104	text -e -l $nodeName nw4cSetFrameExtensionList_NodeName;
105
106	//-----------------------------------------------------------------------------
107	// set current attr & change command
108	if ($enableFlag)
109	{
110		string $node = $files[0];
111
112		textFieldGrp -e -tx `nw4cSetFrameExtensionList_Get_FrameExtensionList $node`
113			-cc ("nw4cSetFrameExtensionList_ListCB " + $node)
114			nw4cSetFrameExtensionList_List;
115
116		SetJob_FrameExtensionList($node);
117	}
118
119	//-----------------------------------------------------------------------------
120	// set enable state
121	control -e -en $enableFlag nw4cSetFrameExtensionList_List;
122	control -e -en $enableFlag nw4cSetFrameExtensionList_Sample;
123}
124
125/******************************************************************************
126	main
127******************************************************************************/
128global proc NW4C_SetFrameExtensionList()
129{
130	//-----------------------------------------------------------------------------
131	// create window
132	int $wd = 400;
133	int $ht = 228;
134	if (!`window -exists nw4cSetFrameExtensionList_Win`)
135	{
136		window -t "NW4C Set Frame Extension List" -wh $wd $ht -mxb 0 -mb 1
137			nw4cSetFrameExtensionList_Win;
138		menu -l "Help";
139		menuItem -l ("Help on " + `window -q -t nw4cSetFrameExtensionList_Win` + "...")
140			-c "NW4C_ShowHelp \"html/NW4C_SetFrameExtensionList.html\" \"\"";
141
142		columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 4;
143
144		//-----------------------------------------------------------------------------
145		// node name
146		frameLayout -l "Selected File Node" -cll 0 -cl 0 -bv 1 -bs "etchedIn";
147			columnLayout -adj 1 -cal "center" -rs 8;
148
149			text -l "" nw4cSetFrameExtensionList_NodeName;
150
151			setParent ..; // columnLayout
152		setParent ..; // frameLayout
153
154		//-----------------------------------------------------------------------------
155		// set
156		frameLayout -l "Set" -cll 0 -cl 0 -bv 1 -bs "etchedIn";
157			string $setForm = `formLayout -nd 100`;
158				textFieldGrp -l "" -tx "" -cw2 1 360 -adj 2
159					nw4cSetFrameExtensionList_List;
160				text -l "ex.  \"1,2,3\"  or  \"1-3\"  or  \"1-3,10\"" -al "center"
161					nw4cSetFrameExtensionList_Sample;
162			formLayout -e
163				-af nw4cSetFrameExtensionList_List "left" 0
164				-af nw4cSetFrameExtensionList_List "top" 8
165				-af nw4cSetFrameExtensionList_List "right" 10
166				-an nw4cSetFrameExtensionList_List "bottom"
167
168				-af nw4cSetFrameExtensionList_Sample "left" 8
169				-ac nw4cSetFrameExtensionList_Sample "top" 8 nw4cSetFrameExtensionList_List
170				-af nw4cSetFrameExtensionList_Sample "right" 8
171				-af nw4cSetFrameExtensionList_Sample "bottom" 8
172				$setForm;
173			setParent ..; // formLayout
174		setParent ..; // frameLayout
175
176		//-----------------------------------------------------------------------------
177		// close button
178		string $closeCmd = "deleteUI nw4cSetFrameExtensionList_Win";
179		string $form = `formLayout -nd 100`;
180			string $closeBtn = `button -h 26 -l "Close" -c $closeCmd`;
181			formLayout -e
182				-af $closeBtn "top" 0
183				-af $closeBtn "left" 0
184				-af $closeBtn "bottom" 0
185				-af $closeBtn "right" 0
186				$form;
187		setParent ..; // formLayout
188
189		setParent ..; // columnLayout
190
191		//setFocus $closeBtn;
192		setFocus nw4cSetFrameExtensionList_List;
193
194		//-----------------------------------------------------------------------------
195		// set selection change job
196		scriptJob -p nw4cSetFrameExtensionList_Win
197			-e "SelectionChanged" "nw4cSetFrameExtensionList_UpdateWindow";
198	}
199	if (`window -q -w nw4cSetFrameExtensionList_Win` < $wd)
200	{
201		window -e -w $wd nw4cSetFrameExtensionList_Win;
202	}
203	if (`window -q -h nw4cSetFrameExtensionList_Win` < $ht)
204	{
205		window -e -h $ht nw4cSetFrameExtensionList_Win;
206	}
207	//window -e -wh $wd $ht nw4cSetFrameExtensionList_Win;
208
209	//-----------------------------------------------------------------------------
210	// update window
211	nw4cSetFrameExtensionList_UpdateWindow();
212
213	//-----------------------------------------------------------------------------
214	// show window
215	showWindow nw4cSetFrameExtensionList_Win;
216}
217
218