-
Notifications
You must be signed in to change notification settings - Fork 11
/
MainWindow.vala
83 lines (72 loc) · 2.77 KB
/
MainWindow.vala
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
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2020-2024 Ryo Nakano <ryonakaknock3@gmail.com>
*/
[GtkTemplate (ui = "/com/github/ryonakano/konbucase/ui/main-window.ui")]
public class MainWindow : Adw.ApplicationWindow {
// Main menu model
public Menu main_menu { get; private set; }
[GtkChild]
private unowned Adw.ToastOverlay overlay;
[GtkChild]
private unowned TextPane source_pane;
[GtkChild]
private unowned TextPane result_pane;
[GtkChild]
private unowned TextPaneModel source_model;
[GtkChild]
private unowned TextPaneModel result_model;
[GtkChild]
private unowned MainWindowModel window_model;
public MainWindow (Application app) {
Object (
application: app
);
}
construct {
// Distinct development build visually
if (".Devel" in Config.APP_ID) {
add_css_class ("devel");
}
var style_submenu = new Menu ();
style_submenu.append (_("S_ystem"), "app.color-scheme(\"default\")");
style_submenu.append (_("_Light"), "app.color-scheme(\"force-light\")");
style_submenu.append (_("_Dark"), "app.color-scheme(\"force-dark\")");
main_menu = new Menu ();
main_menu.append_submenu (_("_Style"), style_submenu);
// Pantheon prefers AppCenter instead of an about dialog for app details, so prevent it from being shown on Pantheon
if (!Application.IS_ON_PANTHEON) {
///TRANSLATORS: Do NOT translate the phrase "KonbuCase"; it's the name of the app which is a proper noun.
main_menu.append (_("_About KonbuCase"), "app.about");
}
// The action users most frequently take is to input the source text.
// So, forcus to the source view by default.
source_pane.get_source_view ().grab_focus ();
// Perform conversion when:
//
// * case type of the source text is changed
// * case type of the result text is changed
// * the source text is changed
source_pane.dropdown_changed.connect (() => {
window_model.do_convert ();
});
result_pane.dropdown_changed.connect (() => {
window_model.do_convert ();
});
source_model.notify["text"].connect (() => {
window_model.do_convert ();
});
source_pane.copy_button_clicked.connect (() => {
get_clipboard ().set_text (source_model.text);
show_toast ();
});
result_pane.copy_button_clicked.connect (() => {
get_clipboard ().set_text (result_model.text);
show_toast ();
});
}
private void show_toast () {
var toast = new Adw.Toast (_("Text copied!"));
overlay.add_toast (toast);
}
}