src/eric7/VCS/ProjectBrowserHelper.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/VCS/ProjectBrowserHelper.py
--- a/src/eric7/VCS/ProjectBrowserHelper.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/VCS/ProjectBrowserHelper.py	Wed Jul 13 14:55:47 2022 +0200
@@ -17,8 +17,9 @@
 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
 
 from Project.ProjectBrowserModel import (
-    ProjectBrowserSimpleDirectoryItem, ProjectBrowserFileItem,
-    ProjectBrowserDirectoryItem
+    ProjectBrowserSimpleDirectoryItem,
+    ProjectBrowserFileItem,
+    ProjectBrowserDirectoryItem,
 )
 
 import Preferences
@@ -28,11 +29,19 @@
     """
     Class implementing the base class of the VCS project browser helper.
     """
-    def __init__(self, vcsObject, browserObject, projectObject,
-                 isTranslationsBrowser, parent=None, name=None):
+
+    def __init__(
+        self,
+        vcsObject,
+        browserObject,
+        projectObject,
+        isTranslationsBrowser,
+        parent=None,
+        name=None,
+    ):
         """
         Constructor
-        
+
         @param vcsObject reference to the vcs object
         @param browserObject reference to the project browser object
         @param projectObject reference to the project object
@@ -44,18 +53,17 @@
         super().__init__(parent)
         if name:
             self.setObjectName(name)
-        
+
         self.vcs = vcsObject
         self.browser = browserObject
         self.isTranslationsBrowser = isTranslationsBrowser
         self.project = projectObject
-    
-    def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu,
-                    dirMultiMenu):
+
+    def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu, dirMultiMenu):
         """
         Public method to add the VCS entries to the various project browser
         menus.
-        
+
         @param mainMenu reference to the main menu (QPopupMenu)
         @param multiMenu reference to the multiple selection menu (QPopupMenu)
         @param backMenu reference to the background menu (QPopupMenu)
@@ -68,85 +76,89 @@
         self._addVCSMenuBack(backMenu)
         self._addVCSMenuDir(dirMenu)
         self._addVCSMenuDirMulti(dirMultiMenu)
-    
+
     def showContextMenu(self, menu, standardItems):
         """
         Public slot called before the context menu is shown.
-        
+
         It enables/disables the VCS menu entries depending on the overall
         VCS status and the file status.
-        
+
         @param menu reference to the menu to be shown
         @param standardItems array of standard items that need
             activation/deactivation depending on the overall VCS status
         @exception RuntimeError to indicate that this method must be
             implemented by a subclass
         """
-        raise RuntimeError('Not implemented')
-    
+        raise RuntimeError("Not implemented")
+
     def showContextMenuMulti(self, menu, standardItems):
         """
         Public slot called before the context menu (multiple selections) is
         shown.
-        
+
         It enables/disables the VCS menu entries depending on the overall
         VCS status and the files status.
-        
+
         @param menu reference to the menu to be shown
         @param standardItems array of standard items that need
             activation/deactivation depending on the overall VCS status
         @exception RuntimeError to indicate that this method must be
             implemented by a subclass
         """
-        raise RuntimeError('Not implemented')
-    
+        raise RuntimeError("Not implemented")
+
     def showContextMenuDir(self, menu, standardItems):
         """
         Public slot called before the context menu is shown.
-        
+
         It enables/disables the VCS menu entries depending on the overall
         VCS status and the directory status.
-        
+
         @param menu reference to the menu to be shown
         @param standardItems array of standard items that
             need activation/deactivation depending on the overall VCS status
         @exception RuntimeError to indicate that this method must be
             implemented by a subclass
         """
-        raise RuntimeError('Not implemented')
-    
+        raise RuntimeError("Not implemented")
+
     def showContextMenuDirMulti(self, menu, standardItems):
         """
         Public slot called before the context menu is shown.
-        
+
         It enables/disables the VCS menu entries depending on the overall
         VCS status and the directory status.
-        
+
         @param menu reference to the menu to be shown
         @param standardItems array of standard items that need
             activation/deactivation depending on the overall VCS status
         @exception RuntimeError to indicate that this method must be
             implemented by a subclass
         """
-        raise RuntimeError('Not implemented')
+        raise RuntimeError("Not implemented")
 
     ###########################################################################
     ## General menu handling methods below
     ###########################################################################
-    
+
     def _VCSUpdate(self):
         """
         Protected slot called by the context menu to update a file from the
         VCS repository.
         """
         if self.isTranslationsBrowser:
-            names = [itm.dirName()
-                     for itm in self.browser.getSelectedItems(
-                         [ProjectBrowserSimpleDirectoryItem])]
+            names = [
+                itm.dirName()
+                for itm in self.browser.getSelectedItems(
+                    [ProjectBrowserSimpleDirectoryItem]
+                )
+            ]
             if not names:
-                names = [itm.fileName()
-                         for itm in self.browser.getSelectedItems(
-                             [ProjectBrowserFileItem])]
+                names = [
+                    itm.fileName()
+                    for itm in self.browser.getSelectedItems([ProjectBrowserFileItem])
+                ]
         else:
             names = []
             for itm in self.browser.getSelectedItems():
@@ -156,20 +168,24 @@
                     name = itm.dirName()
                 names.append(name)
         self.vcs.vcsUpdate(names)
-        
+
     def _VCSCommit(self):
         """
         Protected slot called by the context menu to commit the changes to the
         VCS repository.
         """
         if self.isTranslationsBrowser:
-            names = [itm.dirName()
-                     for itm in self.browser.getSelectedItems(
-                         [ProjectBrowserSimpleDirectoryItem])]
+            names = [
+                itm.dirName()
+                for itm in self.browser.getSelectedItems(
+                    [ProjectBrowserSimpleDirectoryItem]
+                )
+            ]
             if not names:
-                names = [itm.fileName()
-                         for itm in self.browser.getSelectedItems(
-                             [ProjectBrowserFileItem])]
+                names = [
+                    itm.fileName()
+                    for itm in self.browser.getSelectedItems([ProjectBrowserFileItem])
+                ]
         else:
             names = []
             for itm in self.browser.getSelectedItems():
@@ -182,16 +198,15 @@
             vm = ericApp().getObject("ViewManager")
             for name in names:
                 vm.saveEditor(name)
-        self.vcs.vcsCommit(names, '')
-        
+        self.vcs.vcsCommit(names, "")
+
     def _VCSAdd(self):
         """
         Protected slot called by the context menu to add the selected file to
         the VCS repository.
         """
         if self.isTranslationsBrowser:
-            items = self.browser.getSelectedItems(
-                [ProjectBrowserSimpleDirectoryItem])
+            items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem])
             if items:
                 names = [itm.dirName() for itm in items]
                 qnames = []
@@ -201,7 +216,7 @@
                 qnames = []
                 for itm in items:
                     name = itm.fileName()
-                    if name.endswith('.qm'):
+                    if name.endswith(".qm"):
                         qnames.append(name)
                     else:
                         names.append(name)
@@ -214,10 +229,10 @@
                     name = itm.dirName()
                 names.append(name)
             qnames = []
-        
+
         if not len(names + qnames):
             return
-        
+
         if len(names + qnames) == 1:
             if names:
                 self.vcs.vcsAdd(names[0], os.path.isdir(names[0]))
@@ -235,11 +250,11 @@
                     self.vcs.vcsAddBinary(qnames)
         for fn in names + qnames:
             self._updateVCSStatus(fn)
-        
+
     def _VCSAddTree(self):
         """
         Protected slot called by the context menu.
-        
+
         It is used to add the selected
         directory tree to the VCS repository.
         """
@@ -253,57 +268,57 @@
         self.vcs.vcsAddTree(names)
         for fn in names:
             self._updateVCSStatus(fn)
-        
+
     def _VCSRemove(self):
         """
         Protected slot called by the context menu to remove the selected file
         from the VCS repository.
         """
         if self.isTranslationsBrowser:
-            items = self.browser.getSelectedItems(
-                [ProjectBrowserSimpleDirectoryItem])
+            items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem])
             if items:
-                return      # not supported
-            
+                return  # not supported
+
             isRemoveDirs = False
             items = self.browser.getSelectedItems([ProjectBrowserFileItem])
             names = [itm.fileName() for itm in items]
-            
+
             dlg = DeleteFilesConfirmationDialog(
                 self.parent(),
                 QCoreApplication.translate(
-                    "VcsProjectBrowserHelper",
-                    "Remove from repository (and disk)"),
+                    "VcsProjectBrowserHelper", "Remove from repository (and disk)"
+                ),
                 QCoreApplication.translate(
                     "VcsProjectBrowserHelper",
                     "Do you really want to remove these translation files from"
-                    " the repository (and disk)?"),
-                names)
+                    " the repository (and disk)?",
+                ),
+                names,
+            )
         else:
             items = self.browser.getSelectedItems()
-            isRemoveDirs = (
-                len(items) == self.browser.getSelectedItemsCount(
-                    [ProjectBrowserSimpleDirectoryItem,
-                     ProjectBrowserDirectoryItem])
+            isRemoveDirs = len(items) == self.browser.getSelectedItemsCount(
+                [ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]
             )
             if isRemoveDirs:
                 names = [itm.dirName() for itm in items]
             else:
                 names = [itm.fileName() for itm in items]
-            files = [self.browser.project.getRelativePath(name)
-                     for name in names]
-            
+            files = [self.browser.project.getRelativePath(name) for name in names]
+
             dlg = DeleteFilesConfirmationDialog(
                 self.parent(),
                 QCoreApplication.translate(
-                    "VcsProjectBrowserHelper",
-                    "Remove from repository (and disk)"),
+                    "VcsProjectBrowserHelper", "Remove from repository (and disk)"
+                ),
                 QCoreApplication.translate(
                     "VcsProjectBrowserHelper",
                     "Do you really want to remove these files/directories"
-                    " from the repository (and disk)?"),
-                files)
-        
+                    " from the repository (and disk)?",
+                ),
+                files,
+            )
+
         if dlg.exec() == QDialog.DialogCode.Accepted:
             status = self.vcs.vcsRemove(names)
             if status:
@@ -312,7 +327,7 @@
                     # remove directories from Project
                 else:
                     self.browser._removeFile()  # remove file(s) from project
-        
+
     def _VCSLogBrowser(self):
         """
         Protected slot called by the context menu to show the log browser for a
@@ -326,7 +341,7 @@
             fn = itm.dirName()
             isFile = False
         self.vcs.vcsLogBrowser(fn, isFile=isFile)
-        
+
     def _VCSDiff(self):
         """
         Protected slot called by the context menu to show the difference of a
@@ -340,14 +355,13 @@
                 name = itm.dirName()
             names.append(name)
         self.vcs.vcsDiff(names)
-        
+
     def _VCSStatus(self):
         """
         Protected slot called by the context menu to show the status of a file.
         """
         if self.isTranslationsBrowser:
-            items = self.browser.getSelectedItems(
-                [ProjectBrowserSimpleDirectoryItem])
+            items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem])
             if items:
                 names = [itm.dirName() for itm in items]
             else:
@@ -388,12 +402,13 @@
         except AttributeError:
             name = itm.dirName()
         self.vcs.vcsMerge(name)
-    
+
     def _VCSInfoDisplay(self):
         """
         Protected slot called to show some vcs information.
         """
         from .RepositoryInfoDialog import VcsRepositoryInfoDialog
+
         info = self.vcs.vcsRepositoryInfos(self.project.ppath)
         dlg = VcsRepositoryInfoDialog(None, info)
         dlg.exec()
@@ -401,7 +416,7 @@
     def _updateVCSStatus(self, name):
         """
         Protected method to update the VCS status of an item.
-        
+
         @param name filename or directoryname of the item to be updated
             (string)
         """

eric ide

mercurial