« FMNext 2020 | Home | Thanksgiving Sale »

Use Text Finder for TextArea in Xojo

Have you checked the NSTextFinderMBS class for macOS to show a search field within a text area?

With a little code you can provide a find & replace toolbar within the text area like this:

The GUI is standard from macOS and localized by the system.

Here is the sample code you can use:

Sub ToggleFindbar() // get MBS objects for the Xojo controls Dim textView As NSTextViewMBS = TextArea1.NSTextViewMBS Dim scrollView As NSScrollViewMBS = TextArea1.NSScrollViewMBS // first run, we create the TextFinder object If finder = Nil Then finder = New NSTextFinderMBS // connect it to the text view and the finder.client = textView finder.findBarContainer = scrollView finder.incrementalSearchingEnabled = True End If If CheckFindbar.Value Then // enable find bar If scrollView.FindBarVisible Then // show the find interface finder.performAction finder.kActionShowFindInterface Return End If If textView.usesFindBar Then // show the find interface, if it was hidden before scrollView.FindBarVisible = True Return End If // enables find bar textView.usesFindBar = True End If If CheckFindbar.Value Then // show it finder.performAction finder.kActionShowFindInterface Else // hide it finder.performAction finder.kActionHideFindInterface End If End Sub

You may just have a menu command for search and when it's triggered, you can check what Window.Focus points to. If a text area is in focus, you can simply call the method above and pass the text area to show the find bar.

Please don't hesitate to contact us with your questions.

26 11 20 - 08:58