-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.vala
96 lines (78 loc) · 3.07 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
namespace ETerm {
public class App: Gtk.Application {
public App() {
GLib.Object(application_id: "org.edge.terminal", flags: GLib.ApplicationFlags.FLAGS_NONE);
}
protected override void activate() {
this.window_removed.connect(this.window_removed_cb);
this.add_actions();
this.set_dark_theme();
this.new_window();
}
private void add_actions() {
GLib.SimpleAction action;
action = new GLib.SimpleAction("copy", null);
action.activate.connect(this.copy);
this.add_action(action);
action = new GLib.SimpleAction("paste", null);
action.activate.connect(this.paste);
this.add_action(action);
action = new GLib.SimpleAction("new-window", null);
action.activate.connect(this.new_window);
this.add_action(action);
action = new GLib.SimpleAction("new-tab", null);
action.activate.connect(this.new_tab);
this.add_action(action);
action = new GLib.SimpleAction("close-tab", null);
action.activate.connect(this.close_tab);
this.add_action(action);
action = new GLib.SimpleAction("about", null);
action.activate.connect(this.about);
this.add_action(action);
this.set_accels_for_action("app.copy", { "<Primary><Shift>C" });
this.set_accels_for_action("app.paste", { "<Primary><Shift>V" });
this.set_accels_for_action("app.new-window", { "<Primary><Shift>N" });
this.set_accels_for_action("app.new-tab", { "<Primary><Shift>T" });
this.set_accels_for_action("app.close-tab", { "<Primary><Shift>W" });
}
private void set_dark_theme() {
Gtk.Settings settings = Gtk.Settings.get_default();
settings.gtk_application_prefer_dark_theme = false;
}
private void window_removed_cb(Gtk.Application self, Gtk.Window window) {
if (this.get_windows().length() == 0) {
this.quit();
}
}
public void new_window() {
ETerm.Window win = new ETerm.Window(this);
this.add_window(win);
}
public ETerm.Window get_current_window() {
Gtk.Window win = this.get_active_window();
return (win as ETerm.Window);
}
public void about() {
stdout.printf("about!\n");
}
public void copy() {
this.get_current_window().copy();
}
public void paste() {
this.get_current_window().paste();
}
public void new_tab() {
ETerm.Window win = this.get_current_window();
win.selected_terminal.update_image();
win.new_terminal();
}
public void close_tab() {
ETerm.Window win = this.get_current_window();
win.close_tab_from_term(win.selected_terminal);
}
}
}
int main(string[] args) {
ETerm.App app = new ETerm.App();
return app.run();
}