Mon, 09 Feb 2015 19:57:45 +0100
Changed the diff dialog to use the new diff highlighter logic.
--- a/APIs/Python3/eric6.api Sun Feb 08 19:12:05 2015 +0100 +++ b/APIs/Python3/eric6.api Mon Feb 09 19:57:45 2015 +0100 @@ -8152,6 +8152,8 @@ eric6.UI.DiffDialog.DiffWindow?1(parent=None) eric6.UI.DiffDialog.context_diff?4(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n') eric6.UI.DiffDialog.unified_diff?4(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n') +eric6.UI.DiffHighlighter.DiffHighlighter.generateRules?4() +eric6.UI.DiffHighlighter.DiffHighlighter?1(doc) eric6.UI.EmailDialog.EmailDialog.attachFile?4(fname, deleteFile) eric6.UI.EmailDialog.EmailDialog.keyPressEvent?4(ev) eric6.UI.EmailDialog.EmailDialog.on_addButton_clicked?4()
--- a/APIs/Python3/eric6.bas Sun Feb 08 19:12:05 2015 +0100 +++ b/APIs/Python3/eric6.bas Mon Feb 09 19:57:45 2015 +0100 @@ -123,6 +123,7 @@ DebuggerRubyPage ConfigurationPageBase Ui_DebuggerRubyPage DeleteFilesConfirmationDialog QDialog Ui_DeleteFilesConfirmationDialog DiffDialog QWidget Ui_DiffDialog +DiffHighlighter E5GenericDiffHighlighter DiffReport StandardReport DiffWindow E5MainWindow DirectorySyncHandler SyncHandler
--- a/Documentation/Help/source.qhp Sun Feb 08 19:12:05 2015 +0100 +++ b/Documentation/Help/source.qhp Mon Feb 09 19:57:45 2015 +0100 @@ -960,6 +960,7 @@ <section title="eric6.UI.Config" ref="eric6.UI.Config.html" /> <section title="eric6.UI.DeleteFilesConfirmationDialog" ref="eric6.UI.DeleteFilesConfirmationDialog.html" /> <section title="eric6.UI.DiffDialog" ref="eric6.UI.DiffDialog.html" /> + <section title="eric6.UI.DiffHighlighter" ref="eric6.UI.DiffHighlighter.html" /> <section title="eric6.UI.EmailDialog" ref="eric6.UI.EmailDialog.html" /> <section title="eric6.UI.ErrorLogDialog" ref="eric6.UI.ErrorLogDialog.html" /> <section title="eric6.UI.FindFileDialog" ref="eric6.UI.FindFileDialog.html" /> @@ -3315,6 +3316,10 @@ <keyword name="DiffDialog.on_file2Button_clicked" id="DiffDialog.on_file2Button_clicked" ref="eric6.UI.DiffDialog.html#DiffDialog.on_file2Button_clicked" /> <keyword name="DiffDialog.on_saveButton_clicked" id="DiffDialog.on_saveButton_clicked" ref="eric6.UI.DiffDialog.html#DiffDialog.on_saveButton_clicked" /> <keyword name="DiffDialog.show" id="DiffDialog.show" ref="eric6.UI.DiffDialog.html#DiffDialog.show" /> + <keyword name="DiffHighlighter" id="DiffHighlighter" ref="eric6.UI.DiffHighlighter.html#DiffHighlighter" /> + <keyword name="DiffHighlighter (Constructor)" id="DiffHighlighter (Constructor)" ref="eric6.UI.DiffHighlighter.html#DiffHighlighter.__init__" /> + <keyword name="DiffHighlighter (Module)" id="DiffHighlighter (Module)" ref="eric6.UI.DiffHighlighter.html" /> + <keyword name="DiffHighlighter.generateRules" id="DiffHighlighter.generateRules" ref="eric6.UI.DiffHighlighter.html#DiffHighlighter.generateRules" /> <keyword name="DiffReport" id="DiffReport" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.pep8.html#DiffReport" /> <keyword name="DiffReport (Constructor)" id="DiffReport (Constructor)" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.pep8.html#DiffReport.__init__" /> <keyword name="DiffReport.error" id="DiffReport.error" ref="eric6.Plugins.CheckerPlugins.CodeStyleChecker.pep8.html#DiffReport.error" /> @@ -14377,6 +14382,7 @@ <file>eric6.UI.Config.html</file> <file>eric6.UI.DeleteFilesConfirmationDialog.html</file> <file>eric6.UI.DiffDialog.html</file> + <file>eric6.UI.DiffHighlighter.html</file> <file>eric6.UI.EmailDialog.html</file> <file>eric6.UI.ErrorLogDialog.html</file> <file>eric6.UI.FindFileDialog.html</file>
--- a/Documentation/Source/eric6.UI.DiffDialog.html Sun Feb 08 19:12:05 2015 +0100 +++ b/Documentation/Source/eric6.UI.DiffDialog.html Mon Feb 09 19:57:45 2015 +0100 @@ -119,16 +119,13 @@ </dd> </dl><a NAME="DiffDialog.__appendText" ID="DiffDialog.__appendText"></a> <h4>DiffDialog.__appendText</h4> -<b>__appendText</b>(<i>txt, format</i>) +<b>__appendText</b>(<i>txt</i>) <p> Private method to append text to the end of the contents pane. </p><dl> <dt><i>txt</i></dt> <dd> text to insert (string) -</dd><dt><i>format</i></dt> -<dd> -text format to be used (QTextCharFormat) </dd> </dl><a NAME="DiffDialog.__fileChanged" ID="DiffDialog.__fileChanged"></a> <h4>DiffDialog.__fileChanged</h4>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Documentation/Source/eric6.UI.DiffHighlighter.html Mon Feb 09 19:57:45 2015 +0100 @@ -0,0 +1,89 @@ +<!DOCTYPE html> +<html><head> +<title>eric6.UI.DiffHighlighter</title> +<meta charset="UTF-8"> +<style> +body { + background: #EDECE6; + margin: 0em 1em 10em 1em; + color: black; +} + +h1 { color: white; background: #85774A; } +h2 { color: white; background: #85774A; } +h3 { color: white; background: #9D936E; } +h4 { color: white; background: #9D936E; } + +a { color: #BA6D36; } + +</style> +</head> +<body><a NAME="top" ID="top"></a> +<h1>eric6.UI.DiffHighlighter</h1> +<p> +Module implementing a syntax highlighter for unified and context diff outputs. +</p> +<h3>Global Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Classes</h3> +<table> +<tr> +<td><a href="#DiffHighlighter">DiffHighlighter</a></td> +<td>Class implementing a diff highlighter for Git.</td> +</tr> +</table> +<h3>Functions</h3> +<table> +<tr><td>None</td></tr> +</table> +<hr /><hr /> +<a NAME="DiffHighlighter" ID="DiffHighlighter"></a> +<h2>DiffHighlighter</h2> +<p> + Class implementing a diff highlighter for Git. +</p> +<h3>Derived from</h3> +E5GenericDiffHighlighter +<h3>Class Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#DiffHighlighter.__init__">DiffHighlighter</a></td> +<td>Constructor</td> +</tr><tr> +<td><a href="#DiffHighlighter.generateRules">generateRules</a></td> +<td>Public method to generate the rule set.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="DiffHighlighter.__init__" ID="DiffHighlighter.__init__"></a> +<h4>DiffHighlighter (Constructor)</h4> +<b>DiffHighlighter</b>(<i>doc</i>) +<p> + Constructor +</p><dl> +<dt><i>doc</i></dt> +<dd> +reference to the text document (QTextDocument) +</dd> +</dl><a NAME="DiffHighlighter.generateRules" ID="DiffHighlighter.generateRules"></a> +<h4>DiffHighlighter.generateRules</h4> +<b>generateRules</b>(<i></i>) +<p> + Public method to generate the rule set. +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /> +</body></html> \ No newline at end of file
--- a/Documentation/Source/index-eric6.UI.html Sun Feb 08 19:12:05 2015 +0100 +++ b/Documentation/Source/index-eric6.UI.html Mon Feb 09 19:57:45 2015 +0100 @@ -62,6 +62,9 @@ <td><a href="eric6.UI.DiffDialog.html">DiffDialog</a></td> <td>Module implementing a dialog to compare two files.</td> </tr><tr> +<td><a href="eric6.UI.DiffHighlighter.html">DiffHighlighter</a></td> +<td>Module implementing a syntax highlighter for unified and context diff outputs.</td> +</tr><tr> <td><a href="eric6.UI.EmailDialog.html">EmailDialog</a></td> <td>Module implementing a dialog to send bug reports.</td> </tr><tr>
--- a/E5Gui/E5GenericDiffHighlighter.py Sun Feb 08 19:12:05 2015 +0100 +++ b/E5Gui/E5GenericDiffHighlighter.py Mon Feb 09 19:57:45 2015 +0100 @@ -44,7 +44,7 @@ self.removedColor = QColor(237, 190, 190) self.replacedColor = QColor(190, 190, 237) self.contextColor = QColor(255, 220, 168) - self.headerColor = QColor(190, 190, 237) + self.headerColor = QColor(237, 237, 190) self.normalFormat = self.makeFormat()
--- a/UI/DiffDialog.py Sun Feb 08 19:12:05 2015 +0100 +++ b/UI/DiffDialog.py Mon Feb 09 19:57:45 2015 +0100 @@ -13,7 +13,7 @@ import time from PyQt5.QtCore import QFileInfo, QEvent, pyqtSlot -from PyQt5.QtGui import QColor, QBrush, QTextCursor +from PyQt5.QtGui import QTextCursor from PyQt5.QtWidgets import QWidget, QApplication, QDialogButtonBox from E5Gui.E5Completers import E5FileCompleter @@ -21,6 +21,7 @@ from E5Gui.E5MainWindow import E5MainWindow from .Ui_DiffDialog import Ui_DiffDialog +from .DiffHighlighter import DiffHighlighter import Utilities import Preferences @@ -242,15 +243,7 @@ self.contents.setFontFamily(font.family()) self.contents.setFontPointSize(font.pointSize()) - self.cNormalFormat = self.contents.currentCharFormat() - self.cAddedFormat = self.contents.currentCharFormat() - self.cAddedFormat.setBackground(QBrush(QColor(190, 237, 190))) - self.cRemovedFormat = self.contents.currentCharFormat() - self.cRemovedFormat.setBackground(QBrush(QColor(237, 190, 190))) - self.cReplacedFormat = self.contents.currentCharFormat() - self.cReplacedFormat.setBackground(QBrush(QColor(190, 190, 237))) - self.cLineNoFormat = self.contents.currentCharFormat() - self.cLineNoFormat.setBackground(QBrush(QColor(255, 220, 168))) + self.highlighter = DiffHighlighter(self.contents.document()) # connect some of our widgets explicitly self.file1Edit.textChanged.connect(self.__fileChanged) @@ -393,17 +386,15 @@ self.saveButton.setEnabled(True) - def __appendText(self, txt, format): + def __appendText(self, txt): """ Private method to append text to the end of the contents pane. @param txt text to insert (string) - @param format text format to be used (QTextCharFormat) """ tc = self.contents.textCursor() tc.movePosition(QTextCursor.End) self.contents.setTextCursor(tc) - self.contents.setCurrentCharFormat(format) self.contents.insertPlainText(txt) def __generateUnifiedDiff(self, a, b, fromfile, tofile, @@ -421,15 +412,7 @@ paras = 0 for line in unified_diff(a, b, fromfile, tofile, fromfiledate, tofiledate): - if line.startswith('+') or line.startswith('>'): - format = self.cAddedFormat - elif line.startswith('-') or line.startswith('<'): - format = self.cRemovedFormat - elif line.startswith('@@'): - format = self.cLineNoFormat - else: - format = self.cNormalFormat - self.__appendText(line, format) + self.__appendText(line) paras += 1 if not (paras % self.updateInterval): QApplication.processEvents() @@ -453,18 +436,7 @@ paras = 0 for line in context_diff(a, b, fromfile, tofile, fromfiledate, tofiledate): - if line.startswith('+ '): - format = self.cAddedFormat - elif line.startswith('- '): - format = self.cRemovedFormat - elif line.startswith('! '): - format = self.cReplacedFormat - elif (line.startswith('*** ') or line.startswith('--- ')) and \ - paras > 1: - format = self.cLineNoFormat - else: - format = self.cNormalFormat - self.__appendText(line, format) + self.__appendText(line) paras += 1 if not (paras % self.updateInterval): QApplication.processEvents()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/DiffHighlighter.py Mon Feb 09 19:57:45 2015 +0100 @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a syntax highlighter for unified and context diff outputs. +""" + +from __future__ import unicode_literals + +from E5Gui.E5GenericDiffHighlighter import TERMINAL, E5GenericDiffHighlighter + + +class DiffHighlighter(E5GenericDiffHighlighter): + """ + Class implementing a diff highlighter for Git. + """ + def __init__(self, doc): + """ + Constructor + + @param doc reference to the text document (QTextDocument) + """ + super(DiffHighlighter, self).__init__(doc) + + def generateRules(self): + """ + Public method to generate the rule set. + """ + diffHeaderBold = self.makeFormat(fg=self.textColor, + bg=self.headerColor, + bold=True) + diffContext = self.makeFormat(fg=self.textColor, + bg=self.contextColor) + + diffAdded = self.makeFormat(fg=self.textColor, + bg=self.addedColor) + diffRemoved = self.makeFormat(fg=self.textColor, + bg=self.removedColor) + diffReplaced = self.makeFormat(fg=self.textColor, + bg=self.replacedColor) + + diffBarRegex = TERMINAL(r'^\*+$') + + diffOldRegex = TERMINAL(r'^--- ') + diffNewRegex = TERMINAL(r'^\+\+\+ |^\*\*\*') + diffContextRegex = TERMINAL(r'^@@ ') + + diffAddedRegex = TERMINAL(r'^[+>]') + diffRemovedRegex = TERMINAL(r'^[-<]') + diffReplacedRegex = TERMINAL(r'^!') + + self.createRules((diffBarRegex, diffHeaderBold), + (diffOldRegex, diffRemoved), + (diffNewRegex, diffAdded), + (diffContextRegex, diffContext), + (diffAddedRegex, diffAdded), + (diffRemovedRegex, diffRemoved), + (diffReplacedRegex, diffReplaced), + )
--- a/eric6.e4p Sun Feb 08 19:12:05 2015 +0100 +++ b/eric6.e4p Mon Feb 09 19:57:45 2015 +0100 @@ -1155,6 +1155,7 @@ <Source>Preferences/ConfigurationPages/LogViewerPage.py</Source> <Source>Preferences/ConfigurationPages/MimeTypesPage.py</Source> <Source>E5Gui/E5GenericDiffHighlighter.py</Source> + <Source>UI/DiffHighlighter.py</Source> </Sources> <Forms> <Form>PyUnit/UnittestDialog.ui</Form>