eric6/Plugins/VcsPlugins/vcsGit/GitStatusDialog.py

branch
maintenance
changeset 8176
31965986ecd1
parent 8151
8c1445825e7b
child 8218
7c09585bd960
equal deleted inserted replaced
8153:e01ae92db699 8176:31965986ecd1
39 Class implementing a dialog to show the output of the git status command 39 Class implementing a dialog to show the output of the git status command
40 process. 40 process.
41 """ 41 """
42 ConflictStates = ["AA", "AU", "DD", "DU", "UA", "UD", "UU"] 42 ConflictStates = ["AA", "AU", "DD", "DU", "UA", "UD", "UU"]
43 43
44 ConflictRole = Qt.UserRole 44 ConflictRole = Qt.ItemDataRole.UserRole
45 45
46 def __init__(self, vcs, parent=None): 46 def __init__(self, vcs, parent=None):
47 """ 47 """
48 Constructor 48 Constructor
49 49
58 self.__statusIndexColumn = 2 58 self.__statusIndexColumn = 2
59 self.__pathColumn = 3 59 self.__pathColumn = 3
60 self.__lastColumn = self.statusList.columnCount() 60 self.__lastColumn = self.statusList.columnCount()
61 61
62 self.refreshButton = self.buttonBox.addButton( 62 self.refreshButton = self.buttonBox.addButton(
63 self.tr("Refresh"), QDialogButtonBox.ActionRole) 63 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole)
64 self.refreshButton.setToolTip( 64 self.refreshButton.setToolTip(
65 self.tr("Press to refresh the status display")) 65 self.tr("Press to refresh the status display"))
66 self.refreshButton.setEnabled(False) 66 self.refreshButton.setEnabled(False)
67 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 67 self.buttonBox.button(
68 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 68 QDialogButtonBox.StandardButton.Close).setEnabled(False)
69 self.buttonBox.button(
70 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
69 71
70 self.diff = None 72 self.diff = None
71 self.vcs = vcs 73 self.vcs = vcs
72 self.vcs.committed.connect(self.__committed) 74 self.vcs.committed.connect(self.__committed)
73 self.process = QProcess() 75 self.process = QProcess()
84 self.__hDiffSplitterState = None 86 self.__hDiffSplitterState = None
85 self.__vDiffSplitterState = None 87 self.__vDiffSplitterState = None
86 88
87 self.statusList.headerItem().setText(self.__lastColumn, "") 89 self.statusList.headerItem().setText(self.__lastColumn, "")
88 self.statusList.header().setSortIndicator( 90 self.statusList.header().setSortIndicator(
89 self.__pathColumn, Qt.AscendingOrder) 91 self.__pathColumn, Qt.SortOrder.AscendingOrder)
90 92
91 font = Preferences.getEditorOtherFonts("MonospacedFont") 93 font = Preferences.getEditorOtherFonts("MonospacedFont")
92 self.lDiffEdit.document().setDefaultFont(font) 94 self.lDiffEdit.document().setDefaultFont(font)
93 self.rDiffEdit.document().setDefaultFont(font) 95 self.rDiffEdit.document().setDefaultFont(font)
94 self.lDiffEdit.customContextMenuRequested.connect( 96 self.lDiffEdit.customContextMenuRequested.connect(
263 265
264 @param e close event (QCloseEvent) 266 @param e close event (QCloseEvent)
265 """ 267 """
266 if ( 268 if (
267 self.process is not None and 269 self.process is not None and
268 self.process.state() != QProcess.NotRunning 270 self.process.state() != QProcess.ProcessState.NotRunning
269 ): 271 ):
270 self.process.terminate() 272 self.process.terminate()
271 QTimer.singleShot(2000, self.process.kill) 273 QTimer.singleShot(2000, self.process.kill)
272 self.process.waitForFinished(3000) 274 self.process.waitForFinished(3000)
273 275
313 315
314 def __resizeColumns(self): 316 def __resizeColumns(self):
315 """ 317 """
316 Private method to resize the list columns. 318 Private method to resize the list columns.
317 """ 319 """
318 self.statusList.header().resizeSections(QHeaderView.ResizeToContents) 320 self.statusList.header().resizeSections(
321 QHeaderView.ResizeMode.ResizeToContents)
319 self.statusList.header().setStretchLastSection(True) 322 self.statusList.header().setStretchLastSection(True)
320 323
321 def __generateItem(self, status, path): 324 def __generateItem(self, status, path):
322 """ 325 """
323 Private method to generate a status item in the status list. 326 Private method to generate a status item in the status list.
332 statusWorkText, 335 statusWorkText,
333 statusIndexText, 336 statusIndexText,
334 path, 337 path,
335 ]) 338 ])
336 339
337 itm.setTextAlignment(self.__statusWorkColumn, Qt.AlignHCenter) 340 itm.setTextAlignment(self.__statusWorkColumn,
338 itm.setTextAlignment(self.__statusIndexColumn, Qt.AlignHCenter) 341 Qt.AlignmentFlag.AlignHCenter)
339 itm.setTextAlignment(self.__pathColumn, Qt.AlignLeft) 342 itm.setTextAlignment(self.__statusIndexColumn,
343 Qt.AlignmentFlag.AlignHCenter)
344 itm.setTextAlignment(self.__pathColumn,
345 Qt.AlignmentFlag.AlignLeft)
340 346
341 if ( 347 if (
342 status not in self.ConflictStates + ["??", "!!"] and 348 status not in self.ConflictStates + ["??", "!!"] and
343 statusIndexText in self.modifiedIndicators 349 statusIndexText in self.modifiedIndicators
344 ): 350 ):
345 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) 351 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable)
346 itm.setCheckState(self.__toBeCommittedColumn, Qt.Checked) 352 itm.setCheckState(self.__toBeCommittedColumn,
347 else: 353 Qt.CheckState.Checked)
348 itm.setFlags(itm.flags() & ~Qt.ItemIsUserCheckable) 354 else:
355 itm.setFlags(itm.flags() & ~Qt.ItemFlag.ItemIsUserCheckable)
349 356
350 if statusWorkText not in self.__statusFilters: 357 if statusWorkText not in self.__statusFilters:
351 self.__statusFilters.append(statusWorkText) 358 self.__statusFilters.append(statusWorkText)
352 if statusIndexText not in self.__statusFilters: 359 if statusIndexText not in self.__statusFilters:
353 self.__statusFilters.append(statusIndexText) 360 self.__statusFilters.append(statusIndexText)
410 self.tr( 417 self.tr(
411 'The process {0} could not be started. ' 418 'The process {0} could not be started. '
412 'Ensure, that it is in the search path.' 419 'Ensure, that it is in the search path.'
413 ).format('git')) 420 ).format('git'))
414 else: 421 else:
415 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 422 self.buttonBox.button(
416 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 423 QDialogButtonBox.StandardButton.Close).setEnabled(False)
417 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 424 self.buttonBox.button(
425 QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
426 self.buttonBox.button(
427 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
418 428
419 self.refreshButton.setEnabled(False) 429 self.refreshButton.setEnabled(False)
420 430
421 def __finish(self): 431 def __finish(self):
422 """ 432 """
423 Private slot called when the process finished or the user pressed 433 Private slot called when the process finished or the user pressed
424 the button. 434 the button.
425 """ 435 """
426 if ( 436 if (
427 self.process is not None and 437 self.process is not None and
428 self.process.state() != QProcess.NotRunning 438 self.process.state() != QProcess.ProcessState.NotRunning
429 ): 439 ):
430 self.process.terminate() 440 self.process.terminate()
431 QTimer.singleShot(2000, self.process.kill) 441 QTimer.singleShot(2000, self.process.kill)
432 self.process.waitForFinished(3000) 442 self.process.waitForFinished(3000)
433 443
434 self.inputGroup.setEnabled(False) 444 self.inputGroup.setEnabled(False)
435 self.inputGroup.hide() 445 self.inputGroup.hide()
436 self.refreshButton.setEnabled(True) 446 self.refreshButton.setEnabled(True)
437 447
438 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 448 self.buttonBox.button(
439 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 449 QDialogButtonBox.StandardButton.Close).setEnabled(True)
440 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 450 self.buttonBox.button(
441 self.buttonBox.button(QDialogButtonBox.Close).setFocus( 451 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
442 Qt.OtherFocusReason) 452 self.buttonBox.button(
453 QDialogButtonBox.StandardButton.Close).setDefault(True)
454 self.buttonBox.button(
455 QDialogButtonBox.StandardButton.Close).setFocus(
456 Qt.FocusReason.OtherFocusReason)
443 457
444 self.__statusFilters.sort() 458 self.__statusFilters.sort()
445 self.__statusFilters.insert(0, "<{0}>".format(self.tr("all"))) 459 self.__statusFilters.insert(0, "<{0}>".format(self.tr("all")))
446 self.statusFilterCombo.addItems(self.__statusFilters) 460 self.statusFilterCombo.addItems(self.__statusFilters)
447 461
454 """ 468 """
455 Private slot called by a button of the button box clicked. 469 Private slot called by a button of the button box clicked.
456 470
457 @param button button that was clicked (QAbstractButton) 471 @param button button that was clicked (QAbstractButton)
458 """ 472 """
459 if button == self.buttonBox.button(QDialogButtonBox.Close): 473 if button == self.buttonBox.button(
474 QDialogButtonBox.StandardButton.Close
475 ):
460 self.close() 476 self.close()
461 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 477 elif button == self.buttonBox.button(
478 QDialogButtonBox.StandardButton.Cancel
479 ):
462 self.__finish() 480 self.__finish()
463 elif button == self.refreshButton: 481 elif button == self.refreshButton:
464 self.on_refreshButton_clicked() 482 self.on_refreshButton_clicked()
465 483
466 def __procFinished(self, exitCode, exitStatus): 484 def __procFinished(self, exitCode, exitStatus):
478 496
479 It reads the output of the process, formats it and inserts it into 497 It reads the output of the process, formats it and inserts it into
480 the contents pane. 498 the contents pane.
481 """ 499 """
482 if self.process is not None: 500 if self.process is not None:
483 self.process.setReadChannel(QProcess.StandardOutput) 501 self.process.setReadChannel(QProcess.ProcessChannel.StandardOutput)
484 502
485 while self.process.canReadLine(): 503 while self.process.canReadLine():
486 line = str(self.process.readLine(), self.__ioEncoding, 504 line = str(self.process.readLine(), self.__ioEncoding,
487 'replace') 505 'replace')
488 506
513 Private slot to handle the password checkbox toggled. 531 Private slot to handle the password checkbox toggled.
514 532
515 @param isOn flag indicating the status of the check box (boolean) 533 @param isOn flag indicating the status of the check box (boolean)
516 """ 534 """
517 if isOn: 535 if isOn:
518 self.input.setEchoMode(QLineEdit.Password) 536 self.input.setEchoMode(QLineEdit.EchoMode.Password)
519 else: 537 else:
520 self.input.setEchoMode(QLineEdit.Normal) 538 self.input.setEchoMode(QLineEdit.EchoMode.Normal)
521 539
522 @pyqtSlot() 540 @pyqtSlot()
523 def on_sendButton_clicked(self): 541 def on_sendButton_clicked(self):
524 """ 542 """
525 Private slot to send the input to the git process. 543 Private slot to send the input to the git process.
569 else: 587 else:
570 self.__selectedName = "" 588 self.__selectedName = ""
571 589
572 self.start(self.args) 590 self.start(self.args)
573 591
574 @pyqtSlot(str) 592 @pyqtSlot(int)
575 def on_statusFilterCombo_activated(self, txt): 593 def on_statusFilterCombo_activated(self, index):
576 """ 594 """
577 Private slot to react to the selection of a status filter. 595 Private slot to react to the selection of a status filter.
578 596
579 @param txt selected status filter (string) 597 @param index index of the selected entry
580 """ 598 @type int
599 """
600 txt = self.statusFilterCombo.itemText(index)
581 if txt == "<{0}>".format(self.tr("all")): 601 if txt == "<{0}>".format(self.tr("all")):
582 for topIndex in range(self.statusList.topLevelItemCount()): 602 for topIndex in range(self.statusList.topLevelItemCount()):
583 topItem = self.statusList.topLevelItem(topIndex) 603 topItem = self.statusList.topLevelItem(topIndex)
584 topItem.setHidden(False) 604 topItem.setHidden(False)
585 else: 605 else:
901 @return list of all items, the user has checked 921 @return list of all items, the user has checked
902 """ 922 """
903 commitableItems = [] 923 commitableItems = []
904 for index in range(self.statusList.topLevelItemCount()): 924 for index in range(self.statusList.topLevelItemCount()):
905 itm = self.statusList.topLevelItem(index) 925 itm = self.statusList.topLevelItem(index)
906 if itm.checkState(self.__toBeCommittedColumn) == Qt.Checked: 926 if (
927 itm.checkState(self.__toBeCommittedColumn) ==
928 Qt.CheckState.Checked
929 ):
907 commitableItems.append(itm) 930 commitableItems.append(itm)
908 return commitableItems 931 return commitableItems
909 932
910 def __getCommitableUnselectedItems(self): 933 def __getCommitableUnselectedItems(self):
911 """ 934 """
916 """ 939 """
917 items = [] 940 items = []
918 for index in range(self.statusList.topLevelItemCount()): 941 for index in range(self.statusList.topLevelItemCount()):
919 itm = self.statusList.topLevelItem(index) 942 itm = self.statusList.topLevelItem(index)
920 if ( 943 if (
921 itm.flags() & Qt.ItemIsUserCheckable and 944 itm.flags() & Qt.ItemFlag.ItemIsUserCheckable and
922 itm.checkState(self.__toBeCommittedColumn) == Qt.Unchecked 945 itm.checkState(self.__toBeCommittedColumn) ==
946 Qt.CheckState.Unchecked
923 ): 947 ):
924 items.append(itm) 948 items.append(itm)
925 return items 949 return items
926 950
927 def __getModifiedItems(self): 951 def __getModifiedItems(self):
1026 1050
1027 @param selected commit selection state to be set (boolean) 1051 @param selected commit selection state to be set (boolean)
1028 """ 1052 """
1029 for index in range(self.statusList.topLevelItemCount()): 1053 for index in range(self.statusList.topLevelItemCount()):
1030 itm = self.statusList.topLevelItem(index) 1054 itm = self.statusList.topLevelItem(index)
1031 if itm.flags() & Qt.ItemIsUserCheckable: 1055 if itm.flags() & Qt.ItemFlag.ItemIsUserCheckable:
1032 if selected: 1056 if selected:
1033 itm.setCheckState(self.__toBeCommittedColumn, Qt.Checked) 1057 itm.setCheckState(self.__toBeCommittedColumn,
1058 Qt.CheckState.Checked)
1034 else: 1059 else:
1035 itm.setCheckState(self.__toBeCommittedColumn, Qt.Unchecked) 1060 itm.setCheckState(self.__toBeCommittedColumn,
1061 Qt.CheckState.Unchecked)
1036 1062
1037 ########################################################################### 1063 ###########################################################################
1038 ## Diff handling methods below 1064 ## Diff handling methods below
1039 ########################################################################### 1065 ###########################################################################
1040 1066
1085 else: 1111 else:
1086 self.rDiffParser = None 1112 self.rDiffParser = None
1087 1113
1088 for diffEdit in [self.lDiffEdit, self.rDiffEdit]: 1114 for diffEdit in [self.lDiffEdit, self.rDiffEdit]:
1089 tc = diffEdit.textCursor() 1115 tc = diffEdit.textCursor()
1090 tc.movePosition(QTextCursor.Start) 1116 tc.movePosition(QTextCursor.MoveOperation.Start)
1091 diffEdit.setTextCursor(tc) 1117 diffEdit.setTextCursor(tc)
1092 diffEdit.ensureCursorVisible() 1118 diffEdit.ensureCursorVisible()
1093 1119
1094 def __showLDiffContextMenu(self, coord): 1120 def __showLDiffContextMenu(self, coord):
1095 """ 1121 """

eric ide

mercurial