/
appStorePages.js
63 lines (50 loc) · 1.58 KB
/
appStorePages.js
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
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Signals = imports.signals;
var AppStorePageManager = new Lang.Class({
Name: 'AppStorePageManager',
Extends: Gtk.Stack,
_init: function() {
this._providers = {};
this.parent({ visible: true });
this.connect('notify::visible-child-name', Lang.bind(this, this._onPageChanged));
},
_onPageChanged: function() {
let page = this.visible_child;
if (page) {
page.populate();
}
},
_ensurePage: function(pageId) {
let page = this.get_child_by_name(pageId);
if (page) {
return page;
}
let provider = this._providers[pageId];
if (!provider) {
return null;
}
page = provider.createPage(pageId);
this.add_named(page, pageId);
this.child_set_property(page, 'title', page.getName());
this.child_set_property(page, 'icon-name', page.getIcon());
return page;
},
registerProvider: function(provider) {
let pageIds = provider.getPageIds();
pageIds.forEach(Lang.bind(this, function(pageId) {
this._providers[pageId] = provider;
this._ensurePage(pageId);
}));
},
showPage: function(pageId) {
this.visible_child_name = pageId;
}
});
var AppStorePageProvider = new Lang.Interface({
Name: 'AppStorePageProvider',
createPage: Lang.Interface.UNIMPLEMENTED,
getPageIds: Lang.Interface.UNIMPLEMENTED
});
Signals.addSignalMethods(AppStorePageProvider.prototype);