-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiButtonDialog.js
73 lines (64 loc) · 1.96 KB
/
multiButtonDialog.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
const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const ModalDialog = imports.ui.modalDialog;
const Signals = imports.signals;
const St = imports.gi.St;
const Gettext = imports.gettext;
const _ = Gettext.domain('gnome-shell-extensions-scriptproxies').gettext;
const ButtonMapping = new Lang.Class({
Name: 'ButtonMapping',
label: null,
key: null,
action: null,
_init: function(label, key, action) {
this.label = label;
this.key = key;
this.action = action;
}
});
const MultiButtonDialog = new Lang.Class({
Name: 'MultiButtonDialog',
Extends: ModalDialog.ModalDialog,
question: null,
title: null,
_init: function(title, question, buttonMappings) {
this.question = question;
this.title = title;
this.parent({
styleClass: 'confirm-dialog'
});
let tlabel = new St.Label({
style_class: 'confirm-dialog-title',
text: this.title
});
this.contentLayout.add(tlabel, {
x_align: St.Align.MIDDLE,
y_align: St.Align.START
});
let label = new St.Label({
style_class: 'confirm-dialog-label',
text: this.question
});
this.contentLayout.add(label, {
y_align: St.Align.MIDDLE
});
let buttons = [];
for (let i in buttonMappings) {
if (buttonMappings.hasOwnProperty(i)) {
let mapping = buttonMappings[i];
buttons.push({
label: mapping.label,
key: mapping.key,
action: Lang.bind(this, function() {
if (mapping.action !== null) {
mapping.action();
}
this.close();
})
});
}
}
this.setButtons(buttons);
},
});
Signals.addSignalMethods(MultiButtonDialog.prototype);