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. |
901 @return list of all items, the user has checked |
919 @return list of all items, the user has checked |
902 """ |
920 """ |
903 commitableItems = [] |
921 commitableItems = [] |
904 for index in range(self.statusList.topLevelItemCount()): |
922 for index in range(self.statusList.topLevelItemCount()): |
905 itm = self.statusList.topLevelItem(index) |
923 itm = self.statusList.topLevelItem(index) |
906 if itm.checkState(self.__toBeCommittedColumn) == Qt.Checked: |
924 if ( |
|
925 itm.checkState(self.__toBeCommittedColumn) == |
|
926 Qt.CheckState.Checked |
|
927 ): |
907 commitableItems.append(itm) |
928 commitableItems.append(itm) |
908 return commitableItems |
929 return commitableItems |
909 |
930 |
910 def __getCommitableUnselectedItems(self): |
931 def __getCommitableUnselectedItems(self): |
911 """ |
932 """ |
1026 |
1048 |
1027 @param selected commit selection state to be set (boolean) |
1049 @param selected commit selection state to be set (boolean) |
1028 """ |
1050 """ |
1029 for index in range(self.statusList.topLevelItemCount()): |
1051 for index in range(self.statusList.topLevelItemCount()): |
1030 itm = self.statusList.topLevelItem(index) |
1052 itm = self.statusList.topLevelItem(index) |
1031 if itm.flags() & Qt.ItemIsUserCheckable: |
1053 if itm.flags() & Qt.ItemFlag.ItemIsUserCheckable: |
1032 if selected: |
1054 if selected: |
1033 itm.setCheckState(self.__toBeCommittedColumn, Qt.Checked) |
1055 itm.setCheckState(self.__toBeCommittedColumn, |
|
1056 Qt.CheckState.Checked) |
1034 else: |
1057 else: |
1035 itm.setCheckState(self.__toBeCommittedColumn, Qt.Unchecked) |
1058 itm.setCheckState(self.__toBeCommittedColumn, |
|
1059 Qt.CheckState.Unchecked) |
1036 |
1060 |
1037 ########################################################################### |
1061 ########################################################################### |
1038 ## Diff handling methods below |
1062 ## Diff handling methods below |
1039 ########################################################################### |
1063 ########################################################################### |
1040 |
1064 |
1085 else: |
1109 else: |
1086 self.rDiffParser = None |
1110 self.rDiffParser = None |
1087 |
1111 |
1088 for diffEdit in [self.lDiffEdit, self.rDiffEdit]: |
1112 for diffEdit in [self.lDiffEdit, self.rDiffEdit]: |
1089 tc = diffEdit.textCursor() |
1113 tc = diffEdit.textCursor() |
1090 tc.movePosition(QTextCursor.Start) |
1114 tc.movePosition(QTextCursor.MoveOperation.Start) |
1091 diffEdit.setTextCursor(tc) |
1115 diffEdit.setTextCursor(tc) |
1092 diffEdit.ensureCursorVisible() |
1116 diffEdit.ensureCursorVisible() |
1093 |
1117 |
1094 def __showLDiffContextMenu(self, coord): |
1118 def __showLDiffContextMenu(self, coord): |
1095 """ |
1119 """ |