/*
	ML2ME (Material Library To Material Editor)
	v.1.0 [2010-01-29] by Anubis [project3d.narod.ru]
*/
if ro_ML2ME != undefined do (destroyDialog ro_ML2ME)
rollout ro_ML2ME "MatLib 2 MEditor"
(
	local allMatLibs = #()
	local mlPath = getDir #matlib
	
	button bt_getDir "Choose Library Directory" align:#left across:2
	button bt_update "Update" align:#right --width:140
	listBox ml_list items:#() height:10
	label usage "Double click to load"
	
	on ro_ML2ME open do
	(
		allMatLibs = getFiles "$matlibs/*.mat"
		list = for i in allMatLibs collect (getFilenameFile i)
		ml_list.items = list
	)
	on bt_getDir pressed do
	(
		newDir = getSavePath caption:"Choose Library Directory" initialDir:"$matlibs"
		if newDir != undefined do
		(
			mlPath = newDir
			allMatLibs = getFiles (newDir + "/*.mat")
			list = for i in allMatLibs collect (getFilenameFile i)
			ml_list.items = list
		)
	)
	on bt_update pressed do
	(
		allMatLibs = getFiles (mlPath + "/*.mat")
		list = for i in allMatLibs collect (getFilenameFile i)
		ml_list.items = list
	)
	on ml_list doubleClicked itm do
	(
		new = #()
		tmp = loadTempMaterialLibrary allMatLibs[itm]
		if tmp.count > 24 then
		(for i = 1 to 24 do append new tmp[i])
		else (for i in tmp do append new i)
		for i = 1 to new.count do (setMeditMaterial i new[i])
	)
)
createDialog ro_ML2ME 210 190 \
style:#(#style_titlebar,#style_sysmenu,#style_minimizebox)
