1
/* You may find the license in the LICENSE file */
3
const EXPORTED_SYMBOLS = ['FileExtensionSheet'];
5
const Cc = Components.classes;
6
const Ci = Components.interfaces;
7
const Cr = Components.results;
8
const Cu = Components.utils;
9
const Exception = Components.Exception;
11
Cu.import("resource://dta/utils.jsm");
12
Cu.import("resource://dta/support/icons.jsm");
13
Cu.import("resource://dta/support/timers.jsm");
15
const Timers = new TimerManager();
17
ServiceGetter(this, "Atoms", "@mozilla.org/atom-service;1", "nsIAtomService");
21
function FileExtensionSheet(window) {
22
this._windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
24
let document = window.document;
25
this._stylesheet = null;
27
for each (let ss in document.styleSheets) {
28
Debug.log("sheet: " + ss.href);
29
if (/^chrome:\/\/dta\//.test(ss.href)) {
30
this._stylesheet = ss;
31
Debug.log("found stylesheet " + ss.href + ", rules: " + ss.cssRules.length);
35
if (!this._stylesheet) {
36
throw new Exception("didn't find stylesheet");
40
Debug.log("sheet:", ex);
46
FileExtensionSheet.prototype = {
47
getAtom: function FES_getAtom(fileName, metalink) {
48
let ext = fileName.getExtension();
55
let key = 'ext:' + ext;
56
let entry = this._entries[key];
58
entry = Atoms.getAtom("icon" + newUUIDString().replace(/\W/g, ''));
59
let rule = 'treechildren::-moz-tree-image(iconic,'
61
+ ') { list-style-image: url('
62
+ getIcon('file.' + ext, metalink || ext == 'metalink')
64
this._stylesheet.insertRule(rule, this._stylesheet.cssRules.length);
65
Debug.log("sheet: " + rule);
67
// this is a moz-2 hack, as it will otherwise not correctly redraw!
68
this._timer = Timers.createOneshot(0, this._updateSheet, this);
70
this._entries[key] = entry;
74
_updateSheet: function FES__updateSheet() {
76
this._windowUtils.redraw();
b'\\ No newline at end of file'