Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This Source Code is subject to the terms of the Mozilla Public License | |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | |
4 * http://mozilla.org/MPL/2.0/. | |
5 */ | |
6 | |
7 /** | |
8 * @fileOverview Adds typo correction feature | |
9 */ | |
10 | |
11 Cu.import("resource://gre/modules/AddonManager.jsm"); | |
12 | |
13 let {TimeLine} = require("timeline"); | |
14 let {Prefs} = require("prefs"); | |
15 TimeLine.log("Done loading preferences"); | |
Wladimir Palant
2012/11/19 17:24:23
Please remove this, it assumes that no other modul
| |
16 | |
17 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}"; | |
18 let addonListener = null; | |
19 | |
20 function init() | |
21 { | |
22 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos )) | |
23 { | |
24 AddonManager.getAddonByID(urlfixerID, function(addon) | |
25 { | |
26 startTypoCorrection(addon && addon.isActive); | |
27 }); | |
28 } | |
29 else | |
30 { | |
31 function onPrefChange(name) | |
32 { | |
33 if (name == "correctTypos" && Prefs[name]) | |
34 { | |
35 init(); | |
36 Prefs.removeListener(onPrefChange); | |
37 } | |
38 } | |
39 | |
40 Prefs.addListener(onPrefChange); | |
41 } | |
42 } | |
43 | |
44 function startTypoCorrection(isInstalledAndEnabled) | |
45 { | |
46 if (isInstalledAndEnabled) | |
47 require("typoFixer").detachWindowObserver(); | |
48 else | |
49 require("typoFixer").attachWindowObserver(); | |
50 | |
51 if (!addonListener) | |
52 { | |
53 addonListener = { | |
54 onEnabling: function(addon, needsRestart) | |
55 { | |
56 if (addon.id == urlfixerID) | |
57 startTypoCorrection(true); | |
58 }, | |
59 onDisabled: function(addon) | |
60 { | |
61 if (addon.id == urlfixerID) | |
62 startTypoCorrection(false); | |
63 }, | |
64 onInstalling: function(addon, needsRestart) | |
65 { | |
66 if (addon.id == urlfixerID) | |
67 startTypoCorrection(true); | |
68 }, | |
69 onUninstalled: function(addon) | |
70 { | |
71 if (addon.id == urlfixerID) | |
72 startTypoCorrection(false); | |
73 } | |
74 } | |
75 AddonManager.addAddonListener(addonListener); | |
Wladimir Palant
2012/11/19 17:24:23
This needs cleanup code - remove this listener on
| |
76 } | |
77 } | |
78 | |
79 init(); | |
OLD | NEW |