doing the right thing to fix bug 40656, r=cmanske

This commit is contained in:
morse%netscape.com 2000-05-31 03:28:57 +00:00
Родитель 69eb2844b7
Коммит 1bb7b10eee
2 изменённых файлов: 191 добавлений и 105 удалений

Просмотреть файл

@ -1,93 +1,167 @@
function selectDialogOnLoad()
{
dump("selectDialogOnLoad \n");
doSetOKCancel( commonDialogOnOK, commonDialogOnCancel );
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Alec Flett <alecf@netscape.com>
*/
function selectDialogOnLoad() {
dump("selectDialogOnLoad \n");
doSetOKCancel( commonDialogOnOK, commonDialogOnCancel );
param = window.arguments[0].QueryInterface( Components.interfaces.nsIDialogParamBlock );
if( !param )
dump( " error getting param block interface\n" );
var messageText = param.GetString( 1 );
dump("message: "+ messageText +"\n");
{
var messageFragment;
// Let the caller use "\n" to cause breaks
// Translate these into <br> tags
var messageParent = (document.getElementById("info.txt"));
done = false;
while (!done) {
breakIndex = messageText.indexOf('\n');
if (breakIndex == 0) {
// Ignore break at the first character
messageText = messageText.slice(1);
dump("Found break at begining\n");
messageFragment = "";
} else if (breakIndex > 0) {
// The fragment up to the break
messageFragment = messageText.slice(0, breakIndex);
// Chop off fragment we just found from remaining string
messageText = messageText.slice(breakIndex+1);
} else {
// "\n" not found. We're done
done = true;
messageFragment = messageText;
}
messageNode = document.createTextNode(messageFragment);
if (messageNode) {
messageParent.appendChild(messageNode);
}
// This is needed when the default namespace of the document is XUL
breakNode = document.createElementWithNameSpace("BR", "http://www.w3.org/TR/REC-html40");
if (breakNode) {
messageParent.appendChild(breakNode);
}
}
}
param = window.arguments[0].QueryInterface( Components.interfaces.nsIDialogParamBlock );
if( !param )
dump( " error getting param block interface\n" );
var messageText = param.GetString( 1 );
dump("message: "+ messageText +"\n");
{
var messageFragment;
var windowTitle = param.GetString( 0 );
dump("title: "+ windowTitle +"\n");
window.title = windowTitle;
// Let the caller use "\n" to cause breaks
// Translate these into <br> tags
var messageParent = (document.getElementById("info.txt"));
done = false;
while (!done) {
breakIndex = messageText.indexOf('\n');
if (breakIndex == 0) {
// Ignore break at the first character
messageText = messageText.slice(1);
dump("Found break at begining\n");
messageFragment = "";
} else if (breakIndex > 0) {
// The fragment up to the break
messageFragment = messageText.slice(0, breakIndex);
listBox = document.getElementById("list");
var numItems = param.GetInt( 2 )
// Chop off fragment we just found from remaining string
messageText = messageText.slice(breakIndex+1);
} else {
// "\n" not found. We're done
done = true;
messageFragment = messageText;
}
messageNode = document.createTextNode(messageFragment);
if (messageNode)
messageParent.appendChild(messageNode);
for ( i = 2; i <= numItems+1; i++ ) {
var newString = param.GetString( i );
dump("setting string "+newString+"\n");
AppendStringToTreelist(listBox, newString);
}
dump("number of items "+ listBox.options.length +" "+listBox.length+"\n");
listBox.selectedIndex = 0;
// This is needed when the default namespace of the document is XUL
breakNode = document.createElementWithNameSpace("BR", "http://www.w3.org/TR/REC-html40");
if (breakNode)
messageParent.appendChild(breakNode);
}
}
var windowTitle = param.GetString( 0 );
dump("title: "+ windowTitle +"\n");
window.title = windowTitle;
listBox = document.getElementById("list");
var numItems = param.GetInt( 2 )
for ( i = 2; i <= numItems+1; i++ )
{
var newString = param.GetString( i );
dump("setting string "+newString+"\n");
var newOption = new Option( newString );
listBox.options[listBox.options.length] = newOption;
}
dump("number of items "+ listBox.options.length +" "+listBox.length+"\n");
listBox.selectedIndex = 0;
// resize the window to the content
window.sizeToContent();
// resize the window to the content
window.sizeToContent();
// Move to the right location
moveToAlertPosition();
param.SetInt(0, 1 );
centerWindowOnScreen();
// Move to the right location
moveToAlertPosition();
param.SetInt(0, 1 );
centerWindowOnScreen();
}
function commonDialogOnOK()
{
dump("commonDialogOnOK \n");
param.SetInt(2, listBox.selectedIndex );
param.SetInt(0, 0 );
return true;
function commonDialogOnOK() {
dump("commonDialogOnOK \n");
param.SetInt(2, listBox.selectedIndex );
param.SetInt(0, 0 );
return true;
}
function commonDialogOnCancel()
function commonDialogOnCancel() {
dump("commonDialogOnCancel \n");
param.SetInt(2, listBox.selectedIndex );
param.SetInt(0, 1 );
return true;
}
// following routine should really be in a global utilities package
function AppendStringToMenulist(menulist, string) {
if (menulist) {
var menupopup = menulist.firstChild;
// May not have any popup yet -- so create one
if (!menupopup)
{
menupopup = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menupopup");
if (menupopup) {
menulist.appendChild(menupopup);
} else {
dump("Failed to create menupoup\n");
return null;
}
}
menuItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
if (menuItem) {
menuItem.setAttribute("value", string);
menupopup.appendChild(menuItem);
return menuItem;
}
}
return null;
}
function AppendStringToTreelist(tree, string)
{
dump("commonDialogOnCancel \n");
param.SetInt(2, listBox.selectedIndex );
param.SetInt(0, 1 );
return true;
if (tree)
{
var treechildren = tree.firstChild;
if (!treechildren)
{
treechildren = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "treechildren");
if (treechildren)
tree.appendChild(treechildren);
else
{
dump("Failed to create <treechildren>\n");
return null;
}
}
var treeitem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "treeitem");
var treerow = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "treerow");
var treecell = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "treecell");
if (treeitem && treerow && treecell)
{
treerow.appendChild(treecell);
treeitem.appendChild(treerow);
treechildren.appendChild(treeitem)
treecell.setAttribute("value", string);
var len = Number(tree.getAttribute("length"));
if (!len) len = -1;
tree.setAttribute("length",len+1);
return treeitem;
}
}
return null;
}

Просмотреть файл

@ -1,31 +1,43 @@
<?xml version="1.0"?>
<!-- The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s): ______________________________________. -->
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
<!DOCTYPE window SYSTEM "chrome://global/locale/commonDialog.dtd">
<window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
align="vertical"
onload="selectDialogOnLoad()"
class="dialog"
height ="250">
<script language="JavaScript" src="chrome://global/content/selectDialog.js" />
<keyset id="keyset"/>
<box align="vertical" style="width: 24em;margin: 5px;">
<html:div id="info.txt" style="margin-left:2em; margin-right:2em; margin-top:5px;" flex="100%">
</html:div>
<html:select size="8" id ="list" style=" margin-top:5px;margin-left:2em; margin-right:2em;" >
</html:select>
</box>
<box id="okCancelButtons"/>
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
align="vertical"
onload="selectDialogOnLoad()"
class="dialog">
<script language="JavaScript" src="chrome://global/content/selectDialog.js" />
<keyset id="keyset"/>
<box align="vertical" style="width: 24em;margin: 5px;">
<div id="info.txt" style="margin-left:2em; margin-right:2em; margin-top:5px;" flex="100%"/>
<box orient="vertical">
<tree rows="4" class="list" id="list" flex="1"/>
</box>
</box>
<box id="okCancelButtons"/>
</window>