first add. not part of the build system yet. fix 38321
git-svn-id: svn://10.0.0.236/trunk@69104 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
326
mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.js
Normal file
326
mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.js
Normal file
@@ -0,0 +1,326 @@
|
||||
/*
|
||||
* 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):
|
||||
* Frank Tang ftang@netscape.com
|
||||
*/
|
||||
|
||||
|
||||
var charsetList = new Array();
|
||||
var charsetDict = new Array();
|
||||
var title="";
|
||||
var charset="";
|
||||
var titleWasEdited = false;
|
||||
var charsetWasChanged = false;
|
||||
var insertNewContentType = false;
|
||||
var contenttypeElement;
|
||||
var initDone = false;
|
||||
|
||||
|
||||
//Cancel() is in EdDialogCommon.js
|
||||
|
||||
// dialog initialization code
|
||||
function Startup()
|
||||
{
|
||||
if (!InitEditorShell())
|
||||
return;
|
||||
|
||||
doSetOKCancel(onOK, null);
|
||||
|
||||
// Create dialog object to store controls for easy access
|
||||
dialog = new Object;
|
||||
// GET EACH CONTROL -- E.G.:
|
||||
dialog.TitleInput = document.getElementById("TitleInput");
|
||||
dialog.charsetTree = document.getElementById('CharsetTree');
|
||||
//dialog.charsetRoot = document.getElementById('CharsetRoot');
|
||||
|
||||
contenttypeElement = GetHTTPEquivMetaElement("content-type");
|
||||
if(! contenttypeElement )
|
||||
{
|
||||
contenttypeElement = CreateHTTPEquivMetaElement("content-type");
|
||||
if( ! contenttypeElement )
|
||||
window.close();
|
||||
insertNewContentType = true;
|
||||
}
|
||||
|
||||
InitDialog();
|
||||
|
||||
// SET FOCUS TO FIRST CONTROL
|
||||
//dialog.editBox.focus();
|
||||
//dialog.TitleInput.focus();
|
||||
dialog.charsetTree.focus();
|
||||
LoadAvailableCharSets();
|
||||
initDone = true;
|
||||
}
|
||||
|
||||
function InitDialog() {
|
||||
|
||||
dialog.TitleInput.value = editorShell.GetDocumentTitle();
|
||||
charset = editorShell.GetDocumentCharacterSet();
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
if(ValidateData())
|
||||
{
|
||||
if(titleWasEdited) {
|
||||
editorShell.SetDocumentTitle(title);
|
||||
}
|
||||
|
||||
if(charsetWasChanged)
|
||||
{
|
||||
SetMetaElementContent(contenttypeElement, "text/html; charset=" + charset, insertNewContentType);
|
||||
editorShell.SetDocumentCharacterSet(charset);
|
||||
}
|
||||
// goDoCommand('cmd_saveAs');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function LoadAvailableCharSets()
|
||||
{
|
||||
try {
|
||||
var ccm = Components.classes['component://netscape/charset-converter-manager'];
|
||||
|
||||
if (ccm) {
|
||||
ccm = ccm.getService();
|
||||
ccm = ccm.QueryInterface(Components.interfaces.nsICharsetConverterManager2);
|
||||
charsetList = ccm.GetDecoderList();
|
||||
charsetList = charsetList.QueryInterface(Components.interfaces.nsISupportsArray);
|
||||
charsetList.sort;
|
||||
}
|
||||
} catch(ex)
|
||||
{
|
||||
dump("failed to get charset mgr\n");
|
||||
}
|
||||
if (charsetList)
|
||||
{
|
||||
var j=0;
|
||||
for (i = 0; i < charsetList.Count(); i++)
|
||||
{
|
||||
atom = charsetList.GetElementAt(i);
|
||||
atom = atom.QueryInterface(Components.interfaces.nsIAtom);
|
||||
|
||||
if (atom) {
|
||||
str = atom.GetUnicode();
|
||||
try {
|
||||
tit = ccm.GetCharsetTitle(atom);
|
||||
} catch (ex) {
|
||||
tit = str; //don't ignore charset detectors without a title
|
||||
}
|
||||
|
||||
try {
|
||||
visible = ccm.GetCharsetData(atom,'.notForBrowser');
|
||||
visible = false;
|
||||
} catch (ex) {
|
||||
visible = true;
|
||||
charsetDict[j] = new Array(2);
|
||||
charsetDict[j][0] = tit;
|
||||
charsetDict[j][1] = str;
|
||||
j++;
|
||||
//dump('Getting invisible for:' + str + ' failed!\n');
|
||||
}
|
||||
} //atom
|
||||
|
||||
} //for
|
||||
|
||||
ClearTreelist(dialog.charsetTree);
|
||||
charsetDict.sort();
|
||||
var selItem;
|
||||
if (charsetDict)
|
||||
{
|
||||
for (i = 0; i < charsetDict.length; i++)
|
||||
{
|
||||
try { //let's beef up our error handling for charsets without label / title
|
||||
|
||||
dump("add " + charsetDict[i][0] + charsetDict[i][1] + "\n");
|
||||
var item = AppendStringToTreelist(dialog.charsetTree, charsetDict[i][0]);
|
||||
if(item) {
|
||||
var row= item.firstChild;
|
||||
if(row) {
|
||||
var cell= row.firstChild;
|
||||
if(cell) {
|
||||
cell.setAttribute("data", charsetDict[i][1]);
|
||||
}
|
||||
}
|
||||
if(charset == charsetDict[i][1] )
|
||||
{
|
||||
selItem = item;
|
||||
dump("hit default " + charset + "\n");
|
||||
}
|
||||
}
|
||||
} //try
|
||||
catch (ex) {
|
||||
dump("*** Failed to add charset: " + tit + ex + "\n");
|
||||
} //catch
|
||||
|
||||
} //for
|
||||
} // if
|
||||
if(selItem) {
|
||||
try {
|
||||
dialog.charsetTree.selectItem(selItem);
|
||||
dialog.charsetTree.ensureElementIsVisible(selItem);
|
||||
} catch (ex) {
|
||||
dump("*** Failed to select and ensure : " + ex + "\n");
|
||||
}
|
||||
}
|
||||
} // if
|
||||
}
|
||||
function SelectCharset()
|
||||
{
|
||||
if(initDone) {
|
||||
dump("HHHH\n");
|
||||
try {
|
||||
charset = GetSelectedTreelistAttribute(dialog.charsetTree, "data");
|
||||
dump("charset = " + charset + "\n");
|
||||
if(charset != "") {
|
||||
charsetWasChanged = true;
|
||||
}
|
||||
} catch(ex) {
|
||||
dump("failed to get selected data" + ex + "\n");
|
||||
}
|
||||
dump(">HHHH\n");
|
||||
}
|
||||
}
|
||||
function ValidateData()
|
||||
{
|
||||
title=dialog.TitleInput.value.trimString();
|
||||
return true;
|
||||
}
|
||||
function TitleChanged()
|
||||
{
|
||||
titleWasEdited = true;
|
||||
}
|
||||
// copy from EdPageProps.js
|
||||
function GetMetaElement(name)
|
||||
{
|
||||
if (name)
|
||||
{
|
||||
name = name.toLowerCase();
|
||||
if (name != "")
|
||||
{
|
||||
var metaNodes = editorShell.editorDocument.getElementsByTagName("meta");
|
||||
if (metaNodes && metaNodes.length > 0)
|
||||
{
|
||||
for (var i = 0; i < metaNodes.length; i++)
|
||||
{
|
||||
var metaNode = metaNodes.item(i);
|
||||
if (metaNode && metaNode.getAttribute("name") == name)
|
||||
return metaNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function GetHTTPEquivMetaElement(name)
|
||||
{
|
||||
if (name)
|
||||
{
|
||||
name = name.toLowerCase();
|
||||
if (name != "")
|
||||
{
|
||||
var metaNodes = editorShell.editorDocument.getElementsByTagName("meta");
|
||||
if (metaNodes && metaNodes.length > 0)
|
||||
{
|
||||
for (var i = 0; i < metaNodes.length; i++)
|
||||
{
|
||||
var metaNode = metaNodes.item(i);
|
||||
if (metaNode && metaNode.getAttribute("http-equiv") == name)
|
||||
return metaNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function CreateMetaElement(name)
|
||||
{
|
||||
metaElement = editorShell.CreateElementWithDefaults("meta");
|
||||
if (metaElement)
|
||||
metaElement.setAttribute("name", name);
|
||||
else
|
||||
dump("Failed to create metaElement!\n");
|
||||
|
||||
return metaElement;
|
||||
}
|
||||
function CreateHTTPEquivMetaElement(name)
|
||||
{
|
||||
metaElement = editorShell.CreateElementWithDefaults("meta");
|
||||
if (metaElement)
|
||||
metaElement.setAttribute("http-equiv", name);
|
||||
else
|
||||
dump("Failed to create httpequivMetaElement!\n");
|
||||
|
||||
return metaElement;
|
||||
}
|
||||
|
||||
function CreateHTTPEquivElement(name)
|
||||
{
|
||||
metaElement = editorShell.CreateElementWithDefaults("meta");
|
||||
if (metaElement)
|
||||
metaElement.setAttribute("http-equiv", name);
|
||||
else
|
||||
dump("Failed to create metaElement for http-equiv!\n");
|
||||
|
||||
return metaElement;
|
||||
}
|
||||
|
||||
// Change "content" attribute on a META element,
|
||||
// or delete entire element it if content is empty
|
||||
// This uses undoable editor transactions
|
||||
function SetMetaElementContent(metaElement, content, insertNew)
|
||||
{
|
||||
if (metaElement)
|
||||
{
|
||||
if(!content || content == "")
|
||||
{
|
||||
if (!insertNew)
|
||||
editorShell.DeleteElement(metaElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (insertNew)
|
||||
{
|
||||
// Don't need undo for set attribute, just for InsertElement
|
||||
metaElement.setAttribute("content", content);
|
||||
AppendHeadElement(metaElement);
|
||||
}
|
||||
else
|
||||
editorShell.SetAttribute(metaElement, "content", content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function GetHeadElement()
|
||||
{
|
||||
var headList = editorShell.editorDocument.getElementsByTagName("head");
|
||||
if (headList)
|
||||
return headList.item(0);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function AppendHeadElement(element)
|
||||
{
|
||||
var head = GetHeadElement();
|
||||
if (head)
|
||||
head.appendChild(element);
|
||||
}
|
||||
64
mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.xul
Normal file
64
mozilla/editor/ui/dialogs/content/EditorSaveAsCharset.xul
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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://editor/skin/editor.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://editor/skin/EditorDialog.css" type="text/css"?>
|
||||
|
||||
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://editor/content/EdDialogOverlay.xul"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://editor/locale/EditorSaveAsCharset.dtd">
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<!-- WE SHOULD NOT USE ABSOLUTE WITH AND HEIGHT - USE BOXES INSTEAD? -->
|
||||
<window class="dialog" title="&windowTitle.label;"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()"
|
||||
orient="vertical">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editor/content/EdDialogCommon.js">
|
||||
</script>
|
||||
<script language="JavaScript" src="chrome://editor/content/EditorSaveAsCharset.js"/>
|
||||
<script language="JavaScript" src="chrome://global/content/dialogOverlay.js" />
|
||||
|
||||
<broadcaster id="args" value=""/>
|
||||
<keyset id="keyset"/>
|
||||
|
||||
<box orient="vertical">
|
||||
<titledbox orient="vertical"><title><text align="left" value="&documentTitleTitle.label;"/></title>
|
||||
<text class="label" value="&documentTitleDesc.label;"/>
|
||||
<textfield id="TitleInput" flex="1" onkeyup="TitleChanged();"/>
|
||||
</titledbox>
|
||||
|
||||
<titledbox orient="vertical"><title><text class="label" value="&documentCharsetTitle.label;"/></title>
|
||||
<text class="label" value="&documentCharsetDesc.label;"/>
|
||||
<box>
|
||||
<tree class="list" id="CharsetTree" rows="10" flex="1" onselect="SelectCharset();"/>
|
||||
</box>
|
||||
</titledbox>
|
||||
</box>
|
||||
<!-- from global dialogOverlay -->
|
||||
<box id="okCancelButtons"/>
|
||||
</window>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!--
|
||||
- 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):
|
||||
-->
|
||||
|
||||
<!-- These strings are generic to all or most of the editor's dialogs. -->
|
||||
|
||||
<!-- This button is for the progressive disclosure of additional editing functionality -->
|
||||
|
||||
<!-- These strings are for use specifically in the editor's link dialog. -->
|
||||
<!ENTITY windowTitle.label "Save As Charset...">
|
||||
<!ENTITY documentTitleTitle.label "Document Title">
|
||||
<!ENTITY documentTitleDesc.label "Input document title here:">
|
||||
<!ENTITY documentCharsetTitle.label "Document Charset">
|
||||
<!ENTITY documentCharsetDesc.label "Select the charset you want to save as:">
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user