From 0272c78739438677c8d556b4a52aab163e9798c3 Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Tue, 19 Nov 2013 12:46:11 +0100 Subject: [PATCH] Add layout save and load of last active term for windows without tabs --- terminatorlib/container.py | 5 ++++- terminatorlib/terminal.py | 8 +++++++- terminatorlib/terminator.py | 15 +++++++++++++-- terminatorlib/window.py | 19 +++++++++++++++++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/terminatorlib/container.py b/terminatorlib/container.py index 0c47e933..5630c910 100755 --- a/terminatorlib/container.py +++ b/terminatorlib/container.py @@ -281,7 +281,10 @@ the %s will also close all terminals within it.') % (reqtype, reqtype)) labels.append(label.get_custom_label()) layout['labels'] = labels layout['active_page'] = self.get_current_page() - + else: + if hasattr(self, 'last_active_term') and self.last_active_term is not None: + layout['last_active_term'] = self.last_active_term + if mytype == 'Window': if self.uuid == self.terminator.last_active_window: layout['last_active_window'] = True diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index ce42dbed..a31558eb 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1088,7 +1088,13 @@ class Terminal(gtk.VBox): self.vte.set_colors(self.fgcolor_active, self.bgcolor, self.palette_active) self.set_cursor_color() - self.terminator.last_focused_term = self + if not self.terminator.doing_layout: + self.terminator.last_focused_term = self + if self.get_toplevel().is_child_notebook(): + # TODO: Will need some code for the tabs active terms to work + self.get_toplevel().last_active_term = None + else: + self.get_toplevel().last_active_term = self.uuid self.emit('focus-in') def on_vte_focus_out(self, _widget, _event): diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index add1ad68..22565d4f 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -293,14 +293,25 @@ class Terminator(Borg): """Layout operations have finished, record that fact""" self.doing_layout = False + window_last_active_term_mapping={} for window in self.windows: - if window.uuid == self.last_active_window: - window.show() + # TODO: Will need some code for the tabs active terms to work + window_last_active_term_mapping[window]=copy.deepcopy(window.last_active_term) for terminal in self.terminals: if not terminal.pid: terminal.spawn_child() + for window in self.windows: + if window.last_active_term: + # TODO: Will need some code for the tabs active terms to work + term = self.find_terminal_by_uuid(window_last_active_term_mapping[window].urn) + term.ensure_visible_and_focussed() + + for window in self.windows: + if window.uuid == self.last_active_window: + window.show() + def reconfigure(self): """Update configuration for the whole application""" diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 14829191..2cb6f67e 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -5,12 +5,13 @@ import copy import time +import uuid import pygtk pygtk.require('2.0') import gobject import gtk -from util import dbg, err +from util import dbg, err, make_uuid import util from translation import _ from version import APP_NAME @@ -38,6 +39,7 @@ class Window(Container, gtk.Window): position = None ignore_startup_show = None set_pos_by_ratio = None + last_active_term = None zoom_data = None @@ -239,7 +241,17 @@ class Window(Container, gtk.Window): def on_focus_in(self, window, event): """Focus has entered the window""" self.set_urgency_hint(False) - self.terminator.last_active_window = self.uuid + term = None + if self.is_child_notebook(): + # TODO: Will need some code for the tabs active terms to work + pass + else: + if isinstance(self.last_active_term, uuid.UUID): + term = self.terminator.find_terminal_by_uuid(self.last_active_term.urn) + if term: + gobject.idle_add(term.ensure_visible_and_focussed) + if not self.terminator.doing_layout: + self.terminator.last_active_window = self.uuid # FIXME: Cause the terminal titlebars to update here def is_child_notebook(self): @@ -866,6 +878,9 @@ class Window(Container, gtk.Window): self.get_children()[0].create_layout(child) + if layout.has_key('last_active_term') and layout['last_active_term'] not in ['', None]: + self.last_active_term = make_uuid(layout['last_active_term']) + if layout.has_key('last_active_window') and layout['last_active_window'] == 'True': self.terminator.last_active_window = self.uuid