(trunk-1575) Fix drag and drop of files (Schplurtz le Déboulonné, LP#1311481) and some tweaks (Steve Boddy)
Schplurtz le Déboulonné - multiple files can be dropped in terminal - correctly sh-quote filenames, even those with ' - also fixes LP#1311481 (\n after dropped filename) Steve Boddy - changes to the logic, where all lines are now checked for the file:// prefix - text blocks now insert in full, not just first line - Oddly gtk3 changes dropped text blocks from '\n' to '\r\n' (gtk2->gtk3)
This commit is contained in:
parent
d56da596b3
commit
43c134b5c5
|
@ -1024,12 +1024,24 @@ class Terminal(Gtk.VBox):
|
||||||
dbg('drag data received of type: %s' % (selection_data.get_data_type()))
|
dbg('drag data received of type: %s' % (selection_data.get_data_type()))
|
||||||
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 to destination
|
# copy text with no modification yet to destination
|
||||||
txt = selection_data.get_data().strip(' ')
|
txt = selection_data.get_data()
|
||||||
if txt[0:7] == 'file://':
|
txt_lines = txt.split( "\r\n" )
|
||||||
txt = "'%s'" % urllib.unquote(txt[7:])
|
if txt_lines[-1] == '':
|
||||||
else:
|
for line in txt_lines[:-1]:
|
||||||
txt = txt.split('\n')[0]
|
if line[0:7] != 'file://':
|
||||||
|
txt = txt.replace('\r\n','\n')
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# It is a list of crlf terminated file:// URL. let's
|
||||||
|
# iterate over all elements except the last one.
|
||||||
|
str=''
|
||||||
|
for fname in txt_lines[:-1]:
|
||||||
|
dbg('drag data fname: %s' % fname)
|
||||||
|
fname = "'%s'" % urllib.unquote(fname[7:].replace("'",
|
||||||
|
'\'\\\'\''))
|
||||||
|
str += fname + ' '
|
||||||
|
txt=str
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue