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