зеркало из https://github.com/mozilla/pjs.git
Context doesn't persist in find/replace dialog and other cleanup (66456). r=timeless sr=kin
This commit is contained in:
Родитель
ea02998848
Коммит
937d210d6d
|
@ -26,23 +26,10 @@ var gFindComponent; // Find component.
|
|||
var gFindReplaceData; // Search context (passed as argument).
|
||||
var gReplaceDialog; // Quick access to document/form elements.
|
||||
|
||||
function string2Bool( value )
|
||||
{
|
||||
return value != "false";
|
||||
}
|
||||
|
||||
function bool2String( value )
|
||||
{
|
||||
if ( value )
|
||||
return "true";
|
||||
else
|
||||
return "false";
|
||||
}
|
||||
|
||||
function initDialog()
|
||||
function initDialogObject()
|
||||
{
|
||||
// Create gReplaceDialog object and initialize.
|
||||
gReplaceDialog = new Object;
|
||||
gReplaceDialog = new Object();
|
||||
gReplaceDialog.findKey = document.getElementById("dialog.findKey");
|
||||
gReplaceDialog.replaceKey = document.getElementById("dialog.replaceKey");
|
||||
gReplaceDialog.caseSensitive = document.getElementById("dialog.caseSensitive");
|
||||
|
@ -51,46 +38,20 @@ function initDialog()
|
|||
gReplaceDialog.findNext = document.getElementById("findNext");
|
||||
gReplaceDialog.replace = document.getElementById("replace");
|
||||
gReplaceDialog.replaceAll = document.getElementById("replaceAll");
|
||||
gReplaceDialog.close = document.getElementById("close");
|
||||
gReplaceDialog.enabled = false;
|
||||
gReplaceDialog.bundle = null;
|
||||
}
|
||||
|
||||
function loadDialog()
|
||||
{
|
||||
// Set initial dialog field contents.
|
||||
gReplaceDialog.findKey.setAttribute( "value", gFindReplaceData.searchString );
|
||||
gReplaceDialog.replaceKey.setAttribute( "value", gFindReplaceData.replaceString );
|
||||
gReplaceDialog.findKey.value = gFindReplaceData.searchString;
|
||||
gReplaceDialog.replaceKey.value = gFindReplaceData.replaceString;
|
||||
|
||||
if ( gFindReplaceData.caseSensitive ) {
|
||||
gReplaceDialog.caseSensitive.setAttribute( "checked", "" );
|
||||
} else {
|
||||
gReplaceDialog.caseSensitive.removeAttribute( "checked" );
|
||||
}
|
||||
gReplaceDialog.caseSensitive.checked = gFindReplaceData.caseSensitive;
|
||||
gReplaceDialog.wrap.checked = gFindReplaceData.wrapSearch;
|
||||
gReplaceDialog.searchBackwards.checked = gFindReplaceData.searchBackwards;
|
||||
|
||||
if ( gFindReplaceData.wrapSearch ) {
|
||||
gReplaceDialog.wrap.setAttribute( "checked", "" );
|
||||
} else {
|
||||
gReplaceDialog.wrap.removeAttribute( "checked" );
|
||||
}
|
||||
|
||||
if ( gFindReplaceData.searchBackwards ) {
|
||||
gReplaceDialog.searchBackwards.setAttribute( "checked", "" );
|
||||
} else {
|
||||
gReplaceDialog.searchBackwards.removeAttribute( "checked" );
|
||||
}
|
||||
|
||||
// disable the findNext button if no text
|
||||
if (gReplaceDialog.findKey.getAttribute("value") == "") {
|
||||
gReplaceDialog.findNext.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
// disable the replace and replaceAll buttons if no
|
||||
// find or replace text
|
||||
if (gReplaceDialog.findKey.getAttribute("value") == "") {
|
||||
gReplaceDialog.replace.setAttribute("disabled", "true");
|
||||
gReplaceDialog.replaceAll.setAttribute("disabled", "true");
|
||||
}
|
||||
gReplaceDialog.findKey.focus();
|
||||
doEnabling();
|
||||
}
|
||||
|
||||
function loadData()
|
||||
|
@ -106,16 +67,11 @@ function loadData()
|
|||
function onLoad()
|
||||
{
|
||||
// Init gReplaceDialog.
|
||||
initDialog();
|
||||
initDialogObject();
|
||||
|
||||
// Get find component.
|
||||
gFindComponent = Components.classes[ "@mozilla.org/appshell/component/find;1" ].getService();
|
||||
gFindComponent = gFindComponent.QueryInterface( Components.interfaces.nsIFindComponent );
|
||||
if ( !gFindComponent ) {
|
||||
alert( "Error accessing find component\n" );
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Save search context.
|
||||
gFindReplaceData = window.arguments[0];
|
||||
|
@ -126,7 +82,9 @@ function onLoad()
|
|||
// Fill dialog.
|
||||
loadDialog();
|
||||
|
||||
// Give focus to search text field.
|
||||
if (gReplaceDialog.findKey.value)
|
||||
gReplaceDialog.findKey.select();
|
||||
else
|
||||
gReplaceDialog.findKey.focus();
|
||||
}
|
||||
|
||||
|
@ -141,9 +99,12 @@ function onFindNext()
|
|||
loadData();
|
||||
|
||||
// Search.
|
||||
gFindComponent.findNext( gFindReplaceData );
|
||||
|
||||
return true;
|
||||
var result = gFindComponent.findNext(gFindReplaceData);
|
||||
if (!result) {
|
||||
if (!gReplaceDialog.bundle)
|
||||
gReplaceDialog.bundle = document.getElementById("replaceBundle");
|
||||
alert(gReplaceDialog.bundle.getString("notFoundWarning"));
|
||||
}
|
||||
}
|
||||
|
||||
function onReplace()
|
||||
|
@ -153,8 +114,6 @@ function onReplace()
|
|||
|
||||
// Replace.
|
||||
gFindComponent.replaceNext(gFindReplaceData, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onReplaceAll()
|
||||
|
@ -164,37 +123,12 @@ function onReplaceAll()
|
|||
|
||||
// Replace.
|
||||
gFindComponent.replaceNext(gFindReplaceData, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onClose()
|
||||
function doEnabling()
|
||||
{
|
||||
window.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
function onTyping()
|
||||
{
|
||||
if ( gReplaceDialog.enabled ) {
|
||||
// Disable findNext, replace, and replaceAll if they delete all the text.
|
||||
if ( gReplaceDialog.findKey.value == "" ) {
|
||||
gReplaceDialog.enabled = false;
|
||||
gReplaceDialog.findNext.setAttribute("disabled", "true");
|
||||
}
|
||||
} else {
|
||||
// Enable OK once the user types something.
|
||||
if ( gReplaceDialog.findKey.value != "" ) {
|
||||
gReplaceDialog.enabled = true;
|
||||
gReplaceDialog.findNext.removeAttribute("disabled");
|
||||
}
|
||||
}
|
||||
|
||||
if ( gReplaceDialog.enabled ) {
|
||||
gReplaceDialog.replace.removeAttribute("disabled");
|
||||
gReplaceDialog.replaceAll.removeAttribute("disabled");
|
||||
} else {
|
||||
gReplaceDialog.replace.setAttribute("disabled", "true");
|
||||
gReplaceDialog.replaceAll.setAttribute("disabled", "true");
|
||||
}
|
||||
gReplaceDialog.enabled = gReplaceDialog.findKey.value;
|
||||
gReplaceDialog.findNext.disabled = !gReplaceDialog.findKey.value;
|
||||
gReplaceDialog.replace.disabled = !gReplaceDialog.enabled;
|
||||
gReplaceDialog.replaceAll.disabled = !gReplaceDialog.enabled;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
The contents of this file are subject to the Netscape Public
|
||||
|
@ -23,9 +23,7 @@ Contributor(s): Kin Blas <kin@netscape.com>
|
|||
-->
|
||||
|
||||
<?xml-stylesheet href="chrome://navigator/skin/" type="text/css"?>
|
||||
|
||||
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://global/locale/replacedialog.dtd">
|
||||
|
||||
<window xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
|
@ -34,39 +32,40 @@ Contributor(s): Kin Blas <kin@netscape.com>
|
|||
onload="onLoad();"
|
||||
onunload="onUnload();"
|
||||
title="&replaceDialog.title;"
|
||||
debug="false"
|
||||
class="dialog"
|
||||
align="vertical"
|
||||
persist="screenX screenY"
|
||||
screenX="24" screenY="24">
|
||||
|
||||
<html:script language="JavaScript" src="chrome://global/content/replacedialog.js"/>
|
||||
<script type="text/javascript" src="chrome://global/content/replacedialog.js"/>
|
||||
<stringbundle id="replaceBundle" src="chrome://global/locale/finddialog.properties"/>
|
||||
|
||||
<box>
|
||||
|
||||
<!-- hack. we seem to need this separator to get it to render -->
|
||||
<separator orient="vertical" class="thin"/>
|
||||
|
||||
<box orient="vertical">
|
||||
<vbox>
|
||||
<text class="label" value="&findField.label;"/>
|
||||
<separator class="thin"/>
|
||||
<text class="label" value="&replaceField.label;"/>
|
||||
</box>
|
||||
</vbox>
|
||||
|
||||
<box orient="vertical">
|
||||
<textfield id="dialog.findKey" oninput="return onTyping();"/>
|
||||
<textfield id="dialog.replaceKey" oninput="return onTyping();"/>
|
||||
<box orient="vertical" autostretch="never">
|
||||
<vbox>
|
||||
<textfield id="dialog.findKey" oninput="doEnabling();"/>
|
||||
<textfield id="dialog.replaceKey" oninput="doEnabling();"/>
|
||||
<vbox autostretch="never">
|
||||
<checkbox id="dialog.caseSensitive" value="&caseSensitiveCheckbox.label;"/>
|
||||
<checkbox id="dialog.wrap" value="&wrapCheckbox.label;"/>
|
||||
<checkbox id="dialog.searchBackwards" value="&backwardsCheckbox.label;"/>
|
||||
</box>
|
||||
</box>
|
||||
<box orient="vertical">
|
||||
</vbox>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<button class="dialog" id="findNext" value="&findNextButton.label;" oncommand="onFindNext();"/>
|
||||
<button class="dialog" id="replace" value="&replaceButton.label;" oncommand="onReplace();"/>
|
||||
<button class="dialog" id="replaceAll" value="&replaceAllButton.label;" oncommand="onReplaceAll();"/>
|
||||
<button class="dialog" id="close" value="&closeButton.label;" oncommand="onClose();"/>
|
||||
</box>
|
||||
<button class="dialog" id="close" value="&closeButton.label;" oncommand="close();"/>
|
||||
</vbox>
|
||||
</box>
|
||||
|
||||
<separator/>
|
||||
|
|
Загрузка…
Ссылка в новой задаче