This repository was archived by the owner on Nov 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathTerminalWidget.vala
More file actions
190 lines (147 loc) · 5.29 KB
/
Copy pathTerminalWidget.vala
File metadata and controls
190 lines (147 loc) · 5.29 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Copyright © 2013–2014 Philipp Emanuel Weidmann <pew@worldwidemann.com>
*
* Nemo vir est qui mundum non reddat meliorem.
*
*
* This file is part of Final Term.
*
* Final Term is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Final Term is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Final Term. If not, see <http://www.gnu.org/licenses/>.
*/
public class TerminalWidget : GtkClutter.Embed, NestingContainerChild {
public bool is_active { get; set; }
public string title { get; set; }
private Clutter.Stage stage;
private Terminal terminal;
private TerminalView terminal_view;
// This has to be a field rather than a local variable
// because it gets destroyed immediately otherwise
private Gtk.Menu context_menu;
public TerminalWidget() {
stage = (Clutter.Stage)get_stage();
stage.use_alpha = true;
terminal = new Terminal();
title = terminal.terminal_output.terminal_title;
terminal.terminal_output.notify["terminal-title"].connect(() => {
title = terminal.terminal_output.terminal_title;
});
bool shell_terminated_called = false;
bool close_called = false;
terminal.shell_terminated.connect(() => {
shell_terminated_called = true;
if (!close_called)
close();
});
close.connect(() => {
close_called = true;
if (!shell_terminated_called)
terminal.terminate_shell();
});
terminal_view = new TerminalView(terminal, this);
terminal.terminal_view = terminal_view;
stage.add(terminal_view);
var inactive_effect = new Clutter.BrightnessContrastEffect();
inactive_effect.set_brightness(-0.2f);
inactive_effect.set_contrast(-0.4f);
notify["is-active"].connect(() => {
terminal_view.clear_effects();
if (!is_active)
terminal_view.add_effect(inactive_effect);
terminal_view.terminal_output_view.is_active = is_active;
});
configure_event.connect(on_configure_event);
button_press_event.connect(on_button_press_event);
on_settings_changed(null);
Settings.get_default().changed.connect(on_settings_changed);
}
protected override void get_preferred_width(out int minimum_width, out int natural_width) {
natural_width = terminal_view.terminal_output_view.get_horizontal_padding() +
(terminal.columns * Settings.get_default().character_width);
}
protected override void get_preferred_height(out int minimum_height, out int natural_height) {
natural_height = terminal_view.terminal_output_view.get_vertical_padding() +
(terminal.lines * Settings.get_default().character_height);
}
public void clear_shell_command() {
terminal.clear_command();
}
public void set_shell_command(string command) {
terminal.set_command(command);
}
public void run_shell_command(string command) {
terminal.run_command(command);
}
public void send_text_to_shell(string text) {
terminal.send_text(text);
}
public TerminalOutput.TerminalMode get_terminal_modes() {
return terminal.terminal_output.terminal_modes;
}
private bool on_configure_event(Gdk.EventConfigure event) {
// TODO: Use "expand" properties to achieve this?
terminal_view.width = event.width;
terminal_view.height = event.height;
// Reposition autocompletion popup when window is moved or resized
// to make it "stick" to the prompt line
if (FinalTerm.autocompletion.is_popup_visible()) {
terminal.update_autocompletion_position();
}
return false;
}
private bool on_button_press_event(Gdk.EventButton event) {
if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 1) {
// Left mouse button pressed
is_active = true;
return true;
} else if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3) {
// Right mouse button pressed
get_context_menu().popup(null, null, null, event.button, event.time);
return true;
}
return false;
}
private Gtk.Menu get_context_menu() {
context_menu = new Gtk.Menu();
Gtk.MenuItem menu_item;
menu_item = new Gtk.MenuItem.with_label(_("New Tab"));
menu_item.activate.connect(() => {
add_tab();
});
context_menu.append(menu_item);
context_menu.append(new Gtk.SeparatorMenuItem());
menu_item = new Gtk.MenuItem.with_label(_("Split Vertically"));
menu_item.activate.connect(() => {
split(Gtk.Orientation.HORIZONTAL);
});
context_menu.append(menu_item);
menu_item = new Gtk.MenuItem.with_label(_("Split Horizontally"));
menu_item.activate.connect(() => {
split(Gtk.Orientation.VERTICAL);
});
context_menu.append(menu_item);
context_menu.append(new Gtk.SeparatorMenuItem());
menu_item = new Gtk.MenuItem.with_label(_("Close"));
menu_item.activate.connect(() => {
close();
});
context_menu.append(menu_item);
context_menu.show_all();
return context_menu;
}
private void on_settings_changed(string? key) {
var background_color = Settings.get_default().background_color;
background_color.alpha = (uint8)(Settings.get_default().opacity * 255.0);
stage.background_color = background_color;
}
}