Merge lp:~stephen-j-boddy/terminator/feature-remember-focus into lp:terminator/trunk
- feature-remember-focus
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 1490 |
Proposed branch: | lp:~stephen-j-boddy/terminator/feature-remember-focus |
Merge into: | lp:terminator/trunk |
Diff against target: |
443 lines (+186/-28) 6 files modified
terminatorlib/container.py (+15/-3) terminatorlib/notebook.py (+89/-14) terminatorlib/terminal.py (+19/-9) terminatorlib/terminator.py (+49/-0) terminatorlib/util.py (+3/-1) terminatorlib/window.py (+11/-1) |
To merge this branch: | bzr merge lp:~stephen-j-boddy/terminator/feature-remember-focus |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Terminator | Pending | ||
Review via email: mp+199654@code.launchpad.net |
Commit message
Description of the change
OK, This took longer and was more tricky than I first anticipated. When loading/saving layouts, Terminator now remembers which:
1) was the active window,
2) terminal was active in non-tabbed windows,
3) tab was current in tabbed windows,
4) terminal was active in each tab (also remembered when switching between tabs at runtime),
5) UUID was assigned to a terminal, and restores it.
(5) means you can rely on the shell environment variable TERMINATOR_UUID to always be the same on relaunching a layout.
I tend to dogfood everything I code, but I'd appreciate it if some others could download and give this a workout before I go and apply to trunk.
Stephen Boddy (stephen-j-boddy) wrote : | # |
- 1484. By Stephen Boddy
-
Remove the unnecessary cruft left over in the windows on_focus_in related to terminal focus
- 1485. By Stephen Boddy
-
Missed a line in the cruft removal
Preview Diff
1 | === modified file 'terminatorlib/container.py' | |||
2 | --- terminatorlib/container.py 2013-09-25 22:07:01 +0000 | |||
3 | +++ terminatorlib/container.py 2014-01-21 22:41:47 +0000 | |||
4 | @@ -263,6 +263,7 @@ | |||
5 | 263 | 263 | ||
6 | 264 | if hasattr(self, 'isfullscreen'): | 264 | if hasattr(self, 'isfullscreen'): |
7 | 265 | layout['fullscreen'] = self.isfullscreen | 265 | layout['fullscreen'] = self.isfullscreen |
8 | 266 | |||
9 | 266 | if hasattr(self, 'ratio'): | 267 | if hasattr(self, 'ratio'): |
10 | 267 | layout['ratio'] = self.ratio | 268 | layout['ratio'] = self.ratio |
11 | 268 | 269 | ||
12 | @@ -272,15 +273,26 @@ | |||
13 | 272 | if hasattr(self, 'title'): | 273 | if hasattr(self, 'title'): |
14 | 273 | layout['title'] = self.title.text | 274 | layout['title'] = self.title.text |
15 | 274 | 275 | ||
16 | 275 | labels = [] | ||
17 | 276 | if mytype == 'Notebook': | 276 | if mytype == 'Notebook': |
18 | 277 | labels = [] | ||
19 | 278 | last_active_term = [] | ||
20 | 277 | for tabnum in xrange(0, self.get_n_pages()): | 279 | for tabnum in xrange(0, self.get_n_pages()): |
21 | 278 | page = self.get_nth_page(tabnum) | 280 | page = self.get_nth_page(tabnum) |
22 | 279 | label = self.get_tab_label(page) | 281 | label = self.get_tab_label(page) |
23 | 280 | labels.append(label.get_custom_label()) | 282 | labels.append(label.get_custom_label()) |
24 | 283 | last_active_term.append(self.last_active_term[self.get_nth_page(tabnum)]) | ||
25 | 284 | layout['labels'] = labels | ||
26 | 285 | layout['last_active_term'] = last_active_term | ||
27 | 281 | layout['active_page'] = self.get_current_page() | 286 | layout['active_page'] = self.get_current_page() |
30 | 282 | if len(labels) > 0: | 287 | else: |
31 | 283 | layout['labels'] = labels | 288 | if hasattr(self, 'last_active_term') and self.last_active_term is not None: |
32 | 289 | layout['last_active_term'] = self.last_active_term | ||
33 | 290 | |||
34 | 291 | if mytype == 'Window': | ||
35 | 292 | if self.uuid == self.terminator.last_active_window: | ||
36 | 293 | layout['last_active_window'] = True | ||
37 | 294 | else: | ||
38 | 295 | layout['last_active_window'] = False | ||
39 | 284 | 296 | ||
40 | 285 | name = 'child%d' % count | 297 | name = 'child%d' % count |
41 | 286 | count = count + 1 | 298 | count = count + 1 |
42 | 287 | 299 | ||
43 | === modified file 'terminatorlib/notebook.py' | |||
44 | --- terminatorlib/notebook.py 2013-10-25 14:55:26 +0000 | |||
45 | +++ terminatorlib/notebook.py 2014-01-21 22:41:47 +0000 | |||
46 | @@ -12,11 +12,14 @@ | |||
47 | 12 | from container import Container | 12 | from container import Container |
48 | 13 | from editablelabel import EditableLabel | 13 | from editablelabel import EditableLabel |
49 | 14 | from translation import _ | 14 | from translation import _ |
51 | 15 | from util import err, dbg, enumerate_descendants | 15 | from util import err, dbg, enumerate_descendants, make_uuid |
52 | 16 | 16 | ||
53 | 17 | class Notebook(Container, gtk.Notebook): | 17 | class Notebook(Container, gtk.Notebook): |
54 | 18 | """Class implementing a gtk.Notebook container""" | 18 | """Class implementing a gtk.Notebook container""" |
55 | 19 | window = None | 19 | window = None |
56 | 20 | last_active_term = None | ||
57 | 21 | pending_on_tab_switch = None | ||
58 | 22 | pending_on_tab_switch_args = None | ||
59 | 20 | 23 | ||
60 | 21 | def __init__(self, window): | 24 | def __init__(self, window): |
61 | 22 | """Class initialiser""" | 25 | """Class initialiser""" |
62 | @@ -30,12 +33,16 @@ | |||
63 | 30 | self.window = window | 33 | self.window = window |
64 | 31 | gobject.type_register(Notebook) | 34 | gobject.type_register(Notebook) |
65 | 32 | self.register_signals(Notebook) | 35 | self.register_signals(Notebook) |
66 | 36 | self.connect('switch-page', self.deferred_on_tab_switch) | ||
67 | 33 | self.configure() | 37 | self.configure() |
68 | 34 | 38 | ||
69 | 35 | child = window.get_child() | 39 | child = window.get_child() |
70 | 36 | window.remove(child) | 40 | window.remove(child) |
71 | 37 | window.add(self) | 41 | window.add(self) |
72 | 38 | self.newtab(widget=child) | 42 | self.newtab(widget=child) |
73 | 43 | if window.last_active_term: | ||
74 | 44 | self.set_last_active_term(window.last_active_term) | ||
75 | 45 | window.last_active_term = None | ||
76 | 39 | 46 | ||
77 | 40 | self.show_all() | 47 | self.show_all() |
78 | 41 | 48 | ||
79 | @@ -63,6 +70,7 @@ | |||
80 | 63 | style.xthickness = 0 | 70 | style.xthickness = 0 |
81 | 64 | style.ythickness = 0 | 71 | style.ythickness = 0 |
82 | 65 | self.modify_style(style) | 72 | self.modify_style(style) |
83 | 73 | self.last_active_term = {} | ||
84 | 66 | 74 | ||
85 | 67 | def create_layout(self, layout): | 75 | def create_layout(self, layout): |
86 | 68 | """Apply layout configuration""" | 76 | """Apply layout configuration""" |
87 | @@ -117,10 +125,14 @@ | |||
88 | 117 | label = self.get_tab_label(page) | 125 | label = self.get_tab_label(page) |
89 | 118 | label.set_custom_label(labeltext) | 126 | label.set_custom_label(labeltext) |
90 | 119 | page.create_layout(children[child_key]) | 127 | page.create_layout(children[child_key]) |
91 | 128 | |||
92 | 129 | if layout.get('last_active_term', None): | ||
93 | 130 | self.last_active_term[page] = make_uuid(layout['last_active_term'][num]) | ||
94 | 120 | num = num + 1 | 131 | num = num + 1 |
95 | 121 | 132 | ||
96 | 122 | if layout.has_key('active_page'): | 133 | if layout.has_key('active_page'): |
98 | 123 | self.set_current_page(int(layout['active_page'])) | 134 | # Need to do it later, or layout changes result |
99 | 135 | gobject.idle_add(self.set_current_page, int(layout['active_page'])) | ||
100 | 124 | else: | 136 | else: |
101 | 125 | self.set_current_page(0) | 137 | self.set_current_page(0) |
102 | 126 | 138 | ||
103 | @@ -167,12 +179,13 @@ | |||
104 | 167 | self.set_current_page(page_num) | 179 | self.set_current_page(page_num) |
105 | 168 | 180 | ||
106 | 169 | self.show_all() | 181 | self.show_all() |
107 | 170 | terminal.grab_focus() | ||
108 | 171 | 182 | ||
109 | 172 | while gtk.events_pending(): | 183 | while gtk.events_pending(): |
110 | 173 | gtk.main_iteration_do(False) | 184 | gtk.main_iteration_do(False) |
111 | 174 | self.get_toplevel().set_pos_by_ratio = False | 185 | self.get_toplevel().set_pos_by_ratio = False |
112 | 175 | 186 | ||
113 | 187 | gobject.idle_add(terminal.ensure_visible_and_focussed) | ||
114 | 188 | |||
115 | 176 | def add(self, widget, metadata=None): | 189 | def add(self, widget, metadata=None): |
116 | 177 | """Add a widget to the container""" | 190 | """Add a widget to the container""" |
117 | 178 | dbg('adding a new tab') | 191 | dbg('adding a new tab') |
118 | @@ -268,15 +281,22 @@ | |||
119 | 268 | 281 | ||
120 | 269 | dbg('inserting page at position: %s' % tabpos) | 282 | dbg('inserting page at position: %s' % tabpos) |
121 | 270 | self.insert_page(widget, None, tabpos) | 283 | self.insert_page(widget, None, tabpos) |
126 | 271 | self.set_tab_label(widget, label) | 284 | child_widgets = [widget] |
127 | 272 | self.set_tab_label_packing(widget, not self.config['scroll_tabbar'], | 285 | child_widgets .extend(enumerate_descendants(widget)) |
128 | 273 | not self.config['scroll_tabbar'], | 286 | term_widget = None |
129 | 274 | gtk.PACK_START) | 287 | for term_widget in child_widgets: |
130 | 288 | if maker.isinstance(term_widget, 'Terminal'): | ||
131 | 289 | self.set_last_active_term(term_widget.uuid) | ||
132 | 290 | self.set_tab_label(term_widget, label) | ||
133 | 291 | self.set_tab_label_packing(term_widget, not self.config['scroll_tabbar'], | ||
134 | 292 | not self.config['scroll_tabbar'], | ||
135 | 293 | gtk.PACK_START) | ||
136 | 294 | break | ||
137 | 275 | 295 | ||
138 | 276 | self.set_tab_reorderable(widget, True) | 296 | self.set_tab_reorderable(widget, True) |
139 | 277 | self.set_current_page(tabpos) | 297 | self.set_current_page(tabpos) |
140 | 278 | self.show_all() | 298 | self.show_all() |
142 | 279 | if maker.isinstance(widget, 'Terminal'): | 299 | if maker.isinstance(term_widget, 'Terminal'): |
143 | 280 | widget.grab_focus() | 300 | widget.grab_focus() |
144 | 281 | 301 | ||
145 | 282 | def wrapcloseterm(self, widget): | 302 | def wrapcloseterm(self, widget): |
146 | @@ -311,6 +331,7 @@ | |||
147 | 311 | 331 | ||
148 | 312 | if maker.isinstance(child, 'Terminal'): | 332 | if maker.isinstance(child, 'Terminal'): |
149 | 313 | dbg('Notebook::closetab: child is a single Terminal') | 333 | dbg('Notebook::closetab: child is a single Terminal') |
150 | 334 | del nb.last_active_term[child] | ||
151 | 314 | child.close() | 335 | child.close() |
152 | 315 | # FIXME: We only do this del and return here to avoid removing the | 336 | # FIXME: We only do this del and return here to avoid removing the |
153 | 316 | # page below, which child.close() implicitly does | 337 | # page below, which child.close() implicitly does |
154 | @@ -318,9 +339,7 @@ | |||
155 | 318 | return | 339 | return |
156 | 319 | elif maker.isinstance(child, 'Container'): | 340 | elif maker.isinstance(child, 'Container'): |
157 | 320 | dbg('Notebook::closetab: child is a Container') | 341 | dbg('Notebook::closetab: child is a Container') |
161 | 321 | dialog = self.construct_confirm_close(self.window, _('tab')) | 342 | result = self.construct_confirm_close(self.window, _('tab')) |
159 | 322 | result = dialog.run() | ||
160 | 323 | dialog.destroy() | ||
162 | 324 | 343 | ||
163 | 325 | if result == gtk.RESPONSE_ACCEPT: | 344 | if result == gtk.RESPONSE_ACCEPT: |
164 | 326 | containers = None | 345 | containers = None |
165 | @@ -340,9 +359,6 @@ | |||
166 | 340 | err('Notebook::closetab: child is unknown type %s' % child) | 359 | err('Notebook::closetab: child is unknown type %s' % child) |
167 | 341 | return | 360 | return |
168 | 342 | 361 | ||
169 | 343 | nb.remove_page(tabnum) | ||
170 | 344 | del(label) | ||
171 | 345 | |||
172 | 346 | def resizeterm(self, widget, keyname): | 362 | def resizeterm(self, widget, keyname): |
173 | 347 | """Handle a keyboard event requesting a terminal resize""" | 363 | """Handle a keyboard event requesting a terminal resize""" |
174 | 348 | raise NotImplementedError('resizeterm') | 364 | raise NotImplementedError('resizeterm') |
175 | @@ -403,6 +419,65 @@ | |||
176 | 403 | terms = parent.get_visible_terminals() | 419 | terms = parent.get_visible_terminals() |
177 | 404 | terms.keys()[-1].grab_focus() | 420 | terms.keys()[-1].grab_focus() |
178 | 405 | 421 | ||
179 | 422 | def page_num_descendant(self, widget): | ||
180 | 423 | """Find the tabnum of the tab containing a widget at any level""" | ||
181 | 424 | tabnum = self.page_num(widget) | ||
182 | 425 | dbg("widget is direct child if not equal -1 - tabnum: %d" % tabnum) | ||
183 | 426 | while tabnum == -1 and widget.get_parent(): | ||
184 | 427 | widget = widget.get_parent() | ||
185 | 428 | tabnum = self.page_num(widget) | ||
186 | 429 | dbg("found tabnum containing widget: %d" % tabnum) | ||
187 | 430 | return tabnum | ||
188 | 431 | |||
189 | 432 | def set_last_active_term(self, uuid): | ||
190 | 433 | """Set the last active term for uuid""" | ||
191 | 434 | widget = self.terminator.find_terminal_by_uuid(uuid.urn) | ||
192 | 435 | if not widget: | ||
193 | 436 | err("Cannot find terminal with uuid: %s, so cannot make it active" % (uuid.urn)) | ||
194 | 437 | return | ||
195 | 438 | tabnum = self.page_num_descendant(widget) | ||
196 | 439 | if tabnum == -1: | ||
197 | 440 | err("No tabnum found for terminal with uuid: %s" % (uuid.urn)) | ||
198 | 441 | return | ||
199 | 442 | nth_page = self.get_nth_page(tabnum) | ||
200 | 443 | self.last_active_term[nth_page] = uuid | ||
201 | 444 | |||
202 | 445 | def clean_last_active_term(self): | ||
203 | 446 | """Clean up old entries in last_active_term""" | ||
204 | 447 | if self.terminator.doing_layout == True: | ||
205 | 448 | return | ||
206 | 449 | last_active_term = {} | ||
207 | 450 | for tabnum in xrange(0, self.get_n_pages()): | ||
208 | 451 | nth_page = self.get_nth_page(tabnum) | ||
209 | 452 | if nth_page in self.last_active_term: | ||
210 | 453 | last_active_term[nth_page] = self.last_active_term[nth_page] | ||
211 | 454 | self.last_active_term = last_active_term | ||
212 | 455 | |||
213 | 456 | def deferred_on_tab_switch(self, notebook, page, page_num, data=None): | ||
214 | 457 | """Prime a single idle tab switch signal, using the most recent set of params""" | ||
215 | 458 | tabs_last_active_term = self.last_active_term.get(self.get_nth_page(page_num), None) | ||
216 | 459 | data = {'tabs_last_active_term':tabs_last_active_term} | ||
217 | 460 | |||
218 | 461 | self.pending_on_tab_switch_args = (notebook, page, page_num, data) | ||
219 | 462 | if self.pending_on_tab_switch == True: | ||
220 | 463 | return | ||
221 | 464 | gobject.idle_add(self.do_deferred_on_tab_switch) | ||
222 | 465 | self.pending_on_tab_switch = True | ||
223 | 466 | |||
224 | 467 | def do_deferred_on_tab_switch(self): | ||
225 | 468 | """Perform the latest tab switch signal, and resetting the pending flag""" | ||
226 | 469 | self.on_tab_switch(*self.pending_on_tab_switch_args) | ||
227 | 470 | self.pending_on_tab_switch = False | ||
228 | 471 | self.pending_on_tab_switch_args = None | ||
229 | 472 | |||
230 | 473 | def on_tab_switch(self, notebook, page, page_num, data=None): | ||
231 | 474 | """Do the real work for a tab switch""" | ||
232 | 475 | tabs_last_active_term = data['tabs_last_active_term'] | ||
233 | 476 | if tabs_last_active_term: | ||
234 | 477 | term = self.terminator.find_terminal_by_uuid(tabs_last_active_term.urn) | ||
235 | 478 | gobject.idle_add(term.ensure_visible_and_focussed) | ||
236 | 479 | return True | ||
237 | 480 | |||
238 | 406 | class TabLabel(gtk.HBox): | 481 | class TabLabel(gtk.HBox): |
239 | 407 | """Class implementing a label widget for Notebook tabs""" | 482 | """Class implementing a label widget for Notebook tabs""" |
240 | 408 | notebook = None | 483 | notebook = None |
241 | 409 | 484 | ||
242 | === modified file 'terminatorlib/terminal.py' | |||
243 | --- terminatorlib/terminal.py 2013-10-25 14:57:14 +0000 | |||
244 | +++ terminatorlib/terminal.py 2014-01-21 22:41:47 +0000 | |||
245 | @@ -15,7 +15,7 @@ | |||
246 | 15 | import subprocess | 15 | import subprocess |
247 | 16 | import urllib | 16 | import urllib |
248 | 17 | 17 | ||
250 | 18 | from util import dbg, err, gerr, spawn_new_terminator | 18 | from util import dbg, err, gerr, spawn_new_terminator, make_uuid |
251 | 19 | import util | 19 | import util |
252 | 20 | from config import Config | 20 | from config import Config |
253 | 21 | from cwd import get_default_cwd | 21 | from cwd import get_default_cwd |
254 | @@ -1069,13 +1069,12 @@ | |||
255 | 1069 | maker = Factory() | 1069 | maker = Factory() |
256 | 1070 | 1070 | ||
257 | 1071 | if maker.isinstance(topchild, 'Notebook'): | 1071 | if maker.isinstance(topchild, 'Notebook'): |
265 | 1072 | prevtmp = None | 1072 | # Find which page number this term is on |
266 | 1073 | tmp = self.get_parent() | 1073 | tabnum = topchild.page_num_descendant(self) |
267 | 1074 | while tmp != topchild: | 1074 | # If terms page number is not the current one, switch to it |
268 | 1075 | prevtmp = tmp | 1075 | current_page = topchild.get_current_page() |
269 | 1076 | tmp = tmp.get_parent() | 1076 | if tabnum != current_page: |
270 | 1077 | page = topchild.page_num(prevtmp) | 1077 | topchild.set_current_page(tabnum) |
264 | 1078 | topchild.set_current_page(page) | ||
271 | 1079 | 1078 | ||
272 | 1080 | self.grab_focus() | 1079 | self.grab_focus() |
273 | 1081 | 1080 | ||
274 | @@ -1088,7 +1087,15 @@ | |||
275 | 1088 | self.vte.set_colors(self.fgcolor_active, self.bgcolor, | 1087 | self.vte.set_colors(self.fgcolor_active, self.bgcolor, |
276 | 1089 | self.palette_active) | 1088 | self.palette_active) |
277 | 1090 | self.set_cursor_color() | 1089 | self.set_cursor_color() |
279 | 1091 | self.terminator.last_focused_term = self | 1090 | if not self.terminator.doing_layout: |
280 | 1091 | self.terminator.last_focused_term = self | ||
281 | 1092 | if self.get_toplevel().is_child_notebook(): | ||
282 | 1093 | notebook = self.get_toplevel().get_children()[0] | ||
283 | 1094 | notebook.set_last_active_term(self.uuid) | ||
284 | 1095 | notebook.clean_last_active_term() | ||
285 | 1096 | self.get_toplevel().last_active_term = None | ||
286 | 1097 | else: | ||
287 | 1098 | self.get_toplevel().last_active_term = self.uuid | ||
288 | 1092 | self.emit('focus-in') | 1099 | self.emit('focus-in') |
289 | 1093 | 1100 | ||
290 | 1094 | def on_vte_focus_out(self, _widget, _event): | 1101 | def on_vte_focus_out(self, _widget, _event): |
291 | @@ -1490,6 +1497,7 @@ | |||
292 | 1490 | title = self.titlebar.get_custom_string() | 1497 | title = self.titlebar.get_custom_string() |
293 | 1491 | if title: | 1498 | if title: |
294 | 1492 | layout['title'] = title | 1499 | layout['title'] = title |
295 | 1500 | layout['uuid'] = self.uuid | ||
296 | 1493 | name = 'terminal%d' % count | 1501 | name = 'terminal%d' % count |
297 | 1494 | count = count + 1 | 1502 | count = count + 1 |
298 | 1495 | global_layout[name] = layout | 1503 | global_layout[name] = layout |
299 | @@ -1511,6 +1519,8 @@ | |||
300 | 1511 | self.titlebar.set_custom_string(layout['title']) | 1519 | self.titlebar.set_custom_string(layout['title']) |
301 | 1512 | if layout.has_key('directory') and layout['directory'] != '': | 1520 | if layout.has_key('directory') and layout['directory'] != '': |
302 | 1513 | self.directory = layout['directory'] | 1521 | self.directory = layout['directory'] |
303 | 1522 | if layout.has_key('uuid') and layout['uuid'] != '': | ||
304 | 1523 | self.uuid = make_uuid(layout['uuid']) | ||
305 | 1514 | 1524 | ||
306 | 1515 | def scroll_by_page(self, pages): | 1525 | def scroll_by_page(self, pages): |
307 | 1516 | """Scroll up or down in pages""" | 1526 | """Scroll up or down in pages""" |
308 | 1517 | 1527 | ||
309 | === modified file 'terminatorlib/terminator.py' | |||
310 | --- terminatorlib/terminator.py 2013-09-04 20:59:27 +0000 | |||
311 | +++ terminatorlib/terminator.py 2014-01-21 22:41:47 +0000 | |||
312 | @@ -34,6 +34,7 @@ | |||
313 | 34 | debug_address = None | 34 | debug_address = None |
314 | 35 | 35 | ||
315 | 36 | doing_layout = None | 36 | doing_layout = None |
316 | 37 | last_active_window = None | ||
317 | 37 | 38 | ||
318 | 38 | groupsend = None | 39 | groupsend = None |
319 | 39 | groupsend_type = {'all':0, 'group':1, 'off':2} | 40 | groupsend_type = {'all':0, 'group':1, 'off':2} |
320 | @@ -291,11 +292,59 @@ | |||
321 | 291 | def layout_done(self): | 292 | def layout_done(self): |
322 | 292 | """Layout operations have finished, record that fact""" | 293 | """Layout operations have finished, record that fact""" |
323 | 293 | self.doing_layout = False | 294 | self.doing_layout = False |
324 | 295 | maker = Factory() | ||
325 | 296 | |||
326 | 297 | window_last_active_term_mapping = {} | ||
327 | 298 | for window in self.windows: | ||
328 | 299 | if window.is_child_notebook(): | ||
329 | 300 | source = window.get_toplevel().get_children()[0] | ||
330 | 301 | else: | ||
331 | 302 | source = window | ||
332 | 303 | window_last_active_term_mapping[window] = copy.copy(source.last_active_term) | ||
333 | 294 | 304 | ||
334 | 295 | for terminal in self.terminals: | 305 | for terminal in self.terminals: |
335 | 296 | if not terminal.pid: | 306 | if not terminal.pid: |
336 | 297 | terminal.spawn_child() | 307 | terminal.spawn_child() |
337 | 298 | 308 | ||
338 | 309 | for window in self.windows: | ||
339 | 310 | if window.is_child_notebook(): | ||
340 | 311 | # For windows with a notebook | ||
341 | 312 | notebook = window.get_toplevel().get_children()[0] | ||
342 | 313 | # Cycle through pages by number | ||
343 | 314 | for page in xrange(0, notebook.get_n_pages()): | ||
344 | 315 | # Try and get the entry in the previously saved mapping | ||
345 | 316 | mapping = window_last_active_term_mapping[window] | ||
346 | 317 | page_last_active_term = mapping.get(notebook.get_nth_page(page), None) | ||
347 | 318 | if page_last_active_term is None: | ||
348 | 319 | # Couldn't find entry, so we find the first child of type Terminal | ||
349 | 320 | children = notebook.get_nth_page(page).get_children() | ||
350 | 321 | for page_last_active_term in children: | ||
351 | 322 | if maker.isinstance(page_last_active_term, 'Terminal'): | ||
352 | 323 | page_last_active_term = page_last_active_term.uuid | ||
353 | 324 | break | ||
354 | 325 | else: | ||
355 | 326 | err('Should never reach here!') | ||
356 | 327 | page_last_active_term = None | ||
357 | 328 | if page_last_active_term is None: | ||
358 | 329 | # Bail on this tab as we're having no luck here, continue with the next | ||
359 | 330 | continue | ||
360 | 331 | # Set the notebook entry, then ensure Terminal is visible and focussed | ||
361 | 332 | urn = page_last_active_term.urn | ||
362 | 333 | notebook.last_active_term[notebook.get_nth_page(page)] = page_last_active_term | ||
363 | 334 | if urn: | ||
364 | 335 | term = self.find_terminal_by_uuid(urn) | ||
365 | 336 | if term: | ||
366 | 337 | term.ensure_visible_and_focussed() | ||
367 | 338 | else: | ||
368 | 339 | # For windows without a notebook ensure Terminal is visible and focussed | ||
369 | 340 | if window_last_active_term_mapping[window]: | ||
370 | 341 | term = self.find_terminal_by_uuid(window_last_active_term_mapping[window].urn) | ||
371 | 342 | term.ensure_visible_and_focussed() | ||
372 | 343 | |||
373 | 344 | for window in self.windows: | ||
374 | 345 | if window.uuid == self.last_active_window: | ||
375 | 346 | window.show() | ||
376 | 347 | |||
377 | 299 | def reconfigure(self): | 348 | def reconfigure(self): |
378 | 300 | """Update configuration for the whole application""" | 349 | """Update configuration for the whole application""" |
379 | 301 | 350 | ||
380 | 302 | 351 | ||
381 | === modified file 'terminatorlib/util.py' | |||
382 | --- terminatorlib/util.py 2013-08-28 21:09:17 +0000 | |||
383 | +++ terminatorlib/util.py 2014-01-21 22:41:47 +0000 | |||
384 | @@ -277,8 +277,10 @@ | |||
385 | 277 | len(terminals), parent)) | 277 | len(terminals), parent)) |
386 | 278 | return(containers, terminals) | 278 | return(containers, terminals) |
387 | 279 | 279 | ||
389 | 280 | def make_uuid(): | 280 | def make_uuid(str_uuid=None): |
390 | 281 | """Generate a UUID for an object""" | 281 | """Generate a UUID for an object""" |
391 | 282 | if str_uuid: | ||
392 | 283 | return uuid.UUID(str_uuid) | ||
393 | 282 | return uuid.uuid4() | 284 | return uuid.uuid4() |
394 | 283 | 285 | ||
395 | 284 | def inject_uuid(target): | 286 | def inject_uuid(target): |
396 | 285 | 287 | ||
397 | === modified file 'terminatorlib/window.py' | |||
398 | --- terminatorlib/window.py 2013-10-25 14:57:14 +0000 | |||
399 | +++ terminatorlib/window.py 2014-01-21 22:41:47 +0000 | |||
400 | @@ -5,12 +5,13 @@ | |||
401 | 5 | 5 | ||
402 | 6 | import copy | 6 | import copy |
403 | 7 | import time | 7 | import time |
404 | 8 | import uuid | ||
405 | 8 | import pygtk | 9 | import pygtk |
406 | 9 | pygtk.require('2.0') | 10 | pygtk.require('2.0') |
407 | 10 | import gobject | 11 | import gobject |
408 | 11 | import gtk | 12 | import gtk |
409 | 12 | 13 | ||
411 | 13 | from util import dbg, err | 14 | from util import dbg, err, make_uuid |
412 | 14 | import util | 15 | import util |
413 | 15 | from translation import _ | 16 | from translation import _ |
414 | 16 | from version import APP_NAME | 17 | from version import APP_NAME |
415 | @@ -38,6 +39,7 @@ | |||
416 | 38 | position = None | 39 | position = None |
417 | 39 | ignore_startup_show = None | 40 | ignore_startup_show = None |
418 | 40 | set_pos_by_ratio = None | 41 | set_pos_by_ratio = None |
419 | 42 | last_active_term = None | ||
420 | 41 | 43 | ||
421 | 42 | zoom_data = None | 44 | zoom_data = None |
422 | 43 | 45 | ||
423 | @@ -239,6 +241,8 @@ | |||
424 | 239 | def on_focus_in(self, window, event): | 241 | def on_focus_in(self, window, event): |
425 | 240 | """Focus has entered the window""" | 242 | """Focus has entered the window""" |
426 | 241 | self.set_urgency_hint(False) | 243 | self.set_urgency_hint(False) |
427 | 244 | if not self.terminator.doing_layout: | ||
428 | 245 | self.terminator.last_active_window = self.uuid | ||
429 | 242 | # FIXME: Cause the terminal titlebars to update here | 246 | # FIXME: Cause the terminal titlebars to update here |
430 | 243 | 247 | ||
431 | 244 | def is_child_notebook(self): | 248 | def is_child_notebook(self): |
432 | @@ -865,6 +869,12 @@ | |||
433 | 865 | 869 | ||
434 | 866 | self.get_children()[0].create_layout(child) | 870 | self.get_children()[0].create_layout(child) |
435 | 867 | 871 | ||
436 | 872 | if layout.has_key('last_active_term') and layout['last_active_term'] not in ['', None]: | ||
437 | 873 | self.last_active_term = make_uuid(layout['last_active_term']) | ||
438 | 874 | |||
439 | 875 | if layout.has_key('last_active_window') and layout['last_active_window'] == 'True': | ||
440 | 876 | self.terminator.last_active_window = self.uuid | ||
441 | 877 | |||
442 | 868 | class WindowTitle(object): | 878 | class WindowTitle(object): |
443 | 869 | """Class to handle the setting of the window title""" | 879 | """Class to handle the setting of the window title""" |
444 | 870 | 880 |
Ha, continuing my tradition of spotting errors after I submit for merging, I just noticed the following: window. py
terminatorlib/
@@ -239,6 +241,17 @@
Of that entire block of added lines, only the last two are needed. It doesn't do any harm being there, so I'll change it later. Must be something I tried while fighting to get all these other lines to do what *I* wanted.