src/eric7/Plugins/VcsPlugins/vcsGit/ProjectBrowserHelper.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
22 22
23 class GitProjectBrowserHelper(VcsProjectBrowserHelper): 23 class GitProjectBrowserHelper(VcsProjectBrowserHelper):
24 """ 24 """
25 Class implementing the VCS project browser helper for Git. 25 Class implementing the VCS project browser helper for Git.
26 """ 26 """
27 def __init__(self, vcsObject, browserObject, projectObject, 27
28 isTranslationsBrowser, parent=None, name=None): 28 def __init__(
29 self,
30 vcsObject,
31 browserObject,
32 projectObject,
33 isTranslationsBrowser,
34 parent=None,
35 name=None,
36 ):
29 """ 37 """
30 Constructor 38 Constructor
31 39
32 @param vcsObject reference to the vcs object 40 @param vcsObject reference to the vcs object
33 @param browserObject reference to the project browser object 41 @param browserObject reference to the project browser object
34 @param projectObject reference to the project object 42 @param projectObject reference to the project object
35 @param isTranslationsBrowser flag indicating, the helper is requested 43 @param isTranslationsBrowser flag indicating, the helper is requested
36 for the translations browser (this needs some special treatment) 44 for the translations browser (this needs some special treatment)
37 @param parent parent widget (QWidget) 45 @param parent parent widget (QWidget)
38 @param name name of this object (string) 46 @param name name of this object (string)
39 """ 47 """
40 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject, 48 VcsProjectBrowserHelper.__init__(
41 projectObject, isTranslationsBrowser, 49 self,
42 parent, name) 50 vcsObject,
43 51 browserObject,
52 projectObject,
53 isTranslationsBrowser,
54 parent,
55 name,
56 )
57
44 def showContextMenu(self, menu, standardItems): 58 def showContextMenu(self, menu, standardItems):
45 """ 59 """
46 Public slot called before the context menu is shown. 60 Public slot called before the context menu is shown.
47 61
48 It enables/disables the VCS menu entries depending on the overall 62 It enables/disables the VCS menu entries depending on the overall
49 VCS status and the file status. 63 VCS status and the file status.
50 64
51 @param menu reference to the menu to be shown 65 @param menu reference to the menu to be shown
52 @param standardItems array of standard items that need 66 @param standardItems array of standard items that need
53 activation/deactivation depending on the overall VCS status 67 activation/deactivation depending on the overall VCS status
54 """ 68 """
55 if self.browser.currentItem().data(1) == self.vcs.vcsName(): 69 if self.browser.currentItem().data(1) == self.vcs.vcsName():
60 else: 74 else:
61 for act in self.vcsMenuActions: 75 for act in self.vcsMenuActions:
62 act.setEnabled(False) 76 act.setEnabled(False)
63 for act in standardItems: 77 for act in standardItems:
64 act.setEnabled(True) 78 act.setEnabled(True)
65 79
66 def showContextMenuMulti(self, menu, standardItems): 80 def showContextMenuMulti(self, menu, standardItems):
67 """ 81 """
68 Public slot called before the context menu (multiple selections) is 82 Public slot called before the context menu (multiple selections) is
69 shown. 83 shown.
70 84
71 It enables/disables the VCS menu entries depending on the overall 85 It enables/disables the VCS menu entries depending on the overall
72 VCS status and the files status. 86 VCS status and the files status.
73 87
74 @param menu reference to the menu to be shown 88 @param menu reference to the menu to be shown
75 @param standardItems array of standard items that need 89 @param standardItems array of standard items that need
76 activation/deactivation depending on the overall VCS status 90 activation/deactivation depending on the overall VCS status
77 """ 91 """
78 vcsName = self.vcs.vcsName() 92 vcsName = self.vcs.vcsName()
80 vcsItems = 0 94 vcsItems = 0
81 # determine number of selected items under VCS control 95 # determine number of selected items under VCS control
82 for itm in items: 96 for itm in items:
83 if itm.data(1) == vcsName: 97 if itm.data(1) == vcsName:
84 vcsItems += 1 98 vcsItems += 1
85 99
86 if vcsItems > 0: 100 if vcsItems > 0:
87 if vcsItems != len(items): 101 if vcsItems != len(items):
88 for act in self.vcsMultiMenuActions: 102 for act in self.vcsMultiMenuActions:
89 act.setEnabled(False) 103 act.setEnabled(False)
90 else: 104 else:
95 else: 109 else:
96 for act in self.vcsMultiMenuActions: 110 for act in self.vcsMultiMenuActions:
97 act.setEnabled(False) 111 act.setEnabled(False)
98 for act in standardItems: 112 for act in standardItems:
99 act.setEnabled(True) 113 act.setEnabled(True)
100 114
101 def showContextMenuDir(self, menu, standardItems): 115 def showContextMenuDir(self, menu, standardItems):
102 """ 116 """
103 Public slot called before the context menu is shown. 117 Public slot called before the context menu is shown.
104 118
105 It enables/disables the VCS menu entries depending on the overall 119 It enables/disables the VCS menu entries depending on the overall
106 VCS status and the directory status. 120 VCS status and the directory status.
107 121
108 @param menu reference to the menu to be shown 122 @param menu reference to the menu to be shown
109 @param standardItems array of standard items that need 123 @param standardItems array of standard items that need
110 activation/deactivation depending on the overall VCS status 124 activation/deactivation depending on the overall VCS status
111 """ 125 """
112 if self.browser.currentItem().data(1) == self.vcs.vcsName(): 126 if self.browser.currentItem().data(1) == self.vcs.vcsName():
117 else: 131 else:
118 for act in self.vcsDirMenuActions: 132 for act in self.vcsDirMenuActions:
119 act.setEnabled(False) 133 act.setEnabled(False)
120 for act in standardItems: 134 for act in standardItems:
121 act.setEnabled(True) 135 act.setEnabled(True)
122 136
123 def showContextMenuDirMulti(self, menu, standardItems): 137 def showContextMenuDirMulti(self, menu, standardItems):
124 """ 138 """
125 Public slot called before the context menu is shown. 139 Public slot called before the context menu is shown.
126 140
127 It enables/disables the VCS menu entries depending on the overall 141 It enables/disables the VCS menu entries depending on the overall
128 VCS status and the directory status. 142 VCS status and the directory status.
129 143
130 @param menu reference to the menu to be shown 144 @param menu reference to the menu to be shown
131 @param standardItems array of standard items that need 145 @param standardItems array of standard items that need
132 activation/deactivation depending on the overall VCS status 146 activation/deactivation depending on the overall VCS status
133 """ 147 """
134 vcsName = self.vcs.vcsName() 148 vcsName = self.vcs.vcsName()
136 vcsItems = 0 150 vcsItems = 0
137 # determine number of selected items under VCS control 151 # determine number of selected items under VCS control
138 for itm in items: 152 for itm in items:
139 if itm.data(1) == vcsName: 153 if itm.data(1) == vcsName:
140 vcsItems += 1 154 vcsItems += 1
141 155
142 if vcsItems > 0: 156 if vcsItems > 0:
143 if vcsItems != len(items): 157 if vcsItems != len(items):
144 for act in self.vcsDirMultiMenuActions: 158 for act in self.vcsDirMultiMenuActions:
145 act.setEnabled(False) 159 act.setEnabled(False)
146 else: 160 else:
151 else: 165 else:
152 for act in self.vcsDirMultiMenuActions: 166 for act in self.vcsDirMultiMenuActions:
153 act.setEnabled(False) 167 act.setEnabled(False)
154 for act in standardItems: 168 for act in standardItems:
155 act.setEnabled(True) 169 act.setEnabled(True)
156 170
157 ########################################################################### 171 ###########################################################################
158 ## Protected menu generation methods below 172 ## Protected menu generation methods below
159 ########################################################################### 173 ###########################################################################
160 174
161 def _addVCSMenu(self, mainMenu): 175 def _addVCSMenu(self, mainMenu):
162 """ 176 """
163 Protected method used to add the VCS menu to all project browsers. 177 Protected method used to add the VCS menu to all project browsers.
164 178
165 @param mainMenu reference to the menu to be amended 179 @param mainMenu reference to the menu to be amended
166 """ 180 """
167 self.vcsMenuActions = [] 181 self.vcsMenuActions = []
168 self.vcsAddMenuActions = [] 182 self.vcsAddMenuActions = []
169 183
170 menu = QMenu(self.tr("Version Control")) 184 menu = QMenu(self.tr("Version Control"))
171 185
172 act = menu.addAction( 186 act = menu.addAction(
173 UI.PixmapCache.getIcon( 187 UI.PixmapCache.getIcon(
174 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")), 188 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")
175 self.vcs.vcsName(), self._VCSInfoDisplay) 189 ),
190 self.vcs.vcsName(),
191 self._VCSInfoDisplay,
192 )
176 font = act.font() 193 font = act.font()
177 font.setBold(True) 194 font.setBold(True)
178 act.setFont(font) 195 act.setFont(font)
179 menu.addSeparator() 196 menu.addSeparator()
180 197
181 act = menu.addAction( 198 act = menu.addAction(
182 UI.PixmapCache.getIcon("vcsCommit"), 199 UI.PixmapCache.getIcon("vcsCommit"),
183 self.tr('Commit changes to repository...'), 200 self.tr("Commit changes to repository..."),
184 self._VCSCommit) 201 self._VCSCommit,
202 )
185 self.vcsMenuActions.append(act) 203 self.vcsMenuActions.append(act)
186 menu.addSeparator() 204 menu.addSeparator()
187 act = menu.addAction( 205 act = menu.addAction(
188 UI.PixmapCache.getIcon("vcsAdd"), 206 UI.PixmapCache.getIcon("vcsAdd"),
189 self.tr('Add/Stage to repository'), 207 self.tr("Add/Stage to repository"),
190 self._VCSAdd) 208 self._VCSAdd,
209 )
191 act = menu.addAction( 210 act = menu.addAction(
192 UI.PixmapCache.getIcon("vcsRevert"), 211 UI.PixmapCache.getIcon("vcsRevert"),
193 self.tr('Unstage changes'), 212 self.tr("Unstage changes"),
194 self.__GitUnstage) 213 self.__GitUnstage,
214 )
195 self.vcsMenuActions.append(act) 215 self.vcsMenuActions.append(act)
196 menu.addSeparator() 216 menu.addSeparator()
197 act = menu.addAction( 217 act = menu.addAction(
198 UI.PixmapCache.getIcon("vcsRemove"), 218 UI.PixmapCache.getIcon("vcsRemove"),
199 self.tr('Remove from repository (and disk)'), 219 self.tr("Remove from repository (and disk)"),
200 self._VCSRemove) 220 self._VCSRemove,
221 )
201 self.vcsMenuActions.append(act) 222 self.vcsMenuActions.append(act)
202 act = menu.addAction( 223 act = menu.addAction(
203 UI.PixmapCache.getIcon("vcsRemove"), 224 UI.PixmapCache.getIcon("vcsRemove"),
204 self.tr('Remove from repository only'), 225 self.tr("Remove from repository only"),
205 self.__GitForget) 226 self.__GitForget,
206 self.vcsMenuActions.append(act) 227 )
207 menu.addSeparator() 228 self.vcsMenuActions.append(act)
208 act = menu.addAction(self.tr('Copy'), self.__GitCopy) 229 menu.addSeparator()
209 self.vcsMenuActions.append(act) 230 act = menu.addAction(self.tr("Copy"), self.__GitCopy)
210 act = menu.addAction(self.tr('Move'), self.__GitMove) 231 self.vcsMenuActions.append(act)
232 act = menu.addAction(self.tr("Move"), self.__GitMove)
211 self.vcsMenuActions.append(act) 233 self.vcsMenuActions.append(act)
212 menu.addSeparator() 234 menu.addSeparator()
213 act = menu.addAction( 235 act = menu.addAction(
214 UI.PixmapCache.getIcon("vcsLog"), 236 UI.PixmapCache.getIcon("vcsLog"),
215 self.tr('Show log browser'), self._VCSLogBrowser) 237 self.tr("Show log browser"),
216 self.vcsMenuActions.append(act) 238 self._VCSLogBrowser,
217 menu.addSeparator() 239 )
218 act = menu.addAction( 240 self.vcsMenuActions.append(act)
219 UI.PixmapCache.getIcon("vcsStatus"), 241 menu.addSeparator()
220 self.tr('Show status'), self._VCSStatus) 242 act = menu.addAction(
243 UI.PixmapCache.getIcon("vcsStatus"), self.tr("Show status"), self._VCSStatus
244 )
221 self.vcsMenuActions.append(act) 245 self.vcsMenuActions.append(act)
222 menu.addSeparator() 246 menu.addSeparator()
223 act = menu.addAction( 247 act = menu.addAction(
224 UI.PixmapCache.getIcon("vcsDiff"), 248 UI.PixmapCache.getIcon("vcsDiff"),
225 self.tr('Show differences'), self._VCSDiff) 249 self.tr("Show differences"),
250 self._VCSDiff,
251 )
226 self.vcsMenuActions.append(act) 252 self.vcsMenuActions.append(act)
227 act = menu.addAction( 253 act = menu.addAction(
228 UI.PixmapCache.getIcon("vcsSbsDiff"), 254 UI.PixmapCache.getIcon("vcsSbsDiff"),
229 self.tr('Show differences side-by-side'), self.__GitSbsDiff) 255 self.tr("Show differences side-by-side"),
256 self.__GitSbsDiff,
257 )
230 self.vcsMenuActions.append(act) 258 self.vcsMenuActions.append(act)
231 act = menu.addAction( 259 act = menu.addAction(
232 UI.PixmapCache.getIcon("vcsDiff"), 260 UI.PixmapCache.getIcon("vcsDiff"),
233 self.tr('Show differences (extended)'), 261 self.tr("Show differences (extended)"),
234 self.__GitExtendedDiff) 262 self.__GitExtendedDiff,
263 )
235 self.vcsMenuActions.append(act) 264 self.vcsMenuActions.append(act)
236 act = menu.addAction( 265 act = menu.addAction(
237 UI.PixmapCache.getIcon("vcsSbsDiff"), 266 UI.PixmapCache.getIcon("vcsSbsDiff"),
238 self.tr('Show differences side-by-side (extended)'), 267 self.tr("Show differences side-by-side (extended)"),
239 self.__GitSbsExtendedDiff) 268 self.__GitSbsExtendedDiff,
269 )
240 self.vcsMenuActions.append(act) 270 self.vcsMenuActions.append(act)
241 menu.addSeparator() 271 menu.addSeparator()
242 self.annotateAct = menu.addAction( 272 self.annotateAct = menu.addAction(
243 self.tr('Show annotated file'), 273 self.tr("Show annotated file"), self.__GitBlame
244 self.__GitBlame) 274 )
245 self.vcsMenuActions.append(self.annotateAct) 275 self.vcsMenuActions.append(self.annotateAct)
246 menu.addSeparator() 276 menu.addSeparator()
247 act = menu.addAction( 277 act = menu.addAction(
248 UI.PixmapCache.getIcon("vcsRevert"), 278 UI.PixmapCache.getIcon("vcsRevert"),
249 self.tr('Revert changes'), self.__GitRevert) 279 self.tr("Revert changes"),
250 self.vcsMenuActions.append(act) 280 self.__GitRevert,
251 menu.addSeparator() 281 )
252 menu.addAction(self.tr('Select all local file entries'), 282 self.vcsMenuActions.append(act)
253 self.browser.selectLocalEntries) 283 menu.addSeparator()
254 menu.addAction(self.tr('Select all versioned file entries'), 284 menu.addAction(
255 self.browser.selectVCSEntries) 285 self.tr("Select all local file entries"), self.browser.selectLocalEntries
256 menu.addAction(self.tr('Select all local directory entries'), 286 )
257 self.browser.selectLocalDirEntries) 287 menu.addAction(
258 menu.addAction(self.tr('Select all versioned directory entries'), 288 self.tr("Select all versioned file entries"), self.browser.selectVCSEntries
259 self.browser.selectVCSDirEntries) 289 )
290 menu.addAction(
291 self.tr("Select all local directory entries"),
292 self.browser.selectLocalDirEntries,
293 )
294 menu.addAction(
295 self.tr("Select all versioned directory entries"),
296 self.browser.selectVCSDirEntries,
297 )
260 menu.addSeparator() 298 menu.addSeparator()
261 menu.addAction(self.tr("Configure..."), self.__GitConfigure) 299 menu.addAction(self.tr("Configure..."), self.__GitConfigure)
262 300
263 mainMenu.addSeparator() 301 mainMenu.addSeparator()
264 mainMenu.addMenu(menu) 302 mainMenu.addMenu(menu)
265 self.menu = menu 303 self.menu = menu
266 304
267 def _addVCSMenuMulti(self, mainMenu): 305 def _addVCSMenuMulti(self, mainMenu):
268 """ 306 """
269 Protected method used to add the VCS menu for multi selection to all 307 Protected method used to add the VCS menu for multi selection to all
270 project browsers. 308 project browsers.
271 309
272 @param mainMenu reference to the menu to be amended 310 @param mainMenu reference to the menu to be amended
273 """ 311 """
274 self.vcsMultiMenuActions = [] 312 self.vcsMultiMenuActions = []
275 313
276 menu = QMenu(self.tr("Version Control")) 314 menu = QMenu(self.tr("Version Control"))
277 315
278 act = menu.addAction( 316 act = menu.addAction(
279 UI.PixmapCache.getIcon( 317 UI.PixmapCache.getIcon(
280 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")), 318 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")
281 self.vcs.vcsName(), self._VCSInfoDisplay) 319 ),
320 self.vcs.vcsName(),
321 self._VCSInfoDisplay,
322 )
282 font = act.font() 323 font = act.font()
283 font.setBold(True) 324 font.setBold(True)
284 act.setFont(font) 325 act.setFont(font)
285 menu.addSeparator() 326 menu.addSeparator()
286 327
287 act = menu.addAction( 328 act = menu.addAction(
288 UI.PixmapCache.getIcon("vcsCommit"), 329 UI.PixmapCache.getIcon("vcsCommit"),
289 self.tr('Commit changes to repository...'), 330 self.tr("Commit changes to repository..."),
290 self._VCSCommit) 331 self._VCSCommit,
332 )
291 self.vcsMultiMenuActions.append(act) 333 self.vcsMultiMenuActions.append(act)
292 menu.addSeparator() 334 menu.addSeparator()
293 act = menu.addAction( 335 act = menu.addAction(
294 UI.PixmapCache.getIcon("vcsAdd"), 336 UI.PixmapCache.getIcon("vcsAdd"),
295 self.tr('Add/Stage to repository'), self._VCSAdd) 337 self.tr("Add/Stage to repository"),
338 self._VCSAdd,
339 )
296 act = menu.addAction( 340 act = menu.addAction(
297 UI.PixmapCache.getIcon("vcsRevert"), 341 UI.PixmapCache.getIcon("vcsRevert"),
298 self.tr('Unstage changes'), 342 self.tr("Unstage changes"),
299 self.__GitUnstage) 343 self.__GitUnstage,
344 )
300 self.vcsMultiMenuActions.append(act) 345 self.vcsMultiMenuActions.append(act)
301 menu.addSeparator() 346 menu.addSeparator()
302 act = menu.addAction( 347 act = menu.addAction(
303 UI.PixmapCache.getIcon("vcsRemove"), 348 UI.PixmapCache.getIcon("vcsRemove"),
304 self.tr('Remove from repository (and disk)'), 349 self.tr("Remove from repository (and disk)"),
305 self._VCSRemove) 350 self._VCSRemove,
351 )
306 self.vcsMultiMenuActions.append(act) 352 self.vcsMultiMenuActions.append(act)
307 act = menu.addAction( 353 act = menu.addAction(
308 UI.PixmapCache.getIcon("vcsRemove"), 354 UI.PixmapCache.getIcon("vcsRemove"),
309 self.tr('Remove from repository only'), 355 self.tr("Remove from repository only"),
310 self.__GitForget) 356 self.__GitForget,
357 )
311 self.vcsMultiMenuActions.append(act) 358 self.vcsMultiMenuActions.append(act)
312 menu.addSeparator() 359 menu.addSeparator()
313 act = menu.addAction( 360 act = menu.addAction(
314 UI.PixmapCache.getIcon("vcsStatus"), 361 UI.PixmapCache.getIcon("vcsStatus"), self.tr("Show status"), self._VCSStatus
315 self.tr('Show status'), self._VCSStatus) 362 )
316 self.vcsMultiMenuActions.append(act) 363 self.vcsMultiMenuActions.append(act)
317 menu.addSeparator() 364 menu.addSeparator()
318 act = menu.addAction( 365 act = menu.addAction(
319 UI.PixmapCache.getIcon("vcsDiff"), 366 UI.PixmapCache.getIcon("vcsDiff"),
320 self.tr('Show differences'), self._VCSDiff) 367 self.tr("Show differences"),
368 self._VCSDiff,
369 )
321 self.vcsMultiMenuActions.append(act) 370 self.vcsMultiMenuActions.append(act)
322 act = menu.addAction( 371 act = menu.addAction(
323 UI.PixmapCache.getIcon("vcsDiff"), 372 UI.PixmapCache.getIcon("vcsDiff"),
324 self.tr('Show differences (extended)'), 373 self.tr("Show differences (extended)"),
325 self.__GitExtendedDiff) 374 self.__GitExtendedDiff,
375 )
326 self.vcsMultiMenuActions.append(act) 376 self.vcsMultiMenuActions.append(act)
327 menu.addSeparator() 377 menu.addSeparator()
328 act = menu.addAction( 378 act = menu.addAction(
329 UI.PixmapCache.getIcon("vcsRevert"), 379 UI.PixmapCache.getIcon("vcsRevert"),
330 self.tr('Revert changes'), self.__GitRevert) 380 self.tr("Revert changes"),
381 self.__GitRevert,
382 )
331 self.vcsMultiMenuActions.append(act) 383 self.vcsMultiMenuActions.append(act)
332 menu.addSeparator() 384 menu.addSeparator()
333 385
334 menu.addSeparator() 386 menu.addSeparator()
335 menu.addAction(self.tr('Select all local file entries'), 387 menu.addAction(
336 self.browser.selectLocalEntries) 388 self.tr("Select all local file entries"), self.browser.selectLocalEntries
337 menu.addAction(self.tr('Select all versioned file entries'), 389 )
338 self.browser.selectVCSEntries) 390 menu.addAction(
339 menu.addAction(self.tr('Select all local directory entries'), 391 self.tr("Select all versioned file entries"), self.browser.selectVCSEntries
340 self.browser.selectLocalDirEntries) 392 )
341 menu.addAction(self.tr('Select all versioned directory entries'), 393 menu.addAction(
342 self.browser.selectVCSDirEntries) 394 self.tr("Select all local directory entries"),
395 self.browser.selectLocalDirEntries,
396 )
397 menu.addAction(
398 self.tr("Select all versioned directory entries"),
399 self.browser.selectVCSDirEntries,
400 )
343 menu.addSeparator() 401 menu.addSeparator()
344 menu.addAction(self.tr("Configure..."), self.__GitConfigure) 402 menu.addAction(self.tr("Configure..."), self.__GitConfigure)
345 403
346 mainMenu.addSeparator() 404 mainMenu.addSeparator()
347 mainMenu.addMenu(menu) 405 mainMenu.addMenu(menu)
348 self.menuMulti = menu 406 self.menuMulti = menu
349 407
350 def _addVCSMenuBack(self, mainMenu): 408 def _addVCSMenuBack(self, mainMenu):
351 """ 409 """
352 Protected method used to add the VCS menu to all project browsers. 410 Protected method used to add the VCS menu to all project browsers.
353 411
354 @param mainMenu reference to the menu to be amended 412 @param mainMenu reference to the menu to be amended
355 """ 413 """
356 menu = QMenu(self.tr("Version Control")) 414 menu = QMenu(self.tr("Version Control"))
357 415
358 act = menu.addAction( 416 act = menu.addAction(
359 UI.PixmapCache.getIcon( 417 UI.PixmapCache.getIcon(
360 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")), 418 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")
361 self.vcs.vcsName(), self._VCSInfoDisplay) 419 ),
420 self.vcs.vcsName(),
421 self._VCSInfoDisplay,
422 )
362 font = act.font() 423 font = act.font()
363 font.setBold(True) 424 font.setBold(True)
364 act.setFont(font) 425 act.setFont(font)
365 menu.addSeparator() 426 menu.addSeparator()
366 427
367 menu.addAction(self.tr('Select all local file entries'), 428 menu.addAction(
368 self.browser.selectLocalEntries) 429 self.tr("Select all local file entries"), self.browser.selectLocalEntries
369 menu.addAction(self.tr('Select all versioned file entries'), 430 )
370 self.browser.selectVCSEntries) 431 menu.addAction(
371 menu.addAction(self.tr('Select all local directory entries'), 432 self.tr("Select all versioned file entries"), self.browser.selectVCSEntries
372 self.browser.selectLocalDirEntries) 433 )
373 menu.addAction(self.tr('Select all versioned directory entries'), 434 menu.addAction(
374 self.browser.selectVCSDirEntries) 435 self.tr("Select all local directory entries"),
436 self.browser.selectLocalDirEntries,
437 )
438 menu.addAction(
439 self.tr("Select all versioned directory entries"),
440 self.browser.selectVCSDirEntries,
441 )
375 menu.addSeparator() 442 menu.addSeparator()
376 menu.addAction(self.tr("Configure..."), self.__GitConfigure) 443 menu.addAction(self.tr("Configure..."), self.__GitConfigure)
377 444
378 mainMenu.addSeparator() 445 mainMenu.addSeparator()
379 mainMenu.addMenu(menu) 446 mainMenu.addMenu(menu)
380 self.menuBack = menu 447 self.menuBack = menu
381 448
382 def _addVCSMenuDir(self, mainMenu): 449 def _addVCSMenuDir(self, mainMenu):
383 """ 450 """
384 Protected method used to add the VCS menu to all project browsers. 451 Protected method used to add the VCS menu to all project browsers.
385 452
386 @param mainMenu reference to the menu to be amended 453 @param mainMenu reference to the menu to be amended
387 """ 454 """
388 if mainMenu is None: 455 if mainMenu is None:
389 return 456 return
390 457
391 self.vcsDirMenuActions = [] 458 self.vcsDirMenuActions = []
392 self.vcsAddDirMenuActions = [] 459 self.vcsAddDirMenuActions = []
393 460
394 menu = QMenu(self.tr("Version Control")) 461 menu = QMenu(self.tr("Version Control"))
395 462
396 act = menu.addAction( 463 act = menu.addAction(
397 UI.PixmapCache.getIcon( 464 UI.PixmapCache.getIcon(
398 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")), 465 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")
399 self.vcs.vcsName(), self._VCSInfoDisplay) 466 ),
467 self.vcs.vcsName(),
468 self._VCSInfoDisplay,
469 )
400 font = act.font() 470 font = act.font()
401 font.setBold(True) 471 font.setBold(True)
402 act.setFont(font) 472 act.setFont(font)
403 menu.addSeparator() 473 menu.addSeparator()
404 474
405 act = menu.addAction( 475 act = menu.addAction(
406 UI.PixmapCache.getIcon("vcsCommit"), 476 UI.PixmapCache.getIcon("vcsCommit"),
407 self.tr('Commit changes to repository...'), 477 self.tr("Commit changes to repository..."),
408 self._VCSCommit) 478 self._VCSCommit,
479 )
409 self.vcsDirMenuActions.append(act) 480 self.vcsDirMenuActions.append(act)
410 menu.addSeparator() 481 menu.addSeparator()
411 act = menu.addAction( 482 act = menu.addAction(
412 UI.PixmapCache.getIcon("vcsAdd"), 483 UI.PixmapCache.getIcon("vcsAdd"),
413 self.tr('Add/Stage to repository'), self._VCSAdd) 484 self.tr("Add/Stage to repository"),
485 self._VCSAdd,
486 )
414 act = menu.addAction( 487 act = menu.addAction(
415 UI.PixmapCache.getIcon("vcsRevert"), 488 UI.PixmapCache.getIcon("vcsRevert"),
416 self.tr('Unstage changes'), 489 self.tr("Unstage changes"),
417 self.__GitUnstage) 490 self.__GitUnstage,
491 )
418 self.vcsDirMenuActions.append(act) 492 self.vcsDirMenuActions.append(act)
419 menu.addSeparator() 493 menu.addSeparator()
420 act = menu.addAction( 494 act = menu.addAction(
421 UI.PixmapCache.getIcon("vcsRemove"), 495 UI.PixmapCache.getIcon("vcsRemove"),
422 self.tr('Remove from repository (and disk)'), 496 self.tr("Remove from repository (and disk)"),
423 self._VCSRemove) 497 self._VCSRemove,
424 self.vcsDirMenuActions.append(act) 498 )
425 menu.addSeparator() 499 self.vcsDirMenuActions.append(act)
426 act = menu.addAction(self.tr('Copy'), self.__GitCopy) 500 menu.addSeparator()
427 self.vcsDirMenuActions.append(act) 501 act = menu.addAction(self.tr("Copy"), self.__GitCopy)
428 act = menu.addAction(self.tr('Move'), self.__GitMove) 502 self.vcsDirMenuActions.append(act)
503 act = menu.addAction(self.tr("Move"), self.__GitMove)
429 self.vcsDirMenuActions.append(act) 504 self.vcsDirMenuActions.append(act)
430 menu.addSeparator() 505 menu.addSeparator()
431 act = menu.addAction( 506 act = menu.addAction(
432 UI.PixmapCache.getIcon("vcsLog"), 507 UI.PixmapCache.getIcon("vcsLog"),
433 self.tr('Show log browser'), self._VCSLogBrowser) 508 self.tr("Show log browser"),
434 self.vcsDirMenuActions.append(act) 509 self._VCSLogBrowser,
435 menu.addSeparator() 510 )
436 act = menu.addAction( 511 self.vcsDirMenuActions.append(act)
437 UI.PixmapCache.getIcon("vcsStatus"), 512 menu.addSeparator()
438 self.tr('Show status'), self._VCSStatus) 513 act = menu.addAction(
514 UI.PixmapCache.getIcon("vcsStatus"), self.tr("Show status"), self._VCSStatus
515 )
439 self.vcsDirMenuActions.append(act) 516 self.vcsDirMenuActions.append(act)
440 menu.addSeparator() 517 menu.addSeparator()
441 act = menu.addAction( 518 act = menu.addAction(
442 UI.PixmapCache.getIcon("vcsDiff"), 519 UI.PixmapCache.getIcon("vcsDiff"),
443 self.tr('Show differences'), self._VCSDiff) 520 self.tr("Show differences"),
521 self._VCSDiff,
522 )
444 self.vcsDirMenuActions.append(act) 523 self.vcsDirMenuActions.append(act)
445 act = menu.addAction( 524 act = menu.addAction(
446 UI.PixmapCache.getIcon("vcsDiff"), 525 UI.PixmapCache.getIcon("vcsDiff"),
447 self.tr('Show differences (extended)'), 526 self.tr("Show differences (extended)"),
448 self.__GitExtendedDiff) 527 self.__GitExtendedDiff,
528 )
449 self.vcsDirMenuActions.append(act) 529 self.vcsDirMenuActions.append(act)
450 menu.addSeparator() 530 menu.addSeparator()
451 act = menu.addAction( 531 act = menu.addAction(
452 UI.PixmapCache.getIcon("vcsRevert"), 532 UI.PixmapCache.getIcon("vcsRevert"),
453 self.tr('Revert changes'), self.__GitRevert) 533 self.tr("Revert changes"),
454 self.vcsDirMenuActions.append(act) 534 self.__GitRevert,
455 menu.addSeparator() 535 )
456 536 self.vcsDirMenuActions.append(act)
457 menu.addSeparator() 537 menu.addSeparator()
458 menu.addAction(self.tr('Select all local file entries'), 538
459 self.browser.selectLocalEntries) 539 menu.addSeparator()
460 menu.addAction(self.tr('Select all versioned file entries'), 540 menu.addAction(
461 self.browser.selectVCSEntries) 541 self.tr("Select all local file entries"), self.browser.selectLocalEntries
462 menu.addAction(self.tr('Select all local directory entries'), 542 )
463 self.browser.selectLocalDirEntries) 543 menu.addAction(
464 menu.addAction(self.tr('Select all versioned directory entries'), 544 self.tr("Select all versioned file entries"), self.browser.selectVCSEntries
465 self.browser.selectVCSDirEntries) 545 )
546 menu.addAction(
547 self.tr("Select all local directory entries"),
548 self.browser.selectLocalDirEntries,
549 )
550 menu.addAction(
551 self.tr("Select all versioned directory entries"),
552 self.browser.selectVCSDirEntries,
553 )
466 menu.addSeparator() 554 menu.addSeparator()
467 menu.addAction(self.tr("Configure..."), self.__GitConfigure) 555 menu.addAction(self.tr("Configure..."), self.__GitConfigure)
468 556
469 mainMenu.addSeparator() 557 mainMenu.addSeparator()
470 mainMenu.addMenu(menu) 558 mainMenu.addMenu(menu)
471 self.menuDir = menu 559 self.menuDir = menu
472 560
473 def _addVCSMenuDirMulti(self, mainMenu): 561 def _addVCSMenuDirMulti(self, mainMenu):
474 """ 562 """
475 Protected method used to add the VCS menu to all project browsers. 563 Protected method used to add the VCS menu to all project browsers.
476 564
477 @param mainMenu reference to the menu to be amended 565 @param mainMenu reference to the menu to be amended
478 """ 566 """
479 if mainMenu is None: 567 if mainMenu is None:
480 return 568 return
481 569
482 self.vcsDirMultiMenuActions = [] 570 self.vcsDirMultiMenuActions = []
483 571
484 menu = QMenu(self.tr("Version Control")) 572 menu = QMenu(self.tr("Version Control"))
485 573
486 act = menu.addAction( 574 act = menu.addAction(
487 UI.PixmapCache.getIcon( 575 UI.PixmapCache.getIcon(
488 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")), 576 os.path.join("VcsPlugins", "vcsGit", "icons", "git.svg")
489 self.vcs.vcsName(), self._VCSInfoDisplay) 577 ),
578 self.vcs.vcsName(),
579 self._VCSInfoDisplay,
580 )
490 font = act.font() 581 font = act.font()
491 font.setBold(True) 582 font.setBold(True)
492 act.setFont(font) 583 act.setFont(font)
493 menu.addSeparator() 584 menu.addSeparator()
494 585
495 act = menu.addAction( 586 act = menu.addAction(
496 UI.PixmapCache.getIcon("vcsCommit"), 587 UI.PixmapCache.getIcon("vcsCommit"),
497 self.tr('Commit changes to repository...'), 588 self.tr("Commit changes to repository..."),
498 self._VCSCommit) 589 self._VCSCommit,
590 )
499 self.vcsDirMultiMenuActions.append(act) 591 self.vcsDirMultiMenuActions.append(act)
500 menu.addSeparator() 592 menu.addSeparator()
501 act = menu.addAction( 593 act = menu.addAction(
502 UI.PixmapCache.getIcon("vcsAdd"), 594 UI.PixmapCache.getIcon("vcsAdd"),
503 self.tr('Add/Stage to repository'), self._VCSAdd) 595 self.tr("Add/Stage to repository"),
596 self._VCSAdd,
597 )
504 act = menu.addAction( 598 act = menu.addAction(
505 UI.PixmapCache.getIcon("vcsRevert"), 599 UI.PixmapCache.getIcon("vcsRevert"),
506 self.tr('Unstage changes'), 600 self.tr("Unstage changes"),
507 self.__GitUnstage) 601 self.__GitUnstage,
602 )
508 self.vcsDirMultiMenuActions.append(act) 603 self.vcsDirMultiMenuActions.append(act)
509 menu.addSeparator() 604 menu.addSeparator()
510 act = menu.addAction( 605 act = menu.addAction(
511 UI.PixmapCache.getIcon("vcsRemove"), 606 UI.PixmapCache.getIcon("vcsRemove"),
512 self.tr('Remove from repository (and disk)'), 607 self.tr("Remove from repository (and disk)"),
513 self._VCSRemove) 608 self._VCSRemove,
609 )
514 self.vcsDirMultiMenuActions.append(act) 610 self.vcsDirMultiMenuActions.append(act)
515 menu.addSeparator() 611 menu.addSeparator()
516 act = menu.addAction( 612 act = menu.addAction(
517 UI.PixmapCache.getIcon("vcsStatus"), 613 UI.PixmapCache.getIcon("vcsStatus"), self.tr("Show status"), self._VCSStatus
518 self.tr('Show status'), self._VCSStatus) 614 )
519 self.vcsDirMultiMenuActions.append(act) 615 self.vcsDirMultiMenuActions.append(act)
520 menu.addSeparator() 616 menu.addSeparator()
521 act = menu.addAction( 617 act = menu.addAction(
522 UI.PixmapCache.getIcon("vcsDiff"), 618 UI.PixmapCache.getIcon("vcsDiff"),
523 self.tr('Show differences'), self._VCSDiff) 619 self.tr("Show differences"),
620 self._VCSDiff,
621 )
524 self.vcsDirMultiMenuActions.append(act) 622 self.vcsDirMultiMenuActions.append(act)
525 act = menu.addAction( 623 act = menu.addAction(
526 UI.PixmapCache.getIcon("vcsDiff"), 624 UI.PixmapCache.getIcon("vcsDiff"),
527 self.tr('Show differences (extended)'), 625 self.tr("Show differences (extended)"),
528 self.__GitExtendedDiff) 626 self.__GitExtendedDiff,
627 )
529 self.vcsDirMultiMenuActions.append(act) 628 self.vcsDirMultiMenuActions.append(act)
530 menu.addSeparator() 629 menu.addSeparator()
531 act = menu.addAction( 630 act = menu.addAction(
532 UI.PixmapCache.getIcon("vcsRevert"), 631 UI.PixmapCache.getIcon("vcsRevert"),
533 self.tr('Revert changes'), self.__GitRevert) 632 self.tr("Revert changes"),
633 self.__GitRevert,
634 )
534 self.vcsDirMultiMenuActions.append(act) 635 self.vcsDirMultiMenuActions.append(act)
535 menu.addSeparator() 636 menu.addSeparator()
536 637
537 menu.addSeparator() 638 menu.addSeparator()
538 menu.addAction(self.tr('Select all local file entries'), 639 menu.addAction(
539 self.browser.selectLocalEntries) 640 self.tr("Select all local file entries"), self.browser.selectLocalEntries
540 menu.addAction(self.tr('Select all versioned file entries'), 641 )
541 self.browser.selectVCSEntries) 642 menu.addAction(
542 menu.addAction(self.tr('Select all local directory entries'), 643 self.tr("Select all versioned file entries"), self.browser.selectVCSEntries
543 self.browser.selectLocalDirEntries) 644 )
544 menu.addAction(self.tr('Select all versioned directory entries'), 645 menu.addAction(
545 self.browser.selectVCSDirEntries) 646 self.tr("Select all local directory entries"),
647 self.browser.selectLocalDirEntries,
648 )
649 menu.addAction(
650 self.tr("Select all versioned directory entries"),
651 self.browser.selectVCSDirEntries,
652 )
546 menu.addSeparator() 653 menu.addSeparator()
547 menu.addAction(self.tr("Configure..."), self.__GitConfigure) 654 menu.addAction(self.tr("Configure..."), self.__GitConfigure)
548 655
549 mainMenu.addSeparator() 656 mainMenu.addSeparator()
550 mainMenu.addMenu(menu) 657 mainMenu.addMenu(menu)
551 self.menuDirMulti = menu 658 self.menuDirMulti = menu
552 659
553 def __GitConfigure(self): 660 def __GitConfigure(self):
554 """ 661 """
555 Private method to open the configuration dialog. 662 Private method to open the configuration dialog.
556 """ 663 """
557 ericApp().getObject("UserInterface").showPreferences("zzz_gitPage") 664 ericApp().getObject("UserInterface").showPreferences("zzz_gitPage")
558 665
559 def __GitForget(self): 666 def __GitForget(self):
560 """ 667 """
561 Private slot called by the context menu to remove the selected file 668 Private slot called by the context menu to remove the selected file
562 from the Git repository leaving a copy in the project directory. 669 from the Git repository leaving a copy in the project directory.
563 """ 670 """
564 from UI.DeleteFilesConfirmationDialog import ( 671 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
565 DeleteFilesConfirmationDialog 672
566 )
567 if self.isTranslationsBrowser: 673 if self.isTranslationsBrowser:
568 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) 674 items = self.browser.getSelectedItems([ProjectBrowserFileItem])
569 names = [itm.fileName() for itm in items] 675 names = [itm.fileName() for itm in items]
570 676
571 dlg = DeleteFilesConfirmationDialog( 677 dlg = DeleteFilesConfirmationDialog(
572 self.parent(), 678 self.parent(),
573 self.tr("Remove from repository only"), 679 self.tr("Remove from repository only"),
574 self.tr( 680 self.tr(
575 "Do you really want to remove these files" 681 "Do you really want to remove these files" " from the repository?"
576 " from the repository?"), 682 ),
577 names) 683 names,
684 )
578 else: 685 else:
579 items = self.browser.getSelectedItems() 686 items = self.browser.getSelectedItems()
580 names = [itm.fileName() for itm in items] 687 names = [itm.fileName() for itm in items]
581 files = [self.browser.project.getRelativePath(name) 688 files = [self.browser.project.getRelativePath(name) for name in names]
582 for name in names] 689
583
584 dlg = DeleteFilesConfirmationDialog( 690 dlg = DeleteFilesConfirmationDialog(
585 self.parent(), 691 self.parent(),
586 self.tr("Remove from repository only"), 692 self.tr("Remove from repository only"),
587 self.tr( 693 self.tr(
588 "Do you really want to remove these files" 694 "Do you really want to remove these files" " from the repository?"
589 " from the repository?"), 695 ),
590 files) 696 files,
591 697 )
698
592 if dlg.exec() == QDialog.DialogCode.Accepted: 699 if dlg.exec() == QDialog.DialogCode.Accepted:
593 self.vcs.vcsRemove(names, stageOnly=True) 700 self.vcs.vcsRemove(names, stageOnly=True)
594 701
595 for fn in names: 702 for fn in names:
596 self._updateVCSStatus(fn) 703 self._updateVCSStatus(fn)
597 704
598 def __GitCopy(self): 705 def __GitCopy(self):
599 """ 706 """
600 Private slot called by the context menu to copy the selected file. 707 Private slot called by the context menu to copy the selected file.
601 """ 708 """
602 itm = self.browser.currentItem() 709 itm = self.browser.currentItem()
603 try: 710 try:
604 fn = itm.fileName() 711 fn = itm.fileName()
605 except AttributeError: 712 except AttributeError:
606 fn = itm.dirName() 713 fn = itm.dirName()
607 self.vcs.gitCopy(fn, self.project) 714 self.vcs.gitCopy(fn, self.project)
608 715
609 def __GitMove(self): 716 def __GitMove(self):
610 """ 717 """
611 Private slot called by the context menu to move the selected file. 718 Private slot called by the context menu to move the selected file.
612 """ 719 """
613 itm = self.browser.currentItem() 720 itm = self.browser.currentItem()
623 self.browser.closeSourceWindow.emit(fn) 730 self.browser.closeSourceWindow.emit(fn)
624 else: 731 else:
625 for mf in movefiles: 732 for mf in movefiles:
626 self.browser.closeSourceWindow.emit(mf) 733 self.browser.closeSourceWindow.emit(mf)
627 self.browser.project.startFileSystemMonitoring() 734 self.browser.project.startFileSystemMonitoring()
628 735
629 def __GitExtendedDiff(self): 736 def __GitExtendedDiff(self):
630 """ 737 """
631 Private slot called by the context menu to show the difference of a 738 Private slot called by the context menu to show the difference of a
632 file to the repository. 739 file to the repository.
633 740
634 This gives the chance to enter the revisions to compare. 741 This gives the chance to enter the revisions to compare.
635 """ 742 """
636 names = [] 743 names = []
637 for itm in self.browser.getSelectedItems(): 744 for itm in self.browser.getSelectedItems():
638 try: 745 try:
639 names.append(itm.fileName()) 746 names.append(itm.fileName())
640 except AttributeError: 747 except AttributeError:
641 names.append(itm.dirName()) 748 names.append(itm.dirName())
642 self.vcs.gitExtendedDiff(names) 749 self.vcs.gitExtendedDiff(names)
643 750
644 def __GitSbsDiff(self): 751 def __GitSbsDiff(self):
645 """ 752 """
646 Private slot called by the context menu to show the difference of a 753 Private slot called by the context menu to show the difference of a
647 file to the repository side-by-side. 754 file to the repository side-by-side.
648 """ 755 """
649 itm = self.browser.currentItem() 756 itm = self.browser.currentItem()
650 fn = itm.fileName() 757 fn = itm.fileName()
651 self.vcs.vcsSbsDiff(fn) 758 self.vcs.vcsSbsDiff(fn)
652 759
653 def __GitSbsExtendedDiff(self): 760 def __GitSbsExtendedDiff(self):
654 """ 761 """
655 Private slot called by the context menu to show the difference of a 762 Private slot called by the context menu to show the difference of a
656 file to the repository side-by-side. 763 file to the repository side-by-side.
657 764
658 It allows the selection of revisions to compare. 765 It allows the selection of revisions to compare.
659 """ 766 """
660 itm = self.browser.currentItem() 767 itm = self.browser.currentItem()
661 fn = itm.fileName() 768 fn = itm.fileName()
662 self.vcs.vcsSbsDiff(fn, extended=True) 769 self.vcs.vcsSbsDiff(fn, extended=True)
663 770
664 def __GitUnstage(self): 771 def __GitUnstage(self):
665 """ 772 """
666 Private slot to unstage changes. 773 Private slot to unstage changes.
667 """ 774 """
668 names = [] 775 names = []
671 name = itm.fileName() 778 name = itm.fileName()
672 except AttributeError: 779 except AttributeError:
673 name = itm.dirName() 780 name = itm.dirName()
674 names.append(name) 781 names.append(name)
675 self.vcs.gitUnstage(names) 782 self.vcs.gitUnstage(names)
676 783
677 def __GitRevert(self): 784 def __GitRevert(self):
678 """ 785 """
679 Private slot to revert changes of the working area. 786 Private slot to revert changes of the working area.
680 """ 787 """
681 names = [] 788 names = []
684 name = itm.fileName() 791 name = itm.fileName()
685 except AttributeError: 792 except AttributeError:
686 name = itm.dirName() 793 name = itm.dirName()
687 names.append(name) 794 names.append(name)
688 self.vcs.vcsRevert(names) 795 self.vcs.vcsRevert(names)
689 796
690 def __GitBlame(self): 797 def __GitBlame(self):
691 """ 798 """
692 Private slot called by the context menu to show the annotations of a 799 Private slot called by the context menu to show the annotations of a
693 file. 800 file.
694 """ 801 """

eric ide

mercurial