home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / globalOverlay.js < prev    next >
Text File  |  2001-02-14  |  4KB  |  145 lines

  1. function goQuitApplication()
  2. {
  3.     var ObserverService = Components.classes["@mozilla.org/observer-service;1"].getService();
  4.     ObserverService = ObserverService.QueryInterface(Components.interfaces.nsIObserverService);
  5.     if (ObserverService)
  6.     {
  7.         try 
  8.         {
  9.             ObserverService.Notify(null, "quit-application", null);
  10.         } 
  11.         catch (ex) 
  12.         {
  13.             // dump("no observer found \n");
  14.         }
  15.     }
  16.     
  17.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  18.     var    windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  19.     var enumerator = windowManagerInterface.getEnumerator( null );
  20.  
  21.     while ( enumerator.hasMoreElements()  )
  22.     {
  23.         var  windowToClose = enumerator.getNext();
  24.         var domWindow = windowManagerInterface.convertISupportsToDOMWindow( windowToClose );
  25.         domWindow.focus();
  26.         if ( domWindow.tryToClose == null )
  27.         {
  28.             // dump(" window.close \n");
  29.             domWindow.close();
  30.         }
  31.         else
  32.         {
  33.             // dump(" try to close \n" );
  34.             if ( !domWindow.tryToClose() )
  35.                 return false;
  36.         }
  37.     };
  38.     
  39.     // call appshell exit
  40.     var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
  41.     appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService );
  42.     appShell.Quit();
  43.     return true;
  44. }
  45.  
  46. //
  47. // Command Updater functions
  48. //
  49. function goUpdateCommand(command)
  50. {
  51.   try {
  52.       var controller = top.document.commandDispatcher.getControllerForCommand(command);
  53.       
  54.       var enabled = false;
  55.       
  56.       if ( controller )
  57.           enabled = controller.isCommandEnabled(command);
  58.  
  59.       goSetCommandEnabled(command, enabled);
  60.   }
  61.   catch (e) {
  62.     dump("An error occurred updating the "+command+" command\n");
  63.   }        
  64. }
  65.  
  66. function goDoCommand(command)
  67. {
  68.  
  69.   try {
  70.       var controller = top.document.commandDispatcher.getControllerForCommand(command);
  71.  
  72.       if ( controller && controller.isCommandEnabled(command))
  73.           controller.doCommand(command);
  74.   }
  75.   catch (e) {
  76.     dump("An error occurred executing the "+command+" command\n");
  77.   }        
  78. }
  79.  
  80.  
  81. function goSetCommandEnabled(id, enabled)
  82. {
  83.     var node = top.document.getElementById(id);
  84.  
  85.     if ( node )
  86.     {
  87.         if ( enabled )
  88.             node.removeAttribute("disabled");
  89.         else
  90.             node.setAttribute('disabled', 'true');
  91.     }
  92. }
  93.  
  94. function goSetMenuValue(command, valueAttribute)
  95. {
  96.     var commandNode = top.document.getElementById(command);
  97.     if ( commandNode )
  98.     {
  99.         var value = commandNode.getAttribute(valueAttribute);
  100.         if ( value )
  101.             commandNode.setAttribute('value', value);
  102.     }
  103. }
  104.  
  105. // this function is used to inform all the controllers attached to a node that an event has occurred
  106. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  107. // menu items back to their default values)
  108. function goOnEvent(node, event)
  109. {
  110.     var numControllers = node.controllers.getControllerCount();
  111.     var controller;
  112.     
  113.     for ( var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++ )
  114.     {
  115.         controller = node.controllers.getControllerAt(controllerIndex);
  116.         if ( controller )
  117.             controller.onEvent(event);
  118.     }
  119. }
  120.  
  121. function setTooltipText(aID, aTooltipText)
  122. {
  123.   var element = document.getElementById(aID);
  124.   if (element)
  125.     element.setAttribute("tooltiptext", aTooltipText);
  126. }
  127.  
  128. function FillInTooltip ( tipElement )
  129. {
  130.   var retVal = false;
  131.   var textNode = document.getElementById("TOOLTIP_tooltipText");
  132.   if ( textNode ) {
  133.     try {  
  134.       var tipText = tipElement.getAttribute("tooltiptext");
  135.       if ( tipText != "" ) {
  136.         textNode.setAttribute('value', tipText);
  137.         retVal = true;
  138.       }
  139.     }
  140.     catch (e) { }
  141.   }
  142.   
  143.   return retVal;
  144. }
  145.