UI/FindFileDialog.py

changeset 855
d8c4113a9274
parent 846
869c200be26e
child 880
52ed20236a1c
equal deleted inserted replaced
854:2f4ffd2c7d02 855:d8c4113a9274
266 """ 266 """
267 if button == self.findButton: 267 if button == self.findButton:
268 self.__doSearch() 268 self.__doSearch()
269 elif button == self.stopButton: 269 elif button == self.stopButton:
270 self.__stopSearch() 270 self.__stopSearch()
271
272 def __stripEol(self, txt):
273 """
274 Private method to strip the eol part.
275
276 @param txt line of text that should be treated (string)
277 @return text with eol stripped (string)
278 """
279 return txt.replace("\r", "").replace("\n", "")
271 280
272 def __stopSearch(self): 281 def __stopSearch(self):
273 """ 282 """
274 Private slot to handle the stop button being pressed. 283 Private slot to handle the stop button being pressed.
275 """ 284 """
418 else: 427 else:
419 fn = file 428 fn = file
420 # read the file and split it into textlines 429 # read the file and split it into textlines
421 try: 430 try:
422 text, encoding, hash = Utilities.readEncodedFileWithHash(fn) 431 text, encoding, hash = Utilities.readEncodedFileWithHash(fn)
423 lines = text.splitlines() 432 lines = text.splitlines(True)
424 except (UnicodeError, IOError): 433 except (UnicodeError, IOError):
425 progress += 1 434 progress += 1
426 self.findProgress.setValue(progress) 435 self.findProgress.setValue(progress)
427 continue 436 continue
428 437
439 end = contains.end() 448 end = contains.end()
440 if self.__replaceMode: 449 if self.__replaceMode:
441 rline = search.sub(replTxt, line) 450 rline = search.sub(replTxt, line)
442 else: 451 else:
443 rline = "" 452 rline = ""
453 line = self.__stripEol(line)
444 if len(line) > 1024: 454 if len(line) > 1024:
445 line = "{0} ...".format(line[:1024]) 455 line = "{0} ...".format(line[:1024])
446 if self.__replaceMode: 456 if self.__replaceMode:
447 if len(rline) > 1024: 457 if len(rline) > 1024:
448 rline = "{0} ...".format(line[:1024]) 458 rline = "{0} ...".format(line[:1024])
449 line = "- {0}\n+ {1}".format(line, rline) 459 line = "- {0}\n+ {1}".format(
460 line, self.__stripEol(rline))
450 self.__createItem(file, count, line, start, end, 461 self.__createItem(file, count, line, start, end,
451 rline, hash) 462 rline, hash)
452 463
453 if self.feelLikeCheckBox.isChecked(): 464 if self.feelLikeCheckBox.isChecked():
454 fn = os.path.join(self.project.ppath, file) 465 fn = os.path.join(self.project.ppath, file)
579 590
580 # read the file and split it into textlines 591 # read the file and split it into textlines
581 try: 592 try:
582 text, encoding, hash = \ 593 text, encoding, hash = \
583 Utilities.readEncodedFileWithHash(fn) 594 Utilities.readEncodedFileWithHash(fn)
584 lines = text.splitlines() 595 lines = text.splitlines(True)
585 except (UnicodeError, IOError): 596 except (UnicodeError, IOError):
586 E5MessageBox.critical(self, 597 E5MessageBox.critical(self,
587 self.trUtf8("Replace in Files"), 598 self.trUtf8("Replace in Files"),
588 self.trUtf8( 599 self.trUtf8(
589 """<p>Could not read the file <b>{0}</b>.""" 600 """<p>Could not read the file <b>{0}</b>."""
616 line = citm.data(0, self.lineRole) 627 line = citm.data(0, self.lineRole)
617 rline = citm.data(0, self.replaceRole) 628 rline = citm.data(0, self.replaceRole)
618 lines[line - 1] = rline 629 lines[line - 1] = rline
619 630
620 # write the file 631 # write the file
621 if self.project.isProjectFile(fn): 632 txt = "".join(lines)
622 eol = self.project.getEolString()
623 else:
624 eol = Utilities.linesep()
625 txt = eol.join(lines) + Utilities.linesep()
626 try: 633 try:
627 Utilities.writeEncodedFile(fn, txt, encoding) 634 Utilities.writeEncodedFile(fn, txt, encoding)
628 except (IOError, Utilities.CodingError, UnicodeError) as err: 635 except (IOError, Utilities.CodingError, UnicodeError) as err:
629 E5MessageBox.critical(self, 636 E5MessageBox.critical(self,
630 self.trUtf8("Replace in Files"), 637 self.trUtf8("Replace in Files"),

eric ide

mercurial