Merge pull request #589 from Vulcalien/zoom-on-notebook
Zoom on notebook even if there is only one terminal in the tab + keep tab position and label in notebook rotation
This commit is contained in:
commit
a83ee32840
|
@ -144,17 +144,6 @@ class Container(object):
|
||||||
"""Handle a keyboard event requesting a terminal resize"""
|
"""Handle a keyboard event requesting a terminal resize"""
|
||||||
raise NotImplementedError('resizeterm')
|
raise NotImplementedError('resizeterm')
|
||||||
|
|
||||||
def toggle_zoom(self, widget, fontscale = False):
|
|
||||||
"""Toggle the existing zoom state"""
|
|
||||||
try:
|
|
||||||
if self.get_property('term_zoomed'):
|
|
||||||
self.unzoom(widget)
|
|
||||||
else:
|
|
||||||
self.zoom(widget, fontscale)
|
|
||||||
except TypeError:
|
|
||||||
err('Container::toggle_zoom: %s is unable to handle zooming, for \
|
|
||||||
%s' % (self, widget))
|
|
||||||
|
|
||||||
def zoom(self, widget, fontscale = False):
|
def zoom(self, widget, fontscale = False):
|
||||||
"""Zoom a terminal"""
|
"""Zoom a terminal"""
|
||||||
raise NotImplementedError('zoom')
|
raise NotImplementedError('zoom')
|
||||||
|
|
|
@ -291,7 +291,9 @@ class Notebook(Container, Gtk.Notebook):
|
||||||
'ungroup-tab': top_window.ungroup_tab,
|
'ungroup-tab': top_window.ungroup_tab,
|
||||||
'move-tab': top_window.move_tab,
|
'move-tab': top_window.move_tab,
|
||||||
'tab-new': [top_window.tab_new, widget],
|
'tab-new': [top_window.tab_new, widget],
|
||||||
'navigate': top_window.navigate_terminal}
|
'navigate': top_window.navigate_terminal,
|
||||||
|
'zoom': top_window.zoom,
|
||||||
|
'maximise': [top_window.zoom, False]}
|
||||||
|
|
||||||
if maker.isinstance(widget, 'Terminal'):
|
if maker.isinstance(widget, 'Terminal'):
|
||||||
for signal in signals:
|
for signal in signals:
|
||||||
|
|
|
@ -425,7 +425,7 @@ class Paned(Container):
|
||||||
"""We don't want focus, we want a Terminal to have it"""
|
"""We don't want focus, we want a Terminal to have it"""
|
||||||
self.get_child1().grab_focus()
|
self.get_child1().grab_focus()
|
||||||
|
|
||||||
def rotate_recursive(self, parent, w, h, clockwise):
|
def rotate_recursive(self, parent, w, h, clockwise, metadata=None):
|
||||||
"""
|
"""
|
||||||
Recursively rotate "self" into a new paned that'll have "w" x "h" size. Attach it to "parent".
|
Recursively rotate "self" into a new paned that'll have "w" x "h" size. Attach it to "parent".
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ class Paned(Container):
|
||||||
w2 = max(w - w1 - handle_size, 0)
|
w2 = max(w - w1 - handle_size, 0)
|
||||||
|
|
||||||
container.set_pos(pos)
|
container.set_pos(pos)
|
||||||
parent.add(container)
|
parent.add(container, metadata=metadata)
|
||||||
|
|
||||||
if maker.isinstance(children[0], 'Terminal'):
|
if maker.isinstance(children[0], 'Terminal'):
|
||||||
children[0].get_parent().remove(children[0])
|
children[0].get_parent().remove(children[0])
|
||||||
|
|
|
@ -538,6 +538,7 @@ class Window(Container, Gtk.Window):
|
||||||
|
|
||||||
def zoom(self, widget, font_scale=True):
|
def zoom(self, widget, font_scale=True):
|
||||||
"""Zoom a terminal widget"""
|
"""Zoom a terminal widget"""
|
||||||
|
maker = Factory()
|
||||||
children = self.get_children()
|
children = self.get_children()
|
||||||
|
|
||||||
if widget in children:
|
if widget in children:
|
||||||
|
@ -550,8 +551,13 @@ class Window(Container, Gtk.Window):
|
||||||
self.zoom_data['old_child'] = children[0]
|
self.zoom_data['old_child'] = children[0]
|
||||||
self.zoom_data['font_scale'] = font_scale
|
self.zoom_data['font_scale'] = font_scale
|
||||||
|
|
||||||
|
old_parent = self.zoom_data['old_parent']
|
||||||
|
if maker.isinstance(old_parent, 'Notebook'):
|
||||||
|
self.zoom_data['notebook_tabnum'] = old_parent.page_num(widget)
|
||||||
|
self.zoom_data['notebook_label'] = old_parent.get_tab_label(widget).get_label()
|
||||||
|
|
||||||
self.remove(self.zoom_data['old_child'])
|
self.remove(self.zoom_data['old_child'])
|
||||||
self.zoom_data['old_parent'].remove(widget)
|
old_parent.remove(widget)
|
||||||
self.add(widget)
|
self.add(widget)
|
||||||
self.set_property('term_zoomed', True)
|
self.set_property('term_zoomed', True)
|
||||||
|
|
||||||
|
@ -563,6 +569,8 @@ class Window(Container, Gtk.Window):
|
||||||
|
|
||||||
def unzoom(self, widget=None):
|
def unzoom(self, widget=None):
|
||||||
"""Restore normal terminal layout"""
|
"""Restore normal terminal layout"""
|
||||||
|
maker = Factory()
|
||||||
|
|
||||||
if not self.is_zoomed():
|
if not self.is_zoomed():
|
||||||
# We're not zoomed anyway
|
# We're not zoomed anyway
|
||||||
dbg('not zoomed, no-op')
|
dbg('not zoomed, no-op')
|
||||||
|
@ -574,7 +582,13 @@ class Window(Container, Gtk.Window):
|
||||||
|
|
||||||
self.remove(widget)
|
self.remove(widget)
|
||||||
self.add(self.zoom_data['old_child'])
|
self.add(self.zoom_data['old_child'])
|
||||||
self.zoom_data['old_parent'].add(widget)
|
if maker.isinstance(self.zoom_data['old_parent'], 'Notebook'):
|
||||||
|
self.zoom_data['old_parent'].newtab(widget=widget, metadata={
|
||||||
|
'tabnum': self.zoom_data['notebook_tabnum'],
|
||||||
|
'label': self.zoom_data['notebook_label']
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
self.zoom_data['old_parent'].add(widget)
|
||||||
widget.grab_focus()
|
widget.grab_focus()
|
||||||
self.zoom_data = None
|
self.zoom_data = None
|
||||||
self.set_property('term_zoomed', False)
|
self.set_property('term_zoomed', False)
|
||||||
|
@ -592,8 +606,17 @@ class Window(Container, Gtk.Window):
|
||||||
|
|
||||||
# If our child is a Notebook, reset to work from its visible child
|
# If our child is a Notebook, reset to work from its visible child
|
||||||
if maker.isinstance(child, 'Notebook'):
|
if maker.isinstance(child, 'Notebook'):
|
||||||
pagenum = child.get_current_page()
|
notebook = child
|
||||||
child = child.get_nth_page(pagenum)
|
|
||||||
|
pagenum = notebook.get_current_page()
|
||||||
|
child = notebook.get_nth_page(pagenum)
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
'tabnum': pagenum,
|
||||||
|
'label': notebook.get_tab_label(child).get_label()
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
metadata = None
|
||||||
|
|
||||||
if maker.isinstance(child, 'Paned'):
|
if maker.isinstance(child, 'Paned'):
|
||||||
parent = child.get_parent()
|
parent = child.get_parent()
|
||||||
|
@ -601,7 +624,7 @@ class Window(Container, Gtk.Window):
|
||||||
# otherwise _sometimes_ we get incorrect values.
|
# otherwise _sometimes_ we get incorrect values.
|
||||||
alloc = child.get_allocation()
|
alloc = child.get_allocation()
|
||||||
parent.remove(child)
|
parent.remove(child)
|
||||||
child.rotate_recursive(parent, alloc.width, alloc.height, clockwise)
|
child.rotate_recursive(parent, alloc.width, alloc.height, clockwise, metadata)
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
while Gtk.events_pending():
|
while Gtk.events_pending():
|
||||||
|
|
Loading…
Reference in New Issue