home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 March / PCWorld_2005-03_cd.bin / komunikace / kmeleon / kmeleon09.exe / comm.jar / content / communicator / tasksOverlay.js < prev    next >
Text File  |  2003-07-19  |  9KB  |  244 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 toOpenWindow( aWindow )
  88. {
  89.   aWindow.document.commandDispatcher.focusedWindow.focus();
  90. }
  91.  
  92. function toOpenWindowByType( inType, uri )
  93. {
  94.   // Recently opened one.
  95.   if (uri in window)
  96.     return;
  97.  
  98.   var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(nsIWindowMediator);
  99.  
  100.   var topWindow = windowManager.getMostRecentWindow( inType );
  101.  
  102.   if ( topWindow )
  103.     toOpenWindow( topWindow );
  104.   else
  105.   {
  106.     function newWindowLoaded(event) {
  107.       delete window[uri];
  108.     }
  109.     window[uri] = window.openDialog(uri, "", "all,dialog=no");
  110.     window[uri].addEventListener("load", newWindowLoaded, false);
  111.   }
  112. }
  113.  
  114.  
  115. function OpenBrowserWindow()
  116. {
  117.   var charsetArg = new String();
  118.   var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser'];
  119.   handler = handler.getService();
  120.   handler = handler.QueryInterface(Components.interfaces.nsICmdLineHandler);
  121.   var url = handler.chromeUrlForTask;
  122.   var wintype = document.documentElement.getAttribute('windowtype');
  123.   var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  124.   var browserWin = windowMediator.getMostRecentWindow("navigator:browser");
  125.  
  126.   // if a browser window already exists then set startpage to null so
  127.   // navigator.js can check pref for how new window should be opened
  128.   var startpage = browserWin ? null : handler.defaultArgs;
  129.  
  130.   // if and only if the current window is a browser window and it has a document with a character
  131.   // set, then extract the current charset menu setting from the current document and use it to
  132.   // initialize the new browser window...
  133.   if (window && (wintype == "navigator:browser") && window._content && window._content.document)
  134.   {
  135.     var DocCharset = window._content.document.characterSet;
  136.     charsetArg = "charset="+DocCharset;
  137.  
  138.     //we should "inherit" the charset menu setting in a new window
  139.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage, charsetArg);
  140.   }
  141.   else // forget about the charset information.
  142.   {
  143.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage);
  144.   }
  145. }
  146.  
  147. function CycleWindow( aType )
  148. {
  149.   var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  150.   var windowManagerInterface = windowManager.QueryInterface(nsIWindowMediator);
  151.  
  152.   var topWindowOfType = windowManagerInterface.getMostRecentWindow( aType );
  153.   var topWindow = windowManagerInterface.getMostRecentWindow( null );
  154.  
  155.   if ( topWindowOfType == null )
  156.     return null;
  157.  
  158.   if ( topWindowOfType != topWindow ) {
  159.     toOpenWindow(topWindowOfType);
  160.     return topWindowOfType;
  161.   }
  162.  
  163.   var enumerator = windowManagerInterface.getEnumerator( aType );
  164.   var firstWindow = enumerator.getNext().QueryInterface(nsIDOMWindowInternal);
  165.   var iWindow = firstWindow;
  166.   while (iWindow != topWindow && enumerator.hasMoreElements())
  167.     iWindow = enumerator.getNext().QueryInterface(nsIDOMWindowInternal);
  168.  
  169.   if (enumerator.hasMoreElements()) {
  170.     iWindow = enumerator.getNext().QueryInterface(nsIDOMWindowInternal);
  171.     toOpenWindow(iWindow);
  172.     return iWindow;
  173.   }
  174.  
  175.   if (firstWindow == topWindow) // Only one window
  176.     return null;
  177.  
  178.   toOpenWindow(firstWindow);
  179.   return firstWindow;
  180. }
  181.  
  182. function ShowWindowFromResource( node )
  183. {
  184.     var windowManagerDS = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService(nsIWindowDataSource);
  185.     
  186.     var desiredWindow = null;
  187.     var url = node.getAttribute('id');
  188.     desiredWindow = windowManagerDS.getWindowForResource( url );
  189.     if ( desiredWindow )
  190.     {
  191.         toOpenWindow(desiredWindow);
  192.     }
  193. }
  194.  
  195. function OpenTaskURL( inURL )
  196. {
  197.     
  198.     window.open( inURL );
  199. }
  200.  
  201. function ShowUpdateFromResource( node )
  202. {
  203.     var url = node.getAttribute('url');
  204.         // hack until I get a new interface on xpiflash to do a 
  205.         // look up on the name/url pair.
  206.     OpenTaskURL( "http://www.mozilla.org/binaries.html");
  207. }
  208.  
  209. function checkFocusedWindow()
  210. {
  211.   var windowManagerDS = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService(nsIWindowDataSource);
  212.  
  213.   var sep = document.getElementById("sep-window-list");
  214.   // Using double parens to avoid warning
  215.   while ((sep = sep.nextSibling)) {
  216.     var url = sep.getAttribute('id');
  217.     var win = windowManagerDS.getWindowForResource(url);
  218.     if (win == window) {
  219.       sep.setAttribute("checked", "true");
  220.       break;
  221.     }
  222.   }
  223. }
  224.  
  225. function toProfileManager()
  226. {
  227.   var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  228.              .getService(Components.interfaces.nsIWindowWatcher);
  229.   var params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
  230.                  .createInstance(Components.interfaces.nsIDialogParamBlock);
  231.   
  232.   params.SetNumberStrings(1);
  233.   params.SetString(0, "menu");
  234.   ww.openWindow(null, // no parent
  235.                 "chrome://communicator/content/profile/profileSelection.xul",
  236.                 null,
  237.                 "centerscreen,chrome,modal,titlebar",
  238.                 params);
  239.   
  240.   // Here, we don't care about the result code
  241.   // that was returned in the param block.
  242. }
  243.  
  244.