File: FindInDirService.py

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (601 lines) | stat: -rw-r--r-- 27,569 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
#----------------------------------------------------------------------------
# Name:         IDEFindService.py
# Purpose:      Find Service for pydocview
#
# Author:       Morgan Hua
#
# Created:      8/15/03
# CVS-ID:       $Id$
# Copyright:    (c) 2004-2005 ActiveGrid, Inc.
# License:      wxWindows License
#----------------------------------------------------------------------------

import wx
import wx.lib.docview
import os
from os.path import join
import re
import ProjectEditor
import MessageService
import FindService
import OutlineService
_ = wx.GetTranslation


#----------------------------------------------------------------------------
# Constants
#----------------------------------------------------------------------------
FILENAME_MARKER = _("Found in file: ")
PROJECT_MARKER = _("Searching project: ")
FILE_MARKER = _("Searching file: ")
FIND_MATCHDIR = "FindMatchDir"
FIND_MATCHDIRSUBFOLDERS = "FindMatchDirSubfolders"

SPACE = 10
HALF_SPACE = 5


class FindInDirService(FindService.FindService):

    #----------------------------------------------------------------------------
    # Constants
    #----------------------------------------------------------------------------
    FINDFILE_ID = wx.NewId()        # for bringing up Find in File dialog box
    FINDALL_ID = wx.NewId()         # for bringing up Find All dialog box
    FINDDIR_ID = wx.NewId()         # for bringing up Find Dir dialog box


    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
        FindService.FindService.InstallControls(self, frame, menuBar, toolBar, statusBar, document)

        editMenu = menuBar.GetMenu(menuBar.FindMenu(_("&Edit")))
        wx.EVT_MENU(frame, FindInDirService.FINDFILE_ID, self.ProcessEvent)
        wx.EVT_UPDATE_UI(frame, FindInDirService.FINDFILE_ID, self.ProcessUpdateUIEvent)
        editMenu.Append(FindInDirService.FINDFILE_ID, _("Find in File...\tCtrl+Shift+F"), _("Searches for the specified text in the current file"))
        wx.EVT_MENU(frame, FindInDirService.FINDALL_ID, self.ProcessEvent)
        wx.EVT_UPDATE_UI(frame, FindInDirService.FINDALL_ID, self.ProcessUpdateUIEvent)
        editMenu.Append(FindInDirService.FINDALL_ID, _("Find in Project...\tCtrl+Shift+P"), _("Searches for the specified text in all the files in the project"))
        wx.EVT_MENU(frame, FindInDirService.FINDDIR_ID, self.ProcessEvent)
        wx.EVT_UPDATE_UI(frame, FindInDirService.FINDDIR_ID, self.ProcessUpdateUIEvent)
        editMenu.Append(FindInDirService.FINDDIR_ID, _("Find in Directory...\tCtrl+Shift+D"), _("Searches for the specified text in all the files in the directory"))


    def ProcessEvent(self, event):
        id = event.GetId()
        if id == FindInDirService.FINDFILE_ID:
            view = wx.GetApp().GetDocumentManager().GetCurrentView()
            if hasattr(view, "GetCtrl") and view.GetCtrl() and hasattr(view.GetCtrl(), "GetSelectedText"):
                self.ShowFindInFileDialog(view.GetCtrl().GetSelectedText())
            else:
                self.ShowFindInFileDialog()
            return True
        elif id == FindInDirService.FINDALL_ID:
            view = wx.GetApp().GetDocumentManager().GetCurrentView()
            if hasattr(view, "GetCtrl") and view.GetCtrl() and hasattr(view.GetCtrl(), "GetSelectedText"):
                self.ShowFindInProjectDialog(view.GetCtrl().GetSelectedText())
            else:
                self.ShowFindInProjectDialog()
            return True
        elif id == FindInDirService.FINDDIR_ID:
            view = wx.GetApp().GetDocumentManager().GetCurrentView()
            if hasattr(view, "GetCtrl") and view.GetCtrl() and hasattr(view.GetCtrl(), "GetSelectedText"):
                self.ShowFindInDirDialog(view.GetCtrl().GetSelectedText())
            else:
                self.ShowFindInDirDialog()
            return True
        else:
            return FindService.FindService.ProcessEvent(self, event)


    def ProcessUpdateUIEvent(self, event):
        id = event.GetId()
        if id == FindInDirService.FINDFILE_ID:
            view = wx.GetApp().GetDocumentManager().GetCurrentView()
            if view and view.GetDocument() and not isinstance(view.GetDocument(), ProjectEditor.ProjectDocument):  # don't search project model
                event.Enable(True)
            else:
                event.Enable(False)
            return True
        elif id == FindInDirService.FINDALL_ID:
            projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)
            if projectService.GetFilesFromCurrentProject():
                event.Enable(True)
            else:
                event.Enable(False)
            return True
        elif id == FindInDirService.FINDDIR_ID:
            event.Enable(True)
        else:
            return FindService.FindService.ProcessUpdateUIEvent(self, event)


    def ShowFindInDirDialog(self, findString=None):
        config = wx.ConfigBase_Get()

        frame = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("Find in Directory"), size= (320,200))
        borderSizer = wx.BoxSizer(wx.HORIZONTAL)

        contentSizer = wx.BoxSizer(wx.VERTICAL)
        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
        lineSizer.Add(wx.StaticText(frame, -1, _("Directory:")), 0, wx.ALIGN_CENTER | wx.RIGHT, HALF_SPACE)
        dirCtrl = wx.TextCtrl(frame, -1, config.Read(FIND_MATCHDIR, ""), size=(200,-1))
        dirCtrl.SetToolTipString(dirCtrl.GetValue())
        lineSizer.Add(dirCtrl, 0, wx.LEFT, HALF_SPACE)
        findDirButton = wx.Button(frame, -1, _("Browse..."))
        lineSizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE)
        contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE)

        def OnBrowseButton(event):
            dlg = wx.DirDialog(frame, _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE)
            dir = dirCtrl.GetValue()
            if len(dir):
                dlg.SetPath(dir)
            dlg.CenterOnParent()
            if dlg.ShowModal() == wx.ID_OK:
                dirCtrl.SetValue(dlg.GetPath())
                dirCtrl.SetToolTipString(dirCtrl.GetValue())
                dirCtrl.SetInsertionPointEnd()
            dlg.Destroy()
        wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton)

        subfolderCtrl = wx.CheckBox(frame, -1, _("Search in subdirectories"))
        subfolderCtrl.SetValue(config.ReadInt(FIND_MATCHDIRSUBFOLDERS, True))
        contentSizer.Add(subfolderCtrl, 0, wx.BOTTOM, SPACE)

        lineSizer = wx.BoxSizer(wx.VERTICAL)    # let the line expand horizontally without vertical expansion
        lineSizer.Add(wx.StaticLine(frame, -1, size = (10,-1)), 0, flag=wx.EXPAND)
        contentSizer.Add(lineSizer, flag=wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.BOTTOM, border=HALF_SPACE)

        if wx.Platform == "__WXMAC__":
            contentSizer.Add((-1, 10), 0, wx.EXPAND)

        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
        lineSizer.Add(wx.StaticText(frame, -1, _("Find what:")), 0, wx.ALIGN_CENTER | wx.RIGHT, HALF_SPACE)
        if not findString:
            findString = config.Read(FindService.FIND_MATCHPATTERN, "")
        findCtrl = wx.TextCtrl(frame, -1, findString, size=(200,-1))
        findCtrl.SetFocus()
        findCtrl.SetSelection(0,-1)
        lineSizer.Add(findCtrl, 0, wx.LEFT, HALF_SPACE)
        contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE)
        wholeWordCtrl = wx.CheckBox(frame, -1, _("Match whole word only"))
        wholeWordCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHWHOLEWORD, False))
        matchCaseCtrl = wx.CheckBox(frame, -1, _("Match case"))
        matchCaseCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHCASE, False))
        regExprCtrl = wx.CheckBox(frame, -1, _("Regular expression"))
        regExprCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHREGEXPR, False))
        contentSizer.Add(wholeWordCtrl, 0, wx.BOTTOM, SPACE)
        contentSizer.Add(matchCaseCtrl, 0, wx.BOTTOM, SPACE)
        contentSizer.Add(regExprCtrl, 0, wx.BOTTOM, SPACE)
        borderSizer.Add(contentSizer, 0, wx.TOP | wx.BOTTOM | wx.LEFT, SPACE)

        buttonSizer = wx.BoxSizer(wx.VERTICAL)
        findBtn = wx.Button(frame, wx.ID_OK, _("Find"))
        findBtn.SetDefault()
        BTM_SPACE = HALF_SPACE
        if wx.Platform == "__WXMAC__":
            BTM_SPACE = SPACE
        buttonSizer.Add(findBtn, 0, wx.BOTTOM, BTM_SPACE)
        buttonSizer.Add(wx.Button(frame, wx.ID_CANCEL), 0)
        borderSizer.Add(buttonSizer, 0, wx.ALL, SPACE)

        frame.SetSizer(borderSizer)
        frame.Fit()

        frame.CenterOnParent()
        status = frame.ShowModal()

        passedCheck = False
        while status == wx.ID_OK and not passedCheck:
            if not os.path.exists(dirCtrl.GetValue()):
                dlg = wx.MessageDialog(frame,
                                       _("'%s' does not exist.") % dirCtrl.GetValue(),
                                       _("Find in Directory"),
                                       wx.OK | wx.ICON_EXCLAMATION
                                       )
                dlg.CenterOnParent()
                dlg.ShowModal()
                dlg.Destroy()

                status = frame.ShowModal()
            elif len(findCtrl.GetValue()) == 0:
                dlg = wx.MessageDialog(frame,
                                       _("'Find what:' cannot be empty."),
                                       _("Find in Directory"),
                                       wx.OK | wx.ICON_EXCLAMATION
                                       )
                dlg.CenterOnParent()
                dlg.ShowModal()
                dlg.Destroy()

                status = frame.ShowModal()
            else:
                passedCheck = True


        # save user choice state for this and other Find Dialog Boxes
        dirString = dirCtrl.GetValue()
        searchSubfolders = subfolderCtrl.IsChecked()
        self.SaveFindInDirConfig(dirString, searchSubfolders)

        findString = findCtrl.GetValue()
        matchCase = matchCaseCtrl.IsChecked()
        wholeWord = wholeWordCtrl.IsChecked()
        regExpr = regExprCtrl.IsChecked()
        self.SaveFindConfig(findString, wholeWord, matchCase, regExpr)

        frame.Destroy()
        if status == wx.ID_OK:
            messageService = wx.GetApp().GetService(MessageService.MessageService)
            messageService.ShowWindow()

            view = messageService.GetView()
            if view:
                wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
                
                try:
                    view.ClearLines()
                    view.SetCallback(self.OnJumpToFoundLine)
    
                    view.AddLines(_("Searching for '%s' in '%s'\n\n") % (findString, dirString))
    
                    if os.path.isfile(dirString):
                        try:
                            docFile = file(dirString, 'r')
                            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 + dirString + "\n")
                                        needToDisplayFilename = False
                                    line = repr(lineNum).zfill(4) + ":" + line
                                    view.AddLines(line)
                                line = docFile.readline()
                                lineNum += 1
                            if not needToDisplayFilename:
                                view.AddLines("\n")
                        except IOError, (code, message):
                            print _("Warning, unable to read file: '%s'.  %s") % (dirString, message)
                    else:
                        # do search in files on disk
                        for root, dirs, files in os.walk(dirString):
                            if not searchSubfolders and root != dirString:
                                break
    
                            for name in files:
                                filename = os.path.join(root, name)
                                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)
                                    line = docFile.readline()
                                    lineNum += 1
                                if not needToDisplayFilename:
                                    view.AddLines("\n")
    
                    view.AddLines(_("Search completed."))
                
                finally:
                    wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))

            return True
        else:
            return False


    def SaveFindInDirConfig(self, dirString, searchSubfolders):
        """ Save search dir patterns and flags to registry.

            dirString = search directory
            searchSubfolders = Search subfolders
        """
        config = wx.ConfigBase_Get()
        config.Write(FIND_MATCHDIR, dirString)
        config.WriteInt(FIND_MATCHDIRSUBFOLDERS, searchSubfolders)


    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)
    
            if jumpToFound:
                self.OnJumpToFoundLine(event=None, defLineNum=firstDef)

        finally:
            wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))

    def FindInProject(self, findString):
        self.DoFindIn(findString, matchCase=True, wholeWord=True, regExpr=True, jumpToFound=True)


    def ShowFindInProjectDialog(self, findString=None):
        config = wx.ConfigBase_Get()

        frame = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("Find in Project"), size= (320,200))
        borderSizer = wx.BoxSizer(wx.HORIZONTAL)

        contentSizer = wx.BoxSizer(wx.VERTICAL)
        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
        lineSizer.Add(wx.StaticText(frame, -1, _("Find what:")), 0, wx.ALIGN_CENTER | wx.RIGHT, HALF_SPACE)
        if not findString:
            findString = config.Read(FindService.FIND_MATCHPATTERN, "")
        findCtrl = wx.TextCtrl(frame, -1, findString, size=(200,-1))
        lineSizer.Add(findCtrl, 0, wx.LEFT, HALF_SPACE)
        contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE)
        wholeWordCtrl = wx.CheckBox(frame, -1, _("Match whole word only"))
        wholeWordCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHWHOLEWORD, False))
        matchCaseCtrl = wx.CheckBox(frame, -1, _("Match case"))
        matchCaseCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHCASE, False))
        regExprCtrl = wx.CheckBox(frame, -1, _("Regular expression"))
        regExprCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHREGEXPR, False))
        contentSizer.Add(wholeWordCtrl, 0, wx.BOTTOM, SPACE)
        contentSizer.Add(matchCaseCtrl, 0, wx.BOTTOM, SPACE)
        contentSizer.Add(regExprCtrl, 0, wx.BOTTOM, SPACE)
        borderSizer.Add(contentSizer, 0, wx.TOP | wx.BOTTOM | wx.LEFT, SPACE)

        buttonSizer = wx.BoxSizer(wx.VERTICAL)
        findBtn = wx.Button(frame, wx.ID_OK, _("Find"))
        findBtn.SetDefault()
        BTM_SPACE = HALF_SPACE
        if wx.Platform == "__WXMAC__":
            BTM_SPACE = SPACE
        buttonSizer.Add(findBtn, 0, wx.BOTTOM, BTM_SPACE)
        buttonSizer.Add(wx.Button(frame, wx.ID_CANCEL), 0)
        borderSizer.Add(buttonSizer, 0, wx.ALL, SPACE)

        frame.SetSizer(borderSizer)
        frame.Fit()

        frame.CenterOnParent()
        status = frame.ShowModal()

        # save user choice state for this and other Find Dialog Boxes
        findString = findCtrl.GetValue()
        matchCase = matchCaseCtrl.IsChecked()
        wholeWord = wholeWordCtrl.IsChecked()
        regExpr = regExprCtrl.IsChecked()
        self.SaveFindConfig(findString, wholeWord, matchCase, regExpr)

        frame.Destroy()

        if status == wx.ID_OK:
            self.DoFindIn(findString, matchCase, wholeWord, regExpr)
            return True
        else:
            return False


    def ShowFindInFileDialog(self, findString=None):
        config = wx.ConfigBase_Get()

        frame = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("Find in File"), size= (320,200))
        borderSizer = wx.BoxSizer(wx.HORIZONTAL)

        contentSizer = wx.BoxSizer(wx.VERTICAL)
        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
        lineSizer.Add(wx.StaticText(frame, -1, _("Find what:")), 0, wx.ALIGN_CENTER | wx.RIGHT, HALF_SPACE)
        if not findString:
            findString = config.Read(FindService.FIND_MATCHPATTERN, "")
        findCtrl = wx.TextCtrl(frame, -1, findString, size=(200,-1))
        lineSizer.Add(findCtrl, 0, wx.LEFT, HALF_SPACE)
        contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE)
        wholeWordCtrl = wx.CheckBox(frame, -1, _("Match whole word only"))
        wholeWordCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHWHOLEWORD, False))
        matchCaseCtrl = wx.CheckBox(frame, -1, _("Match case"))
        matchCaseCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHCASE, False))
        regExprCtrl = wx.CheckBox(frame, -1, _("Regular expression"))
        regExprCtrl.SetValue(config.ReadInt(FindService.FIND_MATCHREGEXPR, False))
        contentSizer.Add(wholeWordCtrl, 0, wx.BOTTOM, SPACE)
        contentSizer.Add(matchCaseCtrl, 0, wx.BOTTOM, SPACE)
        contentSizer.Add(regExprCtrl, 0, wx.BOTTOM, SPACE)
        borderSizer.Add(contentSizer, 0, wx.TOP | wx.BOTTOM | wx.LEFT, SPACE)

        buttonSizer = wx.BoxSizer(wx.VERTICAL)
        findBtn = wx.Button(frame, wx.ID_OK, _("Find"))
        findBtn.SetDefault()
        BTM_SPACE = HALF_SPACE
        if wx.Platform == "__WXMAC__":
            BTM_SPACE = SPACE
        buttonSizer.Add(findBtn, 0, wx.BOTTOM, BTM_SPACE)
        buttonSizer.Add(wx.Button(frame, wx.ID_CANCEL), 0)
        borderSizer.Add(buttonSizer, 0, wx.ALL, SPACE)

        frame.SetSizer(borderSizer)
        frame.Fit()

        frame.CenterOnParent()
        status = frame.ShowModal()

        # save user choice state for this and other Find Dialog Boxes
        findString = findCtrl.GetValue()
        matchCase = matchCaseCtrl.IsChecked()
        wholeWord = wholeWordCtrl.IsChecked()
        regExpr = regExprCtrl.IsChecked()
        self.SaveFindConfig(findString, wholeWord, matchCase, regExpr)

        frame.Destroy()

        if status == wx.ID_OK:
            self.DoFindIn(findString, matchCase, wholeWord, regExpr, currFileOnly=True)
            return True
        else:
            return False


    def OnJumpToFoundLine(self, event=None, defLineNum=-1):
        messageService = wx.GetApp().GetService(MessageService.MessageService)
        if defLineNum == -1:
            lineText, pos = messageService.GetView().GetCurrLine()
        else:
            lineText = messageService.GetView().GetControl().GetLine(defLineNum)
            pos = 0

        if lineText == "\n" or lineText.find(FILENAME_MARKER) != -1 or lineText.find(PROJECT_MARKER) != -1 or lineText.find(FILE_MARKER) != -1:
            return
        lineEnd = lineText.find(":")
        if lineEnd == -1:
            return
        else:
            lineNum = int(lineText[0:lineEnd])

        text = messageService.GetView().GetText()
        if defLineNum == -1:
            curPos = messageService.GetView().GetCurrentPos()
        else:
            curPos = messageService.GetView().GetControl().GetLineEndPosition(defLineNum)

        startPos = text.rfind(FILENAME_MARKER, 0, curPos)
        endPos = text.find("\n", startPos)
        filename = text[startPos + len(FILENAME_MARKER):endPos]

        foundView = None
        openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
        for openDoc in openDocs:
            if openDoc.GetFilename() == filename:
                foundView = openDoc.GetFirstView()
                break

        if not foundView:
            doc = wx.GetApp().GetDocumentManager().CreateDocument(filename, wx.lib.docview.DOC_SILENT|wx.lib.docview.DOC_OPEN_ONCE)
            if doc:
                foundView = doc.GetFirstView()

        if foundView:
            foundView.GetFrame().SetFocus()
            foundView.Activate()
            if hasattr(foundView, "GotoLine"):
                foundView.GotoLine(lineNum)
                startPos = foundView.PositionFromLine(lineNum)
                # wxBug:  Need to select in reverse order, (end, start) to put cursor at head of line so positioning is correct
                #         Also, if we use the correct positioning order (start, end), somehow, when we open a edit window for the first
                #         time, we don't see the selection, it is scrolled off screen
                foundView.SetSelection(startPos - 1 + len(lineText[lineEnd:].rstrip("\n")), startPos)
                wx.GetApp().GetService(OutlineService.OutlineService).LoadOutline(foundView, position=startPos)