home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / communicator / tasksOverlay.js < prev    next >
Encoding:
JavaScript  |  2001-05-20  |  6.5 KB  |  204 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  *  Peter Annema <disttsc@bart.nl>
  22.  */
  23.  
  24. function toNavigator()
  25. {
  26.     CycleWindow('navigator:browser', getBrowserURL());
  27. }
  28.  
  29. // Set up a lame hack to avoid opening two bookmarks.
  30. // Could otherwise happen with two Ctrl-B's in a row.
  31. var gDisableHistory = false;
  32. function enableHistory() {
  33.   gDisableHistory = false;
  34. }
  35.  
  36. function toHistory()
  37. {
  38.   // Use a single sidebar history dialog
  39.  
  40.   var cwindowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  41.   var iwindowManager = Components.interfaces.nsIWindowMediator;
  42.   var windowManager  = cwindowManager.QueryInterface(iwindowManager);
  43.  
  44.   var historyWindow = windowManager.getMostRecentWindow('history:manager');
  45.  
  46.   if (historyWindow) {
  47.     //debug("Reuse existing history window");
  48.     historyWindow.focus();
  49.   } else {
  50.     //debug("Open a new history dialog");
  51.  
  52.     if (true == gDisableHistory) {
  53.       //debug("Recently opened one. Wait a little bit.");
  54.       return;
  55.     }
  56.     gDisableHistory = true;
  57.  
  58.     window.open( "chrome://communicator/content/history/history.xul", "_blank", "chrome,menubar,resizable,scrollbars" );
  59.     setTimeout(enableHistory, 2000);
  60.   }
  61.  
  62. }
  63.  
  64. function toJavaScriptConsole()
  65. {
  66.     toOpenWindowByType("global:console", "chrome://global/content/console.xul");
  67. }
  68.  
  69. function javaItemEnabling()
  70. {
  71.     var element = document.getElementById("java");
  72.     if (navigator.javaEnabled())
  73.       element.removeAttribute("disabled");
  74.     else
  75.       element.setAttribute("disabled", "true");
  76. }
  77.             
  78. function toJavaConsole()
  79. {
  80.     var jvmMgr = Components.classes['@mozilla.org/oji/jvm-mgr;1']
  81.                             .getService(Components.interfaces.nsIJVMManager)
  82.     jvmMgr.showJavaConsole();
  83. }
  84.  
  85. function toOpenWindowByType( inType, uri )
  86. {
  87.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  88.  
  89.     var    windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  90.  
  91.     var topWindow = windowManagerInterface.getMostRecentWindow( inType );
  92.     
  93.     if ( topWindow )
  94.         topWindow.focus();
  95.     else
  96.         window.open(uri, "_blank", "chrome,menubar,toolbar,resizable,scrollbars");
  97. }
  98.  
  99.  
  100. function OpenBrowserWindow()
  101. {
  102.   var charsetArg = new String();
  103.   var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser'];
  104.   handler = handler.getService();
  105.   handler = handler.QueryInterface(Components.interfaces.nsICmdLineHandler);
  106.   var startpage = handler.defaultArgs;
  107.   var url = handler.chromeUrlForTask;
  108.   var wintype = document.firstChild.getAttribute('windowtype');
  109.  
  110.   // if and only if the current window is a browser window and it has a document with a character
  111.   // set, then extract the current charset menu setting from the current document and use it to
  112.   // initialize the new browser window...
  113.   if (window && (wintype == "navigator:browser") && window._content && window._content.document)
  114.   {
  115.     var DocCharset = window._content.document.characterSet;
  116.     charsetArg = "charset="+DocCharset;
  117.  
  118.     //we should "inherit" the charset menu setting in a new window
  119.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage, charsetArg);
  120.   }
  121.   else // forget about the charset information.
  122.   {
  123.     window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage);
  124.   }
  125. }
  126.  
  127. function newWindowOfType( aType )
  128. {
  129.   switch (aType) {
  130.   case "navigator:browser":
  131.     OpenBrowserWindow();
  132.     break;
  133.   case "composer:html":
  134.     NewEditorWindow();
  135.     break;
  136.   default:
  137.     break;
  138.   }
  139. }
  140.  
  141. function CycleWindow( aType, aChromeURL )
  142. {
  143.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  144.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  145.  
  146.   var topWindowOfType = windowManagerInterface.getMostRecentWindow( aType );
  147.   var topWindow = windowManagerInterface.getMostRecentWindow( null );
  148.  
  149.   if ( topWindowOfType == null )
  150.     newWindowOfType( aType );
  151.   else if ( topWindowOfType != topWindow )
  152.     topWindowOfType.focus();
  153.   else {
  154.     var enumerator = windowManagerInterface.getEnumerator( aType );
  155.     var firstWindow = windowManagerInterface.convertISupportsToDOMWindow ( enumerator.getNext() );
  156.     var iWindow = firstWindow; // ;-)
  157.     while ( iWindow != topWindow && enumerator.hasMoreElements() )
  158.       iWindow = windowManagerInterface.convertISupportsToDOMWindow ( enumerator.getNext() );
  159.   
  160.     var desiredWindow = firstWindow;
  161.     if ( enumerator.hasMoreElements() )
  162.       desiredWindow = windowManagerInterface.convertISupportsToDOMWindow ( enumerator.getNext() );
  163.     if ( desiredWindow == topWindow ) // Only one window, open a new one 
  164.       newWindowOfType( aType );
  165.     else
  166.       desiredWindow.focus();
  167.   }
  168. }
  169.  
  170. function toEditor()
  171. {
  172.     CycleWindow('composer:html', 'chrome://editor/content/editor.xul');
  173. }
  174.  
  175. function ShowWindowFromResource( node )
  176. {
  177.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  178.     var    windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  179.     
  180.     var desiredWindow = null;
  181.     var url = node.getAttribute('id');
  182.     desiredWindow = windowManagerInterface.getWindowForResource( url );
  183.     if ( desiredWindow )
  184.     {
  185.         desiredWindow.focus();
  186.     }
  187. }
  188.  
  189. function OpenTaskURL( inURL )
  190. {
  191.     
  192.     window.open( inURL );
  193. }
  194.  
  195. function ShowUpdateFromResource( node )
  196. {
  197.     var url = node.getAttribute('url');
  198.         // hack until I get a new interface on xpiflash to do a 
  199.         // look up on the name/url pair.
  200.     OpenTaskURL( "http://www.mozilla.org/binaries.html");
  201. }
  202.  
  203.  
  204.