eric6/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/ProjectBrowserHelper.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 8218
7c09585bd960
permissions
-rw-r--r--

Updated copyright for 2021.

3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the largefiles extension project browser helper.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
10 from PyQt5.QtWidgets import QMenu
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from ..HgExtensionProjectBrowserHelper import HgExtensionProjectBrowserHelper
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import UI.PixmapCache
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class LargefilesProjectBrowserHelper(HgExtensionProjectBrowserHelper):
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing the largefiles extension project browser helper.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def __init__(self, vcsObject, browserObject, projectObject):
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @param vcsObject reference to the vcs object
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param browserObject reference to the project browser object
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param projectObject reference to the project object
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3359
diff changeset
29 super(LargefilesProjectBrowserHelper, self).__init__(
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3359
diff changeset
30 vcsObject, browserObject, projectObject)
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 def initMenus(self):
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Public method to generate the extension menus.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Note: Derived class must implement this method.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @return dictionary of populated menu (dict of QMenu). The dict
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 must have the keys 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu'
3359
6b6c224d67d6 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3313
diff changeset
40 and 'dirMultiMenu'.
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__menus = {}
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.__addSingleActs = []
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__addMultiActs = []
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 menu = QMenu(self.menuTitle())
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 menu.setTearOffEnabled(True)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 act = menu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
49 UI.PixmapCache.getIcon("vcsAdd"),
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.tr('Add as Large File'),
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 lambda: self.__hgAddLargefiles("large"))
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__addSingleActs.append(act)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 act = menu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
54 UI.PixmapCache.getIcon("vcsAdd"),
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.tr('Add as Normal File'),
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 lambda: self.__hgAddLargefiles("normal"))
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__addSingleActs.append(act)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__menus['mainMenu'] = menu
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 menu = QMenu(self.menuTitle())
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 menu.setTearOffEnabled(True)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 act = menu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
63 UI.PixmapCache.getIcon("vcsAdd"),
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.tr('Add as Large Files'),
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 lambda: self.__hgAddLargefiles("large"))
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.__addMultiActs.append(act)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 act = menu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
68 UI.PixmapCache.getIcon("vcsAdd"),
3313
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.tr('Add as Normal Files'),
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 lambda: self.__hgAddLargefiles("normal"))
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__addMultiActs.append(act)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__menus['multiMenu'] = menu
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 return self.__menus
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 def menuTitle(self):
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 Public method to get the menu title.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Note: Derived class must implement this method.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @return title of the menu (string)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 return self.tr("Large Files")
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 def showExtensionMenu(self, key, controlled):
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 Public method to prepare the extension menu for display.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 @param key menu key (string, one of 'mainMenu', 'multiMenu',
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 'backMenu', 'dirMenu' or 'dirMultiMenu')
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 @param controlled flag indicating to prepare the menu for a
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 version controlled entry or a non-version controlled entry
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 (boolean)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 if key == "mainMenu":
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 for act in self.__addSingleActs:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 act.setEnabled(not controlled)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 elif key == "multiMenu":
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 for act in self.__addMultiActs:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 act.setEnabled(not controlled)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 def __hgAddLargefiles(self, mode):
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 Private slot to add the selected files as large files.
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @param mode add mode (string one of 'normal' or 'large')
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 names = []
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 for itm in self.browser.getSelectedItems():
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 try:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 name = itm.fileName()
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 except AttributeError:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 continue
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 names.append(name)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if names:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 if len(names) == 1:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.vcs.getExtensionObject("largefiles").hgAdd(names[0], mode)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 else:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.vcs.getExtensionObject("largefiles").hgAdd(names, mode)
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 for fn in names:
037642483f35 Implemented the Mercurial largefiles add interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self._updateVCSStatus(fn)

eric ide

mercurial