mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Fix a bug in "Change Selection"
Fix a bug in the "Change Selection" action, whereby changing your selection and picking files from another directory results in: "Dangerzone does not support adding documents from multiple locations. The newly added documents were ignored." To fix this, change the output directory when we change selection as well.
This commit is contained in:
parent
edfba0c783
commit
ba5adb33c0
2 changed files with 16 additions and 14 deletions
|
@ -488,24 +488,20 @@ class ContentWidget(QtWidgets.QWidget):
|
||||||
).exec_()
|
).exec_()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get previously selected documents
|
# Ensure all files in batch are in the same directory
|
||||||
self.dangerzone.clear_documents()
|
dirnames = {os.path.dirname(doc.input_filename) for doc in docs}
|
||||||
self.documents_list.clear()
|
if len(dirnames) > 1:
|
||||||
|
|
||||||
# Assumed all files in batch are in the same directory
|
|
||||||
first_doc = docs[0]
|
|
||||||
output_dir = os.path.dirname(first_doc.input_filename)
|
|
||||||
if not self.dangerzone.output_dir:
|
|
||||||
self.dangerzone.output_dir = output_dir
|
|
||||||
elif self.dangerzone.output_dir != output_dir:
|
|
||||||
Alert(
|
Alert(
|
||||||
self.dangerzone,
|
self.dangerzone,
|
||||||
message="Dangerzone does not support adding documents from multiple locations.\n\n The newly added documents were ignored.",
|
message="Dangerzone does not support adding documents from multiple locations.\n\n The newly added documents were ignored.",
|
||||||
has_cancel=False,
|
has_cancel=False,
|
||||||
).exec_()
|
).exec_()
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
self.dangerzone.output_dir = output_dir
|
# Clear previously selected documents
|
||||||
|
self.dangerzone.clear_documents()
|
||||||
|
self.documents_list.clear()
|
||||||
|
self.dangerzone.output_dir = list(dirnames)[0]
|
||||||
|
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
self.dangerzone.add_document(doc)
|
self.dangerzone.add_document(doc)
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import os
|
||||||
|
import pathlib
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
@ -335,6 +338,7 @@ def test_change_document_button(
|
||||||
mocker: MockerFixture,
|
mocker: MockerFixture,
|
||||||
sample_pdf: str,
|
sample_pdf: str,
|
||||||
sample_doc: str,
|
sample_doc: str,
|
||||||
|
tmp_path: pathlib.Path,
|
||||||
) -> None:
|
) -> None:
|
||||||
# Setup first doc selection
|
# Setup first doc selection
|
||||||
file_dialog_mock = mocker.MagicMock()
|
file_dialog_mock = mocker.MagicMock()
|
||||||
|
@ -350,7 +354,9 @@ def test_change_document_button(
|
||||||
file_dialog_mock.accept()
|
file_dialog_mock.accept()
|
||||||
|
|
||||||
# Setup doc change
|
# Setup doc change
|
||||||
file_dialog_mock.selectedFiles.return_value = (sample_doc,)
|
shutil.copy(sample_doc, tmp_path)
|
||||||
|
tmp_sample_doc = tmp_path / os.path.basename(sample_doc)
|
||||||
|
file_dialog_mock.selectedFiles.return_value = (tmp_sample_doc,)
|
||||||
|
|
||||||
# When clicking on "select docs" button
|
# When clicking on "select docs" button
|
||||||
with qtbot.waitSignal(content_widget.documents_added):
|
with qtbot.waitSignal(content_widget.documents_added):
|
||||||
|
@ -370,4 +376,4 @@ def test_change_document_button(
|
||||||
for doc in content_widget.dangerzone.get_unconverted_documents()
|
for doc in content_widget.dangerzone.get_unconverted_documents()
|
||||||
]
|
]
|
||||||
assert len(docs) is 1
|
assert len(docs) is 1
|
||||||
assert docs[0] == sample_doc
|
assert docs[0] == str(tmp_sample_doc)
|
||||||
|
|
Loading…
Reference in a new issue