]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/samples/ide/activegrid/tool/FindInDirService.py
Add code to remove the selection (if any) in wxTextCtrl::WriteText for multi-line...
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / FindInDirService.py
index f3e9da16c2d7a6571d7b44d9ba870d55f43bcfc6..1fd557b00252dae40e8f10661fbb523c8cdeaa5f 100644 (file)
@@ -58,10 +58,18 @@ class FindInDirService(FindService.FindService):
     def ProcessEvent(self, event):
         id = event.GetId()
         if id == FindInDirService.FINDALL_ID:
-            self.ShowFindAllDialog()
+            view = wx.GetApp().GetDocumentManager().GetCurrentView()
+            if hasattr(view, "GetCtrl") and view.GetCtrl() and hasattr(view.GetCtrl(), "GetSelectedText"):
+                self.ShowFindAllDialog(view.GetCtrl().GetSelectedText())
+            else:
+                self.ShowFindAllDialog()
             return True
         elif id == FindInDirService.FINDDIR_ID:
-            self.ShowFindDirDialog()
+            view = wx.GetApp().GetDocumentManager().GetCurrentView()
+            if hasattr(view, "GetCtrl") and view.GetCtrl() and hasattr(view.GetCtrl(), "GetSelectedText"):
+                self.ShowFindDirDialog(view.GetCtrl().GetSelectedText())
+            else:
+                self.ShowFindDirDialog()
             return True
         else:
             return FindService.FindService.ProcessEvent(self, event)
@@ -71,8 +79,7 @@ class FindInDirService(FindService.FindService):
         id = event.GetId()
         if id == FindInDirService.FINDALL_ID:
             projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)
-            view = projectService.GetView()
-            if view and view.GetDocument() and view.GetDocument().GetFiles():
+            if projectService.GetFilesFromCurrentProject():
                 event.Enable(True)
             else:
                 event.Enable(False)
@@ -83,10 +90,10 @@ class FindInDirService(FindService.FindService):
             return FindService.FindService.ProcessUpdateUIEvent(self, event)
 
 
-    def ShowFindDirDialog(self):
+    def ShowFindDirDialog(self, findString=None):
         config = wx.ConfigBase_Get()
 
-        frame = wx.Dialog(None, -1, _("Find in Directory"), size= (320,200))
+        frame = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("Find in Directory"), size= (320,200))
         borderSizer = wx.BoxSizer(wx.HORIZONTAL)
 
         contentSizer = wx.BoxSizer(wx.VERTICAL)
@@ -95,7 +102,7 @@ class FindInDirService(FindService.FindService):
         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...")
+        findDirButton = wx.Button(frame, -1, _("Browse..."))
         lineSizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE)
         contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE)
         
@@ -104,15 +111,15 @@ class FindInDirService(FindService.FindService):
             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 subfolders"))
+        subfolderCtrl = wx.CheckBox(frame, -1, _("Search in subdirectories"))
         subfolderCtrl.SetValue(config.ReadInt(FIND_MATCHDIRSUBFOLDERS, True))
         contentSizer.Add(subfolderCtrl, 0, wx.BOTTOM, SPACE)
 
@@ -120,9 +127,16 @@ class FindInDirService(FindService.FindService):
         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)
-        findCtrl = wx.TextCtrl(frame, -1, config.Read(FindService.FIND_MATCHPATTERN, ""), size=(200,-1))
+        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"))
@@ -139,13 +153,17 @@ class FindInDirService(FindService.FindService):
         buttonSizer = wx.BoxSizer(wx.VERTICAL)
         findBtn = wx.Button(frame, wx.ID_OK, _("Find"))
         findBtn.SetDefault()
-        buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
-        buttonSizer.Add(wx.Button(frame, wx.ID_CANCEL, _("Cancel")), 0)
+        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
@@ -156,6 +174,7 @@ class FindInDirService(FindService.FindService):
                                        _("Find in Directory"),
                                        wx.OK | wx.ICON_EXCLAMATION
                                        )
+                dlg.CenterOnParent()
                 dlg.ShowModal()
                 dlg.Destroy()
 
@@ -166,6 +185,7 @@ class FindInDirService(FindService.FindService):
                                        _("Find in Directory"),
                                        wx.OK | wx.ICON_EXCLAMATION
                                        )
+                dlg.CenterOnParent()
                 dlg.ShowModal()
                 dlg.Destroy()
 
@@ -185,10 +205,8 @@ class FindInDirService(FindService.FindService):
         regExpr = regExprCtrl.IsChecked()
         self.SaveFindConfig(findString, wholeWord, matchCase, regExpr)
 
-            
+        frame.Destroy()
         if status == wx.ID_OK:            
-            frame.Destroy()
-
             messageService = wx.GetApp().GetService(MessageService.MessageService)
             messageService.ShowWindow()
 
@@ -255,7 +273,6 @@ class FindInDirService(FindService.FindService):
 
             return True
         else:
-            frame.Destroy()
             return False
             
 
@@ -270,16 +287,18 @@ class FindInDirService(FindService.FindService):
         config.WriteInt(FIND_MATCHDIRSUBFOLDERS, searchSubfolders)
     
 
-    def ShowFindAllDialog(self):
+    def ShowFindAllDialog(self, findString=None):
         config = wx.ConfigBase_Get()
 
-        frame = wx.Dialog(None, -1, _("Find in Project"), size= (320,200))
+        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)
-        findCtrl = wx.TextCtrl(frame, -1, config.Read(FindService.FIND_MATCHPATTERN, ""), size=(200,-1))
+        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"))
@@ -296,13 +315,17 @@ class FindInDirService(FindService.FindService):
         buttonSizer = wx.BoxSizer(wx.VERTICAL)
         findBtn = wx.Button(frame, wx.ID_OK, _("Find"))
         findBtn.SetDefault()
-        buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
-        buttonSizer.Add(wx.Button(frame, wx.ID_CANCEL, _("Cancel")), 0)
+        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
@@ -312,9 +335,8 @@ class FindInDirService(FindService.FindService):
         regExpr = regExprCtrl.IsChecked()
         self.SaveFindConfig(findString, wholeWord, matchCase, regExpr)
 
+        frame.Destroy()
         if status == wx.ID_OK:
-            frame.Destroy()
-
             messageService = wx.GetApp().GetService(MessageService.MessageService)
             messageService.ShowWindow()
 
@@ -398,7 +420,6 @@ class FindInDirService(FindService.FindService):
 
             return True
         else:
-            frame.Destroy()
             return False
 
 
@@ -428,8 +449,9 @@ class FindInDirService(FindService.FindService):
                 break
 
         if not foundView:
-            doc = wx.GetApp().GetDocumentManager().CreateDocument(filename, wx.lib.docview.DOC_SILENT)
-            foundView = doc.GetFirstView()
+            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()