/**************************************************************************
*
*  @@@BUILDINFO@@@ 63viewMenu-2.jsx 2.0.0.54  08-Feb-2007
*  Copyright 2006-2007 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains the property of
* Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
* and technical concepts contained herein are proprietary to  Adobe Systems 
* Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
* Patents,patents in process,and are protected by trade secret or copyright 
* law.  Dissemination of this  information or reproduction of this material
* is strictly  forbidden  unless prior written permission is  obtained from 
* Adobe Systems Incorporated.
**************************************************************************/

//////////////////////////////////////////////////////////////////////////
// The View menu.

menus.view = new MenuElement ("menu", "$$$/ESToolkit/Menu/View=&View",
								 "at the end of menubar", "view");

addDelayedTask (setupViewMenu);

function setupViewMenu()
{
	menus.view.wrap = new MenuElement ("command", "$$$/ESToolkit/Menu/view/Wrap=&Word Wrap",
											  "at the end of view", "view/wrap");

	menus.view.lineNum = new MenuElement ("command", "$$$/ESToolkit/Menu/view/LineNum=&Line Numbers",
											  "--at the end of view", "view/lineNum");

	menus.view.folding = new MenuElement ("command", "$$$/ESToolkit/Menu/view/CodeCollapse=&Code Collapse",
											  "at the end of view", "view/collapse");

	//menus.view.highlighting = new MenuElement ("command", "$$$/ESToolkit/Menu/view/Hightlight=Syntax Highlighting",
	//								          "at the end of view", "view/highlighting");

	menus.view.lineNum.onDisplay = function()
	{
		if (document && (document.window == workspace.activeDocument))
		{
			this.enabled = true;
			this.checked = document.lineNumbers;
		}
		else
			this.checked = this.enabled = false;
	}

	menus.view.wrap.onDisplay = function()
	{
		if (document && (document.window == workspace.activeDocument))
		{
			this.enabled = true;
			this.checked = document.wrap;
		}
		else
			this.checked = this.enabled = false;
	}

	menus.view.folding.onDisplay = function()
	{
		if (document && (document.window == workspace.activeDocument))
		{
			this.enabled = true;
			this.checked = (document.folding != 0);
		}
		else
			this.checked = this.enabled = false;
	}

	//menus.view.highlighting.onDisplay = function()
	//{
	//    if(document)
	//    {
	//		this.enabled = true;
	//		this.checked = typeof (document.oldLangID) == 'undefined';
	//    }
	//    else
	//		this.checked = this.enabled = false;
	//}

	menus.view.lineNum.onSelect = function()
	{
		if (document)
			document.lineNumbers = !document.lineNumbers;
	}

	menus.view.wrap.onSelect = function()
	{
		if (document)
			document.wrap = !document.wrap;
	}

	menus.view.folding.onSelect = function()
	{
		if (document)
			document.folding = (document.folding > 0) ? 0 : 3;
	}

	// Create the Language menu
	function addLanguage (langID, text, sep)
	{
		var menu = new MenuElement ("command", text, "at the end of language" + sep);
		menu.langID = langID;
		menu.onDisplay = function()
		{
			this.checked = document ? (document.langID == this.langID) : false;
		}
		menu.onSelect = function()
		{
			if (document)
				document.setLanguage (this.langID);
		}
	}

	menus.view.language = new MenuElement ("menu", "$$$/ESToolkit/Menu/view/Hightlight=&Syntax Highlighting",
										   "--at the end of view", "language");

	menus.view.language.onDisplay = function()
	{
		this.enabled = (document && (document.window == workspace.activeDocument));
	}
	
	addLanguage (languages.text, localize ("$$$/ESToolkit/LanguagesMenu/None=&None"), "---");
	var langObjs = [];

	for (var i = 0; i < lang.langIDs.length; i++)
	{
		var langID  = lang.langIDs [i];
		var langObj = languages [langID];
		if (langID != "text")
			// use the text without any WIndows '&; escapes for comparisons
			langObjs.push ( { id		: langID,
							  text		: langObj.menu.toString(),
							  compare	: langObj.menu.toString().replace (/&([^&])/,"$1") } );
	}

	for (i = 0; i < langObjs.length; i++)
		addLanguage (langObjs [i].id, langObjs [i].text, "");
}

