home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / tasksOverlay.js < prev    next >
Text File  |  2003-06-08  |  8KB  |  226 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *  Peter Annema <disttsc@bart.nl>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. const nsIDOMWindowInternal = Components.interfaces.nsIDOMWindowInternal;
  40. const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
  41. const nsIWindowDataSource = Components.interfaces.nsIWindowDataSource;
  42.  
  43. function toNavigator()
  44. {
  45.   if (!CycleWindow("navigator:browser"))
  46.     OpenBrowserWindow();
  47. }
  48.  
  49. function toDownloadManager()
  50. {
  51.   var dlmgr = Components.classes['@mozilla.org/download-manager;1'].getService();
  52.   dlmgr = dlmgr.QueryInterface(Components.interfaces.nsIDownloadManager);
  53.  
  54.   var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  55.   windowMediator = windowMediator.QueryInterface(nsIWindowMediator);
  56.  
  57.   var dlmgrWindow = windowMediator.getMostRecentWindow("Download:Manager");
  58.   if (dlmgrWindow) {
  59.     dlmgrWindow.focus();
  60.   }
  61.   else {
  62.     dlmgr.open(window, null);
  63.   }
  64. }
  65.   
  66. function toJavaScriptConsole()
  67. {
  68.     toOpenWindowByType("global:console", "chrome://global/content/console.xul");
  69. }
  70.  
  71. function javaItemEnabling()
  72. {
  73.     var element = document.getElementById("java");
  74.     if (navigator.javaEnabled())
  75.       element.removeAttribute("disabled");
  76.     else
  77.       element.setAttribute("disabled", "true");
  78. }
  79.             
  80. function toJavaConsole()
  81. {
  82.     var jvmMgr = Components.classes['@mozilla.org/oji/jvm-mgr;1']
  83.                             .getService(Components.interfaces.nsIJVMManager)
  84.     jvmMgr.showJavaConsole();
  85. }
  86.  
  87. function toOpenWindowByType( inType, uri )
  88. {
  89.     var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  90.  
  91.     var    windowManagerInterface = windowManager.QueryInterface(nsIWindowMediator);
  92.  
  93.     var topWindow = windowManagerInterface.getMostRecentWindow( inType );
  94.     
  95.     if ( topWindow )
  96.         topWindow.focus();
  97.     else
  98.         window.open(uri, "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
  99. }
  100.  
  101.  
  102. function OpenBrowserWindow()
  103. {
  104.   var charsetArg = new String();
  105.   var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser'];
  106.   handler = handler.getService();
  107.   handler = handler.QueryInterface(Components.interfaces.nsICmdLineHandler);
  108.   var startpage = handler.defaultArgs;
  109.   var url = handler.chromeUrlForTask;
  110.   var wintype = document.firstChild.getAttribute('windowtype');
  111.  
  112.   // if and only if the current window is a browser window and it has a document with a character
  113.   // set, then extract the current charset menu setting from the current document and use it to
  114.   // initialize the new browser window...
  115.   if (window && (wintype == "navigator:browser") && window._content && window._content.document)
  116.   {
  117.     var DocCharset = window._content.document.characterSet;
  118.     charsetArg = "charset="+DocCharset;
  119.  
  120.     //we should "inherit" the charset menu setting in a new window
  121.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage, charsetArg);
  122.   }
  123.   else // forget about the charset information.
  124.   {
  125.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage);
  126.   }
  127. }
  128.  
  129. function CycleWindow( aType )
  130. {
  131.   var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  132.   var windowManagerInterface = windowManager.QueryInterface(nsIWindowMediator);
  133.  
  134.   var topWindowOfType = windowManagerInterface.getMostRecentWindow( aType );
  135.   var topWindow = windowManagerInterface.getMostRecentWindow( null );
  136.  
  137.   if ( topWindowOfType == null )
  138.     return null;
  139.  
  140.   if ( topWindowOfType != topWindow ) {
  141.     topWindowOfType.focus();
  142.     return topWindowOfType;
  143.   }
  144.  
  145.   var enumerator = windowManagerInterface.getEnumerator( aType );
  146.   var firstWindow = enumerator.getNext().QueryInterface(nsIDOMWindowInternal);
  147.   var iWindow = firstWindow;
  148.   while (iWindow != topWindow && enumerator.hasMoreElements())
  149.     iWindow = enumerator.getNext().QueryInterface(nsIDOMWindowInternal);
  150.  
  151.   if (enumerator.hasMoreElements()) {
  152.     iWindow = enumerator.getNext().QueryInterface(nsIDOMWindowInternal);
  153.     iWindow.focus();
  154.     return iWindow;
  155.   }
  156.  
  157.   if (firstWindow == topWindow) // Only one window
  158.     return null;
  159.  
  160.   firstWindow.focus();
  161.   return firstWindow;
  162. }
  163.  
  164. function ShowWindowFromResource( node )
  165. {
  166.     var windowManagerDS = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService(nsIWindowDataSource);
  167.     
  168.     var desiredWindow = null;
  169.     var url = node.getAttribute('id');
  170.     desiredWindow = windowManagerDS.getWindowForResource( url );
  171.     if ( desiredWindow )
  172.     {
  173.         desiredWindow.focus();
  174.     }
  175. }
  176.  
  177. function OpenTaskURL( inURL )
  178. {
  179.     
  180.     window.open( inURL );
  181. }
  182.  
  183. function ShowUpdateFromResource( node )
  184. {
  185.     var url = node.getAttribute('url');
  186.         // hack until I get a new interface on xpiflash to do a 
  187.         // look up on the name/url pair.
  188.     OpenTaskURL( "http://www.mozilla.org/binaries.html");
  189. }
  190.  
  191. function checkFocusedWindow()
  192. {
  193.   var windowManagerDS = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService(nsIWindowDataSource);
  194.  
  195.   var sep = document.getElementById("sep-window-list");
  196.   // Using double parens to avoid warning
  197.   while ((sep = sep.nextSibling)) {
  198.     var url = sep.getAttribute('id');
  199.     var win = windowManagerDS.getWindowForResource(url);
  200.     if (win == window) {
  201.       sep.setAttribute("checked", "true");
  202.       break;
  203.     }
  204.   }
  205. }
  206.  
  207. function toProfileManager()
  208. {
  209.   var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  210.              .getService(Components.interfaces.nsIWindowWatcher);
  211.   var params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
  212.                  .createInstance(Components.interfaces.nsIDialogParamBlock);
  213.   
  214.   params.SetNumberStrings(1);
  215.   params.SetString(0, "menu");
  216.   ww.openWindow(null, // no parent
  217.                 "chrome://communicator/content/profile/profileSelection.xul",
  218.                 null,
  219.                 "centerscreen,chrome,modal,titlebar",
  220.                 params);
  221.   
  222.   // Here, we don't care about the result code
  223.   // that was returned in the param block.
  224. }
  225.  
  226.