Notebook rotate: keep tab position and label

This commit is contained in:
Vulcalien 2022-08-27 22:06:00 +02:00
parent 06ada7c655
commit df0643b1a4
2 changed files with 14 additions and 5 deletions

View File

@ -424,7 +424,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".
@ -458,7 +458,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])

View File

@ -597,8 +597,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()
@ -606,7 +615,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():