VCS/ProjectBrowserHelper.py

changeset 3013
fe886b7f8f40
parent 2965
d133c7edd88a
child 3031
ed2eaa573ca5
child 3057
10516539f238
equal deleted inserted replaced
3012:d177226027e2 3013:fe886b7f8f40
24 24
25 class VcsProjectBrowserHelper(QObject): 25 class VcsProjectBrowserHelper(QObject):
26 """ 26 """
27 Class implementing the base class of the VCS project browser helper. 27 Class implementing the base class of the VCS project browser helper.
28 """ 28 """
29 def __init__(self, vcsObject, browserObject, projectObject, isTranslationsBrowser, 29 def __init__(self, vcsObject, browserObject, projectObject,
30 parent=None, name=None): 30 isTranslationsBrowser, parent=None, name=None):
31 """ 31 """
32 Constructor 32 Constructor
33 33
34 @param vcsObject reference to the vcs object 34 @param vcsObject reference to the vcs object
35 @param browserObject reference to the project browser object 35 @param browserObject reference to the project browser object
36 @param projectObject reference to the project object 36 @param projectObject reference to the project object
37 @param isTranslationsBrowser flag indicating, the helper is requested for the 37 @param isTranslationsBrowser flag indicating, the helper is requested
38 translations browser (this needs some special treatment) 38 for the translations browser (this needs some special treatment)
39 @param parent parent widget (QWidget) 39 @param parent parent widget (QWidget)
40 @param name name of this object (string) 40 @param name name of this object (string)
41 """ 41 """
42 super().__init__(parent) 42 super().__init__(parent)
43 if name: 43 if name:
46 self.vcs = vcsObject 46 self.vcs = vcsObject
47 self.browser = browserObject 47 self.browser = browserObject
48 self.isTranslationsBrowser = isTranslationsBrowser 48 self.isTranslationsBrowser = isTranslationsBrowser
49 self.project = projectObject 49 self.project = projectObject
50 50
51 def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu, dirMultiMenu): 51 def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu,
52 """ 52 dirMultiMenu):
53 Public method to add the VCS entries to the various project browser menus. 53 """
54 Public method to add the VCS entries to the various project browser
55 menus.
54 56
55 @param mainMenu reference to the main menu (QPopupMenu) 57 @param mainMenu reference to the main menu (QPopupMenu)
56 @param multiMenu reference to the multiple selection menu (QPopupMenu) 58 @param multiMenu reference to the multiple selection menu (QPopupMenu)
57 @param backMenu reference to the background menu (QPopupMenu) 59 @param backMenu reference to the background menu (QPopupMenu)
58 @param dirMenu reference to the directory menu (QPopupMenu) 60 @param dirMenu reference to the directory menu (QPopupMenu)
71 73
72 It enables/disables the VCS menu entries depending on the overall 74 It enables/disables the VCS menu entries depending on the overall
73 VCS status and the file status. 75 VCS status and the file status.
74 76
75 @param menu reference to the menu to be shown 77 @param menu reference to the menu to be shown
76 @param standardItems array of standard items that need activation/deactivation 78 @param standardItems array of standard items that need
77 depending on the overall VCS status 79 activation/deactivation depending on the overall VCS status
78 @exception RuntimeError to indicate that this method must be 80 @exception RuntimeError to indicate that this method must be
79 implemented by a subclass 81 implemented by a subclass
80 """ 82 """
81 raise RuntimeError('Not implemented') 83 raise RuntimeError('Not implemented')
82 84
86 88
87 It enables/disables the VCS menu entries depending on the overall 89 It enables/disables the VCS menu entries depending on the overall
88 VCS status and the files status. 90 VCS status and the files status.
89 91
90 @param menu reference to the menu to be shown 92 @param menu reference to the menu to be shown
91 @param standardItems array of standard items that need activation/deactivation 93 @param standardItems array of standard items that need
92 depending on the overall VCS status 94 activation/deactivation depending on the overall VCS status
93 @exception RuntimeError to indicate that this method must be 95 @exception RuntimeError to indicate that this method must be
94 implemented by a subclass 96 implemented by a subclass
95 """ 97 """
96 raise RuntimeError('Not implemented') 98 raise RuntimeError('Not implemented')
97 99
101 103
102 It enables/disables the VCS menu entries depending on the overall 104 It enables/disables the VCS menu entries depending on the overall
103 VCS status and the directory status. 105 VCS status and the directory status.
104 106
105 @param menu reference to the menu to be shown 107 @param menu reference to the menu to be shown
106 @param standardItems array of standard items that need activation/deactivation 108 @param standardItems array of standard items that
107 depending on the overall VCS status 109 need activation/deactivation depending on the overall VCS status
108 @exception RuntimeError to indicate that this method must be 110 @exception RuntimeError to indicate that this method must be
109 implemented by a subclass 111 implemented by a subclass
110 """ 112 """
111 raise RuntimeError('Not implemented') 113 raise RuntimeError('Not implemented')
112 114
116 118
117 It enables/disables the VCS menu entries depending on the overall 119 It enables/disables the VCS menu entries depending on the overall
118 VCS status and the directory status. 120 VCS status and the directory status.
119 121
120 @param menu reference to the menu to be shown 122 @param menu reference to the menu to be shown
121 @param standardItems array of standard items that need activation/deactivation 123 @param standardItems array of standard items that need
122 depending on the overall VCS status 124 activation/deactivation depending on the overall VCS status
123 @exception RuntimeError to indicate that this method must be 125 @exception RuntimeError to indicate that this method must be
124 implemented by a subclass 126 implemented by a subclass
125 """ 127 """
126 raise RuntimeError('Not implemented') 128 raise RuntimeError('Not implemented')
127 129
128 ############################################################################ 130 ###########################################################################
129 ## General menu handling methods below 131 ## General menu handling methods below
130 ############################################################################ 132 ###########################################################################
131 133
132 def _VCSUpdate(self): 134 def _VCSUpdate(self):
133 """ 135 """
134 Protected slot called by the context menu to update a file from the 136 Protected slot called by the context menu to update a file from the
135 VCS repository. 137 VCS repository.
136 """ 138 """
137 if self.isTranslationsBrowser: 139 if self.isTranslationsBrowser:
138 names = [itm.dirName() \ 140 names = [itm.dirName()
139 for itm in self.browser.getSelectedItems( 141 for itm in self.browser.getSelectedItems(
140 [ProjectBrowserSimpleDirectoryItem])] 142 [ProjectBrowserSimpleDirectoryItem])]
141 if not names: 143 if not names:
142 names = [itm.fileName() \ 144 names = [itm.fileName()
143 for itm in self.browser.getSelectedItems([ProjectBrowserFileItem])] 145 for itm in self.browser.getSelectedItems(
146 [ProjectBrowserFileItem])]
144 else: 147 else:
145 names = [] 148 names = []
146 for itm in self.browser.getSelectedItems(): 149 for itm in self.browser.getSelectedItems():
147 try: 150 try:
148 name = itm.fileName() 151 name = itm.fileName()
155 """ 158 """
156 Protected slot called by the context menu to commit the changes to the 159 Protected slot called by the context menu to commit the changes to the
157 VCS repository. 160 VCS repository.
158 """ 161 """
159 if self.isTranslationsBrowser: 162 if self.isTranslationsBrowser:
160 names = [itm.dirName() \ 163 names = [itm.dirName()
161 for itm in self.browser.getSelectedItems( 164 for itm in self.browser.getSelectedItems(
162 [ProjectBrowserSimpleDirectoryItem])] 165 [ProjectBrowserSimpleDirectoryItem])]
163 if not names: 166 if not names:
164 names = [itm.fileName() \ 167 names = [itm.fileName()
165 for itm in self.browser.getSelectedItems([ProjectBrowserFileItem])] 168 for itm in self.browser.getSelectedItems(
169 [ProjectBrowserFileItem])]
166 else: 170 else:
167 names = [] 171 names = []
168 for itm in self.browser.getSelectedItems(): 172 for itm in self.browser.getSelectedItems():
169 try: 173 try:
170 name = itm.fileName() 174 name = itm.fileName()
177 vm.saveEditor(name) 181 vm.saveEditor(name)
178 self.vcs.vcsCommit(names, '') 182 self.vcs.vcsCommit(names, '')
179 183
180 def _VCSAdd(self): 184 def _VCSAdd(self):
181 """ 185 """
182 Protected slot called by the context menu to add the selected file to the 186 Protected slot called by the context menu to add the selected file to
183 VCS repository. 187 the VCS repository.
184 """ 188 """
185 if self.isTranslationsBrowser: 189 if self.isTranslationsBrowser:
186 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) 190 items = self.browser.getSelectedItems(
191 [ProjectBrowserSimpleDirectoryItem])
187 if items: 192 if items:
188 names = [itm.dirName() for itm in items] 193 names = [itm.dirName() for itm in items]
189 qnames = [] 194 qnames = []
190 else: 195 else:
191 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) 196 items = self.browser.getSelectedItems([ProjectBrowserFileItem])
246 for fn in names: 251 for fn in names:
247 self._updateVCSStatus(fn) 252 self._updateVCSStatus(fn)
248 253
249 def _VCSRemove(self): 254 def _VCSRemove(self):
250 """ 255 """
251 Protected slot called by the context menu to remove the selected file from the 256 Protected slot called by the context menu to remove the selected file
252 VCS repository. 257 from the VCS repository.
253 """ 258 """
254 if self.isTranslationsBrowser: 259 if self.isTranslationsBrowser:
255 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) 260 items = self.browser.getSelectedItems(
261 [ProjectBrowserSimpleDirectoryItem])
256 if items: 262 if items:
257 return # not supported 263 return # not supported
258 264
259 isRemoveDirs = False 265 isRemoveDirs = False
260 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) 266 items = self.browser.getSelectedItems([ProjectBrowserFileItem])
261 names = [itm.fileName() for itm in items] 267 names = [itm.fileName() for itm in items]
262 268
263 dlg = DeleteFilesConfirmationDialog(self.parent(), 269 dlg = DeleteFilesConfirmationDialog(self.parent(),
264 self.trUtf8("Remove from repository (and disk)"), 270 self.trUtf8("Remove from repository (and disk)"),
265 self.trUtf8("Do you really want to remove these translation files from" 271 self.trUtf8(
272 "Do you really want to remove these translation files from"
266 " the repository (and disk)?"), 273 " the repository (and disk)?"),
267 names) 274 names)
268 else: 275 else:
269 items = self.browser.getSelectedItems() 276 items = self.browser.getSelectedItems()
270 isRemoveDirs = len(items) == \ 277 isRemoveDirs = len(items) == \
271 self.browser.getSelectedItemsCount( 278 self.browser.getSelectedItemsCount(
272 [ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) 279 [ProjectBrowserSimpleDirectoryItem,
280 ProjectBrowserDirectoryItem])
273 if isRemoveDirs: 281 if isRemoveDirs:
274 names = [itm.dirName() for itm in items] 282 names = [itm.dirName() for itm in items]
275 else: 283 else:
276 names = [itm.fileName() for itm in items] 284 names = [itm.fileName() for itm in items]
277 files = [self.browser.project.getRelativePath(name) \ 285 files = [self.browser.project.getRelativePath(name) \
278 for name in names] 286 for name in names]
279 287
280 dlg = DeleteFilesConfirmationDialog(self.parent(), 288 dlg = DeleteFilesConfirmationDialog(self.parent(),
281 self.trUtf8("Remove from repository (and disk)"), 289 self.trUtf8("Remove from repository (and disk)"),
282 self.trUtf8("Do you really want to remove these files/directories" 290 self.trUtf8(
291 "Do you really want to remove these files/directories"
283 " from the repository (and disk)?"), 292 " from the repository (and disk)?"),
284 files) 293 files)
285 294
286 if dlg.exec_() == QDialog.Accepted: 295 if dlg.exec_() == QDialog.Accepted:
287 status = self.vcs.vcsRemove(names) 296 status = self.vcs.vcsRemove(names)
288 if status: 297 if status:
289 if isRemoveDirs: 298 if isRemoveDirs:
290 self.browser._removeDir() # remove directories from Project 299 self.browser._removeDir() # remove directories from
300 # Project
291 else: 301 else:
292 self.browser._removeFile() # remove file(s) from project 302 self.browser._removeFile() # remove file(s) from project
293 303
294 def _VCSLog(self): 304 def _VCSLog(self):
295 """ 305 """
296 Protected slot called by the context menu to show the VCS log of a file/directory. 306 Protected slot called by the context menu to show the VCS log of a
307 file/directory.
297 """ 308 """
298 itm = self.browser.currentItem() 309 itm = self.browser.currentItem()
299 try: 310 try:
300 fn = itm.fileName() 311 fn = itm.fileName()
301 except AttributeError: 312 except AttributeError:
319 def _VCSStatus(self): 330 def _VCSStatus(self):
320 """ 331 """
321 Protected slot called by the context menu to show the status of a file. 332 Protected slot called by the context menu to show the status of a file.
322 """ 333 """
323 if self.isTranslationsBrowser: 334 if self.isTranslationsBrowser:
324 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) 335 items = self.browser.getSelectedItems(
336 [ProjectBrowserSimpleDirectoryItem])
325 if items: 337 if items:
326 names = [itm.dirName() for itm in items] 338 names = [itm.dirName() for itm in items]
327 else: 339 else:
328 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) 340 items = self.browser.getSelectedItems([ProjectBrowserFileItem])
329 names = [itm.fileName() for itm in items] 341 names = [itm.fileName() for itm in items]
337 names.append(name) 349 names.append(name)
338 self.vcs.vcsStatus(names) 350 self.vcs.vcsStatus(names)
339 351
340 def _VCSRevert(self): 352 def _VCSRevert(self):
341 """ 353 """
342 Protected slot called by the context menu to revert changes made to a file. 354 Protected slot called by the context menu to revert changes made to a
355 file.
343 """ 356 """
344 names = [] 357 names = []
345 for itm in self.browser.getSelectedItems(): 358 for itm in self.browser.getSelectedItems():
346 try: 359 try:
347 name = itm.fileName() 360 name = itm.fileName()
350 names.append(name) 363 names.append(name)
351 self.vcs.vcsRevert(names) 364 self.vcs.vcsRevert(names)
352 365
353 def _VCSMerge(self): 366 def _VCSMerge(self):
354 """ 367 """
355 Protected slot called by the context menu to merge changes into to a file. 368 Protected slot called by the context menu to merge changes into to a
369 file.
356 """ 370 """
357 itm = self.browser.currentItem() 371 itm = self.browser.currentItem()
358 try: 372 try:
359 name = itm.fileName() 373 name = itm.fileName()
360 except AttributeError: 374 except AttributeError:
372 386
373 def _updateVCSStatus(self, name): 387 def _updateVCSStatus(self, name):
374 """ 388 """
375 Protected method to update the VCS status of an item. 389 Protected method to update the VCS status of an item.
376 390
377 @param name filename or directoryname of the item to be updated (string) 391 @param name filename or directoryname of the item to be updated
392 (string)
378 """ 393 """
379 self.project.getModel().updateVCSStatus(name) 394 self.project.getModel().updateVCSStatus(name)

eric ide

mercurial