#!/usr/bin/python

# Epiphany notabs extension - new tabs are promoted to new windows
# Copyright (C) 2007 Jon Dowland <jon@alcopop.org>
#
# 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; version 2.
#
# 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 (in
# the file "LICENCE") 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., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import gtk
import epiphany

def tab_killer_keypress_cb(window, event):
    if event.state & gtk.gdk.CONTROL_MASK:
        keyvalname = gtk.gdk.keyval_name(event.keyval)
        if "t" == keyvalname:
            epiphany.ephy_shell_get_default().new_tab(
                window,
                window.get_active_tab(),
                "http://alcopop.org/", # url, # ?
                epiphany.NEW_TAB_NEW_PAGE | epiphany.NEW_TAB_IN_NEW_WINDOW
                # find these constnats
            )
            return True
    
    return False

def attach_window(window):
    signal = window.connect("key-press-event", tab_killer_keypress_cb)
    window._tab_killer_keypress_sig = signal

def detach_window(window):
    if hasattr(window, "_tab_killer_keypress_sig "):
        window.disconnect(window._tab_killer_keypress_sig)
        delattr(window, "_tab_killer_keypress_sig")
