# Copyright (C) 2007 - Nando Vieira # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import gedit import gtk import gtk.gdk import os import os.path from gettext import gettext as _ def debug(text): if os.environ.has_key('TN_DEBUG') and os.environ['TN_DEBUG'] == '1': print "[tab_navigation] %s" % text class TabNavigationPlugin(gedit.Plugin): def __init__(self): gedit.Plugin.__init__(self) self.instances = {} def activate(self, window): debug('activating plugin') self.instances[window] = TabNavigationWindowHelper(self, window) def deactivate(self, window): debug('deactivating plugin') self.instances[window].deactivate() del self.instances[window] def update_ui(self, window): debug('updating ui') self.instances[window].update_ui() class TabNavigationWindowHelper: handlers = {} def __init__(self, plugin, window): self.window = window window.connect('key-press-event', self.on_key_press) def deactivate(self): debug('deactivate function called') self.window.disconnect_by_func(self.on_key_press) self.window = None self.plugin = None def update(self, text=None): pass def update_ui(self): pass def on_key_press(self, view, event): ctrl = False shift = False alt = False tab = False pgdown = False pgup = False left = False right = False if event.state & gtk.gdk.CONTROL_MASK: ctrl = True if event.state & gtk.gdk.SHIFT_MASK: shift = True if event.state & gtk.gdk.MOD1_MASK: alt = True if event.keyval == gtk.keysyms.Tab: tab = True if event.keyval == gtk.keysyms.Page_Down: pgdown = True if event.keyval == gtk.keysyms.Page_Up: pgup = True if event.keyval == gtk.keysyms.Left: left = True if event.keyval == gtk.keysyms.Right: right = True if(ctrl and shift and tab) or (ctrl and pgup) or (alt and left): self.go_to('previous') return True elif (ctrl and tab) or (ctrl and pgdown) or (alt and right): self.go_to('next') return True return False def go_to(self, way): debug('going to %s tab' % way) notebook = self.window.get_active_tab().get_parent() total_tabs = notebook.get_n_pages() current_tab = notebook.get_current_page() if total_tabs <= 1: debug('found just %d tab' % total_tabs) return if way == 'next': if current_tab == total_tabs-1: tab = 0 else: tab = current_tab + 1 else: if current_tab == 0: tab = total_tabs - 1 else: tab = current_tab - 1 debug('going to tab #%d' % tab) notebook.set_current_page(tab)