Merge lp:~niclasl/pantheon-terminal/new-dn-api into lp:~elementary-apps/pantheon-terminal/trunk

Proposed by Niclas Lockner
Status: Merged
Approved by: David Gomes
Approved revision: 544
Merged at revision: 534
Proposed branch: lp:~niclasl/pantheon-terminal/new-dn-api
Merge into: lp:~elementary-apps/pantheon-terminal/trunk
Diff against target: 389 lines (+137/-123)
2 files modified
src/PantheonTerminalWindow.vala (+117/-115)
src/TerminalWidget.vala (+20/-8)
To merge this branch: bzr merge lp:~niclasl/pantheon-terminal/new-dn-api
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+199044@code.launchpad.net

Commit message

Made compatible with DynamicNotebook's new API.

Description of the change

Made compatible with DynamicNotebook's new API

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/PantheonTerminalWindow.vala'
2--- src/PantheonTerminalWindow.vala 2013-10-26 21:22:18 +0000
3+++ src/PantheonTerminalWindow.vala 2013-12-15 14:15:56 +0000
4@@ -69,9 +69,6 @@
5 public Gtk.ActionGroup main_actions;
6 public Gtk.UIManager ui;
7
8- //variable indicating that a tab might has been closed by exit command
9- bool closed_by_exit;
10-
11 public PantheonTerminalWindow (Granite.Application app, bool should_recreate_tabs=true) {
12 this.app = app as PantheonTerminalApp;
13 set_application (app);
14@@ -105,8 +102,6 @@
15 Notify.init (app.program_name);
16 set_visual (Gdk.Screen.get_default ().get_rgba_visual ());
17
18- closed_by_exit = true;
19-
20 Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
21 title = _("Terminal");
22 restore_saved_state (restore_pos);
23@@ -161,81 +156,17 @@
24 notebook.show_tabs = false;
25 }
26
27+ notebook.tab_added.connect (on_tab_added);
28+ notebook.tab_removed.connect (on_tab_removed);
29 notebook.tab_switched.connect (on_switch_page);
30 notebook.tab_moved.connect (on_tab_moved);
31+ notebook.tab_reordered.connect (on_tab_reordered);
32 notebook.tab_duplicated.connect (on_tab_duplicated);
33+ notebook.close_tab_requested.connect (on_close_tab_requested);
34+ notebook.new_tab_requested.connect (on_new_tab_requested);
35 notebook.allow_new_window = true;
36 notebook.allow_duplication = true;
37 notebook.group_name = "pantheon-terminal";
38-
39- notebook.tab_added.connect ((tab) => {
40- if (settings.follow_last_tab)
41- new_tab (previous_terminal.get_shell_location (), tab);
42- else
43- new_tab ("", tab);
44- });
45-
46- notebook.tab_removed.connect ((tab) => {
47- var t = (tab.page as Gtk.Grid).get_child_at (0, 0) as TerminalWidget;
48-
49- if (t.has_foreground_process ()) {
50- var d = new ForegroundProcessDialog ();
51- if (d.run () == 1) {
52- closed_by_exit = false;
53- t.kill_ps_and_fg ();
54-
55- if (notebook.n_tabs - 1 == 0) {
56- update_saved_state ();
57- destroy ();
58- }
59-
60- d.destroy ();
61-
62- if (notebook.n_tabs == 2) {
63- if (settings.tab_bar_behavior == PantheonTerminalTabBarBehavior.SINGLE) {
64- notebook.show_tabs = false;
65- }
66- }
67-
68- return true;
69- }
70-
71- d.destroy ();
72-
73- return false;
74- } else {
75- if (notebook.n_tabs - 1 == 0) {
76- update_saved_state ();
77- tab.parent.parent.parent.destroy ();
78- }
79- }
80-
81- if (current_terminal.tab == tab) {
82- int new_position = notebook.get_tab_position (notebook.current) + 1;
83- if (new_position >= notebook.n_tabs) {
84- new_position = notebook.n_tabs - 2;
85- }
86-
87- foreach (var terminal in terminals) {
88- if (notebook.get_tab_position (terminal.tab) == new_position) {
89- current_terminal = terminal;
90- break;
91- }
92- }
93- }
94-
95- closed_by_exit = false;
96- t.kill_ps ();
97-
98- if (notebook.n_tabs == 2) {
99- if (settings.tab_bar_behavior == PantheonTerminalTabBarBehavior.SINGLE) {
100- notebook.show_tabs = false;
101- }
102- }
103-
104- return true;
105- });
106-
107 notebook.can_focus = false;
108 add (notebook);
109
110@@ -328,18 +259,15 @@
111 saved_state.tabs = "";
112 }
113
114- private void on_tab_moved (Granite.Widgets.Tab tab, int new_pos,
115- bool new_window, int x, int y) {
116- if (new_window) {
117- var win = app.new_window_with_coords (x, y, false);
118-
119- notebook.remove_tab_force (tab);
120-
121- var n = win.notebook;
122- n.insert_tab (tab, -1);
123- } else {
124- current_terminal.grab_focus ();
125- }
126+ private void on_tab_added (Granite.Widgets.Tab tab) {
127+ var t = (tab.page as Gtk.Grid).get_child_at (0, 0) as TerminalWidget;
128+ terminals.append (t);
129+ t.set_parent_window (this);
130+ }
131+
132+ private void on_tab_removed (Granite.Widgets.Tab tab) {
133+ var t = (tab.page as Gtk.Grid).get_child_at (0, 0) as TerminalWidget;
134+ terminals.remove (t);
135
136 if (notebook.n_tabs == 0) {
137 destroy ();
138@@ -347,12 +275,95 @@
139 notebook.show_tabs = false;
140 }
141 }
142+
143+ private bool on_close_tab_requested (Granite.Widgets.Tab tab) {
144+ var t = (tab.page as Gtk.Grid).get_child_at (0, 0) as TerminalWidget;
145+
146+ if (t.has_foreground_process ()) {
147+ var d = new ForegroundProcessDialog ();
148+ if (d.run () == 1) {
149+ t.manually_closed = true;
150+ t.kill_ps_and_fg ();
151+
152+ if (notebook.n_tabs - 1 == 0) {
153+ update_saved_state ();
154+ destroy ();
155+ }
156+
157+ d.destroy ();
158+
159+ if (notebook.n_tabs == 2) {
160+ if (settings.tab_bar_behavior == PantheonTerminalTabBarBehavior.SINGLE) {
161+ notebook.show_tabs = false;
162+ }
163+ }
164+
165+ return true;
166+ }
167+
168+ d.destroy ();
169+
170+ return false;
171+ } else {
172+ if (notebook.n_tabs - 1 == 0) {
173+ update_saved_state ();
174+ tab.parent.parent.parent.destroy ();
175+ }
176+ }
177+
178+ if (current_terminal.tab == tab) {
179+ int new_position = notebook.get_tab_position (notebook.current) + 1;
180+ if (new_position >= notebook.n_tabs) {
181+ new_position = notebook.n_tabs - 2;
182+ }
183+
184+ foreach (var terminal in terminals) {
185+ if (notebook.get_tab_position (terminal.tab) == new_position) {
186+ current_terminal = terminal;
187+ break;
188+ }
189+ }
190+ }
191+
192+ t.manually_closed = true;
193+ t.kill_ps ();
194+
195+ if (notebook.n_tabs == 2) {
196+ if (settings.tab_bar_behavior == PantheonTerminalTabBarBehavior.SINGLE) {
197+ notebook.show_tabs = false;
198+ }
199+ }
200+
201+ return true;
202+ }
203+
204+ private void on_tab_reordered (Granite.Widgets.Tab tab, int new_pos) {
205+ current_terminal.grab_focus ();
206+ }
207+
208+ private void on_tab_moved (Granite.Widgets.Tab tab, int x, int y) {
209+ var new_window = app.new_window_with_coords (x, y, false);
210+ var terminal = (tab.page as Gtk.Grid).get_child_at (0, 0) as TerminalWidget;
211+ var new_notebook = new_window.notebook;
212+
213+ notebook.remove_tab (tab);
214+ new_notebook.insert_tab (tab, -1);
215+ new_window.previous_terminal = terminal;
216+ new_window.current_terminal = terminal;
217+ }
218
219 private void on_tab_duplicated (Granite.Widgets.Tab tab) {
220 var t = (tab.page as Gtk.Grid).get_child_at (0, 0) as TerminalWidget;
221 new_tab (t.get_shell_location ());
222 }
223
224+ private void on_new_tab_requested () {
225+ if (settings.follow_last_tab && previous_terminal != null)
226+ new_tab (previous_terminal.get_shell_location ());
227+ else
228+ new_tab ();
229+ }
230+
231 private void update_context_menu () {
232 clipboard.request_targets (update_context_menu_cb);
233 }
234@@ -430,15 +441,21 @@
235 }
236 }
237
238- private void new_tab (string location="",
239- owned Granite.Widgets.Tab? tab=null,
240- string? program=null) {
241- /* If the user choose to use a specific working directory */
242- if (location == "") {
243+ private void new_tab (string directory="", string? program=null) {
244+ /*
245+ * If the user choose to use a specific working directory.
246+ * Reassigning the directory variable a new value
247+ * leads to free'd memory being read.
248+ */
249+ string location;
250+ if (directory == "") {
251 location = PantheonTerminalApp.working_directory ?? "";
252+ } else {
253+ location = directory;
254 }
255+
256 /* Set up terminal */
257- var t = new TerminalWidget (main_actions, ui, this);
258+ var t = new TerminalWidget (main_actions, this);
259 t.scrollback_lines = settings.scrollback_lines;
260 previous_terminal = current_terminal;
261 current_terminal = t;
262@@ -471,16 +488,7 @@
263 /* Set up actions releated to the terminal */
264 main_actions.get_action ("Copy").set_sensitive (t.get_has_selection ());
265
266- /* Create a new tab if it hasnt already been created by the plus button press */
267- bool to_be_inserted = false;
268- if (tab == null) {
269- tab = new Granite.Widgets.Tab (_("Terminal"), null, g);
270- to_be_inserted = true;
271- } else {
272- tab.page = g;
273- tab.label = _("Terminal");
274- tab.page.show_all ();
275- }
276+ var tab = new Granite.Widgets.Tab (_("Terminal"), null, g);
277
278 t.tab = tab;
279 tab.ellipsize_mode = Pango.EllipsizeMode.START;
280@@ -505,14 +513,13 @@
281 });
282
283 t.selection_changed.connect (() => {
284- main_actions.get_action("Copy").set_sensitive (t.get_has_selection ());
285+ main_actions.get_action ("Copy").set_sensitive (t.get_has_selection ());
286 });
287
288 t.child_exited.connect (() => {
289- if (closed_by_exit)
290- notebook.remove_tab (tab);
291-
292- closed_by_exit = true;
293+ if (!t.manually_closed) {
294+ tab.close ();
295+ }
296 });
297
298 t.set_font (term_font);
299@@ -523,17 +530,13 @@
300 app.minimum_width = minimum_width;
301 app.minimum_height = minimum_height;
302
303- terminals.append (t);
304-
305- if (to_be_inserted)
306- notebook.insert_tab (tab, -1);
307-
308+ notebook.insert_tab (tab, -1);
309 notebook.current = tab;
310 t.grab_focus ();
311 }
312
313 public void run_program_term (string program) {
314- new_tab ("", null, program);
315+ new_tab ("", program);
316 }
317
318 static string get_term_font () {
319@@ -594,8 +597,7 @@
320 }
321
322 void action_close_tab () {
323- terminals.remove (current_terminal);
324- notebook.remove_tab (notebook.current);
325+ current_terminal.tab.close ();
326 }
327
328 void action_new_window () {
329
330=== modified file 'src/TerminalWidget.vala'
331--- src/TerminalWidget.vala 2013-09-29 18:22:11 +0000
332+++ src/TerminalWidget.vala 2013-12-15 14:15:56 +0000
333@@ -26,6 +26,7 @@
334
335 GLib.Pid child_pid;
336 private PantheonTerminalWindow window;
337+ private Gtk.Menu menu;
338 public Granite.Widgets.Tab tab;
339 public string? uri;
340
341@@ -56,22 +57,22 @@
342 "(?:news:|man:|info:)[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+"
343 };
344
345- public TerminalWidget (Gtk.ActionGroup main_actions, Gtk.UIManager ui,
346+ private bool _manually_closed = false;
347+ public bool manually_closed {
348+ get { return _manually_closed; }
349+ set { _manually_closed = value; }
350+ }
351+
352+ public TerminalWidget (Gtk.ActionGroup main_actions,
353 PantheonTerminalWindow parent_window) {
354
355 /* Sets characters that define word for double click selection */
356 set_word_chars ("-A-Za-z0-9/.,_~#%?:=+@");
357
358- /* Set up the parents */
359- this.window = parent_window;
360- app = parent_window.app;
361-
362 restore_settings ();
363 settings.changed.connect (restore_settings);
364
365- /* Create a pop menu */
366- var menu = ui.get_widget ("ui/AppMenu") as Gtk.Menu;
367- menu.show_all ();
368+ set_parent_window (parent_window);
369
370 button_press_event.connect ((event) => {
371 uri = get_link ((long) event.x, (long) event.y);
372@@ -120,6 +121,17 @@
373 this.clickable (regex_strings);
374 }
375
376+ public void set_parent_window (PantheonTerminalWindow parent_window) {
377+ this.window = parent_window;
378+ this.app = parent_window.app;
379+ this.menu = parent_window.ui.get_widget ("ui/AppMenu") as Gtk.Menu;
380+ this.menu.show_all ();
381+ }
382+
383+ public PantheonTerminalWindow get_parent_window () {
384+ return window;
385+ }
386+
387 public void restore_settings () {
388 /* Load configuration */
389 int opacity = settings.opacity * 65535;

Subscribers

People subscribed via source and target branches