eric7/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
9 9
10 import os 10 import os
11 import re 11 import re
12 import collections 12 import collections
13 import contextlib 13 import contextlib
14 import pathlib
14 15
15 from PyQt6.QtCore import pyqtSlot, Qt, QDate, QSize, QPoint, QFileInfo 16 from PyQt6.QtCore import pyqtSlot, Qt, QDate, QSize, QPoint
16 from PyQt6.QtGui import ( 17 from PyQt6.QtGui import (
17 QColor, QPixmap, QPainter, QPen, QBrush, QIcon, QTextCursor, QPalette 18 QColor, QPixmap, QPainter, QPen, QBrush, QIcon, QTextCursor, QPalette
18 ) 19 )
19 from PyQt6.QtWidgets import ( 20 from PyQt6.QtWidgets import (
20 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication, 21 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication,
2683 EricFileDialog.DontConfirmOverwrite) 2684 EricFileDialog.DontConfirmOverwrite)
2684 2685
2685 if not fname: 2686 if not fname:
2686 return # user aborted 2687 return # user aborted
2687 2688
2688 ext = QFileInfo(fname).suffix() 2689 fpath = pathlib.Path(fname)
2689 if not ext: 2690 if not fpath.suffix:
2690 ex = selectedFilter.split("(*")[1].split(")")[0] 2691 ex = selectedFilter.split("(*")[1].split(")")[0]
2691 if ex: 2692 if ex:
2692 fname += ex 2693 fpath = fpath.with_suffix(ex)
2693 if QFileInfo(fname).exists(): 2694 if fpath.exists():
2694 res = EricMessageBox.yesNo( 2695 res = EricMessageBox.yesNo(
2695 self, 2696 self,
2696 self.tr("Save Diff"), 2697 self.tr("Save Diff"),
2697 self.tr("<p>The patch file <b>{0}</b> already exists." 2698 self.tr("<p>The patch file <b>{0}</b> already exists."
2698 " Overwrite it?</p>").format(fname), 2699 " Overwrite it?</p>").format(str(fpath)),
2699 icon=EricMessageBox.Warning) 2700 icon=EricMessageBox.Warning)
2700 if not res: 2701 if not res:
2701 return 2702 return
2702 fname = Utilities.toNativeSeparators(fname)
2703 2703
2704 eol = ericApp().getObject("Project").getEolString() 2704 eol = ericApp().getObject("Project").getEolString()
2705 try: 2705 try:
2706 with open(fname, "w", encoding="utf-8", newline="") as f: 2706 with fpath.open("w", encoding="utf-8", newline="") as f:
2707 f.write(eol.join(self.diffEdit.toPlainText().splitlines())) 2707 f.write(eol.join(self.diffEdit.toPlainText().splitlines()))
2708 except OSError as why: 2708 except OSError as why:
2709 EricMessageBox.critical( 2709 EricMessageBox.critical(
2710 self, self.tr('Save Diff'), 2710 self, self.tr('Save Diff'),
2711 self.tr( 2711 self.tr(
2712 '<p>The patch file <b>{0}</b> could not be saved.' 2712 '<p>The patch file <b>{0}</b> could not be saved.'
2713 '<br>Reason: {1}</p>') 2713 '<br>Reason: {1}</p>')
2714 .format(fname, str(why))) 2714 .format(str(fpath), str(why)))
2715 2715
2716 @pyqtSlot(str) 2716 @pyqtSlot(str)
2717 def on_sbsSelectLabel_linkActivated(self, link): 2717 def on_sbsSelectLabel_linkActivated(self, link):
2718 """ 2718 """
2719 Private slot to handle selection of a side-by-side link. 2719 Private slot to handle selection of a side-by-side link.

eric ide

mercurial