Implemented the Mercurial largefiles add interface.

Sat, 01 Mar 2014 11:50:10 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 01 Mar 2014 11:50:10 +0100
changeset 3313
037642483f35
parent 3312
7535e5a5cbce
child 3314
be841c05a7f3

Implemented the Mercurial largefiles add interface.

Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.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/LargefilesExtension/ProjectBrowserHelper.py	Sat Mar 01 11:50:10 2014 +0100
@@ -0,0 +1,122 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the largefiles extension project browser helper.
+"""
+
+from PyQt4.QtGui import QMenu
+
+from ..HgExtensionProjectBrowserHelper import HgExtensionProjectBrowserHelper
+
+import UI.PixmapCache
+
+
+class LargefilesProjectBrowserHelper(HgExtensionProjectBrowserHelper):
+    """
+    Class implementing the largefiles extension project browser helper.
+    """
+    def __init__(self, vcsObject, browserObject, projectObject):
+        """
+        Constructor
+        
+        @param vcsObject reference to the vcs object
+        @param browserObject reference to the project browser object
+        @param projectObject reference to the project object
+        """
+        super().__init__(vcsObject, browserObject, projectObject)
+    
+    def initMenus(self):
+        """
+        Public method to generate the extension menus.
+        
+        Note: Derived class must implement this method.
+        
+        @return dictionary of populated menu (dict of QMenu). The dict
+            must have the keys 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu'
+            and 'dirMultiMenu'. 
+        """
+        self.__menus = {}
+        self.__addSingleActs = []
+        self.__addMultiActs = []
+        
+        menu = QMenu(self.menuTitle())
+        menu.setTearOffEnabled(True)
+        act = menu.addAction(
+            UI.PixmapCache.getIcon("vcsAdd.png"),
+            self.tr('Add as Large File'),
+            lambda: self.__hgAddLargefiles("large"))
+        self.__addSingleActs.append(act)
+        act = menu.addAction(
+            UI.PixmapCache.getIcon("vcsAdd.png"),
+            self.tr('Add as Normal File'),
+            lambda: self.__hgAddLargefiles("normal"))
+        self.__addSingleActs.append(act)
+        self.__menus['mainMenu'] = menu
+        
+        menu = QMenu(self.menuTitle())
+        menu.setTearOffEnabled(True)
+        act = menu.addAction(
+            UI.PixmapCache.getIcon("vcsAdd.png"),
+            self.tr('Add as Large Files'),
+            lambda: self.__hgAddLargefiles("large"))
+        self.__addMultiActs.append(act)
+        act = menu.addAction(
+            UI.PixmapCache.getIcon("vcsAdd.png"),
+            self.tr('Add as Normal Files'),
+            lambda: self.__hgAddLargefiles("normal"))
+        self.__addMultiActs.append(act)
+        self.__menus['multiMenu'] = menu
+        
+        return self.__menus
+    
+    def menuTitle(self):
+        """
+        Public method to get the menu title.
+        
+        Note: Derived class must implement this method.
+        
+        @return title of the menu (string)
+        """
+        return self.tr("Large Files")
+    
+    def showExtensionMenu(self, key, controlled):
+        """
+        Public method to prepare the extension menu for display.
+        
+        @param key menu key (string, one of 'mainMenu', 'multiMenu',
+            'backMenu', 'dirMenu' or 'dirMultiMenu')
+        @param controlled flag indicating to prepare the menu for a
+            version controlled entry or a non-version controlled entry
+            (boolean)
+        """
+        if key == "mainMenu":
+            for act in self.__addSingleActs:
+                act.setEnabled(not controlled)
+        elif key == "multiMenu":
+            for act in self.__addMultiActs:
+                act.setEnabled(not controlled)
+    
+    def __hgAddLargefiles(self, mode):
+        """
+        Private slot to add the selected files as large files.
+        
+        @param mode add mode (string one of 'normal' or 'large')
+        """
+        names = []
+        for itm in self.browser.getSelectedItems():
+            try:
+                name = itm.fileName()
+            except AttributeError:
+                continue
+            names.append(name)
+        
+        if names:
+            if len(names) == 1:
+                self.vcs.getExtensionObject("largefiles").hgAdd(names[0], mode)
+            else:
+                self.vcs.getExtensionObject("largefiles").hgAdd(names, mode)
+            for fn in names:
+                self._updateVCSStatus(fn)
--- a/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py	Sat Mar 01 11:48:44 2014 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py	Sat Mar 01 11:50:10 2014 +0100
@@ -93,3 +93,41 @@
                         "minsize": minSize, "pattern": patterns})
                 else:
                     self.vcs.hgEditConfig(newName, withLargefiles=False)
+    
+    def hgAdd(self, names, mode):
+        """
+        Public method used to add a file to the Mercurial repository.
+        
+        @param name file name(s) to be added (string or list of string)
+        @param mode add mode (string one of 'normal' or 'large')
+        """
+        args = self.vcs.initCommand("add")
+        args.append("-v")
+        if mode == "large":
+            args.append("--large")
+        else:
+            args.append("--normal")
+        
+        if isinstance(names, list):
+            dname = self.vcs.splitPathList(names)[0]
+        else:
+            dname = self.vcs.splitPath(names)[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
+        
+        if isinstance(names, list):
+            self.vcs.addArguments(args, names)
+        else:
+            args.append(names)
+        
+        dia = HgDialog(
+            self.tr('Adding files to the Mercurial repository'),
+            self.vcs)
+        res = dia.startProcess(args, repodir)
+        if res:
+            dia.exec_()
--- a/eric5.e4p	Sat Mar 01 11:48:44 2014 +0100
+++ b/eric5.e4p	Sat Mar 01 11:50:10 2014 +0100
@@ -1125,6 +1125,7 @@
     <Source>Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/largefiles.py</Source>
     <Source>Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/ProjectHelper.py</Source>
     <Source>Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/LfConvertDataDialog.py</Source>
+    <Source>Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/ProjectBrowserHelper.py</Source>
   </Sources>
   <Forms>
     <Form>PyUnit/UnittestDialog.ui</Form>

eric ide

mercurial