File: __init__.js

package info (click to toggle)
gnome-shell 3.14.4-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 14,412 kB
  • ctags: 7,297
  • sloc: ansic: 45,021; sh: 11,312; xml: 875; makefile: 696; cpp: 57; python: 39; perl: 13
file content (65 lines) | stat: -rw-r--r-- 1,828 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

const Lang = imports.lang;
const Main = imports.ui.main;

const ComponentManager = new Lang.Class({
    Name: 'ComponentManager',

    _init: function() {
        this._allComponents = {};
        this._enabledComponents = [];

        Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
        this._sessionUpdated();
    },

    _sessionUpdated: function() {
        let newEnabledComponents = Main.sessionMode.components;

        newEnabledComponents.filter(Lang.bind(this, function(name) {
            return this._enabledComponents.indexOf(name) == -1;
        })).forEach(Lang.bind(this, function(name) {
            this._enableComponent(name);
        }));

        this._enabledComponents.filter(Lang.bind(this, function(name) {
            return newEnabledComponents.indexOf(name) == -1;
        })).forEach(Lang.bind(this, function(name) {
            this._disableComponent(name);
        }));

        this._enabledComponents = newEnabledComponents;
    },

    _importComponent: function(name) {
        let module = imports.ui.components[name];
        return module.Component;
    },

    _ensureComponent: function(name) {
        let component = this._allComponents[name];
        if (component)
            return component;

	if (Main.sessionMode.isLocked)
	    return null;

        let constructor = this._importComponent(name);
        component = new constructor();
        this._allComponents[name] = component;
        return component;
    },

    _enableComponent: function(name) {
        let component = this._ensureComponent(name);
	if (component)
            component.enable();
    },

    _disableComponent: function(name) {
        let component = this._allComponents[name];
        if (component == null)
            return;
        component.disable();
    }
});