﻿#target bridge

/*-------------------------------------------------------------------------------------------------------------- 
	ADOBE SYSTEMS INCORPORATED
	Copyright 2006 - Adobe Systems Incorporated
	All Rights Reserved
 
	If this file is provided by Adobe in modifiable form (e.g., source code or JavaScript), then you may modify this file.  
	You may use and distribute this file, in modified or unmodified form, provided that you must reproduce the above
	acknowledgement and this notice with all copies of the file.
 
	THIS SOFTWARE IS PROVIDED BY ADOBE SYSTEMS INCORPORATED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, 
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ADOBE BE LIABLE TO YOU FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
	SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
	WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------------------------------*/

/* WorflowScriptLoader_CS3.jsx
	Author: 		Bob Stucky
	Description:	Loads the WAS Extension
	Version:		2.0.0.9
	Dated:		11/15/2006
*/
/*  
@@@BUILDINFO@@@ WorflowScriptLoader_CS3.jsx 2.0.0.9  1.0000  15-Nov-2006 
*/
/*
@@@START_XML@@@
<?xml version="1.0" encoding="UTF-8"?>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en_US">
     <dc:title>Workflow Script Loader</dc:title>
     <dc:description>Loads "Create InDesign Contact Sheet" and "Export to SWF", which automate Adobe InDesign CS3 and Adobe Illustrator CS3 respectively.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="de_DE">
    <dc:title>Workflow Script Loader</dc:title>
    <dc:description>Lädt "InDesign-Kontaktabzug erstellen" und "In SWF exportieren", mit denen Adobe InDesign CS3 bzw. Adobe Illustrator CS3 automatisiert werden.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="fr_FR">
    <dc:title>Chargeur de script de flux de travail</dc:title>
    <dc:description>Charge les fonctions "Créer une planche contact InDesign" et "Exporter vers SWF", qui automatisent respectivement Adobe InDesign CS3 et Adobe Illustrator CS3.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="ja_JP">
    <dc:title>Workflow Script Loader</dc:title>
    <dc:description>「InDesign コンタクトシートを作成」と「SWF へ書き出し」コマンドを読み込みます。これにより、Adobe InDesign CS3 と Adobe Illustrator CS3 での操作が自動化されます。</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="da_DK">
     <dc:title>Scriptindlæsning til arbejdsforløb</dc:title>
     <dc:description>Indlæser "Opret kontaktaftryk til InDesign" og "Eksporter til SWF", der automatiserer henholdsvis Adobe InDesign CS3 og Adobe Illustrator CS3.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="es_ES">
     <dc:title>Cargador de scripts de flujo de trabajo</dc:title>
     <dc:description>Carga "Crear hoja de contactos de InDesign" y "Exportar a SWF" que automatizan Adobe InDesign CS3 y Adobe Illustrator CS3 respectivamente.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="it_IT">
     <dc:title>Caricatore script flusso di lavoro</dc:title>
     <dc:description>Carica "Creare un provino a contatto in InDesign" e "Esporta in SWF", che automatizzano rispettivamente Adobe InDesign CS3 e Adobe Illustrator CS3.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="nl_NL">
     <dc:title>Scriptlader voor werkstromen</dc:title>
     <dc:description>Laadt "InDesign-contactblad maken" en "Exporteren naar SWF", waarmee respectievelijk Adobe InDesign CS3 en Adobe Illustrator CS3 worden geautomatiseerd.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="sv_SE">
     <dc:title>Arbetsflöde skriptinläsning</dc:title>
     <dc:description>Läser in "Skapa InDesign-kontaktkarta" och "Exportera till SWF", vilket medför att både Adobe InDesign CS3 och Adobe Illustrator CS3 startas automatiskt.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="ko_KR">
     <dc:title>작업 과정 스크립트 로더</dc:title>
     <dc:description>Adobe InDesign CS3 및 Adobe Illustrator CS3을 각각 자동화하는 "InDesign 밀착 인화 만들기" 및 "SWF로 내보내기"를 불러옵니다.</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="zh_CH ">
     <dc:title>工作流脚本加载程序</dc:title>
     <dc:description>加载“创建 InDesign 联系表”和“导出到 SWF”，它们将分别自动化 Adobe InDesign CS3 和 Adobe Illustrator CS3。</dc:description>
</ScriptInfo>
<ScriptInfo xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="zh_TW">
     <dc:title>工作流程指令碼載入器</dc:title>
     <dc:description>載入「建立 InDesign 縮圖目錄」與「轉存至 SWF」，它們會分別自動化 Adobe InDesign CS3 與 Adobe Illustrator CS3。</dc:description>
</ScriptInfo>
@@@END_XML@@@
*/
	$.level = 0; // change debug level to 0 prior to shipment
	WasLoader = {};
	
	// Watson 1467033 = somewhat brittle fix. This avoids having to move the WorkflowScriptLoader folder down to be a peer of this .jsx file,
	// keeping the .dat files buried away in the Resources folder as per Bridge team spec.
	WasLoader.beginLocalize = function()
	{
		WasLoader.oldZStringPath = app.zStringPathSpecifier;

		var resourcesFolder = new Folder( Folder.commonFiles + "/Adobe/Bridge CS3 Extensions/Adobe Workflow Automation/Resources" );
		app.zStringPathSpecifier = resourcesFolder + "/WorkflowScriptLoader/WorkflowScriptLoader_" + $.locale + ".dat" ;   
	}

	WasLoader.endLocalize = function()
	{
		app.zStringPathSpecifier = WasLoader.oldZStringPath;
	}

	WasLoader.localize = function( str )
	{
	    WasLoader.beginLocalize();
	    var result = localize( str );
	    WasLoader.endLocalize();
	    return result;
	}


	///
	/// createAppMenus - creates the PS, AI, and ID menus for all WAS Scripts
	///
	WasLoader.createAppMenus = function() {
		try {
			try {
				WasLoader.createMenu( "menu", WasLoader.strings.aiMenu, "after tools/ps", "tools/ai" );
			} catch ( e ) {
				var psServicesMenuExists = MenuElement.find ('Tools/PhotoshopServices') != null;
				WasLoader.createMenu( "menu", WasLoader.strings.aiMenu, psServicesMenuExists ? '-after Tools/PhotoshopServices-' : '-at the end of Tools', "tools/ai" );
			}
			WasLoader.createMenu( "menu", WasLoader.strings.idMenu, "after tools/ai", "tools/id" );
		} catch ( e ) {
			alert( WasLoader.localize( "$$$/WAS/wsl/installProb=There is a problem with your installation of the Workflow Automation Scripts. Please re-install." ) );
		}
	}
	///
	/// MenuElement.create 
	///
	WasLoader.createMenu = function( type, text, loc, id ) {
		var menu = MenuElement.find( id );
		if ( !menu ) {
			menu = MenuElement.create( type, text, loc, id );
		}
		return menu;
	}
	///
	///	Execute menus "indirectly" so that the actual WAS scripts can be loaded only on Demand
	///
	WasLoader.executeMenu = function( menu ) {
		try {
			if ( !WasLoader.scripts.library.hasBeenLoaded ) { // see if the library has been loaded
				$.evalFile( WasLoader.scripts.library ); // so load it
				WasLoader.scripts.library.hasBeenLoaded = true; // and flag it as loaded
			}
			if ( !menu.scriptFile.hasBeenLoaded ) {
				$.evalFile( menu.scriptFile );
				menu.hasBeenLoaded = true;
			}
			var exeString = menu.scriptExecutor + "( menu );";
			eval( exeString ); // if this fails, the script hasnt been loaded
		} catch ( e ) { 
			var msg = menu.text + WasLoader.localize( "$$$/WASLoader/failedToLoad= failed to load properly: "  ) + "\n";
			msg += WasLoader.localize( "$$$/WasLoader/scriptFile=Script File: " ) + decodeURI( menu.scriptFile.name ) + "\n";
			msg += WasLoader.localize( "$$$/WasLoader/lineNumber=Line Number: " ) + e.line + "\n";
			msg += e;
			alert( msg );
		}
	}
	///
	/// load - actually performs all the load stuff - I always to stuff in functions to make them easier to debug - ESTK's data browser isn't as cluttered.
	///
	WasLoader.load = function() {
		WasLoader.menus = {};
		WasLoader.scripts = {};
		WasLoader.strings = {};
		
		WasLoader.strings.psMenu = WasLoader.localize( "$$$/wsl/Photoshop=Photoshop" );
		WasLoader.strings.aiMenu = WasLoader.localize( "$$$/wsl/Illustrator=Illustrator" );
		WasLoader.strings.idMenu = WasLoader.localize( "$$$/wsl/InDesign=InDesign" );
		WasLoader.strings.glMenu = WasLoader.localize( "$$$/wsl/GoLive=GoLive" );

		var folder = new Folder( Folder.commonFiles + "/Adobe/Bridge CS3 Extensions/Adobe Workflow Automation/Resources" );
		WasLoader.scripts.library = new File( folder.absoluteURI + "/WasScriptLibrary.jsx" );
		WasLoader.scripts.contactSheet = new File( folder.absoluteURI + "/ContactSheet_ID.jsx" );
		WasLoader.scripts.exportToSWF = new File( folder.absoluteURI + "/ExportToSWF_AI.jsx" );
		
		WasLoader.createAppMenus();
		
		WasLoader.createMenu( "menu", WasLoader.localize("$$$/wasLoader/ETFAIExporttoSWF=Export to SWF"), "at the end of tools/ai", "tools/ai/ExportToSWF" );
		WasLoader.menus.exportToSWFQuick = WasLoader.createMenu( "command", WasLoader.localize("$$$/WAS/ETFAIQuickExport=Quick Export"), "at the end of tools/ai/ExportToSWF", "tools/ai/ExportToSWF/QuickExport");
		WasLoader.menus.exportToSWFCustom = WasLoader.createMenu( "command", WasLoader.localize("$$$/WAS/ETFAICustomExport=Custom Export..."), "at the end of tools/ai/ExportToSWF", "tools/ai/ExportToSWF/CustomExport");

		WasLoader.menus.contactSheet = WasLoader.createMenu( "command", WasLoader.localize( "$$$/wasLoader/ContactSheet/menu=Create InDesign Contact Sheet" ), "at the end of tools/id", "tools/id/contact" );

		WasLoader.menus.exportToSWFQuick.onSelect = WasLoader.executeMenu;
		WasLoader.menus.exportToSWFCustom.onSelect = WasLoader.executeMenu;
		WasLoader.menus.contactSheet.onSelect = WasLoader.executeMenu;

		WasLoader.menus.exportToSWFQuick.scriptExecutor = "ExportToSWFAI.executeQuick";
		WasLoader.menus.exportToSWFCustom.scriptExecutor = "ExportToSWFAI.executeCustom";
		WasLoader.menus.contactSheet.scriptExecutor = "ContactSheet.showDialog";
		
		WasLoader.menus.exportToSWFQuick.scriptFile = WasLoader.scripts.exportToSWF;
		WasLoader.menus.exportToSWFCustom.scriptFile = WasLoader.scripts.exportToSWF;
		WasLoader.menus.contactSheet.scriptFile = WasLoader.scripts.contactSheet;
	}
	WasLoader.load();
	"Adobe WAS Scripts Loaded";
