Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/NSTextFinder and find bar
Required plugins for this example: MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacControls Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSTextFinder and find bar
This example is the version from Fri, 26th Nov 2020.
Project "NSTextFinder and find bar.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control CheckFindbar Inherits CheckBox
ControlInstance CheckFindbar Inherits CheckBox
EventHandler Sub Action()
ToggleFindbar TextArea1
End EventHandler
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Sub ToggleFindbar(TheTextArea as TextArea)
// get MBS objects for the Xojo controls
Dim textView As NSTextViewMBS = TheTextArea.NSTextViewMBS
Dim scrollView As NSScrollViewMBS = TheTextArea.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
Property finder As NSTextFinderMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS MacCocoa Plugin.