UI/FindFileDialog.py

branch
5_0_x
changeset 856
2fd0c2ea2487
parent 792
a13346916170
child 895
d8deb8c8e907
equal deleted inserted replaced
838:505c08c2d645 856:2fd0c2ea2487
248 """ 248 """
249 if button == self.findButton: 249 if button == self.findButton:
250 self.__doSearch() 250 self.__doSearch()
251 elif button == self.stopButton: 251 elif button == self.stopButton:
252 self.__stopSearch() 252 self.__stopSearch()
253
254 def __stripEol(self, txt):
255 """
256 Private method to strip the eol part.
257
258 @param txt line of text that should be treated (string)
259 @return text with eol stripped (string)
260 """
261 return txt.replace("\r", "").replace("\n", "")
253 262
254 def __stopSearch(self): 263 def __stopSearch(self):
255 """ 264 """
256 Private slot to handle the stop button being pressed. 265 Private slot to handle the stop button being pressed.
257 """ 266 """
391 else: 400 else:
392 fn = file 401 fn = file
393 # read the file and split it into textlines 402 # read the file and split it into textlines
394 try: 403 try:
395 text, encoding = Utilities.readEncodedFile(fn) 404 text, encoding = Utilities.readEncodedFile(fn)
396 lines = text.splitlines() 405 lines = text.splitlines(True)
397 except (UnicodeError, IOError): 406 except (UnicodeError, IOError):
398 progress += 1 407 progress += 1
399 self.findProgress.setValue(progress) 408 self.findProgress.setValue(progress)
400 continue 409 continue
401 410
412 end = contains.end() 421 end = contains.end()
413 if self.__replaceMode: 422 if self.__replaceMode:
414 rline = search.sub(replTxt, line) 423 rline = search.sub(replTxt, line)
415 else: 424 else:
416 rline = "" 425 rline = ""
426 line = self.__stripEol(line)
417 if len(line) > 1024: 427 if len(line) > 1024:
418 line = "%s ..." % line[:1024] 428 line = "%s ..." % line[:1024]
419 if self.__replaceMode: 429 if self.__replaceMode:
420 if len(rline) > 1024: 430 if len(rline) > 1024:
421 rline = "%s ..." % line[:1024] 431 rline = "%s ..." % line[:1024]
422 line = "- %s\n+ %s" % (line, rline) 432 line = "- %s\n+ %s" % (
433 line, self.__stripEol(rline))
423 self.__createItem(file, count, line, start, end, rline) 434 self.__createItem(file, count, line, start, end, rline)
424 435
425 if self.feelLikeCheckBox.isChecked(): 436 if self.feelLikeCheckBox.isChecked():
426 fn = os.path.join(self.project.ppath, file) 437 fn = os.path.join(self.project.ppath, file)
427 self.emit(SIGNAL('sourceFile'), fn, count, "", (start, end)) 438 self.emit(SIGNAL('sourceFile'), fn, count, "", (start, end))
548 fn = file 559 fn = file
549 560
550 # read the file and split it into textlines 561 # read the file and split it into textlines
551 try: 562 try:
552 text, encoding = Utilities.readEncodedFile(fn) 563 text, encoding = Utilities.readEncodedFile(fn)
553 lines = text.splitlines() 564 lines = text.splitlines(True)
554 except (UnicodeError, IOError): 565 except (UnicodeError, IOError):
555 QMessageBox.critical(self, 566 QMessageBox.critical(self,
556 self.trUtf8("Replace in Files"), 567 self.trUtf8("Replace in Files"),
557 self.trUtf8("""<p>Could not read the file <b>{0}</b>.""" 568 self.trUtf8("""<p>Could not read the file <b>{0}</b>."""
558 """ Skipping it.</p><p>Reason: {1}</p>""")\ 569 """ Skipping it.</p><p>Reason: {1}</p>""")\
569 line = citm.data(0, self.lineRole) 580 line = citm.data(0, self.lineRole)
570 rline = citm.data(0, self.replaceRole) 581 rline = citm.data(0, self.replaceRole)
571 lines[line - 1] = rline 582 lines[line - 1] = rline
572 583
573 # write the file 584 # write the file
574 txt = Utilities.linesep().join(lines) + Utilities.linesep() 585 txt = "".join(lines)
575 try: 586 try:
576 Utilities.writeEncodedFile(fn, txt, encoding) 587 Utilities.writeEncodedFile(fn, txt, encoding)
577 except (IOError, Utilities.CodingError, UnicodeError) as err: 588 except (IOError, Utilities.CodingError, UnicodeError) as err:
578 QMessageBox.critical(self, 589 QMessageBox.critical(self,
579 self.trUtf8("Replace in Files"), 590 self.trUtf8("Replace in Files"),

eric ide

mercurial