+
+
+ def DoFindIn(self, findString, matchCase, wholeWord, regExpr, currFileOnly=False, jumpToFound=False):
+ messageService = wx.GetApp().GetService(MessageService.MessageService)
+ if not messageService:
+ return
+
+ messageService.ShowWindow()
+
+ view = messageService.GetView()
+ if not view:
+ return
+
+ wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
+
+ try:
+ #Switch to messages tab.
+ view.GetControl().GetParent().SetSelection(0)
+ view.ClearLines()
+ view.SetCallback(self.OnJumpToFoundLine)
+
+ projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)
+
+ if wx.GetApp().GetDocumentManager().GetCurrentView():
+ currDoc = wx.GetApp().GetDocumentManager().GetCurrentView().GetDocument()
+ else:
+ currDoc = None
+ if currFileOnly:
+ if currDoc:
+ projectFilenames = [currDoc.GetFilename()]
+ view.AddLines(FILE_MARKER + currDoc.GetFilename() + "\n\n")
+ else:
+ projectFilenames = []
+ else:
+ projectFilenames = projectService.GetFilesFromCurrentProject()
+
+ projView = projectService.GetView()
+ if projView:
+ projName = wx.lib.docview.FileNameFromPath(projView.GetDocument().GetFilename())
+ view.AddLines(PROJECT_MARKER + projName + "\n\n")
+
+ firstDef = -1
+
+ # do search in open files first, open files may have been modified and different from disk because it hasn't been saved
+ openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
+ openDocsInProject = filter(lambda openDoc: openDoc.GetFilename() in projectFilenames, openDocs)
+ if currDoc and currDoc in openDocsInProject:
+ # make sure current document is searched first.
+ openDocsInProject.remove(currDoc)
+ openDocsInProject.insert(0, currDoc)
+ for openDoc in openDocsInProject:
+ if isinstance(openDoc, ProjectEditor.ProjectDocument): # don't search project model
+ continue
+
+ openDocView = openDoc.GetFirstView()
+ # some views don't have a in memory text object to search through such as the PM and the DM
+ # even if they do have a non-text searchable object, how do we display it in the message window?
+ if not hasattr(openDocView, "GetValue"):
+ continue
+ text = openDocView.GetValue()
+
+ lineNum = 1
+ needToDisplayFilename = True
+ start = 0
+ end = 0
+ count = 0
+ while count != -1:
+ count, foundStart, foundEnd, newText = self.DoFind(findString, None, text, start, end, True, matchCase, wholeWord, regExpr)
+ if count != -1:
+ if needToDisplayFilename:
+ view.AddLines(FILENAME_MARKER + openDoc.GetFilename() + "\n")
+ needToDisplayFilename = False
+
+ lineNum = openDocView.LineFromPosition(foundStart)
+ line = repr(lineNum).zfill(4) + ":" + openDocView.GetLine(lineNum)
+ view.AddLines(line)
+ if firstDef == -1:
+ firstDef = view.GetControl().GetCurrentLine() - 1
+
+ start = text.find("\n", foundStart)
+ if start == -1:
+ break
+ end = start
+ if not needToDisplayFilename:
+ view.AddLines("\n")
+ wx.GetApp().Yield(True)
+ openDocNames = map(lambda openDoc: openDoc.GetFilename(), openDocs)
+
+ # do search in closed files, skipping the open ones we already searched
+ filenames = filter(lambda filename: filename not in openDocNames, projectFilenames)
+ for filename in filenames:
+ try:
+ docFile = file(filename, 'r')
+ except IOError, (code, message):
+ print _("Warning, unable to read file: '%s'. %s") % (filename, message)
+ continue
+
+ lineNum = 1
+ needToDisplayFilename = True
+ line = docFile.readline()
+ while line:
+ count, foundStart, foundEnd, newText = self.DoFind(findString, None, line, 0, 0, True, matchCase, wholeWord, regExpr)
+ if count != -1:
+ if needToDisplayFilename:
+ view.AddLines(FILENAME_MARKER + filename + "\n")
+ needToDisplayFilename = False
+ line = repr(lineNum).zfill(4) + ":" + line
+ view.AddLines(line)
+ if firstDef == -1:
+ firstDef = view.GetControl().GetCurrentLine() - 1
+ line = docFile.readline()
+ lineNum += 1
+ if not needToDisplayFilename:
+ view.AddLines("\n")
+ wx.GetApp().Yield(True)
+
+ view.AddLines(_("Search for '%s' completed.") % findString)