Merge lp:~schplurtz/terminator/cmf into lp:terminator/trunk

Proposed by Schplurtz le déboulonné
Status: Merged
Merged at revision: 1575
Proposed branch: lp:~schplurtz/terminator/cmf
Merge into: lp:terminator/trunk
Diff against target: 29 lines (+13/-4)
1 file modified
terminatorlib/terminal.py (+13/-4)
To merge this branch: bzr merge lp:~schplurtz/terminator/cmf
Reviewer Review Type Date Requested Status
Terminator Pending
Review via email: mp+254356@code.launchpad.net

Description of the change

Hi

I found some problems with file drag and drop in terminator. This merge request fixes them.

Dropping multiple files from filemanager into terminator does not work at all :
when multiple files are dragged from a file manager and dropped in terminator, their filenames
are sent to the terminal as a single sh string enclosed in ' '. More exactly, their file://
URL are sent to the terminal, except for the first filename where file:// is stripped.

Current quoting that just surrounds filenames with ' can't handle filename that contain '.
The solution is: surround filename with '. and then, if there are ' in filename, for each
of them, close the string with a ', add \', and reopen the string with '. example :
that's true! -> 'that'\''s true!' which is a valid sh string

It also fixes LP#1311481 .

Regards,
Schplurtz

To post a comment you must log in.
Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

Thanks for the contribution.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'terminatorlib/terminal.py'
2--- terminatorlib/terminal.py 2015-03-02 21:02:57 +0000
3+++ terminatorlib/terminal.py 2015-03-27 05:29:44 +0000
4@@ -1010,12 +1010,21 @@
5 dbg('drag data received of type: %s' % selection_data.type)
6 if gtk.targets_include_text(drag_context.targets) or \
7 gtk.targets_include_uri(drag_context.targets):
8- # copy text to destination
9- txt = selection_data.data.strip(' ')
10+ # copy text with no modification yet to destination
11+ txt = selection_data.data
12 if txt[0:7] == 'file://':
13- txt = "'%s'" % urllib.unquote(txt[7:])
14+ # It is a list of crlf terminated file:// URL. let's iterate
15+ # over all elements.
16+ str=''
17+ for fname in txt.split( "\r\n" ):
18+ dbg('drag data fname: %s' % fname)
19+ if fname == '':
20+ break # last elem is empty since each URL is terminated bye crlf
21+ fname = "'%s'" % urllib.unquote(fname[7:].replace( "'", '\'\\\'\''))
22+ str += fname + ' '
23+ txt=str
24 else:
25- txt = txt.split('\n')[0]
26+ txt = txt.strip(' ').split('\n')[0]
27 for term in self.terminator.get_target_terms(self):
28 term.feed(txt)
29 return