Added the shelve function to the Mercurial Shelve extension.

Fri, 21 Feb 2014 18:57:15 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 21 Feb 2014 18:57:15 +0100
changeset 3291
58e95eea9b6d
parent 3290
dbb53746813f
child 3292
2feabde31912

Added the shelve function to the Mercurial Shelve extension.

Plugins/VcsPlugins/vcsMercurial/ShelveExtension/HgShelveDataDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/ShelveExtension/HgShelveDataDialog.ui file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/ShelveExtension/ProjectHelper.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/ShelveExtension/shelve.py file | annotate | diff | comparison | revisions
eric5.e4p file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/ShelveExtension/HgShelveDataDialog.py	Fri Feb 21 18:57:15 2014 +0100
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to enter the data for a shelve operation.
+"""
+
+from PyQt4.QtCore import QDateTime
+from PyQt4.QtGui import QDialog
+
+from .Ui_HgShelveDataDialog import Ui_HgShelveDataDialog
+
+
+class HgShelveDataDialog(QDialog, Ui_HgShelveDataDialog):
+    """
+    Class implementing a dialog to enter the data for a shelve operation.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.dateTimeEdit.setDateTime(QDateTime.currentDateTime())
+    
+    def getData(self):
+        """
+        Public method to get the user data.
+        
+        @return tuple containing the name (string), date (QDateTime),
+            message (string) and a flag indicating to add/remove
+            new/missing files (boolean)
+        """
+        return (
+            self.nameEdit.text(),
+            self.dateTimeEdit.dateTime(),
+            self.messageEdit.toPlainText(),
+            self.addRemoveCheckBox.isChecked(),
+        )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/ShelveExtension/HgShelveDataDialog.ui	Fri Feb 21 18:57:15 2014 +0100
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>HgShelveDataDialog</class>
+ <widget class="QDialog" name="HgShelveDataDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>500</width>
+    <height>250</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Shelve</string>
+  </property>
+  <property name="sizeGripEnabled">
+   <bool>true</bool>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Name:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QLineEdit" name="nameEdit">
+     <property name="toolTip">
+      <string>Enter a name for the shelve</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="label_2">
+     <property name="text">
+      <string>Date, Time:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QDateTimeEdit" name="dateTimeEdit">
+       <property name="statusTip">
+        <string>Enter the commit date and time for the shelve</string>
+       </property>
+       <property name="displayFormat">
+        <string>dd.MM.yyyy HH:mm</string>
+       </property>
+       <property name="calendarPopup">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>198</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="2" column="0">
+    <widget class="QLabel" name="label_3">
+     <property name="text">
+      <string>Message:</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1">
+    <widget class="QPlainTextEdit" name="messageEdit">
+     <property name="toolTip">
+      <string>Enter message for the shelve</string>
+     </property>
+     <property name="tabChangesFocus">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0" colspan="2">
+    <widget class="QCheckBox" name="addRemoveCheckBox">
+     <property name="text">
+      <string>Mark new/missing files as added/removed</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0" colspan="2">
+    <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>nameEdit</tabstop>
+  <tabstop>dateTimeEdit</tabstop>
+  <tabstop>messageEdit</tabstop>
+  <tabstop>addRemoveCheckBox</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>HgShelveDataDialog</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>HgShelveDataDialog</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/ShelveExtension/ProjectHelper.py	Thu Feb 20 19:51:30 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/ShelveExtension/ProjectHelper.py	Fri Feb 21 18:57:15 2014 +0100
@@ -9,9 +9,10 @@
 
 from PyQt4.QtGui import QMenu
 
-from ..HgExtensionProjectHelper import HgExtensionProjectHelper
+from E5Gui.E5Action import E5Action
+from E5Gui import E5MessageBox
 
-from .shelve import Shelve
+from ..HgExtensionProjectHelper import HgExtensionProjectHelper
 
 
 class ShelveProjectHelper(HgExtensionProjectHelper):
@@ -28,6 +29,19 @@
         """
         Public method to generate the action objects.
         """
+        self.hgShelveAct = E5Action(
+            self.tr('Shelve changes'),
+            self.tr('Shelve changes...'),
+            0, 0, self, 'mercurial_shelve')
+        self.hgShelveAct.setStatusTip(self.tr(
+            'Shelve all current changes of the project'
+        ))
+        self.hgShelveAct.setWhatsThis(self.tr(
+            """<b>Shelve changes</b>"""
+            """<p>This shelves all current changes of the project.</p>"""
+        ))
+        self.hgShelveAct.triggered[()].connect(self.__hgShelve)
+        self.actions.append(self.hgShelveAct)
     
     def initMenu(self, mainMenu):
         """
@@ -39,6 +53,8 @@
         menu = QMenu(self.menuTitle(), mainMenu)
         menu.setTearOffEnabled(True)
         
+        menu.addAction(self.hgShelveAct)
+        
         return menu
     
     def menuTitle(self):
@@ -48,3 +64,18 @@
         @return title of the menu (string)
         """
         return self.tr("Shelve")
+    
+    def __hgShelve(self):
+        """
+        Private slot used to shelve all current changes.
+        """
+        shouldReopen = self.vcs.getExtensionObject("shelve")\
+            .hgShelve(self.project.getProjectPath())
+        if shouldReopen:
+            res = E5MessageBox.yesNo(
+                None,
+                self.tr("Shelve"),
+                self.tr("""The project should be reread. Do this now?"""),
+                yesDefault=True)
+            if res:
+                self.project.reopenProject()
--- a/Plugins/VcsPlugins/vcsMercurial/ShelveExtension/shelve.py	Thu Feb 20 19:51:30 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/ShelveExtension/shelve.py	Fri Feb 21 18:57:15 2014 +0100
@@ -7,8 +7,13 @@
 Module implementing the shelve extension interface.
 """
 
+import os
+
+from PyQt4.QtCore import QDateTime
+from PyQt4.QtGui import QDialog
+
 from ..HgExtension import HgExtension
-##from ..HgDialog import HgDialog
+from ..HgDialog import HgDialog
 
 
 class Shelve(HgExtension):
@@ -27,3 +32,57 @@
         """
         Public method used to shutdown the shelve interface.
         """
+    
+    def hgShelve(self, name):
+        """
+        Public method to shelve current changes of files or directories.
+        
+        @param name directory or file name (string) or list of directory
+            or file names (list of string)
+        @return flag indicating that the project should be reread (boolean)
+        """
+        if isinstance(name, list):
+            dname = self.vcs.splitPathList(name)[0]
+        else:
+            dname = self.vcs.splitPath(name)[0]
+        
+        # find the root of the repo
+        repodir = dname
+        while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
+            repodir = os.path.dirname(repodir)
+            if os.path.splitdrive(repodir)[1] == os.sep:
+                return False
+        
+        res = False
+        from .HgShelveDataDialog import HgShelveDataDialog
+        dlg = HgShelveDataDialog()
+        if dlg.exec_() == QDialog.Accepted:
+            shelveName, dateTime, message, addRemove = dlg.getData()
+            
+            args = []
+            args.append("shelve")
+            if shelveName:
+                args.append("--name")
+                args.append(shelveName)
+            if message:
+                args.append("--message")
+                args.append(message)
+            if addRemove:
+                args.append("--addRemove")
+            if dateTime != QDateTime.currentDateTime():
+                args.append("--date")
+                args.append(dateTime.toString("yyyy-MM-dd hh:mm:ss"))
+            args.append("-v")
+            
+            if isinstance(name, list):
+                self.vcs.addArguments(args, name)
+            else:
+                args.append(name)
+            
+            dia = HgDialog(self.tr('Shelve current changes'), self.vcs)
+            res = dia.startProcess(args, repodir)
+            if res:
+                dia.exec_()
+                res = dia.hasAddOrDelete()
+                self.vcs.checkVCSStatus()
+        return res
--- a/eric5.e4p	Thu Feb 20 19:51:30 2014 +0100
+++ b/eric5.e4p	Fri Feb 21 18:57:15 2014 +0100
@@ -1115,6 +1115,7 @@
     <Source>Plugins/VcsPlugins/vcsMercurial/ShelveExtension/__init__.py</Source>
     <Source>Plugins/VcsPlugins/vcsMercurial/ShelveExtension/shelve.py</Source>
     <Source>Plugins/VcsPlugins/vcsMercurial/ShelveExtension/ProjectHelper.py</Source>
+    <Source>Plugins/VcsPlugins/vcsMercurial/ShelveExtension/HgShelveDataDialog.py</Source>
   </Sources>
   <Forms>
     <Form>PyUnit/UnittestDialog.ui</Form>
@@ -1436,6 +1437,7 @@
     <Form>Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.ui</Form>
     <Form>Plugins/VcsPlugins/vcsMercurial/HgRepoConfigDataDialog.ui</Form>
     <Form>Plugins/VcsPlugins/vcsMercurial/HgUserConfigDataDialog.ui</Form>
+    <Form>Plugins/VcsPlugins/vcsMercurial/ShelveExtension/HgShelveDataDialog.ui</Form>
   </Forms>
   <Translations>
     <Translation>i18n/eric5_cs.ts</Translation>

eric ide

mercurial