allow drag&drop of multiple files
This commit is contained in:
@@ -144,7 +144,8 @@ class MainWindow(QMainWindow):
|
|||||||
e.ignore()
|
e.ignore()
|
||||||
|
|
||||||
def dropEvent(self, e):
|
def dropEvent(self, e):
|
||||||
file = urlutils.url_to_path(e.mimeData().text())
|
files = urlutils.urls_to_path(e.mimeData().text())
|
||||||
|
for file in files:
|
||||||
PluginRegistry.execute_single("open_file", file)
|
PluginRegistry.execute_single("open_file", file)
|
||||||
|
|
||||||
def _restore_window(self):
|
def _restore_window(self):
|
||||||
|
|||||||
15
urlutils.py
15
urlutils.py
@@ -3,6 +3,14 @@ from urllib.parse import urlparse
|
|||||||
import sys
|
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:
|
def url_to_path(url: str) -> str:
|
||||||
p = urlparse(url)
|
p = urlparse(url)
|
||||||
if sys.platform == 'win32' or sys.platform == 'cygwin':
|
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))
|
return os.path.abspath(os.path.join(p.netloc, p.path))
|
||||||
|
|
||||||
|
|
||||||
def url_is_file(url: str) -> bool:
|
def url_is_file(string: str) -> bool:
|
||||||
|
url_candidates = string.splitlines(keepends=False)
|
||||||
|
for url in url_candidates:
|
||||||
if url.startswith("file://"):
|
if url.startswith("file://"):
|
||||||
path = url_to_path(url)
|
path = url_to_path(url)
|
||||||
return os.path.isfile(path)
|
if not os.path.isfile(path):
|
||||||
return False
|
return False
|
||||||
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user