home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / replacedialog.js < prev    next >
Encoding:
JavaScript  |  2001-02-27  |  4.4 KB  |  135 lines

  1. /* -*- Mode: Java; tab-width: 2; 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 Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): Kin Blas <kin@netscape.com>
  22.  *
  23.  */
  24.  
  25. var gFindComponent;   // Find component.
  26. var gFindReplaceData; // Search context (passed as argument).
  27. var gReplaceDialog;      // Quick access to document/form elements.
  28.  
  29. function initDialogObject()
  30. {
  31.   // Create gReplaceDialog object and initialize.
  32.   gReplaceDialog = new Object();
  33.   gReplaceDialog.findKey         = document.getElementById("dialog.findKey");
  34.   gReplaceDialog.replaceKey      = document.getElementById("dialog.replaceKey");
  35.   gReplaceDialog.caseSensitive   = document.getElementById("dialog.caseSensitive");
  36.   gReplaceDialog.wrap            = document.getElementById("dialog.wrap");
  37.   gReplaceDialog.searchBackwards = document.getElementById("dialog.searchBackwards");
  38.   gReplaceDialog.findNext        = document.getElementById("findNext");
  39.   gReplaceDialog.replace         = document.getElementById("replace");
  40.   gReplaceDialog.replaceAll      = document.getElementById("replaceAll");
  41.   gReplaceDialog.bundle         = null;
  42. }
  43.  
  44. function loadDialog()
  45. {
  46.   // Set initial dialog field contents.
  47.   gReplaceDialog.findKey.value = gFindReplaceData.searchString;
  48.   gReplaceDialog.replaceKey.value = gFindReplaceData.replaceString;
  49.  
  50.   gReplaceDialog.caseSensitive.checked = gFindReplaceData.caseSensitive;
  51.   gReplaceDialog.wrap.checked = gFindReplaceData.wrapSearch;
  52.   gReplaceDialog.searchBackwards.checked = gFindReplaceData.searchBackwards;
  53.  
  54.   doEnabling();
  55. }
  56.  
  57. function loadData()
  58. {
  59.   // Set gFindReplaceData attributes per user input.
  60.   gFindReplaceData.searchString = gReplaceDialog.findKey.value;
  61.   gFindReplaceData.replaceString = gReplaceDialog.replaceKey.value;
  62.   gFindReplaceData.caseSensitive = gReplaceDialog.caseSensitive.checked;
  63.   gFindReplaceData.wrapSearch = gReplaceDialog.wrap.checked;
  64.   gFindReplaceData.searchBackwards = gReplaceDialog.searchBackwards.checked;
  65. }
  66.  
  67. function onLoad()
  68. {
  69.   // Init gReplaceDialog.
  70.   initDialogObject();
  71.  
  72.   // Get find component.
  73.   gFindComponent = Components.classes[ "@mozilla.org/appshell/component/find;1" ].getService();
  74.   gFindComponent = gFindComponent.QueryInterface( Components.interfaces.nsIFindComponent );
  75.  
  76.   // Save search context.
  77.   gFindReplaceData = window.arguments[0];
  78.  
  79.   // Tell search context about this dialog.
  80.   gFindReplaceData.replaceDialog = window;
  81.  
  82.   // Fill dialog.
  83.   loadDialog();
  84.  
  85.   if (gReplaceDialog.findKey.value)
  86.     gReplaceDialog.findKey.select();
  87.   else
  88.     gReplaceDialog.findKey.focus();
  89. }
  90.  
  91. function onUnload() {
  92.   // Disconnect context from this dialog.
  93.   gFindReplaceData.replaceDialog = null;
  94. }
  95.  
  96. function onFindNext()
  97. {
  98.   // Transfer dialog contents to data elements.
  99.   loadData();
  100.  
  101.   // Search.
  102.   var result = gFindComponent.findNext(gFindReplaceData);
  103.   if (!result) {
  104.     if (!gReplaceDialog.bundle)
  105.       gReplaceDialog.bundle = document.getElementById("replaceBundle");
  106.     alert(gReplaceDialog.bundle.getString("notFoundWarning"));
  107.   }
  108. }
  109.  
  110. function onReplace()
  111. {
  112.   // Transfer dialog contents to data elements.
  113.   loadData();
  114.  
  115.   // Replace.
  116.   gFindComponent.replaceNext(gFindReplaceData, false);
  117. }
  118.  
  119. function onReplaceAll()
  120. {
  121.   // Transfer dialog contents to data elements.
  122.   loadData();
  123.  
  124.   // Replace.
  125.   gFindComponent.replaceNext(gFindReplaceData, true);
  126. }
  127.  
  128. function doEnabling()
  129. {
  130.   gReplaceDialog.enabled = gReplaceDialog.findKey.value;
  131.   gReplaceDialog.findNext.disabled = !gReplaceDialog.findKey.value;
  132.   gReplaceDialog.replace.disabled = !gReplaceDialog.enabled;
  133.   gReplaceDialog.replaceAll.disabled = !gReplaceDialog.enabled;
  134. }
  135.