-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathhelp_dialog.js
112 lines (94 loc) · 3.6 KB
/
help_dialog.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
const Lang = imports.lang;
const St = imports.gi.St;
const Main = imports.ui.main;
const Clutter = imports.gi.Clutter;
const ModalDialog = imports.ui.modalDialog;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const PrefsKeys = Me.imports.prefs_keys;
const HelpDialog = new Lang.Class({
Name: 'HelpDialog',
Extends: ModalDialog.ModalDialog,
_init: function() {
this.parent();
this._dialogLayout =
typeof this.dialogLayout === "undefined"
? this._dialogLayout
: this.dialogLayout;
this._dialogLayout.connect('key-press-event', Lang.bind(this,
this._on_key_press_event
));
this._dialogLayout.set_style_class_name('translator-help-box');
this._label = new St.Label({
style_class: 'translator-help-text'
});
this._label.clutter_text.set_line_wrap(true);
let markup =
"<span size='x-large'>Shortcuts:</span>\n" +
"<b><Super>T</b> - open translator dialog.\n" +
"<b><Super><Shift>T</b> - open translator dialog and " +
"translate text from clipboard.\n" +
"<b><Super><Alt>T</b> - open translator dialog and translate " +
"from primary selection.\n<b><Ctrl><Enter></b> - " +
"Translate text.\n<b><Ctrl><Shift>C</b> - copy translated " +
"text to clipboard.\n<b><Ctrl>S</b> - swap languages.\n" +
"<b><Ctrl>D</b> - reset languages to default.\n" +
"<b><Tab></b> - toggle transliteration of result text.\n" +
"<b><Escape></b> - close dialog";
this._label.clutter_text.set_markup(markup);
this._close_button = this._get_close_button();
this.contentLayout.add(this._close_button, {
x_fill: false,
x_align: St.Align.END,
y_fill: false,
y_align: St.Align.START
});
this.contentLayout.add(this._label, {
x_fill: false,
x_align: St.Align.START,
y_fill: false,
y_align: St.Align.END
});
},
_on_key_press_event: function(object, event) {
let symbol = event.get_key_symbol();
if(symbol == Clutter.Escape) {
this.close();
}
},
_get_close_button: function() {
let icon = new St.Icon({
icon_name: Utils.ICONS.close,
icon_size: 20,
style: 'color: grey;'
});
let button = new St.Button({
reactive: true
});
button.connect('clicked', Lang.bind(this, function() {
this.close();
}));
button.add_actor(icon);
return button;
},
_resize: function() {
let width_percents = Utils.SETTINGS.get_int(PrefsKeys.WIDTH_PERCENTS_KEY);
let height_percents = Utils.SETTINGS.get_int(PrefsKeys.HEIGHT_PERCENTS_KEY);
let primary = Main.layoutManager.primaryMonitor;
let translator_width = Math.round(primary.width / 100 * width_percents);
let translator_height = Math.round(primary.height / 100 * height_percents);
let help_width = Math.round(translator_width * 0.9);
let help_height = Math.round(translator_height * 0.9);
this._dialogLayout.set_width(help_width);
this._dialogLayout.set_height(help_height);
},
close: function() {
this.parent();
this.destroy();
},
open: function() {
this._resize()
this.parent()
},
});