forked from Flynsarmy/GEdit3TabSwitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgedit3tabswitch.py
55 lines (41 loc) · 1.54 KB
/
gedit3tabswitch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from gi.repository import GObject, Gtk, Gdk, Gedit
class GEdit3TabSwitch(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "GEdit3TabSwitch"
window = GObject.property(type=Gedit.Window)
def __init__(self):
GObject.Object.__init__(self)
def do_activate(self):
handlers = []
handler_id = self.window.connect('key-press-event', self.on_key_press_event)
handlers.append(handler_id)
setattr(self.window, self.__gtype_name__ + "Handlers", handlers)
def do_deactivate(self):
handlers = getattr(self.window, self.__gtype_name__ + "Handlers", [])
for handler_id in handlers:
self.window.disconnect(handler_id)
def do_update_state(self):
pass
def on_key_press_event(self, window, event):
key = Gdk.keyval_name(event.keyval)
if event.state & Gdk.ModifierType.CONTROL_MASK and \
key in ('Tab', 'ISO_Left_Tab', 'Page_Down', 'Page_Up'):
atab = window.get_active_tab()
tabs = atab.get_parent().get_children()
tlen = len(tabs)
i = 0
tab = atab
for tab in tabs:
i += 1
if tab == atab:
break
if key in ('ISO_Left_Tab', 'Page_Up'):
i -= 2
if i < 0:
tab = tabs[tlen-1]
elif i >= tlen:
tab = tabs[0]
else:
tab = tabs[i]
window.set_active_tab(tab)
return True