<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

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

	<body>
		<hr/>
		<p>ADOBE SYSTEMS INCORPORATED</p>
		<p>Copyright 2001-2003 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> Extension Builder</p>
		<p><b>Folder name:</b> Extension Builder</p>
		<hr/>
		<p><b>Description:</b></p>
		<p>The Extension Builder sample:</p>
		<ol>
			<li>creates a folder for the new extension. Folder name is same as the extension name.</li>
			<li>creates a new Main.html based upon a template (Skeleton.html)</li>
			<li>saves Main.html in the extension folder.</li>
		</ol>
		<p>Skeleton.html is the template used to create Main.html. Extension Builder places the extension name in the following locations:</p>
		<ol>
			<li>in the Title</li>
			<li>in jsxmodule name attribute</li>
			<li>in the contents of the extname element.</li>
		</ol>
		<p><b>How to Use:</b></p>
		<p>From the Extension Menu, select New Extension....</p>
		<p>Specify the name of the extension. This will also be the name of the extension folder.</p>
		<p>Choose whether to create the extension folder in GoLive/Extend Scripts/Modules or another location.</p>
		<p>After selecting OK, a folder will be created for the extension, Main.html will be saved in that folder, and Main.html will open in GoLive.</p>
		<hr/>
		<p><b>Module Definition:</b></p>
		<jsxmodule info="$$$/extendscript/ExtensionBuilder/Description=Extensions > New Extension... displays a dialog that allows you to quickly create a new SDK extension." name="Extension Builder" version="1.0"/>
		<p><b>Scripts:</b></p>
		<script><![CDATA[
//--------------------------------------------------------------------
// CALLBACK FUNCTIONS
//--------------------------------------------------------------------


//---------------------------------------------------------
// controlSignal -  called when the state of a control has changed
//
// Description:
//   Use to extract the state of the control, and react to the state
//   change.
//
// Warning: see documentation for warnings about reparse, 
//   reformat, setInnerHTML, and setOuterHTML.

function controlSignal(control)
{
	switch (control.name) {
	case 'radioGLFolder': 
		if (control.state == true) {
			NewExtensionDlg.editExtName.enabled = true;
			// turn off others
			NewExtensionDlg.editOtherFolder.enabled = false;
			NewExtensionDlg.dialogOtherFolder.enabled = false;
		}
		break;

	case 'radioOtherFolder':
		if (control.state == true) {
			NewExtensionDlg.editExtName.enabled = true;
			NewExtensionDlg.editOtherFolder.enabled = true;
			NewExtensionDlg.dialogOtherFolder.enabled = true;
		}
		break;
		
	case 'dialogOtherFolder':
		var selection = folderGetDialog(localize('$$$/extendscript/ExtensionBuilder/folderSelectMessage=Select path for new extension'));
		if (selection != null)
			NewExtensionDlg.editOtherFolder.value = selection.path;
		break;
	}
}


//---------------------------------------------------------
// initializeModule - called after the module has been loaded
//
// Description
//   Use to initialize global variables and data structures, and
//   create Picture objects using createPicture.

function initializeModule() 
{
	NewExtensionDlg.setup();
}


//---------------------------------------------------------
// menuSignal - called when the user chooses a menu item.
//
// Description: Use it to respond to the user's choice of menu item.

function menuSignal (menuItem) 
{
	if (menuItem.name == 'newExtensionItem') {
		if (NewExtensionDlg.runModal()) {
			if (NewExtensionDlg.editExtName.value == '') {
				alert(localize('$$$/extendscript/ExtensionBuilder/ExtName=Please specify Extension Name.'));
				return;
			}	
			var fileName = null;
		
			// create path and verify that file does not exist
			if ((fileName = getDocumentPath()) == null) {
				return;
			}
				
			var doc = createNewDocument(fileName);
			if (!doc) {
				return;
			}
				
			modifyExtensionName(doc, NewExtensionDlg.editExtName.value);
	
			doc.saveAs(fileName);
		}
	}
}


//--------------------------------------------------------------------
// Extension Specific Functions
//--------------------------------------------------------------------

//---------------------------------------------------------
// NewExtensionDlg.setup - set up the dialog
//
// Description: Initializes the NewExtensionDlg.

function NewExtensionDlg_setup() {
	this.editExtName = '';
	
	this.editExtName.enabled = true;
	this.radioOtherFolder.state = false;
	this.editOtherFolder.enabled = false;
	this.dialogOtherFolder.enabled = false;
	this.radioGLFolder.state = true;
}

NewExtensionDlg.setup = NewExtensionDlg_setup;


//---------------------------------------------------------
// createNewDocument - 
//
// Description: Open Skeleton.html and 
// create the document for the
// new extension.

function createNewDocument()
{
	var skelDoc = app.openDocument(module.folder.url + 'Skeleton.html');
	newDoc = skelDoc.clone();
	skelDoc.close(true);
	return newDoc;
}


//-------------------------------------------------------------------
// fileDelimiter - return platform specific delimiter
// 
// For Macintosh, return :
// For Windows, return \\
// else return /

function fileDelimiter() {
	var win = new RegExp(/^Windows/);
	var mac = new RegExp(/^Macintosh/);
	
	if (app.osVersion.match(win)) {
		return '\\';
	}
	else if (app.osVersion.match(mac)) {
		return '/';
	}
	else { // unknown platform
		return '/'; 
	}
}


//---------------------------------------------------------
// getDocumentPath - create path for new document.
//
// Description: Create the pathname for the
// new Main.html file. Returns the url to Main.html.

function getDocumentPath()
{
	var pathFolder = getPathForNewExtension();
	if (pathFolder == null) {
		return null;
	}
	var fileName = pathFolder.url + 'Main.html';
	
	// check to see if file already exists
	var file = JSXFile(fileName);
	if (file.exists) {
		var message = localize('$$$/extendscript/ExtensionBuilder/FileExistsMsg=Main.html already exists in %1.\n\n Please select a different folder name.', pathFolder.path);
		alert(message);
		return null;
	}
	file.close(true);
	return fileName;
}


//---------------------------------------------------------
// getPathForNewExtension - create path for 
// the new extension
//
// Description: Using values entered in
// NewExtensionDlg, create path to the folder
// for the new extension. Path may be
// in the GoLive/Extend Scripts folder, or
// in a folder specified by the user.
//
// Returns: JSXFile for the folder.

function getPathForNewExtension()
{
	var pathName = '';
	var folder = null;
	
	if (NewExtensionDlg.radioGLFolder.state == true) {
		var folderName = app.settingsFolder.url + 'Extend%20Scripts/' + 
					encodeURI(NewExtensionDlg.editExtName.value);
		folder = JSXFile(folderName);
	}
	else if (NewExtensionDlg.radioOtherFolder.state == true) {
		if (NewExtensionDlg.editOtherFolder.value == '') {
			alert(localize('$$$/extendscript/ExtensionBuilder/FolderName=Please specify folder name.'));
			return null;
		}
		var folderName = NewExtensionDlg.editOtherFolder.value + 
					fileDelimiter() + NewExtensionDlg.editExtName.value;
		folder = JSXFile(folderName);
	}
	if (!folder.exists) {
		if (folder.createFolder() == false) {
			var message = 
			alert(localize('$$$/extendscript/ExtensionBuilder/FldrExistsMsg=Unable to create folder: %1\n\nMake sure that path and folder name are valid for current platform.', folder.path));
				
			return null;
		}
	}
	return folder;
}


//---------------------------------------------------------
// modifyExtensionName: 
//
// Description: insert new extension name in 
// Skeleton.html.
// 
// Parameters:
// doc: the current document: Skeleton.html
// name: Name of new extension

function modifyExtensionName(doc, name)
{
	// modify title
	var title = doc.element.getSubElement('title');  
	if (!title) {
		alert(localize('$$$/extendscript/ExtensionBuilder/TitleMsg=Title element missing from Skeleton.html. Extension will not be created. Please check the installation of extension, %1.', module.name));
		return;
	}
	title.setInnerHTML(name + ' Extension');
	
	// modify jsxmodule name attribute
	var module = doc.element.getSubElement('jsxmodule');
	if (!module) {
		alert(localize('$$$/extendscript/ExtensionBuilder/ModuleMsg=JSXModule element missing from Skeleton.html. Extension will not be created. Please check the installation of extension, %1.', module.name));
		return;
	}
	module.name = name;
	
	// modify <extname>
	var extname = doc.element.getSubElement('extname');
	if (extname) { // unlike module, don't need an alert if it doesn't exist
		extname.setOuterHTML(name);
	}
}
//]]>
</script>
		<hr/>
		<p><b>Dialogs</b> Define Dialogs here.</p>
		<jsxdialog height="160" name="NewExtensionDlg" title="$$$/extendscript/ExtensionBuilder/NewExtensionDlgTitle=Create new Extend Script extension" width="475">
			<table width="437" border="0" cellspacing="0" cellpadding="0" cool="cool" gridx="5" gridy="5" height="194" showgridx="showgridx" showgridy="showgridy">
				<tr height="10">
					<td width="10" height="193" rowspan="10"></td>
					<td width="86" height="18" colspan="2" rowspan="3"></td>
					<td width="2" height="10"></td>
					<td width="252" height="15" colspan="5" rowspan="2"></td>
					<td width="86" height="110" rowspan="7"></td>
					<td width="1" height="10"><spacer type="block" width="1" height="10"/></td>
				</tr>
				<tr height="5">
					<td cslocked="cslocked" content="content" csheight="32" width="2" height="45" rowspan="3" valign="top" xpos="96"></td>
					<td width="1" height="5"><spacer type="block" width="1" height="5"/></td>
				</tr>
				<tr height="3">
					<td width="252" height="40" colspan="5" rowspan="2" valign="top" align="left" xpos="98">
						<jsxcontrol height="19" name="editExtName" posx="98" posy="15" type="edit" value="" width="140"></jsxcontrol>
					</td>
					<td width="1" height="3"><spacer type="block" width="1" height="3"/></td>
				</tr>
				<tr height="37">
					<td width="86" height="37" colspan="2" valign="top" align="left" xpos="10">
						<jsxcontrol height="16" name="static" posx="10" posy="18" type="static" value="$$$/extendscript/ExtensionBuilder/NewExtensionDlg/staticText=Extension Name:" width="85"></jsxcontrol>
					</td>
					<td width="1" height="37"><spacer type="block" width="1" height="37"/></td>
				</tr>
				<tr height="24">
					<td width="340" height="24" colspan="8" valign="top" align="left" xpos="10">
						<jsxcontrol height="19" name="radioGLFolder" group="folder" posx="10" posy="55" type="radiobutton" value="$$$/extendscript/ExtensionBuilder/NewExtensionDlg/radioGLFolder=Save in GoLive/Modules/Extend Scripts folder" width="250"></jsxcontrol>
					</td>
					<td width="1" height="24"><spacer type="block" width="1" height="24"/></td>
				</tr>
				<tr height="6">
					<td width="130" height="6" colspan="5"></td>
					<td cslocked="cslocked" content="content" csheight="32" width="4" height="32" rowspan="3" valign="top" xpos="140"></td>
					<td width="206" height="32" colspan="2" rowspan="3"></td>
					<td width="1" height="6"><spacer type="block" width="1" height="6"/></td>
				</tr>
				<tr height="25">
					<td width="130" height="25" colspan="5" valign="top" align="left" xpos="10">
						<jsxcontrol height="19" name="radioOtherFolder" group="folder" posx="10" posy="85" type="radiobutton" value="$$$/extendscript/ExtensionBuilder/NewExtensionDlg/radioOtherFolder=Save in existing folder" width="130"></jsxcontrol>
					</td>
					<td width="1" height="25"><spacer type="block" width="1" height="25"/></td>
				</tr>
				<tr height="1">
					<td width="20" height="83" rowspan="3"></td>
					<td width="110" height="1" colspan="4"></td>
					<td width="86" height="55" rowspan="2" valign="top" align="left" xpos="350">
						<jsxcontrol halign="right" height="19" name="dialogOtherFolder" posx="350" posy="110" type="button" value="$$$/extendscript/BrowseButton=Browse..." width="80"></jsxcontrol>
					</td>
					<td width="1" height="1"><spacer type="block" width="1" height="1"/></td>
				</tr>
				<tr height="54">
					<td width="320" height="54" colspan="7" valign="top" align="left" xpos="30">
						<jsxcontrol height="20" name="editOtherFolder" posx="30" posy="111" type="edit" value="" width="313"></jsxcontrol>
					</td>
					<td width="1" height="54"><spacer type="block" width="1" height="54"/></td>
				</tr>
				<tr height="28">
					<td width="95" height="28" colspan="3"></td>
					<td width="105" height="28" colspan="3" valign="top" align="left" xpos="125">
						<jsxcontrol height="19" name="dialogok" posx="125" posy="165" type="button" value="$$$/extendscript/OKButton=OK" width="80"></jsxcontrol>
					</td>
					<td width="120" height="28" valign="top" align="left" xpos="230">
						<jsxcontrol height="19" name="dialogcancel" posx="230" posy="165" type="button" value="$$$/extendscript/CancelButton=Cancel" width="80"></jsxcontrol>
					</td>
					<td width="86" height="28"></td>
					<td width="1" height="28"><spacer type="block" width="1" height="28"/></td>
				</tr>
				<tr height="1" cntrlrow="cntrlrow">
					<td width="10" height="1"><spacer type="block" width="10" height="1"/></td>
					<td width="20" height="1"><spacer type="block" width="20" height="1"/></td>
					<td width="66" height="1"><spacer type="block" width="66" height="1"/></td>
					<td width="2" height="1"><spacer type="block" width="2" height="1"/></td>
					<td width="27" height="1"><spacer type="block" width="27" height="1"/></td>
					<td width="15" height="1"><spacer type="block" width="15" height="1"/></td>
					<td width="4" height="1"><spacer type="block" width="4" height="1"/></td>
					<td width="86" height="1"><spacer type="block" width="86" height="1"/></td>
					<td width="120" height="1"><spacer type="block" width="120" height="1"/></td>
					<td width="86" height="1"><spacer type="block" width="86" height="1"/></td>
					<td width="1" height="1"></td>
				</tr>
			</table>
			<jsxlayoutline direction="false" x="97" y="16" length="20"/>
			<jsxlayoutline direction="false" x="344" y="110" length="20"/>
		</jsxdialog>
		<p><b>JSXLocale</b> Specify localized versions of strings used in menu items, dialogs, alerts, etc.</p>
		<jsxlocale>
			<table width="180" border="1" cellspacing="2" cellpadding="0">
				<tr>
					<th>US</th>
					<th>DE</th>
					<th>FR</th>
				</tr>
				<tr>
					<td>Select path for new extension</td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td>Please specify Extension Name.</td>
					<td></td>
					<td></td>
				</tr>
			</table>
		</jsxlocale>
		<p><b>Menu Bar</b> Add items and menus to the GoLive menu bar.</p>
		<jsxmenubar>
			<jsxmenu name="Extensions" title="$$$/extendscript/ExtensionsMenu=Extensions">
				<jsxitem name="newExtensionItem" title="$$$/extendscript/ExtensionBuilder/ExtensionBuilderMenu=New Extension..."/>
			</jsxmenu>
		</jsxmenubar>
		<p></p>
	</body>

</html>