drag and drop of files

- multiple files can be dropped in terminal
  - correctly sh-quote filenames, even those with '
  - also fixes LP#1311481 (\n after dropped filename)

dropped files filename are send to terminal on a
single line, separated by a space.
This commit is contained in:
Schplurtz le Déboulonné 2015-03-27 05:41:28 +01:00
parent 31df80be7f
commit a1aecab22e
1 changed files with 13 additions and 4 deletions

View File

@ -1010,12 +1010,21 @@ class Terminal(gtk.VBox):
dbg('drag data received of type: %s' % selection_data.type)
if gtk.targets_include_text(drag_context.targets) or \
gtk.targets_include_uri(drag_context.targets):
# copy text to destination
txt = selection_data.data.strip(' ')
# copy text with no modification yet to destination
txt = selection_data.data
if txt[0:7] == 'file://':
txt = "'%s'" % urllib.unquote(txt[7:])
# It is a list of crlf terminated file:// URL. let's iterate
# over all elements.
str=''
for fname in txt.split( "\r\n" ):
dbg('drag data fname: %s' % fname)
if fname == '':
break # last elem is empty since each URL is terminated bye crlf
fname = "'%s'" % urllib.unquote(fname[7:].replace( "'", '\'\\\'\''))
str += fname + ' '
txt=str
else:
txt = txt.split('\n')[0]
txt = txt.strip(' ').split('\n')[0]
for term in self.terminator.get_target_terms(self):
term.feed(txt)
return