Merge pull request #275 from mattrose/fix-kde-dnd

fix drag and drop issues on KDE
This commit is contained in:
Matt Rose 2020-11-06 22:06:57 -05:00 committed by GitHub
commit a5339b4cba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -1164,16 +1164,19 @@ class Terminal(Gtk.VBox):
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."""
### FIXME this code is a mess that I don't quite understand how it works.
dbg('drag data received of type: %s' % (selection_data.get_data_type())) dbg('drag data received of type: %s' % (selection_data.get_data_type()))
# print(selection_data.get_urls())
if Gtk.targets_include_text(drag_context.list_targets()) or \ if Gtk.targets_include_text(drag_context.list_targets()) or \
Gtk.targets_include_uri(drag_context.list_targets()): Gtk.targets_include_uri(drag_context.list_targets()):
# copy text with no modification yet to destination # copy text with no modification yet to destination
txt = selection_data.get_data() txt = selection_data.get_data()
# https://bugs.launchpad.net/terminator/+bug/1518705 # https://bugs.launchpad.net/terminator/+bug/1518705
if info == self.TARGET_TYPE_MOZ: if info == self.TARGET_TYPE_MOZ:
txt = txt.decode('utf-16') txt = txt.decode('utf-16')
txt = txt.split('\n')[0] ### KDE ends it's text/x-moz-url text with CRLF, :shrug:
if not txt.endswith('\r\n'):
txt = txt.split('\n')[0]
else: else:
txt = txt.decode() txt = txt.decode()
@ -1188,11 +1191,12 @@ class Terminal(Gtk.VBox):
# iterate over all elements except the last one. # iterate over all elements except the last one.
str='' str=''
for fname in txt_lines[:-1]: for fname in txt_lines[:-1]:
dbg('drag data fname: %s' % fname)
fname = "'%s'" % urlunquote(fname[7:].replace("'", fname = "'%s'" % urlunquote(fname[7:].replace("'",
'\'\\\'\'')) '\'\\\'\''))
str += fname + ' ' str += fname + ' '
txt=str txt=str
### Never send a CRLF to the terminal from here
txt = txt.rstrip('\r\n')
for term in self.terminator.get_target_terms(self): for term in self.terminator.get_target_terms(self):
term.feed(txt) term.feed(txt)
return return