From 99a7f5a89b3f058834c4a426ebd10328bbeba38f Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Wed, 11 Jan 2017 19:29:36 +0530 Subject: [PATCH 1/2] PICARD-884: Add the parent directory if file selected from filebrowser --- picard/ui/filebrowser.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/picard/ui/filebrowser.py b/picard/ui/filebrowser.py index 5ba0d06f4..ebbba06a0 100644 --- a/picard/ui/filebrowser.py +++ b/picard/ui/filebrowser.py @@ -134,10 +134,16 @@ class FileBrowser(QtGui.QTreeView): if not indexes: return path = self.model.filePath(indexes[0]) - config.setting["move_files_to"] = os.path.normpath(unicode(path)) + destination = os.path.normpath(unicode(path)) + if not os.path.isdir(destination): + destination = os.path.dirname(destination) + config.setting["move_files_to"] = destination def set_as_starting_directory(self): indexes = self.selectedIndexes() if indexes: path = self.model.filePath(indexes[0]) - config.setting["starting_directory_path"] = os.path.normpath(unicode(path)) + destination = os.path.normpath(unicode(path)) + if not os.path.isdir(destination): + destination = os.path.dirname(destination) + config.setting["starting_directory_path"] = destination From 2ed88a80f3755122b88a22abd8c83c6caf56c3ee Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Wed, 11 Jan 2017 22:39:48 +0530 Subject: [PATCH 2/2] Refactor redundant code into function --- picard/ui/filebrowser.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/picard/ui/filebrowser.py b/picard/ui/filebrowser.py index ebbba06a0..28b6085e4 100644 --- a/picard/ui/filebrowser.py +++ b/picard/ui/filebrowser.py @@ -129,21 +129,21 @@ class FileBrowser(QtGui.QTreeView): self.expand(index) self.scrollTo(index, scrolltype) + def _get_destination_from_path(self, path): + destination = os.path.normpath(unicode(path)) + if not os.path.isdir(destination): + destination = os.path.dirname(destination) + return destination + def move_files_here(self): indexes = self.selectedIndexes() if not indexes: return path = self.model.filePath(indexes[0]) - destination = os.path.normpath(unicode(path)) - if not os.path.isdir(destination): - destination = os.path.dirname(destination) - config.setting["move_files_to"] = destination + config.setting["move_files_to"] = self._get_destination_from_path(path) def set_as_starting_directory(self): indexes = self.selectedIndexes() if indexes: path = self.model.filePath(indexes[0]) - destination = os.path.normpath(unicode(path)) - if not os.path.isdir(destination): - destination = os.path.dirname(destination) - config.setting["starting_directory_path"] = destination + config.setting["starting_directory_path"] = self._get_destination_from_path(path)