Commits

Yuya Nishihara committed e075e92

rename: sprout function to convert result of QFileDialog to repo-relative path

Comments (0)

Files changed (1)

tortoisehg/hgqt/rename.py

             path = FD.getExistingDirectory(parent=self, caption=caption,
                     options=FD.ShowDirsOnly | FD.ReadOnly)
         if path:
-            path = util.normpath(unicode(path))
-            pathprefix = util.normpath(hglib.tounicode(self.root)) + '/'
-            if not path.startswith(pathprefix):
+            relpath = self.to_relative_path(path)
+            if not relpath:
                 return
-            relpath = path[len(pathprefix):]
             if mode == 'src':
                 self.src_txt.setText(relpath)
             else:
                 self.dest_txt.setText(relpath)
 
+    def to_relative_path(self, fullpath):  # unicode or QString
+        fullpath = util.normpath(unicode(fullpath))
+        pathprefix = util.normpath(hglib.tounicode(self.root)) + '/'
+        if not fullpath.startswith(pathprefix):
+            return
+        return fullpath[len(pathprefix):]
+
     def copy_chk_toggled(self):
         self.setRenameCopy()
         self.show_command(self.compose_command(self.get_src(), self.get_dest()))