home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 March / PCWorld_2005-03_cd.bin / komunikace / kmeleon / kmeleon09.exe / toolkit.jar / content / global / globalOverlay.js < prev    next >
Text File  |  2002-11-07  |  4KB  |  151 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.       // XXX FIX! we should have a way to cancel a requested quit; see
  10.       // bugzilla bug 149764
  11.       ObserverService.notifyObservers(null, "quit-application-requested", null);
  12.     }
  13.     catch (ex)
  14.     {
  15.       // dump("no observer found \n");
  16.     }
  17.   }
  18.  
  19.   var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  20.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  21.   var enumerator = windowManagerInterface.getEnumerator( null );
  22.   var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
  23.   appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService );
  24.  
  25.   var nativeAppSupport = null;
  26.   try {
  27.     nativeAppSupport = appShell.nativeAppSupport;
  28.   }
  29.   catch ( ex ) {
  30.   }
  31.  
  32.   while ( enumerator.hasMoreElements()  )
  33.   {
  34.      var domWindow = enumerator.getNext();
  35.      if (("tryToClose" in domWindow) && !domWindow.tryToClose())
  36.        return false;
  37.      domWindow.close();
  38.   };
  39.   if (!nativeAppSupport || !nativeAppSupport.isServerMode)
  40.     appShell.quit(Components.interfaces.nsIAppShellService.eAttemptQuit);
  41.   return true;
  42. }
  43.  
  44. //
  45. // Command Updater functions
  46. //
  47. function goUpdateCommand(command)
  48. {
  49.   try {
  50.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  51.  
  52.     var enabled = false;
  53.  
  54.     if ( controller )
  55.       enabled = controller.isCommandEnabled(command);
  56.  
  57.     goSetCommandEnabled(command, enabled);
  58.   }
  59.   catch (e) {
  60.     dump("An error occurred updating the "+command+" command\n");
  61.   }
  62. }
  63.  
  64. function goDoCommand(command)
  65. {
  66.   try {
  67.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  68.     if ( controller && controller.isCommandEnabled(command))
  69.       controller.doCommand(command);
  70.   }
  71.   catch (e) {
  72.     dump("An error occurred executing the "+command+" command\n");
  73.   }
  74. }
  75.  
  76.  
  77. function goSetCommandEnabled(id, enabled)
  78. {
  79.   var node = document.getElementById(id);
  80.  
  81.   if ( node )
  82.   {
  83.     if ( enabled )
  84.       node.removeAttribute("disabled");
  85.     else
  86.       node.setAttribute('disabled', 'true');
  87.   }
  88. }
  89.  
  90. function goSetMenuValue(command, labelAttribute)
  91. {
  92.   var commandNode = top.document.getElementById(command);
  93.   if ( commandNode )
  94.   {
  95.     var label = commandNode.getAttribute(labelAttribute);
  96.     if ( label )
  97.       commandNode.setAttribute('label', label);
  98.   }
  99. }
  100.  
  101. function goSetAccessKey(command, valueAttribute)
  102. {
  103.   var commandNode = top.document.getElementById(command);
  104.   if ( commandNode )
  105.   {
  106.     var value = commandNode.getAttribute(valueAttribute);
  107.     if ( value )
  108.       commandNode.setAttribute('accesskey', value);
  109.   }
  110. }
  111.  
  112. // this function is used to inform all the controllers attached to a node that an event has occurred
  113. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  114. // menu items back to their default values)
  115. function goOnEvent(node, event)
  116. {
  117.   var numControllers = node.controllers.getControllerCount();
  118.   var controller;
  119.  
  120.   for ( var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++ )
  121.   {
  122.     controller = node.controllers.getControllerAt(controllerIndex);
  123.     if ( controller )
  124.       controller.onEvent(event);
  125.   }
  126. }
  127.  
  128. function setTooltipText(aID, aTooltipText)
  129. {
  130.   var element = document.getElementById(aID);
  131.   if (element)
  132.     element.setAttribute("tooltiptext", aTooltipText);
  133. }
  134.  
  135. function FillInTooltip ( tipElement )
  136. {
  137.   var retVal = false;
  138.   var textNode = document.getElementById("TOOLTIP-tooltipText");
  139.   if (textNode) {
  140.     while (textNode.hasChildNodes())
  141.       textNode.removeChild(textNode.firstChild);
  142.     var tipText = tipElement.getAttribute("tooltiptext");
  143.     if (tipText) {
  144.       var node = document.createTextNode(tipText);
  145.       textNode.appendChild(node);
  146.       retVal = true;
  147.     }
  148.   }
  149.   return retVal;
  150. }
  151.