From a413134f6896f0a5e90eeb99c6d3b175e9b07b6d Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 14 Jan 2022 08:36:18 +0100 Subject: [PATCH] allow drag&drop of multiple files --- raven/mainwindow.py | 5 +++-- urlutils.py | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/raven/mainwindow.py b/raven/mainwindow.py index 6ba2153..4977af4 100644 --- a/raven/mainwindow.py +++ b/raven/mainwindow.py @@ -144,8 +144,9 @@ class MainWindow(QMainWindow): e.ignore() def dropEvent(self, e): - file = urlutils.url_to_path(e.mimeData().text()) - PluginRegistry.execute_single("open_file", file) + files = urlutils.urls_to_path(e.mimeData().text()) + for file in files: + PluginRegistry.execute_single("open_file", file) def _restore_window(self): qsettings = CuteSettings() diff --git a/urlutils.py b/urlutils.py index 223a735..cf39604 100644 --- a/urlutils.py +++ b/urlutils.py @@ -3,6 +3,14 @@ from urllib.parse import urlparse import sys +def urls_to_path(urls: str) -> [str]: + result = [] + url_list = urls.splitlines(keepends=False) + for url in url_list: + path = url_to_path(url) + result.append(path) + return result + def url_to_path(url: str) -> str: p = urlparse(url) if sys.platform == 'win32' or sys.platform == 'cygwin': @@ -10,8 +18,11 @@ def url_to_path(url: str) -> str: return os.path.abspath(os.path.join(p.netloc, p.path)) -def url_is_file(url: str) -> bool: - if url.startswith("file://"): - path = url_to_path(url) - return os.path.isfile(path) - return False +def url_is_file(string: str) -> bool: + url_candidates = string.splitlines(keepends=False) + for url in url_candidates: + if url.startswith("file://"): + path = url_to_path(url) + if not os.path.isfile(path): + return False + return True