This is just some static backup of the original site, don't expect every link to work!

source: modules/identityDataExtras/characterEncoding.js @ d357c7

ng_0.9
Last change on this file since d357c7 was d357c7, checked in by rene <rene@…>, 6 years ago

CharsetMenu? no longer supports building a menu with no access keys.
You may find more details about this deprecation at: https://bugzilla.mozilla.org/show_bug.cgi?id=1088710

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25var EXPORTED_SYMBOLS = [];
26
27const Ci = Components.interfaces;
28const Cc = Components.classes;
29const Cu = Components.utils;
30
31
32Cu.import("resource://v_identity/vI_identityDataExtras.js");
33Cu.import("resource://v_identity/vI_log.js");
34let legacy = false; // use pre TB-32 legacy code
35try {
36  Cu.import("resource://gre/modules/CharsetMenu.jsm");
37} catch (e) {
38  legacy = true; // pre TB-32-version, might be removed in the future
39}
40
41
42let Log = setupLogging("virtualIdentity.identityDataExtras.characterEncoding");
43
44function identityDataExtrasObject_characterEncoding(currentWindow) {
45  this._currentWindow = currentWindow;
46  this.field = "charEnc"; // description of the option
47  this.option = "storageExtras_characterEncoding"; // option string to get preference settings
48}
49identityDataExtrasObject_characterEncoding.prototype = {
50  __proto__: identityDataExtrasObject.prototype,
51
52  get valueHtml() {
53    return this.valueNice;
54  },
55  get valueNice() {
56    return this.value ? this._currentWindow.gCharsetConvertManager
57      .getCharsetTitle(this._currentWindow.gCharsetConvertManager.getCharsetAlias(this.value)) : "";
58  },
59
60  // pre TB-32-version, might be removed in the future --------------------------------
61  _setMenuMark: function () {
62    var maileditCharsetMenu = this._currentWindow.document.getElementById("maileditCharsetMenu")
63    var value = maileditCharsetMenu.getAttribute("unmarkedValue")
64    if (value) {
65      var menuitem = this._currentWindow.document.getElementById(value);
66      if (menuitem)
67        menuitem.setAttribute('checked', 'true');
68      maileditCharsetMenu.removeAttribute("unmarkedValue")
69    }
70  },
71  // ----------------------------------------------------------------------------------
72
73  setValueToEnvironment_msgCompose: function () {
74    if (!this.value)
75      return;
76    // pre TB-32-version, might be removed in the future --------------------------------
77    if (legacy) {
78      // old style
79      var menuitem = this._currentWindow.document.getElementById(this.value);
80      if (menuitem)
81        menuitem.setAttribute('checked', 'true');
82      else { // set menumark later if menu is not ready yet
83        var maileditCharsetMenu = this._currentWindow.document.getElementById("maileditCharsetMenu")
84        maileditCharsetMenu.setAttribute("unmarkedValue", this.value)
85        var onpopupshowing = maileditCharsetMenu.getAttribute("onpopupshowing")
86        this._currentWindow.document.getElementById("maileditCharsetMenu").setAttribute("onpopupshowing",
87          onpopupshowing + ";this._setMenuMark();")
88      }
89    }
90    // ----------------------------------------------------------------------------------
91    this._currentWindow.gMsgCompose.compFields.characterSet = this.value;
92    this._currentWindow.SetDocumentCharacterSet(this.value);
93  },
94
95  setValueToEnvironment_dataEditor: function () {
96    // pre TB-32-version, might be removed in the future --------------------------------
97    if (legacy) {
98      this._currentWindow.CreateMenu('mailedit'); // this is part of the magic included by the xul-binding
99      if (this.value != null) {
100        this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem = this._currentWindow.document.getElementById(this.value);
101        this._currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
102      }
103    }
104    // ----------------------------------------------------------------------------------
105    else {
106      CharsetMenu.build(this._currentWindow.document.getElementById("charsetPopup"), true, false)
107      if (this.value != null) {
108        let menu = this._currentWindow.document.getElementById("maileditCharsetMenu");
109        let menuitem = menu.getElementsByAttribute("charset", this.value).item(0);
110        if (menuitem) {
111            menu.selectedItem = menuitem;
112            menuitem.setAttribute("checked", "true");
113        }
114        menu.setAttribute("label", CharsetMenu._getCharsetLabel(this.value));
115        this._currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
116      }
117    }
118    this._currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand();
119  },
120
121  getValueFromEnvironment_msgCompose: function () {
122    // read the value from the internal vI object, global object might not be available any more
123    // happens especially while storing after sending the message
124    this.value = this._currentWindow.gMsgCompose.compFields.characterSet;
125    if (this._currentWindow.gCharsetConvertManager) {
126      var charsetAlias = this._currentWindow.gCharsetConvertManager.getCharsetAlias(this.value);
127      if (charsetAlias == "us-ascii")
128        this.value = "ISO-8859-1"; // no menu item for "us-ascii"
129    }
130  },
131
132  getValueFromEnvironment_dataEditor: function () {
133    if (this._currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
134    // check if element is selected (list might not contain relevant entry)
135      if (this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem)
136      // pre TB-32-version, might be removed in the future --------------------------------
137        if (legacy) {
138          this.value = this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.id
139        }
140        // ----------------------------------------------------------------------------------
141        else {
142          this.value = this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.getAttribute('charset');
143        } else
144      this.value = null;
145  }
146}
147registerIdExtrasObject(identityDataExtrasObject_characterEncoding);
Note: See TracBrowser for help on using the repository browser.