From 306bf03f671f38ba3fa409e616aee8618248376a Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Mon, 13 Jul 2015 00:09:39 +0200 Subject: [PATCH] =?UTF-8?q?Drag=20and=20drop=20of=20files=20fine-tuning=20?= =?UTF-8?q?based=20on=20Schplurtz=20le=20d=C3=A9boulonn=C3=A9's=20fix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Slight changes to the logic, where all lines are now checked for the file:// prefix. * Fix dropping of a block of text which was previously broken (only inserts one line) --- terminatorlib/terminal.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index a2e7acbd..7286370a 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1012,19 +1012,21 @@ class Terminal(gtk.VBox): gtk.targets_include_uri(drag_context.targets): # copy text with no modification yet to destination txt = selection_data.data - if txt[0:7] == 'file://': - # 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.strip(' ').split('\n')[0] + txt_lines = txt.split( "\r\n" ) + if txt_lines[-1] == '': + for line in txt_lines[:-1]: + if line[0:7] != 'file://': + 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): term.feed(txt) return