9 |
9 |
10 import os |
10 import os |
11 import collections |
11 import collections |
12 import re |
12 import re |
13 import contextlib |
13 import contextlib |
|
14 import pathlib |
14 |
15 |
15 from PyQt6.QtCore import ( |
16 from PyQt6.QtCore import ( |
16 pyqtSlot, Qt, QDate, QProcess, QTimer, QSize, QPoint, QFileInfo |
17 pyqtSlot, Qt, QDate, QProcess, QTimer, QSize, QPoint |
17 ) |
18 ) |
18 from PyQt6.QtGui import ( |
19 from PyQt6.QtGui import ( |
19 QColor, QPixmap, QPainter, QPen, QIcon, QTextCursor, QPalette |
20 QColor, QPixmap, QPainter, QPen, QIcon, QTextCursor, QPalette |
20 ) |
21 ) |
21 from PyQt6.QtWidgets import ( |
22 from PyQt6.QtWidgets import ( |
34 from .GitDiffHighlighter import GitDiffHighlighter |
35 from .GitDiffHighlighter import GitDiffHighlighter |
35 from .GitDiffGenerator import GitDiffGenerator |
36 from .GitDiffGenerator import GitDiffGenerator |
36 |
37 |
37 import UI.PixmapCache |
38 import UI.PixmapCache |
38 import Preferences |
39 import Preferences |
39 import Utilities |
|
40 |
40 |
41 COLORNAMES = ["red", "green", "purple", "cyan", "olive", "magenta", |
41 COLORNAMES = ["red", "green", "purple", "cyan", "olive", "magenta", |
42 "gray", "yellow", "darkred", "darkgreen", "darkblue", |
42 "gray", "yellow", "darkred", "darkgreen", "darkblue", |
43 "darkcyan", "darkmagenta", "blue"] |
43 "darkcyan", "darkmagenta", "blue"] |
44 COLORS = [str(QColor(x).name()) for x in COLORNAMES] |
44 COLORS = [str(QColor(x).name()) for x in COLORNAMES] |
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 = ericApp().getObject("Project").getProjectFile() |
1712 pfile = ( |
1713 lastModified = QFileInfo(pfile).lastModified().toString() |
1713 pathlib.Path(ericApp().getObject("Project").getProjectFile()) |
|
1714 ) |
|
1715 lastModified = pfile.stat().st_mtime |
1714 shouldReopen = ( |
1716 shouldReopen = ( |
1715 self.vcs.gitCherryPick( |
1717 self.vcs.gitCherryPick( |
1716 self.repodir, |
1718 self.repodir, |
1717 [commits[i] for i in sorted(commits.keys(), reverse=True)] |
1719 [commits[i] for i in sorted(commits.keys(), reverse=True)] |
1718 ) or |
1720 ) or |
1719 QFileInfo(pfile).lastModified().toString() != lastModified |
1721 pfile.stat().st_mtime != lastModified |
1720 ) |
1722 ) |
1721 if shouldReopen: |
1723 if shouldReopen: |
1722 res = EricMessageBox.yesNo( |
1724 res = EricMessageBox.yesNo( |
1723 None, |
1725 None, |
1724 self.tr("Copy Changesets"), |
1726 self.tr("Copy Changesets"), |
1770 branch = "" |
1772 branch = "" |
1771 if branch: |
1773 if branch: |
1772 rev = branch |
1774 rev = branch |
1773 else: |
1775 else: |
1774 rev = commit |
1776 rev = commit |
1775 pfile = ericApp().getObject("Project").getProjectFile() |
1777 pfile = ( |
1776 lastModified = QFileInfo(pfile).lastModified().toString() |
1778 pathlib.Path(ericApp().getObject("Project").getProjectFile()) |
|
1779 ) |
|
1780 lastModified = pfile.stat().st_mtime |
1777 shouldReopen = ( |
1781 shouldReopen = ( |
1778 self.vcs.vcsUpdate(self.repodir, revision=rev) or |
1782 self.vcs.vcsUpdate(self.repodir, revision=rev) or |
1779 QFileInfo(pfile).lastModified().toString() != lastModified |
1783 pfile.stat().st_mtime != lastModified |
1780 ) |
1784 ) |
1781 if shouldReopen: |
1785 if shouldReopen: |
1782 res = EricMessageBox.yesNo( |
1786 res = EricMessageBox.yesNo( |
1783 None, |
1787 None, |
1784 self.tr("Switch"), |
1788 self.tr("Switch"), |
1844 0, False) |
1848 0, False) |
1845 if not ok: |
1849 if not ok: |
1846 return |
1850 return |
1847 else: |
1851 else: |
1848 branch = "" |
1852 branch = "" |
1849 pfile = ericApp().getObject("Project").getProjectFile() |
1853 pfile = ( |
1850 lastModified = QFileInfo(pfile).lastModified().toString() |
1854 pathlib.Path(ericApp().getObject("Project").getProjectFile()) |
|
1855 ) |
|
1856 lastModified = pfile.stat().st_mtime |
1851 res, shouldReopen = self.vcs.gitBranch( |
1857 res, shouldReopen = self.vcs.gitBranch( |
1852 self.repodir, revision=commit, branchName=branch, |
1858 self.repodir, revision=commit, branchName=branch, |
1853 branchOp=GitBranchDialog.CreateSwitchBranch) |
1859 branchOp=GitBranchDialog.CreateSwitchBranch) |
1854 shouldReopen = ( |
1860 shouldReopen |= pfile.stat().st_mtime != lastModified |
1855 shouldReopen or |
|
1856 QFileInfo(pfile).lastModified().toString() != lastModified |
|
1857 ) |
|
1858 if res: |
1861 if res: |
1859 if shouldReopen: |
1862 if shouldReopen: |
1860 res = EricMessageBox.yesNo( |
1863 res = EricMessageBox.yesNo( |
1861 None, |
1864 None, |
1862 self.tr("Switch"), |
1865 self.tr("Switch"), |
2298 EricFileDialog.DontConfirmOverwrite) |
2301 EricFileDialog.DontConfirmOverwrite) |
2299 |
2302 |
2300 if not fname: |
2303 if not fname: |
2301 return # user aborted |
2304 return # user aborted |
2302 |
2305 |
2303 ext = QFileInfo(fname).suffix() |
2306 fpath = pathlib.Path(fname) |
2304 if not ext: |
2307 if not fpath.suffix: |
2305 ex = selectedFilter.split("(*")[1].split(")")[0] |
2308 ex = selectedFilter.split("(*")[1].split(")")[0] |
2306 if ex: |
2309 if ex: |
2307 fname += ex |
2310 fpath = fpath.with_suffix(ex) |
2308 if QFileInfo(fname).exists(): |
2311 if fpath.exists(): |
2309 res = EricMessageBox.yesNo( |
2312 res = EricMessageBox.yesNo( |
2310 self, |
2313 self, |
2311 self.tr("Save Diff"), |
2314 self.tr("Save Diff"), |
2312 self.tr("<p>The patch file <b>{0}</b> already exists." |
2315 self.tr("<p>The patch file <b>{0}</b> already exists." |
2313 " Overwrite it?</p>").format(fname), |
2316 " Overwrite it?</p>").format(fpath), |
2314 icon=EricMessageBox.Warning) |
2317 icon=EricMessageBox.Warning) |
2315 if not res: |
2318 if not res: |
2316 return |
2319 return |
2317 fname = Utilities.toNativeSeparators(fname) |
|
2318 |
2320 |
2319 eol = ericApp().getObject("Project").getEolString() |
2321 eol = ericApp().getObject("Project").getEolString() |
2320 try: |
2322 try: |
2321 with open(fname, "w", encoding="utf-8", newline="") as f: |
2323 with fpath.open("w", encoding="utf-8", newline="") as f: |
2322 f.write(eol.join(self.diffEdit.toPlainText().splitlines())) |
2324 f.write(eol.join(self.diffEdit.toPlainText().splitlines())) |
2323 f.write(eol) |
2325 f.write(eol) |
2324 except OSError as why: |
2326 except OSError as why: |
2325 EricMessageBox.critical( |
2327 EricMessageBox.critical( |
2326 self, self.tr('Save Diff'), |
2328 self, self.tr('Save Diff'), |
2327 self.tr( |
2329 self.tr( |
2328 '<p>The patch file <b>{0}</b> could not be saved.' |
2330 '<p>The patch file <b>{0}</b> could not be saved.' |
2329 '<br>Reason: {1}</p>') |
2331 '<br>Reason: {1}</p>') |
2330 .format(fname, str(why))) |
2332 .format(fpath, str(why))) |
2331 |
2333 |
2332 @pyqtSlot(str) |
2334 @pyqtSlot(str) |
2333 def on_sbsSelectLabel_linkActivated(self, link): |
2335 def on_sbsSelectLabel_linkActivated(self, link): |
2334 """ |
2336 """ |
2335 Private slot to handle selection of a side-by-side link. |
2337 Private slot to handle selection of a side-by-side link. |