!import
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-1999
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Frank Tang ftang@netscape.com
24 * J.M Betak jbetak@netscape.com
25 * Neil Rashbrook <neil@parkwaycc.co.uk>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41
42 var gCharset="";
43 var gTitleWasEdited = false;
44 var gCharsetWasChanged = false;
45 var gInsertNewContentType = false;
46 var gContenttypeElement;
47 var gInitDone = false;
48
49 //Cancel() is in EdDialogCommon.js
50
Startup
51 function Startup()
52 {
53 var editor = GetCurrentEditor();
54 if (!editor)
55 {
56 window.close();
57 return;
58 }
59
60 var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
61 observerService.notifyObservers(null, "charsetmenu-selected", "other");
62
63 gDialog.TitleInput = document.getElementById("TitleInput");
64 gDialog.charsetTree = document.getElementById('CharsetTree');
65 gDialog.exportToText = document.getElementById('ExportToText');
66
67 gContenttypeElement = GetHTTPEquivMetaElement("content-type");
68 if (!gContenttypeElement && (editor.contentsMIMEType != 'text/plain'))
69 {
70 gContenttypeElement = CreateHTTPEquivMetaElement("content-type");
71 if (!gContenttypeElement )
72 {
73 window.close();
74 return;
75 }
76 gInsertNewContentType = true;
77 }
78
79 try {
80 gCharset = editor.documentCharacterSet;
81 } catch (e) {}
82
83 InitDialog();
84
85 // Use the same text as the messagebox for getting title by regular "Save"
86 document.getElementById("EnterTitleLabel").setAttribute("value",GetString("NeedDocTitle"));
87 // This is an <HTML> element so it wraps -- append a child textnode
88 var helpTextParent = document.getElementById("TitleHelp");
89 var helpText = document.createTextNode(GetString("DocTitleHelp"));
90 if (helpTextParent)
91 helpTextParent.appendChild(helpText);
92
93 // SET FOCUS TO FIRST CONTROL
94 SetTextboxFocus(gDialog.TitleInput);
95
96 gInitDone = true;
97
98 SetWindowLocation();
99 }
100
101
InitDialog
102 function InitDialog()
103 {
104 gDialog.TitleInput.value = GetDocumentTitle();
105
106 var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
107 var tree = gDialog.charsetTree;
108 var index = tree.view.getIndexOfResource(RDF.GetResource(gCharset));
109 if (index >= 0) {
110 tree.view.selection.select(index);
111 tree.treeBoxObject.ensureRowIsVisible(index);
112 }
113 }
114
115
onAccept
116 function onAccept()
117 {
118 var editor = GetCurrentEditor();
119 editor.beginTransaction();
120
121 if(gCharsetWasChanged)
122 {
123 try {
124 SetMetaElementContent(gContenttypeElement, "text/html; charset=" + gCharset, gInsertNewContentType, true);
125 editor.documentCharacterSet = gCharset;
126 } catch (e) {}
127 }
128
129 editor.endTransaction();
130
131 if(gTitleWasEdited)
132 SetDocumentTitle(TrimString(gDialog.TitleInput.value));
133
134 window.opener.ok = true;
135 window.opener.exportToText = gDialog.exportToText.checked;
136 SaveWindowLocation();
137 return true;
138 }
139
140
readRDFString
141 function readRDFString(aDS,aRes,aProp)
142 {
143 var n = aDS.GetTarget(aRes, aProp, true);
144 if (n)
145 return n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
146 else
147 return "";
148 }
149
150
SelectCharset
151 function SelectCharset()
152 {
153 if(gInitDone)
154 {
155 try
156 {
157 gCharset = gDialog.charsetTree.builderView.getResourceAtIndex(gDialog.charsetTree.currentIndex).Value;
158 if (gCharset)
159 gCharsetWasChanged = true;
160 }
161 catch(e) {}
162 }
163 }
164
165
TitleChanged
166 function TitleChanged()
167 {
168 gTitleWasEdited = true;
169 }