~ubuntu-branches/debian/stretch/downthemall/stretch

« back to all changes in this revision

Viewing changes to modules/support/fileextsheet.jsm

  • Committer: Package Import Robot
  • Author(s): Michael Meskes
  • Date: 2016-09-21 13:33:55 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20160921133355-ylst3mzzo82mghyw
Tags: upstream-3.0.6
ImportĀ upstreamĀ versionĀ 3.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* You may find the license in the LICENSE file */
2
 
 
3
 
const EXPORTED_SYMBOLS = ['FileExtensionSheet'];
4
 
 
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;
10
 
 
11
 
Cu.import("resource://dta/utils.jsm");
12
 
Cu.import("resource://dta/support/icons.jsm");
13
 
Cu.import("resource://dta/support/timers.jsm");
14
 
 
15
 
const Timers = new TimerManager();
16
 
 
17
 
ServiceGetter(this, "Atoms", "@mozilla.org/atom-service;1", "nsIAtomService");
18
 
 
19
 
extendString(String);
20
 
 
21
 
function FileExtensionSheet(window) {
22
 
        this._windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
23
 
        
24
 
        let document = window.document;
25
 
        this._stylesheet = null;
26
 
        try {
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);
32
 
                                break;
33
 
                        }
34
 
                }
35
 
                if (!this._stylesheet) {
36
 
                        throw new Exception("didn't find stylesheet");
37
 
                }
38
 
        }
39
 
        catch (ex) {
40
 
                Debug.log("sheet:", ex);
41
 
        }
42
 
 
43
 
        this._entries = {};
44
 
}
45
 
 
46
 
FileExtensionSheet.prototype = {
47
 
        getAtom: function FES_getAtom(fileName, metalink) {
48
 
                let ext = fileName.getExtension();
49
 
                if (!ext) {
50
 
                        ext = 'unknown';
51
 
                }
52
 
                if (metalink) {
53
 
                        ext = 'metalink';
54
 
                }
55
 
                let key = 'ext:' + ext;
56
 
                let entry = this._entries[key];
57
 
                if (!entry) {
58
 
                        entry = Atoms.getAtom("icon" + newUUIDString().replace(/\W/g, ''));
59
 
                        let rule = 'treechildren::-moz-tree-image(iconic,' 
60
 
                                + entry.toString()
61
 
                                + ') { list-style-image: url('
62
 
                                + getIcon('file.' + ext, metalink || ext == 'metalink')
63
 
                                + ') !important; }';
64
 
                        this._stylesheet.insertRule(rule, this._stylesheet.cssRules.length);
65
 
                        Debug.log("sheet: " + rule);
66
 
                        if (!this._timer) {
67
 
                                // this is a moz-2 hack, as it will otherwise not correctly redraw!
68
 
                                this._timer = Timers.createOneshot(0, this._updateSheet, this);
69
 
                        }
70
 
                        this._entries[key] = entry;
71
 
                }
72
 
                return entry;
73
 
        },
74
 
        _updateSheet: function FES__updateSheet() {
75
 
                delete this._timer;
76
 
                this._windowUtils.redraw();
77
 
        }
78
 
};
 
 
b'\\ No newline at end of file'