Skip to content

Commit

Permalink
Selection of multiple directories working now
Browse files Browse the repository at this point in the history
  • Loading branch information
SAMAD101 committed Dec 16, 2023
1 parent 055e0a9 commit a8bd917
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
29 changes: 5 additions & 24 deletions src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ def run(self):
self.signal.emit(self.path, str(self.size), str(self.files_count))


class MultiSelectionFileDialog(QFileDialog):
def __init__(self, parent, title, initial_dir=os.path.expanduser('~')):
super().__init__(parent, title, initial_dir)

def selectedFiles(self, tree_view=None):
selected_files = super().selectedFiles()

if self.fileMode() == QFileDialog.FileMode.Directory:
if tree_view:
selected_indexes = tree_view.selectionModel().selectedIndexes()
selected_dirs = [tree_view.model().filePath(index) for index in selected_indexes]
selected_files += selected_dirs

return selected_files


def normalize_path(path):
"""normalize paths for MacOS (but do nothing on other platforms)"""
# HFS+ converts paths to a canonical form, so users shouldn't be required to enter an exact match.
Expand Down Expand Up @@ -189,17 +173,14 @@ def get_dict_from_list(dataDict, mapList):


def choose_file_dialog(parent, title, want_folder=True):
dialog = MultiSelectionFileDialog(parent, title, os.path.expanduser('~'))
dialog = QFileDialog(parent, title, os.path.expanduser('~'))
dialog.setFileMode(QFileDialog.FileMode.Directory if want_folder else QFileDialog.FileMode.ExistingFiles)
dialog.setParent(parent, QtCore.Qt.WindowType.Sheet)
if want_folder:
dialog.setOption(QFileDialog.Option.ShowDirsOnly)
dialog.setOption(QFileDialog.Option.DontUseNativeDialog)
dir_dialog = dialog.findChild(QTreeView)
dir_dialog.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
return dialog, dir_dialog

return dialog
list_view = dialog.findChild(QTreeView)
list_view.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
dialog.exec()
return dialog.selectedFiles()


def is_ssh_private_key_file(filepath: str) -> bool:
Expand Down
11 changes: 4 additions & 7 deletions src/vorta/views/source_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ def sources_update(self):
self.update_path_info(row) # Update data for each entry

def source_add(self, want_folder):
def receive():
dirs = dialog.selectedFiles(dir_dialog) if want_folder else dialog.selectedFiles()
def receive(dirs):
for dir in dirs:
if not os.access(dir, os.R_OK):
msg = QMessageBox()
Expand All @@ -301,11 +300,9 @@ def receive():
new_source.save()

msg = self.tr("Choose directory to back up") if want_folder else self.tr("Choose file(s) to back up")
if want_folder:
dialog, dir_dialog = choose_file_dialog(self, msg, want_folder=want_folder)
else:
dialog = choose_file_dialog(self, msg, want_folder=want_folder)
dialog.open(receive)

paths = choose_file_dialog(self, msg, want_folder=want_folder)
receive(paths)

def source_copy(self, index=None):
"""
Expand Down

0 comments on commit a8bd917

Please sign in to comment.