-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditProxyDialog.js
141 lines (118 loc) · 4.06 KB
/
editProxyDialog.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
138
139
140
141
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 EditProxyDialog = new Lang.Class({
Name: 'EditProxyDialog',
Extends: ModalDialog.ModalDialog,
_init: function(callback, action) {
this.callback = callback;
this.action = action;
this.parent({
styleClass: 'prompt-dialog'
});
let label, buttons;
if (this.action == 'add') {
buttons = [{
label: _('Cancel'),
action: Lang.bind(this, this._onCancelButton),
key: Clutter.Escape
}, {
label: _('Add proxy'),
action: Lang.bind(this, this._addButton)
}];
label = new St.Label({
style_class: 'edit-proxy-dialog-label',
text: _('Enter the name for the new proxy')
});
} else if (this.action == 'edit') {
buttons = [{
label: _('Cancel'),
action: Lang.bind(this, this._onCancelButton),
key: Clutter.Escape
}, {
label: _('Modify script'),
action: Lang.bind(this, this._modifyButton)
}, {
label: _('Rename'),
action: Lang.bind(this, this._renameButton)
}];
label = new St.Label({
style_class: 'edit-proxy-dialog-label',
text: _('Modify the proxy script.') + '\n' + _('Or rename it (leave blank to remove the proxy).')
});
} else {
// this should be this.action == 'editor'
buttons = [{
label: _('Cancel'),
action: Lang.bind(this, this._onCancelButton),
key: Clutter.Escape
}, {
label: _('OK'),
action: Lang.bind(this, this._onSetEditorButton)
}];
label = new St.Label({
style_class: 'edit-proxy-dialog-label',
text: _('To edit your proxy script,') + '\n' + _('please provide the binary name of your text editor.')
});
}
this.contentLayout.add(label, {
y_align: St.Align.START
});
let entry = new St.Entry({
style_class: 'edit-proxy-dialog-entry'
});
entry.label_actor = label;
this._entryText = entry.clutter_text;
this.contentLayout.add(entry, {
y_align: St.Align.START
});
this.setInitialKeyFocus(this._entryText);
this.setButtons(buttons);
this._entryText.connect('key-press-event', Lang.bind(this, function(o, e) {
let symbol = e.get_key_symbol();
if (symbol == Clutter.Return || symbol == Clutter.KP_Enter) {
if (this.action == 'add')
this._addButton();
else if (this.action == 'edit')
this._renameButton();
else
this._onSetEditorButton();
}
}));
},
close: function() {
this.parent();
},
_onCancelButton: function() {
this.close();
},
_addButton: function() {
this.callback(this._entryText.get_text(), 'new');
this.close();
},
_modifyButton: function() {
this.callback(this._entryText.get_text(), 'modify');
this.close();
},
_renameButton: function() {
this.callback(this._entryText.get_text(), 'rename');
this.close();
},
_onSetEditorButton: function() {
this.callback(this._entryText.get_text());
this.close();
},
open: function(initialText) {
if (initialText === null) {
this._entryText.set_text('');
} else {
this._entryText.set_text(initialText);
}
this.parent();
}
});
Signals.addSignalMethods(EditProxyDialog.prototype);