2
// Copyright (C) 2011 Adrien Plazas
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
// Adrien Plazas <kekun.plazas@laposte.net>
21
// Daniel Fore <???@gmail.com>
25
* Set preferences via GSettings ?
26
* Do not focus on buttons
27
* Improve window resize (is it useful ?)
28
* Add right click menu with: copy, paste, preferences?, about
29
* Notify with system bubbles if the window is not focused (check FIXME)
30
* Set Dan correctly as the artist
37
private class PantheonTerminal : Window
43
Notify.Notification notification;
45
private PantheonTerminal()
47
Gtk.Settings.get_default().gtk_application_prefer_dark_theme = true;
48
set_title("Terminal");
51
destroy.connect(close);
53
notebook = new Notebook();
54
var left_box = new HBox(false, 0);
55
var right_box = new HBox(false, 0);
58
notebook.set_action_widget(left_box, PackType.START);
59
notebook.set_action_widget(right_box, PackType.END);
60
notebook.set_scrollable(true);
63
left_box.set_size_request(10, 0);
65
// Set "New tab" button
66
var add_button = new Button();
67
add_button.set_image(new Image.from_stock(Stock.ADD, IconSize.MENU));
69
add_button.set_relief(ReliefStyle.NONE);
70
add_button.set_tooltip_text("Open a new tab");
71
add_button.clicked.connect(new_tab);
72
right_box.pack_start(add_button, false, false, 0);
74
// Get the system's style
76
bgcolor = get_style().bg[StateType.NORMAL];
77
fgcolor = get_style().fg[StateType.NORMAL];
79
// Try to set the icon FIXME
80
Gdk.Pixbuf icon = new Gdk.Pixbuf(Gdk.Colorspace.RGB, true, 8, 1, 1);
81
try { IconTheme.get_default().load_icon("terminal", 16, IconLookupFlags.FORCE_SVG); } catch (Error er) {}
82
try { set_icon(icon); } catch(Error er) {}
88
private void new_tab()
91
var t = new TerminalWithNotification();
92
t.fork_command(null,null,null,null, true, true,true);
94
// Test the "task_over" signal
95
t.task_over.connect(() => {stdout.printf("task_over\n");});
99
// Create a new tab with the terminal
100
var tab = new TabWithCloseButton("Terminal");
101
notebook.insert_page(t, tab, notebook.get_current_page() + 1);
102
notebook.next_page();
103
notebook.set_tab_reorderable(t, true);
106
tab.clicked.connect(() => { notebook.remove(t); });
107
t.window_title_changed.connect(() => { tab.set_text(t.get_window_title()); });
108
notebook.switch_page.connect((page, page_num) => { if (notebook.page_num(t) == (int) page_num) tab.set_notification(false); });
109
t.task_over.connect(() => {
110
if (notebook.page_num(t) != notebook.get_current_page())
111
tab.set_notification(true);
112
if (is_focus) // Check if the window have the focus FIXME
113
stdout.printf("focus\n");
117
t.set_color_background(bgcolor);
118
t.set_color_foreground(fgcolor);
126
private static void main(string[] args)
129
new PantheonTerminal();
134
public class TerminalWithNotification : Terminal
136
public signal void task_over();
138
long last_row_count = 0;
139
long last_column_count = 0;
141
public TerminalWithNotification()
143
set_size_request(320, 200);
144
window_title_changed.connect(check_for_notification);
147
private void check_for_notification()
149
/* Curently I use this trick to know if a task is over, the drawnback is
150
* that when the window is resized and a notification should be received,
151
* the user will not be notified.
153
if (get_row_count() == last_row_count && get_column_count() == last_column_count)
155
last_row_count = get_row_count();
156
last_column_count = get_column_count();
160
public class TabWithCloseButton : HBox
162
public signal void clicked();
164
private Button button;
167
bool notification = false;
169
public TabWithCloseButton(string text)
174
button = new Button();
175
button.set_image(new Image.from_stock(Stock.CLOSE, IconSize.MENU));
177
button.set_relief(ReliefStyle.NONE);
178
button.clicked.connect(() => { clicked(); });
181
label = new Label(text);
185
pack_start(button, false, true, 0);
186
pack_end(label, true, true, 0);
190
public void set_notification(bool notification)
192
this.notification = notification;
194
{ label.set_markup("<span color=\"#18a0c0\">"+text+"</span>"); }
196
{ label.set_markup(text); }
199
public void set_text(string text)
202
set_notification(notification);