home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Menus / MM / Image_Editors_Dynamic.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  3.3 KB  |  109 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3.    function receiveArguments()
  4.    {
  5.       var selection = dw.getSelection();
  6.       var node      = dw.offsetsToNode( selection[0], selection[1] );
  7.       var imageSrc  = node.getAttribute( "src" );
  8.       var fullPath = getFullPath(imageSrc);
  9.  
  10.       var editorURL="";
  11.       for (i=0; i < dw.constructor.gMenuIDs.length-1; i++)
  12.       {
  13.          if (arguments[0] == dw.constructor.gMenuIDs[i])
  14.             editorURL = dw.constructor.gExternalEditors[i*2 + 1];
  15.       }
  16.  
  17.       if (editorURL != "")
  18.       {
  19.          dw.openWithImageEditor(fullPath, editorURL);
  20.          return true;
  21.       }
  22.       else
  23.       {
  24.          dw.openWithBrowseDialog(fullPath);
  25.          return true;
  26.       }
  27.    }
  28.  
  29.    function canAcceptCommand()
  30.    {
  31.       var selection = dw.getSelection();
  32.       var node      = dw.offsetsToNode( selection[0], selection[1] );
  33.       var imageSrc  = node.getAttribute( "src" );
  34.       if (selection && node && imageSrc)
  35.           return true;
  36.       else
  37.         return false;
  38.    }
  39.  
  40.    function getDynamicContent()
  41.    {
  42.       var selection = dw.getSelection();
  43.       var node      = dw.offsetsToNode( selection[0], selection[1] );
  44.       var imageSrc  = node.getAttribute( "src" );
  45.       var fullPath = getFullPath(imageSrc);
  46.  
  47.     // get the primary external editor for the selected item
  48.       var primaryEditorArray = dw.getPrimaryExtensionEditor(fullPath);
  49.       if (primaryEditorArray.length == 1)
  50.       {
  51.           dw.constructor.gPrimaryEditorName = "";
  52.           dw.constructor.gPrimaryEditorURL = "";
  53.       }
  54.       else
  55.       {
  56.           dw.constructor.gPrimaryEditorName = primaryEditorArray[0];
  57.           dw.constructor.gPrimaryEditorURL = primaryEditorArray[1];
  58.       }
  59.     // get the external editors for the selected item
  60.       var externalEditorArray = dw.getExtensionEditorList(fullPath);
  61.       if (externalEditorArray.length <= 1)
  62.           dw.constructor.gExternalEditors = new Array("");
  63.       else if (externalEditorArray.length == 2 && dw.constructor.gPrimaryEditorName != "")
  64.           dw.constructor.gExternalEditors = new Array("");
  65.       else
  66.       {
  67.         dw.constructor.gExternalEditors = new Array(externalEditorArray.length-2);
  68.         var index=0;
  69.           for (i=0; i < externalEditorArray.length; i++)
  70.           {
  71.             // don't add the primary editor to the list of editors
  72.             if (externalEditorArray[i] == dw.constructor.gPrimaryEditorName)
  73.                i++;
  74.             else
  75.                 dw.constructor.gExternalEditors[index++] = externalEditorArray[i];
  76.           }
  77.       }
  78.  
  79.     // put the names of the editors in the menu
  80.       var menuItems;
  81.       var i;
  82.       if (dw.constructor.gExternalEditors.length == 1)
  83.       {
  84.         // we should have pairs... if we don't then just add Browse... to the list
  85.         menuItems = new Array(1);
  86.         dw.constructor.gMenuIDs = new Array(1);
  87.         i=0;
  88.       }
  89.       else
  90.       {
  91.           // we have pairs of editor names and editor paths
  92.         // put the names in the menu and remember the paths
  93.         menuItems = new Array(dw.constructor.gExternalEditors.length/2 + 1);
  94.         dw.constructor.gMenuIDs = new Array(dw.constructor.gExternalEditors.length/2 + 1);
  95.         for (i=0; i < dw.constructor.gExternalEditors.length/2; i++)
  96.         {
  97.             // add non-primary editors to the list of editors
  98.             dw.constructor.gMenuIDs[i] = "Editor" + i;
  99.             menuItems[i] = dw.constructor.gExternalEditors[i*2] + ";id='" + escQuotes(dw.constructor.gMenuIDs[i]) + "'";
  100.         }
  101.       }
  102.  
  103.       // always add Browse... to the bottom of the list
  104.       dw.constructor.gMenuIDs[i] = "ExtEd:Browse";
  105.       menuItems[i] = MENU_Browse+";id='" + escQuotes(dw.constructor.gMenuIDs[i]) + "'";
  106.  
  107.       return menuItems;
  108.    }
  109.