/**************************************************************************
*
*  @@@BUILDINFO@@@ 62editMenu-2.jsx 2.0.1.61  08-Feb-2007
*  Copyright 2006 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 Edit menu

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

addDelayedTask (setupEditMenu);

function setupEditMenu()
{
	menus.edit.undo = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Undo=&Undo",
									   "at the end of edit", "edit/undo");

	menus.edit.redo = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Redo=&Redo",
									   "at the end of edit", "edit/redo");

	menus.edit.cut  = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Cut=Cu&t",
										  "--at the end of edit", "edit/cut");

	menus.edit.copy = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Copy=&Copy",
									   "at the end of edit", "edit/copy");

	menus.edit.paste = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Paste=&Paste",
										"at the end of edit", "edit/paste");

	menus.edit.selectAll = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/SelectAll=Select &All",
											"--at the end of edit", "edit/selectAll");

	menus.edit.selectMatchingBrace = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/SelectMatchingBrace=Select to &Brace",
											"at the end of edit", "edit/selectMatchingBrace");

	menus.edit.selectToMatchingBrace = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/SelectIncludingMatchingBrace=Select &Including Brace",
											"at the end of edit", "edit/selectToMatchingBrace");

	menus.edit.checkSyntax = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/CheckSyntax=Check &Syntax",
											  "--at the end of edit", "edit/checkSyntax");

	menus.edit.version = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Version=Insert &Version Tag",
											  "at the end of edit", "edit/version");
									          
	menus.edit.blockcomment = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Comment=Co&mment or Uncomment Selection",
											  "at the end of edit", "edit/blockcomment");
									          
	menus.edit.findReplace = new MenuElement( "command", "$$$/ESToolkit/Menu/Edit/FindReplace=&Find and Replace",
											  "--at the end of edit", "edit/findReplace");

	menus.edit.findNext = new MenuElement("command", "$$$/ESToolkit/Menu/Edit/FindNext=Find &Next",
											  "at the end of edit", "edit/findNext");

	menus.edit.bookmarks = new MenuElement ("menu", "$$$/ESToolkit/Menu/Edit/Bookmarks=Boo&kmarks",
											  "--at the end of edit", "edit/bookmarks");

	menus.edit.bookmarks.toggleBM = new MenuElement("command", "$$$/ESToolkit/Menu/Edit/ToggleBM=&Toggle Bookmark",
											  "at the end of edit/bookmarks", "edit/bookmarks/toggleBM");

	menus.edit.bookmarks.remAllBMs = new MenuElement("command", "$$$/ESToolkit/Menu/Edit/RemAllBM=Remove &All Bookmarks",
											  "at the end of edit/bookmarks", "edit/bookmarks/remAllBM");

	menus.edit.bookmarks.gotoNextBM = new MenuElement("command", "$$$/ESToolkit/Menu/Edit/gotoNextBM=&Next Bookmark",
											  "at the end of edit/bookmarks", "edit/bookmarks/gotoNextBM");

	menus.edit.bookmarks.gotoPrevBM = new MenuElement("command", "$$$/ESToolkit/Menu/Edit/gotoPrevBM=&Previous Bookmark",
											  "at the end of edit/bookmarks", "edit/bookmarks/gotoPrevBM");

	menus.edit.lineEnds = new MenuElement ("menu", "$$$/ESToolkit/Menu/Edit/LineEnds=&Line Endings",
											  "at the end of edit", "edit/lineEnds");


	menus.edit.lineEnds.mac = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/LineEnds/Mac=&Macintosh",
											  "at the end of edit/lineEnds", "edit/lineEnds/mac");

	menus.edit.lineEnds.unix = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/LineEnds/Unix=&Unix",
											  "at the end of edit/lineEnds", "edit/lineEnds/unix");

	menus.edit.lineEnds.win = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/LineEnds/Win=&Windows",
											  "at the end of edit/lineEnds", "edit/lineEnds/win");

    menus.edit.preferences = new MenuElement ("command", "$$$/ESToolkit/Menu/Edit/Preferences=Pr&eferences...",
								              "--at the end of edit", "tools/preferences");

	menus.edit.undo.onDisplay = function()
	{
		this.enabled = ( document && (document.window == workspace.activeDocument) ) ? document.canUndo() : false;
	}

	menus.edit.redo.onDisplay = function()
	{
		this.enabled = ( document && (document.window == workspace.activeDocument) ) ? document.canRedo() : false;
	}

	menus.edit.cut.onDisplay = 
	menus.edit.copy.onDisplay = function()
	{
		this.enabled = app.canCopy();
	}

	menus.edit.paste.onDisplay = function()
	{
		this.enabled = app.canPaste();
	}

	menus.edit.selectAll.onDisplay =
	menus.edit.checkSyntax.onDisplay = 
	menus.edit.lineEnds.onDisplay = function()
	{
		this.enabled = document && (document.window == workspace.activeDocument);
	}

	menus.edit.selectMatchingBrace.onDisplay =
	menus.edit.selectToMatchingBrace.onDisplay = function()
	{
		this.enabled = document && (document.window == workspace.activeDocument);
	}

	menus.edit.version.onDisplay = function()
	{
		this.enabled = (document && document.isFile() && (document.window == workspace.activeDocument));
	}

	menus.edit.blockcomment.onDisplay = function()
	{
		this.enabled = ( document                                       && 
		                 document.window == workspace.activeDocument    &&
						 document.textselection.length > 0              && 
						 languages[document.langID].comment.block.toString().length > 0 );
	}

	menus.edit.findReplace.onDisplay = function ()
	{
		this.enabled = true;//(document != null);
	}

	menus.edit.findReplace.onSelect = function ()
	{
		findReplaceObj.show();
	}

	menus.edit.findReplace.close = function()
	{
		findReplaceObj.close();
	}

	menus.edit.findNext.onSelect = function ()
	{
		findReplaceObj.find(false);
	}

	menus.edit.findNext.onDisplay = function()
	{
		this.enabled = (document != null) && findReplaceObj && (findReplaceObj.currentSearchString().length > 0);
	}

	menus.edit.bookmarks.toggleBM.onDisplay =
	menus.edit.bookmarks.remAllBMs.onDisplay =
	menus.edit.bookmarks.gotoNextBM.onDisplay =
	menus.edit.bookmarks.gotoPrevBM.onDisplay = function()
	{
		this.enabled = document && (document.window == workspace.activeDocument);
	}

	menus.edit.bookmarks.toggleBM.onSelect = function()
	{
		document.toggleBookmark();
	}

	menus.edit.bookmarks.remAllBMs.onSelect = function()
	{
		document.removeAllBookmarks();
	}

	menus.edit.bookmarks.gotoNextBM.onSelect = function()
	{
		document.nextBookmark( true );
		document.scrollSelection();
	}

	menus.edit.bookmarks.gotoPrevBM.onSelect = function()
	{
		document.nextBookmark( false );
		document.scrollSelection();
	}

	menus.edit.undo.onSelect = function()
	{
		if (document) 
			document.undo();
	}

	menus.edit.redo.onSelect = function()
	{
		if (document) 
			document.redo();
	}

	menus.edit.cut.onSelect = function()
	{
		app.cut();
	}

	menus.edit.copy.onSelect = function()
	{
		app.copy();
	}

	menus.edit.paste.onSelect = function()
	{
		app.paste();
	}

	menus.edit.selectAll.onSelect = function()
	{
		if (document) 
			document.setSelection (0, 0, -1, -1);
	}

	menus.edit.selectMatchingBrace.onSelect= function()
	{
		var braceStyle = languages[document.langID].braces.@style;
	    
		if( braceStyle && braceStyle.toString().length > 0 )
		{
			braceStyle = parseInt( braceStyle.toString() );
	        
			if( !isNaN( braceStyle ) )
			{
				if( document.selectMatchingBrace( braceStyle ) )
					document.scrollSelection();
			}
		}
	}

	menus.edit.selectToMatchingBrace.onSelect = function()
	{
		var braceStyle = languages[document.langID].braces.@style;
	    
		if( braceStyle && braceStyle.toString().length > 0 )
		{
			braceStyle = parseInt( braceStyle.toString() );
	        
			if( !isNaN( braceStyle ) )
			{
				if( document.selectBraces( braceStyle ) )
					document.scrollSelection();
			}
		}
	}

	menus.edit.checkSyntax.onSelect = function()
	{
		if (document)
			document.checkSyntax();
	}

	menus.edit.version.onSelect = function()
	{
		if (document)
			document.insertVersionTag();
	}

	menus.edit.blockcomment.onSelect = function()
	{
		if( document )
			document.comment( languages[document.langID].comment.block, true );
	}

	menus.edit.lineEnds.win.onDisplay = function()
	{
		if (document && (document.window == workspace.activeDocument))
			this.checked = (document.lf == "windows");
	}

	menus.edit.lineEnds.mac.onDisplay = function()
	{
		if (document && (document.window == workspace.activeDocument))
			this.checked = (document.lf == "macintosh");
	}

	menus.edit.lineEnds.unix.onDisplay = function()
	{
		if (document && (document.window == workspace.activeDocument))
			this.checked = (document.lf == "unix");
	}

	menus.edit.lineEnds.win.onSelect = function()
	{
		if (document)
			document.lf = "windows";
	}

	menus.edit.lineEnds.mac.onSelect = function()
	{
		if (document)
			document.lf = "macintosh";
	}

	menus.edit.lineEnds.unix.onSelect = function()
	{
		if (document)
			document.lf = "unix";
	}
	
	menus.edit.preferences.onSelect = function()
	{
	    openPreferencesDialog();
	}
}
