Skip to content

Commit bb2f58a

Browse files
Romain GraslandBoboTiG
authored andcommitted
NXDRIVE-2289: [Direct Transfer] Remember the last selected local folder
When clicking on add files or add folders, Drive will now save the last place accessed to open again there. Also changelog has been updated.
1 parent 9d46442 commit bb2f58a

4 files changed

Lines changed: 56 additions & 11 deletions

File tree

docs/changes/4.4.5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Release date: `2020-xx-xx`
4343
- [NXDRIVE-2267](https://jira.nuxeo.com/browse/NXDRIVE-2267): Do not open the file selection box on click in the systray
4444
- [NXDRIVE-2268](https://jira.nuxeo.com/browse/NXDRIVE-2268): Best efforts to center a window on the screen
4545
- [NXDRIVE-2276](https://jira.nuxeo.com/browse/NXDRIVE-2276): Introduce the notion of sessions
46+
- [NXDRIVE-2289](https://jira.nuxeo.com/browse/NXDRIVE-2289): Remember the last selected local folder
4647
- [NXDRIVE-2300](https://jira.nuxeo.com/browse/NXDRIVE-2300): Update the sync counter in real-time
4748
- [NXDRIVE-2304](https://jira.nuxeo.com/browse/NXDRIVE-2304): Do not allow to upload in documents with the `HiddenInCreation` facet
4849

@@ -120,6 +121,8 @@ Release date: `2020-xx-xx`
120121
- Added `Engine.have_folder_upload`
121122
- Added `Engine.directTransferSessionFinished`
122123
- Added `Engine.handle_session_status()`
124+
- Added `last_selected_file_path` keyword argument to `Engine.direct_transfer_async()`
125+
- Added `last_selected_file_path` keyword argument to `Engine.direct_transfer()`
123126
- Removed `Engine.remove_staled_transfers()`
124127
- Removed `Engine.directTranferStatus`
125128
- Added `limit` keyword argument to `EngineDAO.get_dt_uploads_raw()`
@@ -139,6 +142,7 @@ Release date: `2020-xx-xx`
139142
- Added `recursive` keyword argument to `EngineDAO.remove_state()`
140143
- Removed `EngineDAO.update_pair_state()`
141144
- Added `EngineDAO.update_remote_parent_path_dt()`
145+
- Added `FoldersDialog.last_local_selected_location`
142146
- Added `Tracker.send_hello()`
143147
- Added `anon` keyword argument to `Tracker.send_event()`
144148
- Removed `Translator.format_date()`

nxdrive/engine/engine.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,26 +403,38 @@ def delete_doc(self, path: Path, mode: DelAction = None) -> None:
403403
f"{doc_pair.remote_parent_path}/{doc_pair.remote_ref}"
404404
)
405405

406-
def _save_remote_parent_infos(
407-
self, remote_path: str, remote_ref: str, duplicate_behavior: str
406+
def _save_last_dt_session_infos(
407+
self,
408+
remote_path: str,
409+
remote_ref: str,
410+
duplicate_behavior: str,
411+
last_local_selected_location: Optional[Path],
408412
) -> None:
409-
"""Store remote infos into the database for later runs."""
413+
"""Store last dt session infos into the database for later runs."""
410414
self.dao.update_config("dt_last_remote_location", remote_path)
411415
self.dao.update_config("dt_last_remote_location_ref", remote_ref)
412416
self.dao.update_config("dt_last_duplicates_behavior", duplicate_behavior)
417+
if last_local_selected_location:
418+
self.dao.update_config(
419+
"dt_last_local_selected_location", last_local_selected_location
420+
)
413421

414422
def _direct_transfer(
415423
self,
416424
local_paths: Dict[Path, int],
417425
remote_parent_path: str,
418426
remote_parent_ref: str,
419-
duplicate_behavior: str,
427+
duplicate_behavior: str = "create",
428+
last_local_selected_location: Optional[Path] = None,
420429
) -> None:
421430
"""Plan the Direct Transfer."""
422431

423-
# Save the remote location for next times
424-
self._save_remote_parent_infos(
425-
remote_parent_path, remote_parent_ref, duplicate_behavior
432+
# Save last dt session infos for next times
433+
self._save_last_dt_session_infos(
434+
remote_parent_path,
435+
remote_parent_ref,
436+
duplicate_behavior,
437+
last_local_selected_location,
426438
)
427439

428440
all_paths = local_paths.keys()
@@ -474,13 +486,15 @@ def direct_transfer(
474486
remote_parent_path: str,
475487
remote_parent_ref: str,
476488
duplicate_behavior: str = "create",
489+
last_local_selected_location: Optional[Path] = None,
477490
) -> None:
478491
"""Plan the Direct Transfer."""
479492
self._direct_transfer(
480493
local_paths,
481494
remote_parent_path,
482495
remote_parent_ref,
483496
duplicate_behavior=duplicate_behavior,
497+
last_local_selected_location=last_local_selected_location,
484498
)
485499

486500
def direct_transfer_async(
@@ -489,6 +503,7 @@ def direct_transfer_async(
489503
remote_parent_path: str,
490504
remote_parent_ref: str,
491505
duplicate_behavior: str = "create",
506+
last_local_selected_location: Optional[Path] = None,
492507
) -> None:
493508
"""Plan the Direct Transfer. Async to not freeze the GUI."""
494509
from .workers import Runner
@@ -499,6 +514,7 @@ def direct_transfer_async(
499514
remote_parent_path,
500515
remote_parent_ref,
501516
duplicate_behavior=duplicate_behavior,
517+
last_local_selected_location=last_local_selected_location,
502518
)
503519
self._threadpool.start(runner)
504520

nxdrive/gui/folders_dialog.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def __init__(
220220
self.remote_folder_ref = self.engine.dao.get_config(
221221
"dt_last_remote_location_ref", ""
222222
)
223+
self.last_local_selected_location = self.engine.dao.get_config(
224+
"dt_last_local_selected_location", None
225+
)
223226
self.duplicates_behavior = self.engine.dao.get_config(
224227
"dt_last_duplicates_behavior", "create"
225228
)
@@ -334,6 +337,7 @@ def accept(self) -> None:
334337
self.remote_folder.text(),
335338
self.remote_folder_ref,
336339
duplicate_behavior=self.cb.currentData(),
340+
last_local_selected_location=self.last_local_selected_location,
337341
)
338342

339343
def button_ok_state(self) -> None:
@@ -390,6 +394,8 @@ def _process_additionnal_local_paths(self, paths: List[str]) -> None:
390394
log.warning(f"Error calling stat() on {path!r}", exc_info=True)
391395
continue
392396

397+
self.last_local_selected_location = path.parent
398+
393399
# If .path is None, then pick the first local path to display something useful
394400
if not self.path:
395401
self.path = path
@@ -402,10 +408,18 @@ def _process_additionnal_local_paths(self, paths: List[str]) -> None:
402408

403409
def _select_more_files(self) -> None:
404410
"""Choose additional local files to upload."""
405-
paths, _ = QFileDialog.getOpenFileNames(self, Translator.get("ADD_FILES"))
411+
paths, _ = QFileDialog.getOpenFileNames(
412+
self,
413+
Translator.get("ADD_FILES"),
414+
str(self.last_local_selected_location),
415+
)
406416
self._process_additionnal_local_paths(paths)
407417

408418
def _select_more_folder(self) -> None:
409419
"""Choose an additional local folder to upload."""
410-
path = QFileDialog.getExistingDirectory(self, Translator.get("ADD_FOLDER"))
420+
path = QFileDialog.getExistingDirectory(
421+
self,
422+
Translator.get("ADD_FOLDER"),
423+
str(self.last_local_selected_location),
424+
)
411425
self._process_additionnal_local_paths([path])

tests/old_functional/test_direct_transfer.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"""
44
import logging
55
import re
6+
from pathlib import Path
67
from shutil import copyfile
78
from time import sleep
9+
from typing import Optional
810
from unittest.mock import patch
911
from uuid import uuid4
1012

@@ -91,12 +93,17 @@ def sync_and_check(
9193
else:
9294
assert not self.has_blob()
9395

94-
def direct_transfer(self, duplicate_behavior: str = "create") -> None:
96+
def direct_transfer(
97+
self,
98+
duplicate_behavior: str = "create",
99+
last_local_selected_location: Optional[Path] = None,
100+
) -> None:
95101
self.engine_1.direct_transfer(
96102
{self.file: self.file_size},
97103
self.ws.path,
98104
self.ws.uid,
99105
duplicate_behavior=duplicate_behavior,
106+
last_local_selected_location=last_local_selected_location,
100107
)
101108

102109
def test_upload(self):
@@ -149,11 +156,15 @@ def callback(*_):
149156

150157
with patch.object(engine.remote, "upload_callback", new=callback):
151158
with ensure_no_exception():
152-
self.direct_transfer()
159+
self.direct_transfer(last_local_selected_location=self.file.parent)
153160
self.wait_sync()
154161

155162
assert dao.get_dt_uploads_with_status(TransferStatus.PAUSED)
156163

164+
last_location = dao.get_config("dt_last_local_selected_location", None)
165+
assert last_location
166+
assert Path(last_location) == self.file.parent
167+
157168
# Cancel the upload
158169
upload = list(dao.get_dt_uploads())[0]
159170
engine.cancel_upload(upload.uid)

0 commit comments

Comments
 (0)