<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8">
		<meta name="generator" content="Adobe GoLive">
		<title>Menu Extension</title>
	</head>

	<body>
		<p>Author: Klaas St&ouml;ckmann</p>
		<hr>
	<p>ADOBE SYSTEMS INCORPORATED</p>
		<p>Copyright 2000-2002 Adobe Systems Incorporated<br>
			All Rights Reserved</p>
		<p>NOTICE: Adobe permits you to use, modify, and distribute this 
		file in accordance with the terms of the Adobe license agreement 
		accompanying it. If you have received this file from a source other 
		than Adobe, then your use, modification, or distribution of it requires 
		the prior written permission of Adobe.</p>
		<hr>
		<p><b>Extension Name:</b>Theme Manager</p>
		<p><b>Folder name:</b>ThemeManager</p>
		<hr>
		<p><b>Description:</b></p>
		<p>This extension gives access to modify the different theme source settings.</p>
		<hr>
		<p><b>Module Definition:</b></p>
		<jsxmodule name="Theme Manager" info="This extension gives access to modify the different theme source settings." debug="false" version="1.1">
		<p><b>Scripts:</b></p>
		<script><!--
//--------------------------------------------------------------------
// CALLBACK FUNCTIONS
//--------------------------------------------------------------------

// test the preferences by using a persistent counter

function initializeModule()
{
}

//-------------------------------------------
//	menuSetup
//-------------------------------------------

function readThemes()
{
	themeMgr.themeArray = new Array;

	var osVers = app.osVersion;
	
	osVers = osVers.substring(0,3);
	
	var fileName = "";
	
	if(osVers == "Mac")
		fileName = "codethemesmac.xml";
	else
		fileName = "codethemeswin.xml";

	
	var path = app.userSettingsFolder.url;
	
	path += "Code/" + fileName;
	
	var f = new JSXFile(path);
	
	if(!f.exists)
		{
		var appPath = app.appSettingsFolder.url;
		
		appPath += "Code/" + fileName;
		
		var appF = new JSXFile(appPath);
		
		appF.copy(path);
		}

	f = new JSXFile(path);
	
	var doc = f.openMarkup();
	
	var len = doc.element.getSubElementCount("theme");
	var index = 0;
	
	for(var i=0;i<len;i++)
		{
		var element = doc.element.getSubElement("theme",i);
		var newObj = new Object;
		newObj.theme = element.getInnerHTML();
		newObj.name = element.getAttribute("name");
		themeMgr.themeArray[index] = newObj;
		index++;
		}
		
	doc.close();
			
}

//-------------------------------------------
//	importTheme
//-------------------------------------------

function importTheme()
{
	var f = fileGetDialog("Import Theme");
	if(f != null)
		{
		var doc = f.openMarkup();
		
		var len = doc.element.getSubElementCount("theme");
		var index = themeMgr.themeArray.length;
		
		for(var i=0;i<len;i++)
			{
			var element = doc.element.getSubElement("theme",i);
			var newObj = new Object;
			newObj.theme = element.getInnerHTML();
			newObj.name = element.getAttribute("name");
			themeMgr.themeArray[index] = newObj;
			index++;
			}
			
		doc.close();
		
		updateList();
		updateSelection();
		}
		
}

//-------------------------------------------
//	exportTheme
//-------------------------------------------

function exportTheme()
{
	var sel = themeMgr.themeList.selection;
	if(sel != -1)
		{
		var f = filePutDialog("Export Theme","theme.xml");
		if(f != null)
			{
			var contentStr = "<xml version=\"1.0\" encoding=\"utf-8\">\n";
			contentStr += "<themes>\n";
			contentStr += "\t<theme name=\"" + themeMgr.themeArray[sel].name + "\">\n";
			contentStr += themeMgr.themeArray[sel].theme;
			contentStr += "\n\t</theme>\n";
			contentStr += "</themes>\n";
			f.open("w");
			f.write(contentStr);
			f.close();
			}
		}
}

//-------------------------------------------
//	menuSetup
//-------------------------------------------

function writeThemes()
{
	var osVers = app.osVersion;
	
	osVers = osVers.substring(0,3);
	
	var fileName = "";
	
	if(osVers == "Mac")
		fileName = "codethemesmac.xml";
	else
		fileName = "codethemeswin.xml";

	

	var contentStr = "<themes>\n";
	
	for(var i=0;i<themeMgr.themeArray.length;i++)
		{
		contentStr += "\t<theme name=\"" + themeMgr.themeArray[i].name + "\">\n";
		contentStr += themeMgr.themeArray[i].theme;
		contentStr += "\n\t</theme>\n";
		}
		
	contentStr += "</themes>";
		
	var path = app.userSettingsFolder.url;
	
	path += "Code/" + fileName;
	
	var f = new JSXFile(path);
	
	f.open("w");
	f.write(contentStr);
	f.close();	
}

//-------------------------------------------
//	menuSignal
//-------------------------------------------

function menuSignal(menuItem)
{
	switch (menuItem.name)
	{
		case "themeManager":
			{
			editThemes();
			}
			break;
	}
}

//-------------------------------------------
//	controlSignal
//-------------------------------------------

function controlSignal(control)
{
	switch (control.name)
	{
		case "themeList":
			{
			updateSelection();
			}
			break;
		case "duplicateButton":
			{
			duplicateTheme();
			}
			break;
		case "deleteButton":
			{
			deleteTheme();
			}
			break;
		case "upButton":
			{
			moveTheme(true);
			}
			break;
		case "downButton":
			{
			moveTheme(false);
			}
			break;
		case "nameEdit":
			{
			renameTheme();
			}
			break;
		case "importButton":
			{
			importTheme();
			}
			break;
		case "exportButton":
			{
			exportTheme();
			}
			break;
	}
}

//-------------------------------------------
//	updateSelection
//-------------------------------------------

function duplicateTheme()
{
	var sel = themeMgr.themeList.selection;
	
	if(sel != -1)
		{
		var newObj = new Object;
		
		newObj.name = themeMgr.themeArray[sel].name + " copy";
		newObj.theme = themeMgr.themeArray[sel].theme;
		var len = themeMgr.themeArray.length;
		
		themeMgr.themeArray[len] = newObj;
		updateList();
		themeMgr.themeList.selection = len;
		updateSelection();
		}
}

//-------------------------------------------
//	updateSelection
//-------------------------------------------

function moveTheme(up)
{
	var sel = themeMgr.themeList.selection.index;
	
	if(sel != -1)
		{
		var theme = "";
		var name = "";
		if(up)
			{
			if(sel < 2)
				return;
			theme = themeMgr.themeArray[sel].theme;
			name = themeMgr.themeArray[sel].name;
			
			themeMgr.themeArray[sel].theme = themeMgr.themeArray[sel-1].theme;
			themeMgr.themeArray[sel].name = themeMgr.themeArray[sel-1].name;
			
			themeMgr.themeArray[sel-1].theme = theme;
			themeMgr.themeArray[sel-1].name = name;
			sel--;
			}
		else
			{
			if(sel == 0 || sel == (themeMgr.themeArray.length-1))
				return;
			
			theme = themeMgr.themeArray[sel].theme;
			name = themeMgr.themeArray[sel].name;

			themeMgr.themeArray[sel].theme = themeMgr.themeArray[sel+1].theme;
			themeMgr.themeArray[sel].name = themeMgr.themeArray[sel+1].name;
			
			themeMgr.themeArray[sel+1].theme = theme;
			themeMgr.themeArray[sel+1].name = name;
			sel++;
			}

		updateList();
		themeMgr.themeList.selection = sel;
		}
}

//-------------------------------------------
//	updateSelection
//-------------------------------------------

function deleteTheme()
{
	var sel = themeMgr.themeList.selection;
	
	if(sel != -1 && sel != 0)
		{
		var newArray = new Array;
		
		for(var i=0;i<themeMgr.themeArray.length;i++)
			{
			if(i != sel)
				{
				var newObj = new Object;
				newObj.name = themeMgr.themeArray[i].name;
				newObj.theme = themeMgr.themeArray[i].theme;
				newArray[newArray.length] = newObj;
				}
			}
			
		themeMgr.themeArray = newArray;
		updateList();
		updateSelection();
		}
		
}

//-------------------------------------------
//	updateSelection
//-------------------------------------------

function renameTheme()
{
	var sel = themeMgr.themeList.selection.index;
	
	if(sel != -1)
		{
		themeMgr.themeArray[sel].name = themeMgr.nameEdit.value;
		updateList();
		themeMgr.themeList.selection = sel;
		themeMgr.nameEdit.value = themeMgr.themeArray[sel].name;
		}
}

//-------------------------------------------
//	updateSelection
//-------------------------------------------

function updateSelection()
{
	var sel = themeMgr.themeList.selection;
	
	if(sel != -1)
		{
		themeMgr.nameEdit.value = themeMgr.themeArray[sel].name;
		if(sel == 0)
			{
			themeMgr.deleteButton.enabled = false;
			themeMgr.upButton.enabled = false;
			themeMgr.downButton.enabled = false;
			themeMgr.nameEdit.enabled = false;
			}
		else
			{
			themeMgr.deleteButton.enabled = true;
			themeMgr.upButton.enabled = true;
			themeMgr.downButton.enabled = true;
			themeMgr.nameEdit.enabled = true;
			}
		
		themeMgr.duplicateButton.enabled = true;
		themeMgr.exportButton.enabled = true;
		}
	else
		{
		themeMgr.nameEdit.value = "";
		themeMgr.duplicateButton.enabled = false;
		themeMgr.deleteButton.enabled = false;
		themeMgr.upButton.enabled = false;
		themeMgr.downButton.enabled = false;
		themeMgr.nameEdit.enabled = false;
		themeMgr.exportButton.enabled = false;
		}
}

//-------------------------------------------
//	updateList
//-------------------------------------------

function updateList()
{
	themeMgr.themeList.removeAll();
	
	for(var i=0;i<themeMgr.themeArray.length;i++)
		{
		themeMgr.themeList.addItem(themeMgr.themeArray[i].name);
		}
}

//-------------------------------------------
//	editThemes
//-------------------------------------------

function editThemes()
{
	if(themeMgr.themeArray == undefined)
		{
		readThemes();
		}
		
	updateList();
	
	updateSelection();
	
	if(themeMgr.runModal() != 0)
		{
		writeThemes();
		}
	
}


//-->
</script>
		<!--
		<p>Localization strings
			<jsxlocale src="locale.html">	
			</jsxlocale>
		-->
		<p>The menu bar
			<jsxmenubar>
				<jsxmenu name="special" title="none">
					<jsxitem name="themeManager" title="Theme Manager...">
				</jsxmenu>
			</jsxmenubar>
<!--		<p>The dialog
			<jsxdialog name="fileDialog" title="Open"  width="240" height="80">
					<jsxcontrol name="filename" type="edit" value="" posx=15 posy=15 width=210 height=19>
					<jsxcontrol name="dialogcancel" type="button" value="Cancel" posx=90 posy=40 width=65 height=19>
					<jsxcontrol name="dialogok" type="button" value="OK" posx=160 posy=40 width=65 height=19>
			</jsxdialog>
-->
			<jsxdialog name="themeMgr" title="Theme Manager" width="356" height="225" resize="true">

					<jsxcontrol halign="scale" valign="scale" name="themeList" type="list" value="Themes" posx="10" posy="10" width="140" height="145"></jsxcontrol>
					<jsxcontrol halign="right" name="duplicateButton" type="button" value="Duplicate" posx="210" posy="10" width="106" height="19"></jsxcontrol>
					<jsxcontrol halign="right" name="deleteButton" type="button" value="Delete" posx="210" posy="34" width="106" height="19"></jsxcontrol>
					<jsxcontrol halign="right" name="upButton" type="button" value="Up" posx="210" posy="58" width="50" height="19"></jsxcontrol>
					<jsxcontrol halign="right" name="downButton" type="button" value="Down" posx="266" posy="58" width="50" height="19"></jsxcontrol>
					<jsxcontrol halign="right" name="nameLabel" type="static" value="Name:" posx="160" posy="82" width="40" height="19"></jsxcontrol>
					<jsxcontrol halign="right" name="nameEdit" type="buttonedit" value="" posx="210" posy="80" width="140" height="19"></jsxcontrol>

					<jsxcontrol halign="right" name="importButton" type="button" value="Import Theme" posx="210" posy="100" width="106" height="19"></jsxcontrol>
					<jsxcontrol halign="right" name="exportButton" type="button" value="Export Theme" posx="210" posy="124" width="106" height="19"></jsxcontrol>

					<jsxcontrol name="static" valign="bottom" type="static" value="Changes will only take place after restart!" posx="10" posy="160" width="230" height="20"></jsxcontrol>

					<jsxcontrol name="dialogcancel" halign="right" valign="bottom" type="button" value="Cancel" posx="170" posy="190" width="80" height="19"></jsxcontrol>
					<jsxcontrol halign="right" valign="bottom" name="dialogok" type="button" value="Apply" posx="260" posy="190" width="80" height="19"></jsxcontrol>

			</jsxdialog>
</body>

</html>