Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.

Tue, 18 Jan 2011 19:32:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 18 Jan 2011 19:32:48 +0100
changeset 855
d8c4113a9274
parent 854
2f4ffd2c7d02
child 857
613ded9c3b69

Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.Pep8Dialog.html file | annotate | diff | comparison | revisions
Documentation/Source/eric5.UI.FindFileDialog.html file | annotate | diff | comparison | revisions
UI/FindFileDialog.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Tue Jan 18 16:31:26 2011 +0100
+++ b/Documentation/Help/source.qhp	Tue Jan 18 19:32:48 2011 +0100
@@ -3714,6 +3714,7 @@
       <keyword name="FindFileDialog.__getFileList" id="FindFileDialog.__getFileList" ref="eric5.UI.FindFileDialog.html#FindFileDialog.__getFileList" />
       <keyword name="FindFileDialog.__openFile" id="FindFileDialog.__openFile" ref="eric5.UI.FindFileDialog.html#FindFileDialog.__openFile" />
       <keyword name="FindFileDialog.__stopSearch" id="FindFileDialog.__stopSearch" ref="eric5.UI.FindFileDialog.html#FindFileDialog.__stopSearch" />
+      <keyword name="FindFileDialog.__stripEol" id="FindFileDialog.__stripEol" ref="eric5.UI.FindFileDialog.html#FindFileDialog.__stripEol" />
       <keyword name="FindFileDialog.on_buttonBox_clicked" id="FindFileDialog.on_buttonBox_clicked" ref="eric5.UI.FindFileDialog.html#FindFileDialog.on_buttonBox_clicked" />
       <keyword name="FindFileDialog.on_dirButton_clicked" id="FindFileDialog.on_dirButton_clicked" ref="eric5.UI.FindFileDialog.html#FindFileDialog.on_dirButton_clicked" />
       <keyword name="FindFileDialog.on_dirCombo_editTextChanged" id="FindFileDialog.on_dirCombo_editTextChanged" ref="eric5.UI.FindFileDialog.html#FindFileDialog.on_dirCombo_editTextChanged" />
--- a/Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.Pep8Dialog.html	Tue Jan 18 16:31:26 2011 +0100
+++ b/Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.Pep8Dialog.html	Tue Jan 18 19:32:48 2011 +0100
@@ -167,7 +167,7 @@
         Private method to resort the tree.
 </p><a NAME="Pep8Dialog.__updateStatistics" ID="Pep8Dialog.__updateStatistics"></a>
 <h4>Pep8Dialog.__updateStatistics</h4>
-<b>__updateStatistics</b>(<i>statistics</i>)
+<b>__updateStatistics</b>(<i>statistics, fixer</i>)
 <p>
         Private method to update the collected statistics.
 </p><dl>
@@ -175,6 +175,9 @@
 <dd>
 dictionary of statistical data with
             message code as key and message count as value
+</dd><dt><i>fixer</i></dt>
+<dd>
+reference to the PEP 8 fixer (Pep8Fixer)
 </dd>
 </dl><a NAME="Pep8Dialog.on_buttonBox_clicked" ID="Pep8Dialog.on_buttonBox_clicked"></a>
 <h4>Pep8Dialog.on_buttonBox_clicked</h4>
--- a/Documentation/Source/eric5.UI.FindFileDialog.html	Tue Jan 18 16:31:26 2011 +0100
+++ b/Documentation/Source/eric5.UI.FindFileDialog.html	Tue Jan 18 19:32:48 2011 +0100
@@ -95,6 +95,9 @@
 <td><a href="#FindFileDialog.__stopSearch">__stopSearch</a></td>
 <td>Private slot to handle the stop button being pressed.</td>
 </tr><tr>
+<td><a href="#FindFileDialog.__stripEol">__stripEol</a></td>
+<td>Private method to strip the eol part.</td>
+</tr><tr>
 <td><a href="#FindFileDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td>
 <td>Private slot called by a button of the button box clicked.</td>
 </tr><tr>
@@ -230,7 +233,22 @@
 <b>__stopSearch</b>(<i></i>)
 <p>
         Private slot to handle the stop button being pressed.
-</p><a NAME="FindFileDialog.on_buttonBox_clicked" ID="FindFileDialog.on_buttonBox_clicked"></a>
+</p><a NAME="FindFileDialog.__stripEol" ID="FindFileDialog.__stripEol"></a>
+<h4>FindFileDialog.__stripEol</h4>
+<b>__stripEol</b>(<i>txt</i>)
+<p>
+        Private method to strip the eol part.
+</p><dl>
+<dt><i>txt</i></dt>
+<dd>
+line of text that should be treated (string)
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+text with eol stripped (string)
+</dd>
+</dl><a NAME="FindFileDialog.on_buttonBox_clicked" ID="FindFileDialog.on_buttonBox_clicked"></a>
 <h4>FindFileDialog.on_buttonBox_clicked</h4>
 <b>on_buttonBox_clicked</b>(<i>button</i>)
 <p>
--- a/UI/FindFileDialog.py	Tue Jan 18 16:31:26 2011 +0100
+++ b/UI/FindFileDialog.py	Tue Jan 18 19:32:48 2011 +0100
@@ -269,6 +269,15 @@
         elif button == self.stopButton:
             self.__stopSearch()
         
+    def __stripEol(self, txt):
+        """
+        Private method to strip the eol part.
+        
+        @param txt line of text that should be treated (string)
+        @return text with eol stripped (string)
+        """
+        return txt.replace("\r", "").replace("\n", "")
+        
     def __stopSearch(self):
         """
         Private slot to handle the stop button being pressed.
@@ -420,7 +429,7 @@
             # read the file and split it into textlines
             try:
                 text, encoding, hash = Utilities.readEncodedFileWithHash(fn)
-                lines = text.splitlines()
+                lines = text.splitlines(True)
             except (UnicodeError, IOError):
                 progress += 1
                 self.findProgress.setValue(progress)
@@ -441,12 +450,14 @@
                         rline = search.sub(replTxt, line)
                     else:
                         rline = ""
+                    line = self.__stripEol(line)
                     if len(line) > 1024:
                         line = "{0} ...".format(line[:1024])
                     if self.__replaceMode:
                         if len(rline) > 1024:
                             rline = "{0} ...".format(line[:1024])
-                        line = "- {0}\n+ {1}".format(line, rline)
+                        line = "- {0}\n+ {1}".format(
+                            line, self.__stripEol(rline))
                     self.__createItem(file, count, line, start, end, 
                                       rline, hash)
                     
@@ -581,7 +592,7 @@
                 try:
                     text, encoding, hash = \
                         Utilities.readEncodedFileWithHash(fn)
-                    lines = text.splitlines()
+                    lines = text.splitlines(True)
                 except (UnicodeError, IOError):
                     E5MessageBox.critical(self,
                         self.trUtf8("Replace in Files"),
@@ -618,11 +629,7 @@
                         lines[line - 1] = rline
                 
                 # write the file
-                if self.project.isProjectFile(fn):
-                    eol = self.project.getEolString()
-                else:
-                    eol = Utilities.linesep()
-                txt = eol.join(lines) + Utilities.linesep()
+                txt = "".join(lines)
                 try:
                     Utilities.writeEncodedFile(fn, txt, encoding)
                 except (IOError, Utilities.CodingError, UnicodeError) as err:

eric ide

mercurial