Fix drag and drop of a link from Firefox / Chrome

This commit is contained in:
Stephen Boddy 2015-12-02 19:40:11 +01:00
parent 0c1e16236b
commit 4ead7ba3bb
1 changed files with 10 additions and 3 deletions

View File

@ -76,6 +76,7 @@ class Terminal(gtk.VBox):
} }
TARGET_TYPE_VTE = 8 TARGET_TYPE_VTE = 8
TARGET_TYPE_MOZ = 9
MOUSEBUTTON_LEFT = 1 MOUSEBUTTON_LEFT = 1
MOUSEBUTTON_MIDDLE = 2 MOUSEBUTTON_MIDDLE = 2
@ -265,7 +266,7 @@ class Terminal(gtk.VBox):
userchars = "-A-Za-z0-9" userchars = "-A-Za-z0-9"
passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'" passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
hostchars = "-A-Za-z0-9" hostchars = "-A-Za-z0-9"
pathchars = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%'\"" pathchars = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%'"
schemes = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)" schemes = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
user = "[" + userchars + "]+(:[" + passchars + "]+)?" user = "[" + userchars + "]+(:[" + passchars + "]+)?"
urlpath = "/[" + pathchars + "]*[^]'.}>) \t\r\n,\\\"]" urlpath = "/[" + pathchars + "]*[^]'.}>) \t\r\n,\\\"]"
@ -355,7 +356,7 @@ class Terminal(gtk.VBox):
srcvtetargets = [("vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE)] srcvtetargets = [("vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE)]
dsttargets = [("vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE), dsttargets = [("vte", gtk.TARGET_SAME_APP, self.TARGET_TYPE_VTE),
('text/x-moz-url', 0, 0), ('text/x-moz-url', 0, self.TARGET_TYPE_MOZ),
('_NETSCAPE_URL', 0, 0)] ('_NETSCAPE_URL', 0, 0)]
dsttargets = gtk.target_list_add_text_targets(dsttargets) dsttargets = gtk.target_list_add_text_targets(dsttargets)
dsttargets = gtk.target_list_add_uri_targets(dsttargets) dsttargets = gtk.target_list_add_uri_targets(dsttargets)
@ -1081,7 +1082,7 @@ class Terminal(gtk.VBox):
return(False) return(False)
def on_drag_data_received(self, widget, drag_context, x, y, selection_data, def on_drag_data_received(self, widget, drag_context, x, y, selection_data,
_info, _time, data): info, _time, data):
"""Something has been dragged into the terminal. Handle it as either a """Something has been dragged into the terminal. Handle it as either a
URL or another terminal.""" URL or another terminal."""
dbg('drag data received of type: %s' % selection_data.type) dbg('drag data received of type: %s' % selection_data.type)
@ -1089,6 +1090,12 @@ class Terminal(gtk.VBox):
gtk.targets_include_uri(drag_context.targets): gtk.targets_include_uri(drag_context.targets):
# copy text with no modification yet to destination # copy text with no modification yet to destination
txt = selection_data.data txt = selection_data.data
# https://bugs.launchpad.net/terminator/+bug/1518705
if info == self.TARGET_TYPE_MOZ:
txt = txt.decode('utf-16').encode('utf-8')
txt = txt.split('\n')[0]
txt_lines = txt.split( "\r\n" ) txt_lines = txt.split( "\r\n" )
if txt_lines[-1] == '': if txt_lines[-1] == '':
for line in txt_lines[:-1]: for line in txt_lines[:-1]: