This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
tabswitch.py
62 lines (46 loc) · 1.78 KB
/
tabswitch.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
56
57
58
59
60
61
# -*- coding: utf-8 -*-
VERSION = "0.1"
from gi.repository import GObject, Gtk, Gedit, Gdk, Gio
from gettext import gettext as _
import cPickle, os
class TabSwitchPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "ExamplePyWindowActivatable"
window = GObject.property(type=Gedit.Window)
def __init__(self):
GObject.Object.__init__(self)
self.id_name = 'TabSwitchPluginID'
def do_activate(self):
l_ids = []
for signal in ('key-press-event',):
method = getattr(self, 'on_window_' + signal.replace('-', '_'))
l_ids.append(self.window.connect(signal, method))
self.window.set_data(self.id_name, l_ids)
def do_deactivate(self):
l_ids = self.window.get_data(self.id_name)
for l_id in l_ids:
self.window.disconnect(l_id)
def on_window_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'):
atab = self.window.get_active_tab()
docs = self.window.get_documents()
tabs = []
for doc in docs:
tabs.append(Gedit.Tab.get_from_document(doc))
tlen = len(tabs)
i = 0
tab = atab
for tab in tabs:
i += 1
if tab == atab:
break
if key == 'ISO_Left_Tab':
i -= 2
if i < 0:
tab = tabs[tlen-1]
elif i >= tlen:
tab = tabs[0]
else:
tab = tabs[i]
self.window.set_active_tab(tab)
return True