Continued with support for Mercurial queues extension.

Sat, 21 May 2011 22:21:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 21 May 2011 22:21:14 +0200
changeset 1047
b41a36b201e4
parent 1046
5dd14be5d6a1
child 1048
0cfd237feaf7

Continued with support for Mercurial queues extension.

Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesDefineGuardsDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesGuardsSelectionDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesGuardsSelectionDialog.ui file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/QueuesExtension/ProjectHelper.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py file | annotate | diff | comparison | revisions
eric5.e4p file | annotate | diff | comparison | revisions
--- a/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesDefineGuardsDialog.py	Sat May 21 16:17:31 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesDefineGuardsDialog.py	Sat May 21 22:21:14 2011 +0200
@@ -24,11 +24,12 @@
     """
     Class implementing a dialog to define guards for patches.
     """
-    def __init__(self, vcs, patchesList, parent=None):
+    def __init__(self, vcs, extension, patchesList, parent=None):
         """
         Constructor
         
         @param vcs reference to the vcs object
+        @param extension reference to the extension module (Queues)
         @param patchesList list of patches (list of strings)
         @param parent reference to the parent widget (QWidget)
         """
@@ -37,6 +38,7 @@
         
         self.process = QProcess()
         self.vcs = vcs
+        self.extension = extension
         
         self.__patches = patchesList[:]
         self.patchSelector.addItems([""] + self.__patches)
@@ -93,35 +95,6 @@
         self.__repodir = repodir
         self.on_patchSelector_activated("")
     
-    def __getGuards(self):
-        """
-        Private method to get a list of all guards defined.
-        
-        @return list of guards (list of strings)
-        """
-        guardsList = []
-        
-        ioEncoding = Preferences.getSystem("IOEncoding")
-        process = QProcess()
-        args = []
-        args.append("qselect")
-        args.append("--series")
-        
-        process.setWorkingDirectory(self.__repodir)
-        process.start('hg', args)
-        procStarted = process.waitForStarted()
-        if procStarted:
-            finished = process.waitForFinished(30000)
-            if finished and process.exitCode() == 0:
-                output = \
-                    str(process.readAllStandardOutput(), ioEncoding, 'replace')
-                for guard in output.splitlines():
-                    guard = guard.strip()[1:]
-                    if guard not in guardsList:
-                        guardsList.append(guard)
-        
-        return sorted(guardsList)
-    
     @pyqtSlot(str)
     def on_patchSelector_activated(self, patch):
         """
@@ -147,7 +120,7 @@
         self.patchNameLabel.setText("")
         
         self.guardCombo.clear()
-        guardsList = self.__getGuards()
+        guardsList = self.extension.getGuardsList(self.__repodir)
         self.guardCombo.addItems(guardsList)
         self.guardCombo.setEditText("")
         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesGuardsSelectionDialog.py	Sat May 21 22:21:14 2011 +0200
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to select a list of guards.
+"""
+
+from PyQt4.QtGui import QDialog, QDialogButtonBox, QListWidgetItem, QAbstractItemView
+
+from .Ui_HgQueuesGuardsSelectionDialog import Ui_HgQueuesGuardsSelectionDialog
+
+
+class HgQueuesGuardsSelectionDialog(QDialog, Ui_HgQueuesGuardsSelectionDialog):
+    """
+    Class implementing a dialog to select a list of guards.
+    """
+    def __init__(self, guards, activeGuards=None, listOnly=False, parent=None):
+        """
+        Constructor
+        
+        @param guards list of guards to select from (list of strings)
+        @keyparam activeGuards list of active guards (list of strings)
+        @param listOnly flag indicating to only list the guards (boolean)
+        @param parent reference to the parent widget (QWidget)
+        """
+        QDialog.__init__(self, parent)
+        self.setupUi(self)
+        
+        for guard in guards:
+            itm = QListWidgetItem(guard, self.guardsList)
+            if activeGuards is not None and guard in activeGuards:
+                font = itm.font()
+                font.setBold(True)
+                itm.setFont(font)
+        self.guardsList.sortItems()
+        
+        if listOnly:
+            self.buttonBox.button(QDialogButtonBox.Cancel).hide()
+            self.guardsList.setSelectionMode(QAbstractItemView.NoSelection)
+            self.setWindowTitle(self.trUtf8("Active Guards"))
+    
+    def getData(self):
+        """
+        Public method to retrieve the data.
+        
+        @return list of selected guards (list of strings)
+        """
+        guardsList = []
+        
+        for itm in self.guardsList.selectedItems():
+            guardsList.append(itm.text())
+        
+        return guardsList
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesGuardsSelectionDialog.ui	Sat May 21 22:21:14 2011 +0200
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>HgQueuesGuardsSelectionDialog</class>
+ <widget class="QDialog" name="HgQueuesGuardsSelectionDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>300</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Select Guards</string>
+  </property>
+  <property name="sizeGripEnabled">
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QListWidget" name="guardsList">
+     <property name="alternatingRowColors">
+      <bool>true</bool>
+     </property>
+     <property name="selectionMode">
+      <enum>QAbstractItemView::ExtendedSelection</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <tabstops>
+  <tabstop>guardsList</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>HgQueuesGuardsSelectionDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>HgQueuesGuardsSelectionDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
--- a/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/ProjectHelper.py	Sat May 21 16:17:31 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/ProjectHelper.py	Sat May 21 22:21:14 2011 +0200
@@ -485,12 +485,11 @@
                 self.trUtf8('Identify Active Guards...'),
                 0, 0, self, 'mercurial_queues_guards_identify_active')
         self.hgQueueIdentifyActiveGuardsAct.setStatusTip(self.trUtf8(
-            'Show a list of active guards and affected patches'
+            'Show a list of active guards'
         ))
         self.hgQueueIdentifyActiveGuardsAct.setWhatsThis(self.trUtf8(
             """<b>Identify Active Guards</b>"""
-            """<p>This opens a dialog show a list of active guards and the"""
-            """ patches directly affected by them.</p>"""
+            """<p>This opens a dialog showing a list of active guards.</p>"""
         ))
         self.hgQueueIdentifyActiveGuardsAct.triggered[()].connect(
             self.__hgQueueGuardsIdentifyActive)
@@ -785,16 +784,19 @@
         """
         Private slot used to set the active guards.
         """
-        pass
+        self.vcs.getExtensionObject("mq")\
+            .hgQueueGuardsSetActive(self.project.getProjectPath())
     
     def __hgQueueGuardsDeactivate(self):
         """
         Private slot used to deactivate all active guards.
         """
-        pass
+        self.vcs.getExtensionObject("mq")\
+            .hgQueueGuardsDeactivate(self.project.getProjectPath())
     
     def __hgQueueGuardsIdentifyActive(self):
         """
-        Private slot used to list all active guards and their patches.
+        Private slot used to list all active guards.
         """
-        pass
+        self.vcs.getExtensionObject("mq")\
+            .hgQueueGuardsIdentifyActive(self.project.getProjectPath())
--- a/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py	Sat May 21 16:17:31 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py	Sat May 21 22:21:14 2011 +0200
@@ -24,6 +24,7 @@
 from .HgQueuesListGuardsDialog import HgQueuesListGuardsDialog
 from .HgQueuesListAllGuardsDialog import HgQueuesListAllGuardsDialog
 from .HgQueuesDefineGuardsDialog import HgQueuesDefineGuardsDialog
+from .HgQueuesGuardsSelectionDialog import HgQueuesGuardsSelectionDialog
 
 import Preferences
 
@@ -171,6 +172,40 @@
         
         return message
     
+    def getGuardsList(self, repodir, all=True):
+        """
+        Public method to get a list of all guards defined.
+        
+        @param repodir directory name of the repository (string)
+        @param all flag indicating to get all guards (boolean)
+        @return sorted list of guards (list of strings)
+        """
+        guardsList = []
+        
+        ioEncoding = Preferences.getSystem("IOEncoding")
+        process = QProcess()
+        args = []
+        args.append("qselect")
+        if all:
+            args.append("--series")
+        
+        process.setWorkingDirectory(repodir)
+        process.start('hg', args)
+        procStarted = process.waitForStarted()
+        if procStarted:
+            finished = process.waitForFinished(30000)
+            if finished and process.exitCode() == 0:
+                output = \
+                    str(process.readAllStandardOutput(), ioEncoding, 'replace')
+                for guard in output.splitlines():
+                    guard = guard.strip()
+                    if all:
+                        guard = guard[1:]
+                    if guard not in guardsList:
+                        guardsList.append(guard)
+        
+        return sorted(guardsList)
+    
     def hgQueueNewPatch(self, name):
         """
         Public method to create a new named patch.
@@ -538,7 +573,7 @@
             self.__getPatchesList(repodir, Queues.SERIES_LIST))
         if patchnames:
             self.queuesDefineGuardsDialog = HgQueuesDefineGuardsDialog(
-                self.vcs, patchnames)
+                self.vcs, self, patchnames)
             self.queuesDefineGuardsDialog.show()
             self.queuesDefineGuardsDialog.start(name)
         else:
@@ -586,3 +621,78 @@
             E5MessageBox.information(None,
                 self.trUtf8("Drop All Guards"),
                 self.trUtf8("""No patches available to define guards for."""))
+    
+    def hgQueueGuardsSetActive(self, name):
+        """
+        Public method to set the active guards.
+        
+        @param name file/directory name (string)
+        """
+        # find the root of the repo
+        repodir = self.vcs.splitPath(name)[0]
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if repodir == os.sep:
+                return
+        
+        guardsList = self.getGuardsList(repodir)
+        if guardsList:
+            activeGuardsList = self.getGuardsList(repodir, all=False)
+            dlg = HgQueuesGuardsSelectionDialog(
+                guardsList, activeGuards=activeGuardsList, listOnly=False)
+            if dlg.exec_() == QDialog.Accepted:
+                guards = dlg.getData()
+                if guards:
+                    args = []
+                    args.append("qselect")
+                    args.extend(guards)
+                    
+                    dia = HgDialog(self.trUtf8('Set Active Guards'))
+                    res = dia.startProcess(args, repodir)
+                    if res:
+                        dia.exec_()
+        else:
+            E5MessageBox.information(None,
+                self.trUtf8("Set Active Guards"),
+                self.trUtf8("""No guards available to select from."""))
+            return
+    
+    def hgQueueGuardsDeactivate(self, name):
+        """
+        Public method to deactivate all active guards.
+        
+        @param name file/directory name (string)
+        """
+        # find the root of the repo
+        repodir = self.vcs.splitPath(name)[0]
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if repodir == os.sep:
+                return
+        
+        args = []
+        args.append("qselect")
+        args.append("--none")
+        
+        dia = HgDialog(self.trUtf8('Deactivate Guards'))
+        res = dia.startProcess(args, repodir)
+        if res:
+            dia.exec_()
+    
+    def hgQueueGuardsIdentifyActive(self, name):
+        """
+        Public method to list all active guards.
+        
+        @param name file/directory name (string)
+        """
+        # find the root of the repo
+        repodir = self.vcs.splitPath(name)[0]
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if repodir == os.sep:
+                return
+        
+        guardsList = self.getGuardsList(repodir, all=False)
+        if guardsList:
+            dlg = HgQueuesGuardsSelectionDialog(guardsList, listOnly=True)
+            dlg.exec_()
--- a/eric5.e4p	Sat May 21 16:17:31 2011 +0200
+++ b/eric5.e4p	Sat May 21 22:21:14 2011 +0200
@@ -894,6 +894,7 @@
     <Source>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListGuardsDialog.py</Source>
     <Source>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListAllGuardsDialog.py</Source>
     <Source>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesDefineGuardsDialog.py</Source>
+    <Source>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesGuardsSelectionDialog.py</Source>
   </Sources>
   <Forms>
     <Form>PyUnit/UnittestDialog.ui</Form>
@@ -1145,6 +1146,7 @@
     <Form>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListGuardsDialog.ui</Form>
     <Form>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListAllGuardsDialog.ui</Form>
     <Form>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesDefineGuardsDialog.ui</Form>
+    <Form>Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesGuardsSelectionDialog.ui</Form>
   </Forms>
   <Translations>
     <Translation>i18n/eric5_cs.qm</Translation>

eric ide

mercurial