14 pass |
14 pass |
15 |
15 |
16 import os |
16 import os |
17 |
17 |
18 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo, Qt |
18 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo, Qt |
19 from PyQt5.QtGui import QBrush, QColor, QTextCursor, QCursor |
19 from PyQt5.QtGui import QTextCursor, QCursor |
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QLineEdit, QApplication |
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QLineEdit, QApplication |
21 |
21 |
22 from E5Gui import E5MessageBox, E5FileDialog |
22 from E5Gui import E5MessageBox, E5FileDialog |
23 from E5Gui.E5Application import e5App |
23 from E5Gui.E5Application import e5App |
24 |
24 |
25 from .Ui_HgDiffDialog import Ui_HgDiffDialog |
25 from .Ui_HgDiffDialog import Ui_HgDiffDialog |
|
26 from .HgDiffHighlighter import HgDiffHighlighter |
26 |
27 |
27 import Utilities |
28 import Utilities |
28 import Preferences |
29 import Preferences |
29 |
30 |
30 |
31 |
59 |
60 |
60 font = Preferences.getEditorOtherFonts("MonospacedFont") |
61 font = Preferences.getEditorOtherFonts("MonospacedFont") |
61 self.contents.setFontFamily(font.family()) |
62 self.contents.setFontFamily(font.family()) |
62 self.contents.setFontPointSize(font.pointSize()) |
63 self.contents.setFontPointSize(font.pointSize()) |
63 |
64 |
64 self.cNormalFormat = self.contents.currentCharFormat() |
65 self.highlighter = HgDiffHighlighter(self.contents.document()) |
65 self.cAddedFormat = self.contents.currentCharFormat() |
|
66 self.cAddedFormat.setBackground(QBrush(QColor(190, 237, 190))) |
|
67 self.cRemovedFormat = self.contents.currentCharFormat() |
|
68 self.cRemovedFormat.setBackground(QBrush(QColor(237, 190, 190))) |
|
69 self.cLineNoFormat = self.contents.currentCharFormat() |
|
70 self.cLineNoFormat.setBackground(QBrush(QColor(255, 220, 168))) |
|
71 |
66 |
72 self.process.finished.connect(self.__procFinished) |
67 self.process.finished.connect(self.__procFinished) |
73 self.process.readyReadStandardOutput.connect(self.__readStdout) |
68 self.process.readyReadStandardOutput.connect(self.__readStdout) |
74 self.process.readyReadStandardError.connect(self.__readStderr) |
69 self.process.readyReadStandardError.connect(self.__readStderr) |
75 |
70 |
233 self.inputGroup.setEnabled(False) |
228 self.inputGroup.setEnabled(False) |
234 self.inputGroup.hide() |
229 self.inputGroup.hide() |
235 self.refreshButton.setEnabled(True) |
230 self.refreshButton.setEnabled(True) |
236 |
231 |
237 if self.paras == 0: |
232 if self.paras == 0: |
238 self.contents.setCurrentCharFormat(self.cNormalFormat) |
233 self.contents.setPlainText(self.tr('There is no difference.')) |
239 self.contents.setPlainText( |
|
240 self.tr('There is no difference.')) |
|
241 |
234 |
242 self.buttonBox.button(QDialogButtonBox.Save).setEnabled(self.paras > 0) |
235 self.buttonBox.button(QDialogButtonBox.Save).setEnabled(self.paras > 0) |
243 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
236 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
244 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
237 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
245 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
238 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
251 self.contents.ensureCursorVisible() |
244 self.contents.ensureCursorVisible() |
252 |
245 |
253 self.filesCombo.addItem(self.tr("<Start>"), 0) |
246 self.filesCombo.addItem(self.tr("<Start>"), 0) |
254 self.filesCombo.addItem(self.tr("<End>"), -1) |
247 self.filesCombo.addItem(self.tr("<End>"), -1) |
255 for oldFile, newFile, pos in sorted(self.__fileSeparators): |
248 for oldFile, newFile, pos in sorted(self.__fileSeparators): |
256 if oldFile != newFile: |
249 if not oldFile: |
|
250 self.filesCombo.addItem(newFile, pos) |
|
251 elif oldFile != newFile: |
257 self.filesCombo.addItem( |
252 self.filesCombo.addItem( |
258 "{0}\n{1}".format(oldFile, newFile), pos) |
253 "{0}\n{1}".format(oldFile, newFile), pos) |
259 else: |
254 else: |
260 self.filesCombo.addItem(oldFile, pos) |
255 self.filesCombo.addItem(oldFile, pos) |
261 |
256 |
262 def __appendText(self, txt, format): |
257 def __appendText(self, txt): |
263 """ |
258 """ |
264 Private method to append text to the end of the contents pane. |
259 Private method to append text to the end of the contents pane. |
265 |
260 |
266 @param txt text to insert (string) |
261 @param txt text to insert (string) |
267 @param format text format to be used (QTextCharFormat) |
|
268 """ |
262 """ |
269 tc = self.contents.textCursor() |
263 tc = self.contents.textCursor() |
270 tc.movePosition(QTextCursor.End) |
264 tc.movePosition(QTextCursor.End) |
271 self.contents.setTextCursor(tc) |
265 self.contents.setTextCursor(tc) |
272 self.contents.setCurrentCharFormat(format) |
|
273 self.contents.insertPlainText(txt) |
266 self.contents.insertPlainText(txt) |
274 |
267 |
275 def __extractFileName(self, line): |
268 def __extractFileName(self, line): |
276 """ |
269 """ |
277 Private method to extract the file name out of a file separator line. |
270 Private method to extract the file name out of a file separator line. |
279 @param line line to be processed (string) |
272 @param line line to be processed (string) |
280 @return extracted file name (string) |
273 @return extracted file name (string) |
281 """ |
274 """ |
282 f = line.split(None, 1)[1] |
275 f = line.split(None, 1)[1] |
283 f = f.rsplit(None, 6)[0] |
276 f = f.rsplit(None, 6)[0] |
284 f = f.split("/", 1)[1] |
277 if f == "/dev/null": |
|
278 f = "" |
|
279 else: |
|
280 f = f.split("/", 1)[1] |
285 return f |
281 return f |
286 |
282 |
287 def __processFileLine(self, line): |
283 def __processFileLine(self, line): |
288 """ |
284 """ |
289 Private slot to process a line giving the old/new file. |
285 Private slot to process a line giving the old/new file. |
306 """ |
302 """ |
307 if line.startswith("--- ") or \ |
303 if line.startswith("--- ") or \ |
308 line.startswith("+++ "): |
304 line.startswith("+++ "): |
309 self.__processFileLine(line) |
305 self.__processFileLine(line) |
310 |
306 |
311 if line.startswith('+'): |
307 self.__appendText(line) |
312 format = self.cAddedFormat |
|
313 elif line.startswith('-'): |
|
314 format = self.cRemovedFormat |
|
315 elif line.startswith('@@'): |
|
316 format = self.cLineNoFormat |
|
317 else: |
|
318 format = self.cNormalFormat |
|
319 self.__appendText(line, format) |
|
320 self.paras += 1 |
308 self.paras += 1 |
321 |
309 |
322 def __readStdout(self): |
310 def __readStdout(self): |
323 """ |
311 """ |
324 Private slot to handle the readyReadStandardOutput signal. |
312 Private slot to handle the readyReadStandardOutput signal. |