forked from gufoe/text-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
help_dialog.js
107 lines (90 loc) · 3.36 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
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 GObject = imports.gi.GObject;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const PrefsKeys = Me.imports.prefs_keys;
var HelpDialog = GObject.registerClass({}, class HelpDialog extends ModalDialog.ModalDialog {
_init() {
super._init();
this._dialogLayout =
typeof this.dialogLayout === "undefined"
? this._dialogLayout
: this.dialogLayout;
this._dialogLayout.connect("key-press-event", (o, e) =>
this._on_key_press_event(o, e)
);
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_child(this._close_button);
this.contentLayout.add_child(this._label);
}
_on_key_press_event(object, event) {
let symbol = event.get_key_symbol();
if (symbol == Clutter.Escape) {
this.close();
}
}
_get_close_button() {
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", () => {
this.close();
});
button.add_actor(icon);
return button;
}
_resize() {
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() {
super.close();
this.destroy();
}
open() {
this._resize();
super.open();
}
});