Commits

Yuya Nishihara committed 74f14ab

rename: unify if-switch by src/dest mode

Follows up c33026a291d7.

Comments (0)

Files changed (1)

tortoisehg/hgqt/rename.py

         self.get_file_or_folder('dest')
 
     def get_file_or_folder(self, mode):
+        FD = QFileDialog
         if mode == 'src':
             curr = self.get_src()
             if os.path.isfile(curr):
                 caption = _('Select Source File')
+                path = FD.getOpenFileName(parent=self, caption=caption,
+                                          options=FD.ReadOnly)
             else:
                 caption = _('Select Source Folder')
+                path = FD.getExistingDirectory(parent=self, caption=caption,
+                                               options=FD.ShowDirsOnly | FD.ReadOnly)
+            if not path:
+                return
+            relpath = self.to_relative_path(path)
+            if not relpath:
+                return
+            self.src_txt.setText(relpath)
         else:
             curr = self.get_dest()
             if os.path.isfile(curr):
                 caption = _('Select Destination File')
+                path = FD.getSaveFileName(parent=self, caption=caption,
+                                          options=FD.ReadOnly)
             else:
                 caption = _('Select Destination Folder')
-        FD = QFileDialog
-        if os.path.isfile(curr):
-            if mode == 'src':
-                path = FD.getOpenFileName(parent=self, caption=caption,
-                                          options=FD.ReadOnly)
-            else:
-                path = FD.getSaveFileName(parent=self, caption=caption,
-                                          options=FD.ReadOnly)
-        else:
-            path = FD.getExistingDirectory(parent=self, caption=caption,
-                    options=FD.ShowDirsOnly | FD.ReadOnly)
-        if path:
+                path = FD.getExistingDirectory(parent=self, caption=caption,
+                                               options=FD.ShowDirsOnly | FD.ReadOnly)
+            if not path:
+                return
             relpath = self.to_relative_path(path)
             if not relpath:
                 return
-            if mode == 'src':
-                self.src_txt.setText(relpath)
-            else:
-                self.dest_txt.setText(relpath)
+            self.dest_txt.setText(relpath)
 
     def to_relative_path(self, fullpath):  # unicode or QString
         fullpath = util.normpath(unicode(fullpath))