21 from PyQt6.QtWidgets import ( |
21 from PyQt6.QtWidgets import ( |
22 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication, |
22 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication, |
23 QLineEdit, QMenu, QInputDialog |
23 QLineEdit, QMenu, QInputDialog |
24 ) |
24 ) |
25 |
25 |
26 from E5Gui.E5Application import e5App |
26 from E5Gui.EricApplication import ericApp |
27 from E5Gui import E5MessageBox, E5FileDialog |
27 from E5Gui import EricMessageBox, EricFileDialog |
28 from E5Gui.E5OverrideCursor import E5OverrideCursorProcess |
28 from E5Gui.EricOverrideCursor import EricOverrideCursorProcess |
29 |
29 |
30 from Globals import strToQByteArray |
30 from Globals import strToQByteArray |
31 |
31 |
32 from .Ui_GitLogBrowserDialog import Ui_GitLogBrowserDialog |
32 from .Ui_GitLogBrowserDialog import Ui_GitLogBrowserDialog |
33 |
33 |
116 |
116 |
117 self.__logTreeNormalFont = self.logTree.font() |
117 self.__logTreeNormalFont = self.logTree.font() |
118 self.__logTreeNormalFont.setBold(False) |
118 self.__logTreeNormalFont.setBold(False) |
119 self.__logTreeBoldFont = self.logTree.font() |
119 self.__logTreeBoldFont = self.logTree.font() |
120 self.__logTreeBoldFont.setBold(True) |
120 self.__logTreeBoldFont.setBold(True) |
121 self.__logTreeHasDarkBackground = e5App().usesDarkPalette() |
121 self.__logTreeHasDarkBackground = ericApp().usesDarkPalette() |
122 |
122 |
123 font = Preferences.getEditorOtherFonts("MonospacedFont") |
123 font = Preferences.getEditorOtherFonts("MonospacedFont") |
124 self.diffEdit.document().setDefaultFont(font) |
124 self.diffEdit.document().setDefaultFont(font) |
125 |
125 |
126 self.diffHighlighter = GitDiffHighlighter(self.diffEdit.document()) |
126 self.diffHighlighter = GitDiffHighlighter(self.diffEdit.document()) |
196 self.__committerMailRole = Qt.ItemDataRole.UserRole + 7 |
196 self.__committerMailRole = Qt.ItemDataRole.UserRole + 7 |
197 |
197 |
198 # roles used in the file tree |
198 # roles used in the file tree |
199 self.__diffFileLineRole = Qt.ItemDataRole.UserRole |
199 self.__diffFileLineRole = Qt.ItemDataRole.UserRole |
200 |
200 |
201 self.__process = E5OverrideCursorProcess() |
201 self.__process = EricOverrideCursorProcess() |
202 self.__process.finished.connect(self.__procFinished) |
202 self.__process.finished.connect(self.__procFinished) |
203 self.__process.readyReadStandardOutput.connect(self.__readStdout) |
203 self.__process.readyReadStandardOutput.connect(self.__readStdout) |
204 self.__process.readyReadStandardError.connect(self.__readStderr) |
204 self.__process.readyReadStandardError.connect(self.__readStderr) |
205 |
205 |
206 self.flags = { |
206 self.flags = { |
822 self.__process.start('git', args) |
822 self.__process.start('git', args) |
823 procStarted = self.__process.waitForStarted(5000) |
823 procStarted = self.__process.waitForStarted(5000) |
824 if not procStarted: |
824 if not procStarted: |
825 self.inputGroup.setEnabled(False) |
825 self.inputGroup.setEnabled(False) |
826 self.inputGroup.hide() |
826 self.inputGroup.hide() |
827 E5MessageBox.critical( |
827 EricMessageBox.critical( |
828 self, |
828 self, |
829 self.tr('Process Generation Error'), |
829 self.tr('Process Generation Error'), |
830 self.tr( |
830 self.tr( |
831 'The process {0} could not be started. ' |
831 'The process {0} could not be started. ' |
832 'Ensure, that it is in the search path.' |
832 'Ensure, that it is in the search path.' |
1707 for itm in self.logTree.selectedItems(): |
1707 for itm in self.logTree.selectedItems(): |
1708 index = self.logTree.indexOfTopLevelItem(itm) |
1708 index = self.logTree.indexOfTopLevelItem(itm) |
1709 commits[index] = itm.text(self.CommitIdColumn) |
1709 commits[index] = itm.text(self.CommitIdColumn) |
1710 |
1710 |
1711 if commits: |
1711 if commits: |
1712 pfile = e5App().getObject("Project").getProjectFile() |
1712 pfile = ericApp().getObject("Project").getProjectFile() |
1713 lastModified = QFileInfo(pfile).lastModified().toString() |
1713 lastModified = QFileInfo(pfile).lastModified().toString() |
1714 shouldReopen = ( |
1714 shouldReopen = ( |
1715 self.vcs.gitCherryPick( |
1715 self.vcs.gitCherryPick( |
1716 self.repodir, |
1716 self.repodir, |
1717 [commits[i] for i in sorted(commits.keys(), reverse=True)] |
1717 [commits[i] for i in sorted(commits.keys(), reverse=True)] |
1718 ) or |
1718 ) or |
1719 QFileInfo(pfile).lastModified().toString() != lastModified |
1719 QFileInfo(pfile).lastModified().toString() != lastModified |
1720 ) |
1720 ) |
1721 if shouldReopen: |
1721 if shouldReopen: |
1722 res = E5MessageBox.yesNo( |
1722 res = EricMessageBox.yesNo( |
1723 None, |
1723 None, |
1724 self.tr("Copy Changesets"), |
1724 self.tr("Copy Changesets"), |
1725 self.tr( |
1725 self.tr( |
1726 """The project should be reread. Do this now?"""), |
1726 """The project should be reread. Do this now?"""), |
1727 yesDefault=True) |
1727 yesDefault=True) |
1728 if res: |
1728 if res: |
1729 e5App().getObject("Project").reopenProject() |
1729 ericApp().getObject("Project").reopenProject() |
1730 return |
1730 return |
1731 |
1731 |
1732 self.on_refreshButton_clicked() |
1732 self.on_refreshButton_clicked() |
1733 |
1733 |
1734 @pyqtSlot() |
1734 @pyqtSlot() |
1770 branch = "" |
1770 branch = "" |
1771 if branch: |
1771 if branch: |
1772 rev = branch |
1772 rev = branch |
1773 else: |
1773 else: |
1774 rev = commit |
1774 rev = commit |
1775 pfile = e5App().getObject("Project").getProjectFile() |
1775 pfile = ericApp().getObject("Project").getProjectFile() |
1776 lastModified = QFileInfo(pfile).lastModified().toString() |
1776 lastModified = QFileInfo(pfile).lastModified().toString() |
1777 shouldReopen = ( |
1777 shouldReopen = ( |
1778 self.vcs.vcsUpdate(self.repodir, revision=rev) or |
1778 self.vcs.vcsUpdate(self.repodir, revision=rev) or |
1779 QFileInfo(pfile).lastModified().toString() != lastModified |
1779 QFileInfo(pfile).lastModified().toString() != lastModified |
1780 ) |
1780 ) |
1781 if shouldReopen: |
1781 if shouldReopen: |
1782 res = E5MessageBox.yesNo( |
1782 res = EricMessageBox.yesNo( |
1783 None, |
1783 None, |
1784 self.tr("Switch"), |
1784 self.tr("Switch"), |
1785 self.tr( |
1785 self.tr( |
1786 """The project should be reread. Do this now?"""), |
1786 """The project should be reread. Do this now?"""), |
1787 yesDefault=True) |
1787 yesDefault=True) |
1788 if res: |
1788 if res: |
1789 e5App().getObject("Project").reopenProject() |
1789 ericApp().getObject("Project").reopenProject() |
1790 return |
1790 return |
1791 |
1791 |
1792 self.on_refreshButton_clicked() |
1792 self.on_refreshButton_clicked() |
1793 |
1793 |
1794 @pyqtSlot() |
1794 @pyqtSlot() |
1844 0, False) |
1844 0, False) |
1845 if not ok: |
1845 if not ok: |
1846 return |
1846 return |
1847 else: |
1847 else: |
1848 branch = "" |
1848 branch = "" |
1849 pfile = e5App().getObject("Project").getProjectFile() |
1849 pfile = ericApp().getObject("Project").getProjectFile() |
1850 lastModified = QFileInfo(pfile).lastModified().toString() |
1850 lastModified = QFileInfo(pfile).lastModified().toString() |
1851 res, shouldReopen = self.vcs.gitBranch( |
1851 res, shouldReopen = self.vcs.gitBranch( |
1852 self.repodir, revision=commit, branchName=branch, |
1852 self.repodir, revision=commit, branchName=branch, |
1853 branchOp=GitBranchDialog.CreateSwitchBranch) |
1853 branchOp=GitBranchDialog.CreateSwitchBranch) |
1854 shouldReopen = ( |
1854 shouldReopen = ( |
1855 shouldReopen or |
1855 shouldReopen or |
1856 QFileInfo(pfile).lastModified().toString() != lastModified |
1856 QFileInfo(pfile).lastModified().toString() != lastModified |
1857 ) |
1857 ) |
1858 if res: |
1858 if res: |
1859 if shouldReopen: |
1859 if shouldReopen: |
1860 res = E5MessageBox.yesNo( |
1860 res = EricMessageBox.yesNo( |
1861 None, |
1861 None, |
1862 self.tr("Switch"), |
1862 self.tr("Switch"), |
1863 self.tr( |
1863 self.tr( |
1864 """The project should be reread. Do this now?"""), |
1864 """The project should be reread. Do this now?"""), |
1865 yesDefault=True) |
1865 yesDefault=True) |
1866 if res: |
1866 if res: |
1867 e5App().getObject("Project").reopenProject() |
1867 ericApp().getObject("Project").reopenProject() |
1868 return |
1868 return |
1869 |
1869 |
1870 self.on_refreshButton_clicked() |
1870 self.on_refreshButton_clicked() |
1871 |
1871 |
1872 @pyqtSlot() |
1872 @pyqtSlot() |
2063 txt = topItem.text(fieldIndex) |
2063 txt = topItem.text(fieldIndex) |
2064 if searchRx.search(txt) is not None: |
2064 if searchRx.search(txt) is not None: |
2065 self.logTree.setCurrentItem(self.logTree.topLevelItem(index)) |
2065 self.logTree.setCurrentItem(self.logTree.topLevelItem(index)) |
2066 break |
2066 break |
2067 else: |
2067 else: |
2068 E5MessageBox.information( |
2068 EricMessageBox.information( |
2069 self, |
2069 self, |
2070 self.tr("Find Commit"), |
2070 self.tr("Find Commit"), |
2071 self.tr("""'{0}' was not found.""").format(self.rxEdit.text())) |
2071 self.tr("""'{0}' was not found.""").format(self.rxEdit.text())) |
2072 |
2072 |
2073 ################################################################## |
2073 ################################################################## |
2287 if fname != '.': |
2287 if fname != '.': |
2288 fname = "{0}.diff".format(self.__filename) |
2288 fname = "{0}.diff".format(self.__filename) |
2289 else: |
2289 else: |
2290 fname = dname |
2290 fname = dname |
2291 |
2291 |
2292 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
2292 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
2293 self, |
2293 self, |
2294 self.tr("Save Diff"), |
2294 self.tr("Save Diff"), |
2295 fname, |
2295 fname, |
2296 self.tr("Patch Files (*.diff)"), |
2296 self.tr("Patch Files (*.diff)"), |
2297 None, |
2297 None, |
2298 E5FileDialog.DontConfirmOverwrite) |
2298 EricFileDialog.DontConfirmOverwrite) |
2299 |
2299 |
2300 if not fname: |
2300 if not fname: |
2301 return # user aborted |
2301 return # user aborted |
2302 |
2302 |
2303 ext = QFileInfo(fname).suffix() |
2303 ext = QFileInfo(fname).suffix() |
2304 if not ext: |
2304 if not ext: |
2305 ex = selectedFilter.split("(*")[1].split(")")[0] |
2305 ex = selectedFilter.split("(*")[1].split(")")[0] |
2306 if ex: |
2306 if ex: |
2307 fname += ex |
2307 fname += ex |
2308 if QFileInfo(fname).exists(): |
2308 if QFileInfo(fname).exists(): |
2309 res = E5MessageBox.yesNo( |
2309 res = EricMessageBox.yesNo( |
2310 self, |
2310 self, |
2311 self.tr("Save Diff"), |
2311 self.tr("Save Diff"), |
2312 self.tr("<p>The patch file <b>{0}</b> already exists." |
2312 self.tr("<p>The patch file <b>{0}</b> already exists." |
2313 " Overwrite it?</p>").format(fname), |
2313 " Overwrite it?</p>").format(fname), |
2314 icon=E5MessageBox.Warning) |
2314 icon=EricMessageBox.Warning) |
2315 if not res: |
2315 if not res: |
2316 return |
2316 return |
2317 fname = Utilities.toNativeSeparators(fname) |
2317 fname = Utilities.toNativeSeparators(fname) |
2318 |
2318 |
2319 eol = e5App().getObject("Project").getEolString() |
2319 eol = ericApp().getObject("Project").getEolString() |
2320 try: |
2320 try: |
2321 with open(fname, "w", encoding="utf-8", newline="") as f: |
2321 with open(fname, "w", encoding="utf-8", newline="") as f: |
2322 f.write(eol.join(self.diffEdit.toPlainText().splitlines())) |
2322 f.write(eol.join(self.diffEdit.toPlainText().splitlines())) |
2323 f.write(eol) |
2323 f.write(eol) |
2324 except OSError as why: |
2324 except OSError as why: |
2325 E5MessageBox.critical( |
2325 EricMessageBox.critical( |
2326 self, self.tr('Save Diff'), |
2326 self, self.tr('Save Diff'), |
2327 self.tr( |
2327 self.tr( |
2328 '<p>The patch file <b>{0}</b> could not be saved.' |
2328 '<p>The patch file <b>{0}</b> could not be saved.' |
2329 '<br>Reason: {1}</p>') |
2329 '<br>Reason: {1}</p>') |
2330 .format(fname, str(why))) |
2330 .format(fname, str(why))) |