Reworked the Mercurial checkout dialog.

Thu, 23 Feb 2017 18:44:25 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 23 Feb 2017 18:44:25 +0100
changeset 5548
95b188f96d3d
parent 5546
971f5ab7429c
child 5549
fa21bfab0a29

Reworked the Mercurial checkout dialog.

Plugins/VcsPlugins/vcsMercurial/Config.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/HgNewProjectOptionsDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/HgNewProjectOptionsDialog.ui file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/hg.py file | annotate | diff | comparison | revisions
--- a/Plugins/VcsPlugins/vcsMercurial/Config.py	Wed Feb 22 19:25:07 2017 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/Config.py	Thu Feb 23 18:44:25 2017 +0100
@@ -10,9 +10,9 @@
 from __future__ import unicode_literals
 
 # Available protocols fpr the repository URL
-ConfigHgProtocols = [
-    'file://',
-    'http://',
-    'https://',
-    'ssh://',
-]
+ConfigHgSchemes = (
+    'file',
+    'http',
+    'https',
+    'ssh',
+)
--- a/Plugins/VcsPlugins/vcsMercurial/HgNewProjectOptionsDialog.py	Wed Feb 22 19:25:07 2017 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/HgNewProjectOptionsDialog.py	Thu Feb 23 18:44:25 2017 +0100
@@ -10,15 +10,13 @@
 
 from __future__ import unicode_literals
 
-import os
-
-from PyQt5.QtCore import pyqtSlot, QDir
+from PyQt5.QtCore import pyqtSlot, QUrl
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
 
 from E5Gui.E5PathPicker import E5PathPickerModes
 
 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog
-from .Config import ConfigHgProtocols
+from .Config import ConfigHgSchemes
 
 import Utilities
 import Preferences
@@ -42,18 +40,6 @@
         self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode)
         self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode)
         
-        self.protocolCombo.addItems(ConfigHgProtocols)
-        
-        hd = Utilities.toNativeSeparators(QDir.homePath())
-        hd = os.path.join(hd, 'hgroot')
-        self.vcsUrlPicker.setText(hd)
-        
-        self.vcs = vcs
-        
-        self.localPath = hd
-        self.networkPath = "localhost/"
-        self.localProtocol = True
-        
         ipath = Preferences.getMultiProject("Workspace") or \
             Utilities.getHomeDir()
         self.__initPaths = [
@@ -62,10 +48,8 @@
         ]
         self.vcsProjectDirPicker.setText(self.__initPaths[0])
         
-        self.lfNoteLabel.setVisible(self.vcs.isExtensionActive("largefiles"))
-        self.largeCheckBox.setVisible(self.vcs.isExtensionActive("largefiles"))
-        
-        self.resize(self.width(), self.minimumSizeHint().height())
+        self.lfNoteLabel.setVisible(vcs.isExtensionActive("largefiles"))
+        self.largeCheckBox.setVisible(vcs.isExtensionActive("largefiles"))
         
         self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
         
@@ -84,32 +68,17 @@
             Utilities.fromNativeSeparators(txt) not in self.__initPaths)
     
     @pyqtSlot(str)
-    def on_protocolCombo_activated(self, protocol):
-        """
-        Private slot to switch the status of the directory selection button.
-        
-        @param protocol name of the selected protocol (string)
-        """
-        self.vcsUrlPicker.setPickerEnabled(protocol == "file://")
-        if protocol == "file://":
-            self.networkPath = self.vcsUrlPicker.text()
-            self.vcsUrlPicker.setText(self.localPath)
-            self.localProtocol = True
-        else:
-            if self.localProtocol:
-                self.localPath = self.vcsUrlPicker.text()
-                self.vcsUrlPicker.setText(self.networkPath)
-                self.localProtocol = False
-    
-    @pyqtSlot(str)
     def on_vcsUrlPicker_textChanged(self, txt):
         """
         Private slot to handle changes of the URL.
         
         @param txt current text of the line edit (string)
         """
-        enable = "://" not in txt
+        url = QUrl.fromUserInput(txt)
+        enable = url.isValid() and url.scheme() in ConfigHgSchemes
         self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
+        
+        self.vcsUrlPicker.setPickerEnabled(url.scheme() == "file")
     
     def getData(self):
         """
@@ -118,12 +87,9 @@
         @return a tuple of a string (project directory) and a dictionary
             containing the data entered.
         """
-        scheme = self.protocolCombo.currentText()
-        url = self.vcsUrlPicker.text()
-        if scheme == "file://" and url[0] not in ["\\", "/"]:
-            url = "/{0}".format(url)
+        url = QUrl.fromUserInput(self.vcsUrlPicker.text().replace("\\", "/"))
         vcsdatadict = {
-            "url": '{0}{1}'.format(scheme, url),
+            "url": url.toString(QUrl.None_),
             "revision": self.vcsRevisionEdit.text(),
             "largefiles": self.largeCheckBox.isChecked(),
         }
--- a/Plugins/VcsPlugins/vcsMercurial/HgNewProjectOptionsDialog.ui	Wed Feb 22 19:25:07 2017 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/HgNewProjectOptionsDialog.ui	Thu Feb 23 18:44:25 2017 +0100
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>562</width>
-    <height>191</height>
+    <height>147</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -22,34 +22,7 @@
    <bool>true</bool>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0">
-    <widget class="QLabel" name="textLabel1">
-     <property name="text">
-      <string>&amp;Protocol:</string>
-     </property>
-     <property name="buddy">
-      <cstring>protocolCombo</cstring>
-     </property>
-    </widget>
-   </item>
    <item row="0" column="1">
-    <widget class="QComboBox" name="protocolCombo">
-     <property name="toolTip">
-      <string>Select the protocol to access the repository</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <widget class="QLabel" name="TextLabel2">
-     <property name="text">
-      <string>&amp;URL:</string>
-     </property>
-     <property name="buddy">
-      <cstring>vcsUrlPicker</cstring>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="1">
     <widget class="E5PathPicker" name="vcsUrlPicker" native="true">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@@ -65,37 +38,7 @@
      </property>
     </widget>
    </item>
-   <item row="2" column="0">
-    <widget class="QLabel" name="vcsRevisionLabel">
-     <property name="text">
-      <string>&amp;Revision:</string>
-     </property>
-     <property name="buddy">
-      <cstring>vcsRevisionEdit</cstring>
-     </property>
-    </widget>
-   </item>
    <item row="2" column="1">
-    <widget class="QLineEdit" name="vcsRevisionEdit">
-     <property name="toolTip">
-      <string>Enter the revision the new project should be generated from</string>
-     </property>
-     <property name="whatsThis">
-      <string/>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="0">
-    <widget class="QLabel" name="TextLabel4">
-     <property name="text">
-      <string>Project &amp;Directory:</string>
-     </property>
-     <property name="buddy">
-      <cstring>vcsProjectDirPicker</cstring>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="1">
     <widget class="E5PathPicker" name="vcsProjectDirPicker" native="true">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@@ -116,14 +59,54 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="0" colspan="2">
+   <item row="0" column="0">
+    <widget class="QLabel" name="TextLabel2">
+     <property name="text">
+      <string>&amp;URL:</string>
+     </property>
+     <property name="buddy">
+      <cstring>vcsUrlPicker</cstring>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="vcsRevisionLabel">
+     <property name="text">
+      <string>&amp;Revision:</string>
+     </property>
+     <property name="buddy">
+      <cstring>vcsRevisionEdit</cstring>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QLineEdit" name="vcsRevisionEdit">
+     <property name="toolTip">
+      <string>Enter the revision the new project should be generated from</string>
+     </property>
+     <property name="whatsThis">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <widget class="QLabel" name="TextLabel4">
+     <property name="text">
+      <string>Project &amp;Directory:</string>
+     </property>
+     <property name="buddy">
+      <cstring>vcsProjectDirPicker</cstring>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0" colspan="2">
     <widget class="QCheckBox" name="largeCheckBox">
      <property name="text">
       <string>Download all versions of all large files</string>
      </property>
     </widget>
    </item>
-   <item row="5" column="0" colspan="2">
+   <item row="4" column="0" colspan="2">
     <widget class="QLabel" name="lfNoteLabel">
      <property name="text">
       <string>&lt;b&gt;Note:&lt;/b&gt; This option increases the download time and volume.</string>
@@ -133,7 +116,7 @@
      </property>
     </widget>
    </item>
-   <item row="6" column="0" colspan="2">
+   <item row="5" column="0" colspan="2">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -155,7 +138,6 @@
   </customwidget>
  </customwidgets>
  <tabstops>
-  <tabstop>protocolCombo</tabstop>
   <tabstop>vcsUrlPicker</tabstop>
   <tabstop>vcsRevisionEdit</tabstop>
   <tabstop>vcsProjectDirPicker</tabstop>
--- a/Plugins/VcsPlugins/vcsMercurial/hg.py	Wed Feb 22 19:25:07 2017 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/hg.py	Thu Feb 23 18:44:25 2017 +0100
@@ -353,10 +353,6 @@
         except KeyError:
             rev = None
         vcsUrl = self.hgNormalizeURL(vcsDataDict["url"])
-        if vcsUrl.startswith('/'):
-            vcsUrl = 'file://{0}'.format(vcsUrl)
-        elif vcsUrl[1] in ['|', ':']:
-            vcsUrl = 'file:///{0}'.format(vcsUrl)
         
         args = self.initCommand("clone")
         if rev:
@@ -364,7 +360,7 @@
             args.append(rev)
         if vcsDataDict["largefiles"]:
             args.append("--all-largefiles")
-        args.append(self.__hgURL(vcsUrl))
+        args.append(vcsUrl)
         args.append(projectDir)
         
         if noDialog:
@@ -1494,37 +1490,6 @@
     ## Private Mercurial specific methods are below.
     ###########################################################################
     
-    def __hgURL(self, url):
-        """
-        Private method to format a url for Mercurial.
-        
-        @param url unformatted url string (string)
-        @return properly formated url for mercurial (string)
-        """
-        url = self.hgNormalizeURL(url)
-        url = url.split(':', 2)
-        if len(url) == 4:
-            scheme = url[0]
-            user = url[1]
-            host = url[2]
-            port, path = url[3].split("/", 1)
-            return "{0}:{1}:{2}:{3}/{4}".format(
-                scheme, user, host, port, Utilities.quote(path))
-        elif len(url) == 3:
-            scheme = url[0]
-            host = url[1]
-            port, path = url[2].split("/", 1)
-            return "{0}:{1}:{2}/{3}".format(
-                scheme, host, port, Utilities.quote(path))
-        else:
-            scheme = url[0]
-            if scheme == "file":
-                return "{0}:{1}".format(scheme, Utilities.quote(url[1]))
-            else:
-                host, path = url[1][2:].split("/", 1)
-                return "{0}://{1}/{2}".format(
-                    scheme, host, Utilities.quote(path))
-
     def hgNormalizeURL(self, url):
         """
         Public method to normalize a url for Mercurial.

eric ide

mercurial