]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/FindInDirService.py
1 #----------------------------------------------------------------------------
2 # Name: IDEFindService.py
3 # Purpose: Find Service for pydocview
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
16 from os
. path
import join
25 #----------------------------------------------------------------------------
27 #----------------------------------------------------------------------------
28 FILENAME_MARKER
= _ ( "Found in file: " )
29 PROJECT_MARKER
= _ ( "Searching project: " )
30 FILE_MARKER
= _ ( "Searching file: " )
31 FIND_MATCHDIR
= "FindMatchDir"
32 FIND_MATCHDIRSUBFOLDERS
= "FindMatchDirSubfolders"
38 class FindInDirService ( FindService
. FindService
):
40 #----------------------------------------------------------------------------
42 #----------------------------------------------------------------------------
43 FINDFILE_ID
= wx
. NewId () # for bringing up Find in File dialog box
44 FINDALL_ID
= wx
. NewId () # for bringing up Find All dialog box
45 FINDDIR_ID
= wx
. NewId () # for bringing up Find Dir dialog box
48 def InstallControls ( self
, frame
, menuBar
= None , toolBar
= None , statusBar
= None , document
= None ):
49 FindService
. FindService
. InstallControls ( self
, frame
, menuBar
, toolBar
, statusBar
, document
)
51 editMenu
= menuBar
. GetMenu ( menuBar
. FindMenu ( _ ( "&Edit" )))
52 wx
. EVT_MENU ( frame
, FindInDirService
. FINDFILE_ID
, self
. ProcessEvent
)
53 wx
. EVT_UPDATE_UI ( frame
, FindInDirService
. FINDFILE_ID
, self
. ProcessUpdateUIEvent
)
54 editMenu
. Append ( FindInDirService
. FINDFILE_ID
, _ ( "Find in File... \t Ctrl+Shift+F" ), _ ( "Searches for the specified text in the current file" ))
55 wx
. EVT_MENU ( frame
, FindInDirService
. FINDALL_ID
, self
. ProcessEvent
)
56 wx
. EVT_UPDATE_UI ( frame
, FindInDirService
. FINDALL_ID
, self
. ProcessUpdateUIEvent
)
57 editMenu
. Append ( FindInDirService
. FINDALL_ID
, _ ( "Find in Project... \t Ctrl+Shift+P" ), _ ( "Searches for the specified text in all the files in the project" ))
58 wx
. EVT_MENU ( frame
, FindInDirService
. FINDDIR_ID
, self
. ProcessEvent
)
59 wx
. EVT_UPDATE_UI ( frame
, FindInDirService
. FINDDIR_ID
, self
. ProcessUpdateUIEvent
)
60 editMenu
. Append ( FindInDirService
. FINDDIR_ID
, _ ( "Find in Directory... \t Ctrl+Shift+D" ), _ ( "Searches for the specified text in all the files in the directory" ))
63 def ProcessEvent ( self
, event
):
65 if id == FindInDirService
. FINDFILE_ID
:
66 view
= wx
. GetApp (). GetDocumentManager (). GetCurrentView ()
67 if hasattr ( view
, "GetCtrl" ) and view
. GetCtrl () and hasattr ( view
. GetCtrl (), "GetSelectedText" ):
68 self
. ShowFindInFileDialog ( view
. GetCtrl (). GetSelectedText ())
70 self
. ShowFindInFileDialog ()
72 elif id == FindInDirService
. FINDALL_ID
:
73 view
= wx
. GetApp (). GetDocumentManager (). GetCurrentView ()
74 if hasattr ( view
, "GetCtrl" ) and view
. GetCtrl () and hasattr ( view
. GetCtrl (), "GetSelectedText" ):
75 self
. ShowFindInProjectDialog ( view
. GetCtrl (). GetSelectedText ())
77 self
. ShowFindInProjectDialog ()
79 elif id == FindInDirService
. FINDDIR_ID
:
80 view
= wx
. GetApp (). GetDocumentManager (). GetCurrentView ()
81 if hasattr ( view
, "GetCtrl" ) and view
. GetCtrl () and hasattr ( view
. GetCtrl (), "GetSelectedText" ):
82 self
. ShowFindInDirDialog ( view
. GetCtrl (). GetSelectedText ())
84 self
. ShowFindInDirDialog ()
87 return FindService
. FindService
. ProcessEvent ( self
, event
)
90 def ProcessUpdateUIEvent ( self
, event
):
92 if id == FindInDirService
. FINDFILE_ID
:
93 view
= wx
. GetApp (). GetDocumentManager (). GetCurrentView ()
94 if view
and view
. GetDocument () and not isinstance ( view
. GetDocument (), ProjectEditor
. ProjectDocument
): # don't search project model
99 elif id == FindInDirService
. FINDALL_ID
:
100 projectService
= wx
. GetApp (). GetService ( ProjectEditor
. ProjectService
)
101 if projectService
. GetFilesFromCurrentProject ():
106 elif id == FindInDirService
. FINDDIR_ID
:
109 return FindService
. FindService
. ProcessUpdateUIEvent ( self
, event
)
112 def ShowFindInDirDialog ( self
, findString
= None ):
113 config
= wx
. ConfigBase_Get ()
115 frame
= wx
. Dialog ( wx
. GetApp (). GetTopWindow (), - 1 , _ ( "Find in Directory" ), size
= ( 320 , 200 ))
116 borderSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
118 contentSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
119 lineSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
120 lineSizer
. Add ( wx
. StaticText ( frame
, - 1 , _ ( "Directory:" )), 0 , wx
. ALIGN_CENTER | wx
. RIGHT
, HALF_SPACE
)
121 dirCtrl
= wx
. TextCtrl ( frame
, - 1 , config
. Read ( FIND_MATCHDIR
, "" ), size
=( 200 ,- 1 ))
122 dirCtrl
. SetToolTipString ( dirCtrl
. GetValue ())
123 lineSizer
. Add ( dirCtrl
, 0 , wx
. LEFT
, HALF_SPACE
)
124 findDirButton
= wx
. Button ( frame
, - 1 , _ ( "Browse..." ))
125 lineSizer
. Add ( findDirButton
, 0 , wx
. LEFT
, HALF_SPACE
)
126 contentSizer
. Add ( lineSizer
, 0 , wx
. BOTTOM
, SPACE
)
128 def OnBrowseButton ( event
):
129 dlg
= wx
. DirDialog ( frame
, _ ( "Choose a directory:" ), style
= wx
. DD_DEFAULT_STYLE
)
130 dir = dirCtrl
. GetValue ()
134 if dlg
. ShowModal () == wx
. ID_OK
:
135 dirCtrl
. SetValue ( dlg
. GetPath ())
136 dirCtrl
. SetToolTipString ( dirCtrl
. GetValue ())
137 dirCtrl
. SetInsertionPointEnd ()
139 wx
. EVT_BUTTON ( findDirButton
, - 1 , OnBrowseButton
)
141 subfolderCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Search in subdirectories" ))
142 subfolderCtrl
. SetValue ( config
. ReadInt ( FIND_MATCHDIRSUBFOLDERS
, True ))
143 contentSizer
. Add ( subfolderCtrl
, 0 , wx
. BOTTOM
, SPACE
)
145 lineSizer
= wx
. BoxSizer ( wx
. VERTICAL
) # let the line expand horizontally without vertical expansion
146 lineSizer
. Add ( wx
. StaticLine ( frame
, - 1 , size
= ( 10 ,- 1 )), 0 , flag
= wx
. EXPAND
)
147 contentSizer
. Add ( lineSizer
, flag
= wx
. EXPAND|wx
. ALIGN_CENTER_VERTICAL|wx
. BOTTOM
, border
= HALF_SPACE
)
149 if wx
. Platform
== "__WXMAC__" :
150 contentSizer
. Add ((- 1 , 10 ), 0 , wx
. EXPAND
)
152 lineSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
153 lineSizer
. Add ( wx
. StaticText ( frame
, - 1 , _ ( "Find what:" )), 0 , wx
. ALIGN_CENTER | wx
. RIGHT
, HALF_SPACE
)
155 findString
= config
. Read ( FindService
. FIND_MATCHPATTERN
, "" )
156 findCtrl
= wx
. TextCtrl ( frame
, - 1 , findString
, size
=( 200 ,- 1 ))
158 findCtrl
. SetSelection ( 0 ,- 1 )
159 lineSizer
. Add ( findCtrl
, 0 , wx
. LEFT
, HALF_SPACE
)
160 contentSizer
. Add ( lineSizer
, 0 , wx
. BOTTOM
, SPACE
)
161 wholeWordCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Match whole word only" ))
162 wholeWordCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHWHOLEWORD
, False ))
163 matchCaseCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Match case" ))
164 matchCaseCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHCASE
, False ))
165 regExprCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Regular expression" ))
166 regExprCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHREGEXPR
, False ))
167 contentSizer
. Add ( wholeWordCtrl
, 0 , wx
. BOTTOM
, SPACE
)
168 contentSizer
. Add ( matchCaseCtrl
, 0 , wx
. BOTTOM
, SPACE
)
169 contentSizer
. Add ( regExprCtrl
, 0 , wx
. BOTTOM
, SPACE
)
170 borderSizer
. Add ( contentSizer
, 0 , wx
. TOP | wx
. BOTTOM | wx
. LEFT
, SPACE
)
172 buttonSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
173 findBtn
= wx
. Button ( frame
, wx
. ID_OK
, _ ( "Find" ))
175 BTM_SPACE
= HALF_SPACE
176 if wx
. Platform
== "__WXMAC__" :
178 buttonSizer
. Add ( findBtn
, 0 , wx
. BOTTOM
, BTM_SPACE
)
179 buttonSizer
. Add ( wx
. Button ( frame
, wx
. ID_CANCEL
), 0 )
180 borderSizer
. Add ( buttonSizer
, 0 , wx
. ALL
, SPACE
)
182 frame
. SetSizer ( borderSizer
)
185 frame
. CenterOnParent ()
186 status
= frame
. ShowModal ()
189 while status
== wx
. ID_OK
and not passedCheck
:
190 if not os
. path
. exists ( dirCtrl
. GetValue ()):
191 dlg
= wx
. MessageDialog ( frame
,
192 _ ( "' %s ' does not exist." ) % dirCtrl
. GetValue (),
193 _ ( "Find in Directory" ),
194 wx
. OK | wx
. ICON_EXCLAMATION
200 status
= frame
. ShowModal ()
201 elif len ( findCtrl
. GetValue ()) == 0 :
202 dlg
= wx
. MessageDialog ( frame
,
203 _ ( "'Find what:' cannot be empty." ),
204 _ ( "Find in Directory" ),
205 wx
. OK | wx
. ICON_EXCLAMATION
211 status
= frame
. ShowModal ()
216 # save user choice state for this and other Find Dialog Boxes
217 dirString
= dirCtrl
. GetValue ()
218 searchSubfolders
= subfolderCtrl
. IsChecked ()
219 self
. SaveFindInDirConfig ( dirString
, searchSubfolders
)
221 findString
= findCtrl
. GetValue ()
222 matchCase
= matchCaseCtrl
. IsChecked ()
223 wholeWord
= wholeWordCtrl
. IsChecked ()
224 regExpr
= regExprCtrl
. IsChecked ()
225 self
. SaveFindConfig ( findString
, wholeWord
, matchCase
, regExpr
)
228 if status
== wx
. ID_OK
:
229 messageService
= wx
. GetApp (). GetService ( MessageService
. MessageService
)
230 messageService
. ShowWindow ()
232 view
= messageService
. GetView ()
234 wx
. GetApp (). GetTopWindow (). SetCursor ( wx
. StockCursor ( wx
. CURSOR_WAIT
))
238 view
. SetCallback ( self
. OnJumpToFoundLine
)
240 view
. AddLines ( _ ( "Searching for ' %s ' in ' %s ' \n\n " ) % ( findString
, dirString
))
242 if os
. path
. isfile ( dirString
):
244 docFile
= file ( dirString
, 'r' )
246 needToDisplayFilename
= True
247 line
= docFile
. readline ()
249 count
, foundStart
, foundEnd
, newText
= self
. DoFind ( findString
, None , line
, 0 , 0 , True , matchCase
, wholeWord
, regExpr
)
251 if needToDisplayFilename
:
252 view
. AddLines ( FILENAME_MARKER
+ dirString
+ " \n " )
253 needToDisplayFilename
= False
254 line
= repr ( lineNum
). zfill ( 4 ) + ":" + line
256 line
= docFile
. readline ()
258 if not needToDisplayFilename
:
260 except IOError , ( code
, message
):
261 print _ ( "Warning, unable to read file: ' %s '. %s " ) % ( dirString
, message
)
263 # do search in files on disk
264 for root
, dirs
, files
in os
. walk ( dirString
):
265 if not searchSubfolders
and root
!= dirString
:
269 filename
= os
. path
. join ( root
, name
)
271 docFile
= file ( filename
, 'r' )
272 except IOError , ( code
, message
):
273 print _ ( "Warning, unable to read file: ' %s '. %s " ) % ( filename
, message
)
277 needToDisplayFilename
= True
278 line
= docFile
. readline ()
280 count
, foundStart
, foundEnd
, newText
= self
. DoFind ( findString
, None , line
, 0 , 0 , True , matchCase
, wholeWord
, regExpr
)
282 if needToDisplayFilename
:
283 view
. AddLines ( FILENAME_MARKER
+ filename
+ " \n " )
284 needToDisplayFilename
= False
285 line
= repr ( lineNum
). zfill ( 4 ) + ":" + line
287 line
= docFile
. readline ()
289 if not needToDisplayFilename
:
292 view
. AddLines ( _ ( "Search completed." ))
295 wx
. GetApp (). GetTopWindow (). SetCursor ( wx
. StockCursor ( wx
. CURSOR_DEFAULT
))
302 def SaveFindInDirConfig ( self
, dirString
, searchSubfolders
):
303 """ Save search dir patterns and flags to registry.
305 dirString = search directory
306 searchSubfolders = Search subfolders
308 config
= wx
. ConfigBase_Get ()
309 config
. Write ( FIND_MATCHDIR
, dirString
)
310 config
. WriteInt ( FIND_MATCHDIRSUBFOLDERS
, searchSubfolders
)
313 def DoFindIn ( self
, findString
, matchCase
, wholeWord
, regExpr
, currFileOnly
= False , jumpToFound
= False ):
314 messageService
= wx
. GetApp (). GetService ( MessageService
. MessageService
)
315 if not messageService
:
318 messageService
. ShowWindow ()
320 view
= messageService
. GetView ()
324 wx
. GetApp (). GetTopWindow (). SetCursor ( wx
. StockCursor ( wx
. CURSOR_WAIT
))
327 #Switch to messages tab.
328 view
. GetControl (). GetParent (). SetSelection ( 0 )
330 view
. SetCallback ( self
. OnJumpToFoundLine
)
332 projectService
= wx
. GetApp (). GetService ( ProjectEditor
. ProjectService
)
334 if wx
. GetApp (). GetDocumentManager (). GetCurrentView ():
335 currDoc
= wx
. GetApp (). GetDocumentManager (). GetCurrentView (). GetDocument ()
340 projectFilenames
= [ currDoc
. GetFilename ()]
341 view
. AddLines ( FILE_MARKER
+ currDoc
. GetFilename () + " \n\n " )
343 projectFilenames
= []
345 projectFilenames
= projectService
. GetFilesFromCurrentProject ()
347 projView
= projectService
. GetView ()
349 projName
= wx
. lib
. docview
. FileNameFromPath ( projView
. GetDocument (). GetFilename ())
350 view
. AddLines ( PROJECT_MARKER
+ projName
+ " \n\n " )
354 # do search in open files first, open files may have been modified and different from disk because it hasn't been saved
355 openDocs
= wx
. GetApp (). GetDocumentManager (). GetDocuments ()
356 openDocsInProject
= filter ( lambda openDoc
: openDoc
. GetFilename () in projectFilenames
, openDocs
)
357 if currDoc
and currDoc
in openDocsInProject
:
358 # make sure current document is searched first.
359 openDocsInProject
. remove ( currDoc
)
360 openDocsInProject
. insert ( 0 , currDoc
)
361 for openDoc
in openDocsInProject
:
362 if isinstance ( openDoc
, ProjectEditor
. ProjectDocument
): # don't search project model
365 openDocView
= openDoc
. GetFirstView ()
366 # some views don't have a in memory text object to search through such as the PM and the DM
367 # even if they do have a non-text searchable object, how do we display it in the message window?
368 if not hasattr ( openDocView
, "GetValue" ):
370 text
= openDocView
. GetValue ()
373 needToDisplayFilename
= True
378 count
, foundStart
, foundEnd
, newText
= self
. DoFind ( findString
, None , text
, start
, end
, True , matchCase
, wholeWord
, regExpr
)
380 if needToDisplayFilename
:
381 view
. AddLines ( FILENAME_MARKER
+ openDoc
. GetFilename () + " \n " )
382 needToDisplayFilename
= False
384 lineNum
= openDocView
. LineFromPosition ( foundStart
)
385 line
= repr ( lineNum
). zfill ( 4 ) + ":" + openDocView
. GetLine ( lineNum
)
388 firstDef
= view
. GetControl (). GetCurrentLine () - 1
390 start
= text
. find ( " \n " , foundStart
)
394 if not needToDisplayFilename
:
396 wx
. GetApp (). Yield ( True )
397 openDocNames
= map ( lambda openDoc
: openDoc
. GetFilename (), openDocs
)
399 # do search in closed files, skipping the open ones we already searched
400 filenames
= filter ( lambda filename
: filename
not in openDocNames
, projectFilenames
)
401 for filename
in filenames
:
403 docFile
= file ( filename
, 'r' )
404 except IOError , ( code
, message
):
405 print _ ( "Warning, unable to read file: ' %s '. %s " ) % ( filename
, message
)
409 needToDisplayFilename
= True
410 line
= docFile
. readline ()
412 count
, foundStart
, foundEnd
, newText
= self
. DoFind ( findString
, None , line
, 0 , 0 , True , matchCase
, wholeWord
, regExpr
)
414 if needToDisplayFilename
:
415 view
. AddLines ( FILENAME_MARKER
+ filename
+ " \n " )
416 needToDisplayFilename
= False
417 line
= repr ( lineNum
). zfill ( 4 ) + ":" + line
420 firstDef
= view
. GetControl (). GetCurrentLine () - 1
421 line
= docFile
. readline ()
423 if not needToDisplayFilename
:
425 wx
. GetApp (). Yield ( True )
427 view
. AddLines ( _ ( "Search for ' %s ' completed." ) % findString
)
430 self
. OnJumpToFoundLine ( event
= None , defLineNum
= firstDef
)
433 wx
. GetApp (). GetTopWindow (). SetCursor ( wx
. StockCursor ( wx
. CURSOR_DEFAULT
))
435 def FindInProject ( self
, findString
):
436 self
. DoFindIn ( findString
, matchCase
= True , wholeWord
= True , regExpr
= True , jumpToFound
= True )
439 def ShowFindInProjectDialog ( self
, findString
= None ):
440 config
= wx
. ConfigBase_Get ()
442 frame
= wx
. Dialog ( wx
. GetApp (). GetTopWindow (), - 1 , _ ( "Find in Project" ), size
= ( 320 , 200 ))
443 borderSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
445 contentSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
446 lineSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
447 lineSizer
. Add ( wx
. StaticText ( frame
, - 1 , _ ( "Find what:" )), 0 , wx
. ALIGN_CENTER | wx
. RIGHT
, HALF_SPACE
)
449 findString
= config
. Read ( FindService
. FIND_MATCHPATTERN
, "" )
450 findCtrl
= wx
. TextCtrl ( frame
, - 1 , findString
, size
=( 200 ,- 1 ))
451 lineSizer
. Add ( findCtrl
, 0 , wx
. LEFT
, HALF_SPACE
)
452 contentSizer
. Add ( lineSizer
, 0 , wx
. BOTTOM
, SPACE
)
453 wholeWordCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Match whole word only" ))
454 wholeWordCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHWHOLEWORD
, False ))
455 matchCaseCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Match case" ))
456 matchCaseCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHCASE
, False ))
457 regExprCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Regular expression" ))
458 regExprCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHREGEXPR
, False ))
459 contentSizer
. Add ( wholeWordCtrl
, 0 , wx
. BOTTOM
, SPACE
)
460 contentSizer
. Add ( matchCaseCtrl
, 0 , wx
. BOTTOM
, SPACE
)
461 contentSizer
. Add ( regExprCtrl
, 0 , wx
. BOTTOM
, SPACE
)
462 borderSizer
. Add ( contentSizer
, 0 , wx
. TOP | wx
. BOTTOM | wx
. LEFT
, SPACE
)
464 buttonSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
465 findBtn
= wx
. Button ( frame
, wx
. ID_OK
, _ ( "Find" ))
467 BTM_SPACE
= HALF_SPACE
468 if wx
. Platform
== "__WXMAC__" :
470 buttonSizer
. Add ( findBtn
, 0 , wx
. BOTTOM
, BTM_SPACE
)
471 buttonSizer
. Add ( wx
. Button ( frame
, wx
. ID_CANCEL
), 0 )
472 borderSizer
. Add ( buttonSizer
, 0 , wx
. ALL
, SPACE
)
474 frame
. SetSizer ( borderSizer
)
477 frame
. CenterOnParent ()
478 status
= frame
. ShowModal ()
480 # save user choice state for this and other Find Dialog Boxes
481 findString
= findCtrl
. GetValue ()
482 matchCase
= matchCaseCtrl
. IsChecked ()
483 wholeWord
= wholeWordCtrl
. IsChecked ()
484 regExpr
= regExprCtrl
. IsChecked ()
485 self
. SaveFindConfig ( findString
, wholeWord
, matchCase
, regExpr
)
489 if status
== wx
. ID_OK
:
490 self
. DoFindIn ( findString
, matchCase
, wholeWord
, regExpr
)
496 def ShowFindInFileDialog ( self
, findString
= None ):
497 config
= wx
. ConfigBase_Get ()
499 frame
= wx
. Dialog ( wx
. GetApp (). GetTopWindow (), - 1 , _ ( "Find in File" ), size
= ( 320 , 200 ))
500 borderSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
502 contentSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
503 lineSizer
= wx
. BoxSizer ( wx
. HORIZONTAL
)
504 lineSizer
. Add ( wx
. StaticText ( frame
, - 1 , _ ( "Find what:" )), 0 , wx
. ALIGN_CENTER | wx
. RIGHT
, HALF_SPACE
)
506 findString
= config
. Read ( FindService
. FIND_MATCHPATTERN
, "" )
507 findCtrl
= wx
. TextCtrl ( frame
, - 1 , findString
, size
=( 200 ,- 1 ))
508 lineSizer
. Add ( findCtrl
, 0 , wx
. LEFT
, HALF_SPACE
)
509 contentSizer
. Add ( lineSizer
, 0 , wx
. BOTTOM
, SPACE
)
510 wholeWordCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Match whole word only" ))
511 wholeWordCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHWHOLEWORD
, False ))
512 matchCaseCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Match case" ))
513 matchCaseCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHCASE
, False ))
514 regExprCtrl
= wx
. CheckBox ( frame
, - 1 , _ ( "Regular expression" ))
515 regExprCtrl
. SetValue ( config
. ReadInt ( FindService
. FIND_MATCHREGEXPR
, False ))
516 contentSizer
. Add ( wholeWordCtrl
, 0 , wx
. BOTTOM
, SPACE
)
517 contentSizer
. Add ( matchCaseCtrl
, 0 , wx
. BOTTOM
, SPACE
)
518 contentSizer
. Add ( regExprCtrl
, 0 , wx
. BOTTOM
, SPACE
)
519 borderSizer
. Add ( contentSizer
, 0 , wx
. TOP | wx
. BOTTOM | wx
. LEFT
, SPACE
)
521 buttonSizer
= wx
. BoxSizer ( wx
. VERTICAL
)
522 findBtn
= wx
. Button ( frame
, wx
. ID_OK
, _ ( "Find" ))
524 BTM_SPACE
= HALF_SPACE
525 if wx
. Platform
== "__WXMAC__" :
527 buttonSizer
. Add ( findBtn
, 0 , wx
. BOTTOM
, BTM_SPACE
)
528 buttonSizer
. Add ( wx
. Button ( frame
, wx
. ID_CANCEL
), 0 )
529 borderSizer
. Add ( buttonSizer
, 0 , wx
. ALL
, SPACE
)
531 frame
. SetSizer ( borderSizer
)
534 frame
. CenterOnParent ()
535 status
= frame
. ShowModal ()
537 # save user choice state for this and other Find Dialog Boxes
538 findString
= findCtrl
. GetValue ()
539 matchCase
= matchCaseCtrl
. IsChecked ()
540 wholeWord
= wholeWordCtrl
. IsChecked ()
541 regExpr
= regExprCtrl
. IsChecked ()
542 self
. SaveFindConfig ( findString
, wholeWord
, matchCase
, regExpr
)
546 if status
== wx
. ID_OK
:
547 self
. DoFindIn ( findString
, matchCase
, wholeWord
, regExpr
, currFileOnly
= True )
553 def OnJumpToFoundLine ( self
, event
= None , defLineNum
=- 1 ):
554 messageService
= wx
. GetApp (). GetService ( MessageService
. MessageService
)
556 lineText
, pos
= messageService
. GetView (). GetCurrLine ()
558 lineText
= messageService
. GetView (). GetControl (). GetLine ( defLineNum
)
561 if lineText
== " \n " or lineText
. find ( FILENAME_MARKER
) != - 1 or lineText
. find ( PROJECT_MARKER
) != - 1 or lineText
. find ( FILE_MARKER
) != - 1 :
563 lineEnd
= lineText
. find ( ":" )
567 lineNum
= int ( lineText
[ 0 : lineEnd
])
569 text
= messageService
. GetView (). GetText ()
571 curPos
= messageService
. GetView (). GetCurrentPos ()
573 curPos
= messageService
. GetView (). GetControl (). GetLineEndPosition ( defLineNum
)
575 startPos
= text
. rfind ( FILENAME_MARKER
, 0 , curPos
)
576 endPos
= text
. find ( " \n " , startPos
)
577 filename
= text
[ startPos
+ len ( FILENAME_MARKER
): endPos
]
580 openDocs
= wx
. GetApp (). GetDocumentManager (). GetDocuments ()
581 for openDoc
in openDocs
:
582 if openDoc
. GetFilename () == filename
:
583 foundView
= openDoc
. GetFirstView ()
587 doc
= wx
. GetApp (). GetDocumentManager (). CreateDocument ( filename
, wx
. lib
. docview
. DOC_SILENT|wx
. lib
. docview
. DOC_OPEN_ONCE
)
589 foundView
= doc
. GetFirstView ()
592 foundView
. GetFrame (). SetFocus ()
594 if hasattr ( foundView
, "GotoLine" ):
595 foundView
. GotoLine ( lineNum
)
596 startPos
= foundView
. PositionFromLine ( lineNum
)
597 # wxBug: Need to select in reverse order, (end, start) to put cursor at head of line so positioning is correct
598 # Also, if we use the correct positioning order (start, end), somehow, when we open a edit window for the first
599 # time, we don't see the selection, it is scrolled off screen
600 foundView
. SetSelection ( startPos
- 1 + len ( lineText
[ lineEnd
:]. rstrip ( " \n " )), startPos
)
601 wx
. GetApp (). GetService ( OutlineService
. OutlineService
). LoadOutline ( foundView
, position
= startPos
)