src/eric7/Plugins/VcsPlugins/vcsMercurial/LargefilesExtension/ProjectBrowserHelper.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
16 16
17 class LargefilesProjectBrowserHelper(HgExtensionProjectBrowserHelper): 17 class LargefilesProjectBrowserHelper(HgExtensionProjectBrowserHelper):
18 """ 18 """
19 Class implementing the largefiles extension project browser helper. 19 Class implementing the largefiles extension project browser helper.
20 """ 20 """
21
21 def __init__(self, vcsObject, browserObject, projectObject): 22 def __init__(self, vcsObject, browserObject, projectObject):
22 """ 23 """
23 Constructor 24 Constructor
24 25
25 @param vcsObject reference to the vcs object 26 @param vcsObject reference to the vcs object
26 @param browserObject reference to the project browser object 27 @param browserObject reference to the project browser object
27 @param projectObject reference to the project object 28 @param projectObject reference to the project object
28 """ 29 """
29 super().__init__( 30 super().__init__(vcsObject, browserObject, projectObject)
30 vcsObject, browserObject, projectObject) 31
31
32 def initMenus(self): 32 def initMenus(self):
33 """ 33 """
34 Public method to generate the extension menus. 34 Public method to generate the extension menus.
35 35
36 Note: Derived class must implement this method. 36 Note: Derived class must implement this method.
37 37
38 @return dictionary of populated menu (dict of QMenu). The dict 38 @return dictionary of populated menu (dict of QMenu). The dict
39 must have the keys 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu' 39 must have the keys 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu'
40 and 'dirMultiMenu'. 40 and 'dirMultiMenu'.
41 """ 41 """
42 self.__menus = {} 42 self.__menus = {}
43 self.__addSingleActs = [] 43 self.__addSingleActs = []
44 self.__addMultiActs = [] 44 self.__addMultiActs = []
45 45
46 menu = QMenu(self.menuTitle()) 46 menu = QMenu(self.menuTitle())
47 menu.setTearOffEnabled(True) 47 menu.setTearOffEnabled(True)
48 act = menu.addAction( 48 act = menu.addAction(
49 UI.PixmapCache.getIcon("vcsAdd"), 49 UI.PixmapCache.getIcon("vcsAdd"),
50 self.tr('Add as Large File'), 50 self.tr("Add as Large File"),
51 lambda: self.__hgAddLargefiles("large")) 51 lambda: self.__hgAddLargefiles("large"),
52 )
52 self.__addSingleActs.append(act) 53 self.__addSingleActs.append(act)
53 act = menu.addAction( 54 act = menu.addAction(
54 UI.PixmapCache.getIcon("vcsAdd"), 55 UI.PixmapCache.getIcon("vcsAdd"),
55 self.tr('Add as Normal File'), 56 self.tr("Add as Normal File"),
56 lambda: self.__hgAddLargefiles("normal")) 57 lambda: self.__hgAddLargefiles("normal"),
58 )
57 self.__addSingleActs.append(act) 59 self.__addSingleActs.append(act)
58 self.__menus['mainMenu'] = menu 60 self.__menus["mainMenu"] = menu
59 61
60 menu = QMenu(self.menuTitle()) 62 menu = QMenu(self.menuTitle())
61 menu.setTearOffEnabled(True) 63 menu.setTearOffEnabled(True)
62 act = menu.addAction( 64 act = menu.addAction(
63 UI.PixmapCache.getIcon("vcsAdd"), 65 UI.PixmapCache.getIcon("vcsAdd"),
64 self.tr('Add as Large Files'), 66 self.tr("Add as Large Files"),
65 lambda: self.__hgAddLargefiles("large")) 67 lambda: self.__hgAddLargefiles("large"),
68 )
66 self.__addMultiActs.append(act) 69 self.__addMultiActs.append(act)
67 act = menu.addAction( 70 act = menu.addAction(
68 UI.PixmapCache.getIcon("vcsAdd"), 71 UI.PixmapCache.getIcon("vcsAdd"),
69 self.tr('Add as Normal Files'), 72 self.tr("Add as Normal Files"),
70 lambda: self.__hgAddLargefiles("normal")) 73 lambda: self.__hgAddLargefiles("normal"),
74 )
71 self.__addMultiActs.append(act) 75 self.__addMultiActs.append(act)
72 self.__menus['multiMenu'] = menu 76 self.__menus["multiMenu"] = menu
73 77
74 return self.__menus 78 return self.__menus
75 79
76 def menuTitle(self): 80 def menuTitle(self):
77 """ 81 """
78 Public method to get the menu title. 82 Public method to get the menu title.
79 83
80 Note: Derived class must implement this method. 84 Note: Derived class must implement this method.
81 85
82 @return title of the menu (string) 86 @return title of the menu (string)
83 """ 87 """
84 return self.tr("Large Files") 88 return self.tr("Large Files")
85 89
86 def showExtensionMenu(self, key, controlled): 90 def showExtensionMenu(self, key, controlled):
87 """ 91 """
88 Public method to prepare the extension menu for display. 92 Public method to prepare the extension menu for display.
89 93
90 @param key menu key (string, one of 'mainMenu', 'multiMenu', 94 @param key menu key (string, one of 'mainMenu', 'multiMenu',
91 'backMenu', 'dirMenu' or 'dirMultiMenu') 95 'backMenu', 'dirMenu' or 'dirMultiMenu')
92 @param controlled flag indicating to prepare the menu for a 96 @param controlled flag indicating to prepare the menu for a
93 version controlled entry or a non-version controlled entry 97 version controlled entry or a non-version controlled entry
94 (boolean) 98 (boolean)
97 for act in self.__addSingleActs: 101 for act in self.__addSingleActs:
98 act.setEnabled(not controlled) 102 act.setEnabled(not controlled)
99 elif key == "multiMenu": 103 elif key == "multiMenu":
100 for act in self.__addMultiActs: 104 for act in self.__addMultiActs:
101 act.setEnabled(not controlled) 105 act.setEnabled(not controlled)
102 106
103 def __hgAddLargefiles(self, mode): 107 def __hgAddLargefiles(self, mode):
104 """ 108 """
105 Private slot to add the selected files as large files. 109 Private slot to add the selected files as large files.
106 110
107 @param mode add mode (string one of 'normal' or 'large') 111 @param mode add mode (string one of 'normal' or 'large')
108 """ 112 """
109 names = [] 113 names = []
110 for itm in self.browser.getSelectedItems(): 114 for itm in self.browser.getSelectedItems():
111 try: 115 try:
112 name = itm.fileName() 116 name = itm.fileName()
113 except AttributeError: 117 except AttributeError:
114 continue 118 continue
115 names.append(name) 119 names.append(name)
116 120
117 if names: 121 if names:
118 if len(names) == 1: 122 if len(names) == 1:
119 self.vcs.getExtensionObject("largefiles").hgAdd(names[0], mode) 123 self.vcs.getExtensionObject("largefiles").hgAdd(names[0], mode)
120 else: 124 else:
121 self.vcs.getExtensionObject("largefiles").hgAdd(names, mode) 125 self.vcs.getExtensionObject("largefiles").hgAdd(names, mode)

eric ide

mercurial