Implement tab changing keyboard shortcuts
This commit is contained in:
parent
0f5b6e97a7
commit
9c72b6287d
@ -12,7 +12,7 @@ from factory import Factory
|
|||||||
from container import Container
|
from container import Container
|
||||||
from editablelabel import EditableLabel
|
from editablelabel import EditableLabel
|
||||||
from translation import _
|
from translation import _
|
||||||
from util import err, dbg
|
from util import err, dbg, get_top_window
|
||||||
|
|
||||||
class Notebook(Container, gtk.Notebook):
|
class Notebook(Container, gtk.Notebook):
|
||||||
"""Class implementing a gtk.Notebook container"""
|
"""Class implementing a gtk.Notebook container"""
|
||||||
@ -97,6 +97,8 @@ class Notebook(Container, gtk.Notebook):
|
|||||||
|
|
||||||
def newtab(self, widget=None):
|
def newtab(self, widget=None):
|
||||||
"""Add a new tab, optionally supplying a child widget"""
|
"""Add a new tab, optionally supplying a child widget"""
|
||||||
|
top_window = get_top_window(self)
|
||||||
|
|
||||||
if not widget:
|
if not widget:
|
||||||
maker = Factory()
|
maker = Factory()
|
||||||
widget = maker.make('Terminal')
|
widget = maker.make('Terminal')
|
||||||
@ -112,6 +114,7 @@ class Notebook(Container, gtk.Notebook):
|
|||||||
if maker.isinstance(widget, 'Terminal'):
|
if maker.isinstance(widget, 'Terminal'):
|
||||||
for signal in signals:
|
for signal in signals:
|
||||||
self.connect_child(widget, signal, signals[signal])
|
self.connect_child(widget, signal, signals[signal])
|
||||||
|
self.connect_child(widget, 'tab-change', top_window.tab_change)
|
||||||
|
|
||||||
self.set_tab_reorderable(widget, True)
|
self.set_tab_reorderable(widget, True)
|
||||||
label = TabLabel(self.window.get_title(), self)
|
label = TabLabel(self.window.get_title(), self)
|
||||||
|
@ -91,6 +91,7 @@ class Paned(Container):
|
|||||||
self.connect_child(widget, signal, signals[signal])
|
self.connect_child(widget, signal, signals[signal])
|
||||||
|
|
||||||
self.connect_child(widget, 'maximise', top_window.zoom, False)
|
self.connect_child(widget, 'maximise', top_window.zoom, False)
|
||||||
|
self.connect_child(widget, 'tab-change', top_window.tab_change)
|
||||||
|
|
||||||
widget.grab_focus()
|
widget.grab_focus()
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ class Terminal(gtk.VBox):
|
|||||||
(gobject.TYPE_STRING,)),
|
(gobject.TYPE_STRING,)),
|
||||||
'navigate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
'navigate': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
||||||
(gobject.TYPE_STRING,)),
|
(gobject.TYPE_STRING,)),
|
||||||
|
'tab-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
|
||||||
|
(gobject.TYPE_INT,)),
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET_TYPE_VTE = 8
|
TARGET_TYPE_VTE = 8
|
||||||
@ -1197,43 +1199,40 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
|
|||||||
self.zoom()
|
self.zoom()
|
||||||
|
|
||||||
def key_next_tab(self):
|
def key_next_tab(self):
|
||||||
# FIXME: Implement this
|
self.emit('tab-change', -1)
|
||||||
self.terminator.next_tab (self)
|
|
||||||
|
|
||||||
def key_prev_tab(self):
|
def key_prev_tab(self):
|
||||||
# FIXME: Implement this
|
self.emit('tab-change', -2)
|
||||||
self.terminator.previous_tab (self)
|
|
||||||
|
|
||||||
def key_switch_to_tab_1(self):
|
def key_switch_to_tab_1(self):
|
||||||
# FIXME: Implement these
|
self.emit('tab-change', 0)
|
||||||
self.terminator.switch_to_tab (self, 0)
|
|
||||||
|
|
||||||
def key_switch_to_tab_2(self):
|
def key_switch_to_tab_2(self):
|
||||||
self.terminator.switch_to_tab (self, 1)
|
self.emit('tab-change', 1)
|
||||||
|
|
||||||
def key_switch_to_tab_3(self):
|
def key_switch_to_tab_3(self):
|
||||||
self.terminator.switch_to_tab (self, 2)
|
self.emit('tab-change', 2)
|
||||||
|
|
||||||
def key_switch_to_tab_4(self):
|
def key_switch_to_tab_4(self):
|
||||||
self.terminator.switch_to_tab (self, 3)
|
self.emit('tab-change', 3)
|
||||||
|
|
||||||
def key_switch_to_tab_5(self):
|
def key_switch_to_tab_5(self):
|
||||||
self.terminator.switch_to_tab (self, 4)
|
self.emit('tab-change', 4)
|
||||||
|
|
||||||
def key_switch_to_tab_6(self):
|
def key_switch_to_tab_6(self):
|
||||||
self.terminator.switch_to_tab (self, 5)
|
self.emit('tab-change', 5)
|
||||||
|
|
||||||
def key_switch_to_tab_7(self):
|
def key_switch_to_tab_7(self):
|
||||||
self.terminator.switch_to_tab (self, 6)
|
self.emit('tab-change', 6)
|
||||||
|
|
||||||
def key_switch_to_tab_8(self):
|
def key_switch_to_tab_8(self):
|
||||||
self.terminator.switch_to_tab (self, 7)
|
self.emit('tab-change', 7)
|
||||||
|
|
||||||
def key_switch_to_tab_9(self):
|
def key_switch_to_tab_9(self):
|
||||||
self.terminator.switch_to_tab (self, 8)
|
self.emit('tab-change', 8)
|
||||||
|
|
||||||
def key_switch_to_tab_10(self):
|
def key_switch_to_tab_10(self):
|
||||||
self.terminator.switch_to_tab (self, 9)
|
self.emit('tab-change', 9)
|
||||||
|
|
||||||
def key_reset(self):
|
def key_reset(self):
|
||||||
self.vte.reset (True, False)
|
self.vte.reset (True, False)
|
||||||
@ -1254,6 +1253,7 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
|
|||||||
self.group_tab(self)
|
self.group_tab(self)
|
||||||
|
|
||||||
def key_ungroup_tab(self):
|
def key_ungroup_tab(self):
|
||||||
|
# FIXME: IMplement this
|
||||||
self.ungroup_tab(self)
|
self.ungroup_tab(self)
|
||||||
|
|
||||||
def key_new_window(self):
|
def key_new_window(self):
|
||||||
|
@ -248,6 +248,7 @@ class Window(Container, gtk.Window):
|
|||||||
for signal in signals:
|
for signal in signals:
|
||||||
self.connect_child(widget, signal, signals[signal])
|
self.connect_child(widget, signal, signals[signal])
|
||||||
|
|
||||||
|
self.connect_child(widget, 'tab-change', self.tab_change)
|
||||||
widget.grab_focus()
|
widget.grab_focus()
|
||||||
|
|
||||||
def remove(self, widget):
|
def remove(self, widget):
|
||||||
@ -372,6 +373,38 @@ class Window(Container, gtk.Window):
|
|||||||
self.set_geometry_hints(self, -1, -1, -1, -1, extra_width,
|
self.set_geometry_hints(self, -1, -1, -1, -1, extra_width,
|
||||||
extra_height, font_width, font_height, -1.0, -1.0)
|
extra_height, font_width, font_height, -1.0, -1.0)
|
||||||
|
|
||||||
|
def tab_change(self, widget, num=None):
|
||||||
|
"""Change to a specific tab"""
|
||||||
|
if num is None:
|
||||||
|
err('must specify a tab to change to')
|
||||||
|
|
||||||
|
maker = Factory()
|
||||||
|
child = self.get_child()
|
||||||
|
|
||||||
|
if not maker.isinstance(child, 'Notebook'):
|
||||||
|
dbg('child is not a notebook, nothing to change to')
|
||||||
|
return
|
||||||
|
|
||||||
|
if num == -1:
|
||||||
|
# Go to the next tab
|
||||||
|
cur = child.get_current_page()
|
||||||
|
pages = child.get_n_pages()
|
||||||
|
if cur == pages - 1:
|
||||||
|
num = 0
|
||||||
|
elif num == -2:
|
||||||
|
# Go to the previous tab
|
||||||
|
cur = child.get_current_page()
|
||||||
|
if cur > 0:
|
||||||
|
num = cur - 1
|
||||||
|
else:
|
||||||
|
num = child.get_n_pages() - 1
|
||||||
|
|
||||||
|
child.set_current_page(num)
|
||||||
|
# Work around strange bug in gtk-2.12.11 and pygtk-2.12.1
|
||||||
|
# Without it, the selection changes, but the displayed page doesn't
|
||||||
|
# change
|
||||||
|
child.set_current_page(child.get_current_page())
|
||||||
|
|
||||||
class WindowTitle(object):
|
class WindowTitle(object):
|
||||||
"""Class to handle the setting of the window title"""
|
"""Class to handle the setting of the window title"""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user