-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
137 lines (137 loc) · 6.07 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Copyright 2017 darkoverlordofdata
*
* Module loader/gjs helper
* normalized access to amd, commonjs and gjs imports
*
*/
Object.defineProperties(window, {
define: { value: (function (modules) {
return function (name, deps, callback) {
if (typeof name !== 'string') {
var bundle = deps();
for (name in bundle)
modules[name] = { id: name, exports: bundle[name] };
}
else {
modules[name] = { id: name, exports: {} };
var args = [function (name) { return modules[name] ? modules[name].exports : imports[name]; },
modules[name].exports];
for (var i = 2; i < deps.length; i++)
args.push(modules[deps[i]].exports);
callback.apply(modules[name].exports, args);
}
};
}({
Lang: { id: 'Lang', exports: imports.lang },
Gio: { id: 'Gio', exports: imports.gi.Gio },
Atk: { id: 'Atk', exports: imports.gi.Atk },
Gdk: { id: 'Gdk', exports: imports.gi.Gdk },
Gtk: { id: 'Gtk', exports: imports.gi.Gtk },
GLib: { id: 'GLib', exports: imports.gi.GLib },
Pango: { id: 'Pango', exports: imports.gi.Pango },
GObject: { id: 'GObject', exports: imports.gi.GObject }
})) },
console: { value: {
log: function () { print.apply(null, arguments); },
warn: function () { print.apply(null, arguments); },
error: function () { print.apply(null, arguments); },
info: function () { print.apply(null, arguments); }
} },
_: { value: imports.gettext.gettext }
});
Object.defineProperties(define, {
amd: { value: true },
version: { value: '0.1.0' },
path: { value: function (path) { return imports.searchPath.unshift(path); } },
imports: { value: function (libs) { return define([], function () { return libs; }); } }
});
Object.defineProperties(String.prototype, {
printf: { value: imports.format.format }
});
/**
* Import ambient modules
*/
define.imports({
Gda: imports.gi.Gda,
Soup: imports.gi.Soup,
WebKit: imports.gi.WebKit
});
define("example/example", ["require", "exports", "Gtk"], function (require, exports, Gtk) {
"use strict";
var ListBoxRowWithData = (function () {
function ListBoxRowWithData(data) {
this.object = new Gtk.ListBoxRow();
/* create a custom 'data' field for sorting */
this.object['data'] = data;
this.object.add(new Gtk.Label({ label: data }));
}
return ListBoxRowWithData;
}());
var ListBoxWindow = (function () {
function ListBoxWindow() {
this.object = new Gtk.Window({
window_position: Gtk.WindowPosition.CENTER,
title: "ListBox Demo"
});
var box_outer = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, spacing: 6 });
this.object.add(box_outer);
var listbox = new Gtk.ListBox();
// property not defined error:
// listbox.selection_mode = Gtk.SelectionMode.NONE
// use the api instead:
listbox.set_selection_mode(Gtk.SelectionMode.NONE);
box_outer.pack_start(listbox, true, true, 0);
var row = new Gtk.ListBoxRow();
var hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 50 });
row.add(hbox);
var vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
hbox.pack_start(vbox, true, true, 0);
var label1 = new Gtk.Label({ label: "Automatic Date & Time", xalign: 0 });
var label2 = new Gtk.Label({ label: "Requires internet access", xalign: 0 });
vbox.pack_start(label1, true, true, 0);
vbox.pack_start(label2, true, true, 0);
var swtch = new Gtk.Switch();
// property not defined error:
// swtch.valign = Gtk.Align.CENTER
// use the api instead:
swtch.set_valign(Gtk.Align.CENTER);
hbox.pack_start(swtch, false, true, 0);
listbox.add(row);
row = new Gtk.ListBoxRow();
hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 50 });
row.add(hbox);
var label = new Gtk.Label({ label: "Enable Automatic Update", xalign: 0 });
var check = new Gtk.CheckButton();
hbox.pack_start(label, true, true, 0);
hbox.pack_start(check, false, true, 0);
listbox.add(row);
row = new Gtk.ListBoxRow();
hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 50 });
row.add(hbox);
label = new Gtk.Label({ label: "Date Format", xalign: 0 });
var combo = new Gtk.ComboBoxText();
combo.insert(0, "0", "24-hour");
combo.insert(1, "1", "AM/PM");
hbox.pack_start(label, true, true, 0);
hbox.pack_start(combo, false, true, 0);
listbox.add(row);
var listbox2 = new Gtk.ListBox();
var items = "This is a sorted ListBox Fail".split(' ');
items.forEach(function (item) { return listbox2.add(new ListBoxRowWithData(item).object); });
var sortFunc = (function (row1, row2, data, notifyDestroy) { return row1.data.toLowerCase() > row2.data.toLowerCase(); });
var filterFunc = (function (row, data, notifyDestroy) { return (row.data != 'Fail'); });
listbox2.connect("row-activated", function (widget, row) { return print(row.data); });
listbox2.set_sort_func(sortFunc, null, false);
listbox2.set_filter_func(filterFunc, null, false);
box_outer.pack_start(listbox2, true, true, 0);
listbox2.show_all();
}
return ListBoxWindow;
}());
Gtk.init(null);
var win = new ListBoxWindow();
win.object.connect("delete-event", Gtk.main_quit);
win.object.show_all();
Gtk.main();
});