Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Spellcheck/SpellCheck like TextEdit


Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Spellcheck/SpellCheck like TextEdit

This example is the version from Fri, 7th Sep 2017.

Project "SpellCheck like TextEdit.xojo_binary_project"
Class MainWindow Inherits Window
Control Doc Inherits TextArea
ControlInstance Doc Inherits TextArea
End Control
EventHandler Sub Close() ' have to save ignorewordlist... End EventHandler
EventHandler Sub EnableMenuItems() dim b as Boolean b=spell.Tag<>0 // init worked EditCheckspelling.Enabled=b EditSpelling.Enabled=b End EventHandler
EventHandler Sub Open() spell=new MyNSSpellCheckerMBS spell.t=self // For the demo the bundle should be inside the application folder if spell.Tag<>0 then // available? 'ok else msgBox "Can't load or find the Cocoa Spellchecking stuff." end if End EventHandler
Function EditCheckspelling() As Boolean StartSpelling Return true End Function
Function EditSpelling() As Boolean p=spell.spellingPanel p.Show Return true End Function
Sub ContinueCheck() dim s as string dim wc as integer dim pos as integer dim r as NSRangeMBS ' The easier way is possible, but doesn't do IgnoreLists. r=spell.checkSpellingOfString(doc.text,doc.selstart+doc.sellength,"",false,wc) if r.length>0 then doc.selstart=r.Location doc.sellength=r.length pos=doc.lineNumAtCharPos(doc.selstart) doc.scrollposition=pos-5 s=mid(doc.text,spell.Location+1,spell.length) spell.updateSpellingPanelWithMisspelledWord s else doc.sellength=0 doc.selstart=0 spell.updateSpellingPanelWithMisspelledWord "" spell.WordFieldValue = "" end if End Sub
Sub CorrectWord() doc.seltext=spell.WordFieldValue MoveToNextWord ContinueCheck End Sub
Protected Sub FindNext() MoveToNextWord ContinueCheck End Sub
Sub IgnoreWord() MoveToNextWord spell.ignoreWord spell.WordFieldValue ContinueCheck End Sub
Protected Sub MoveToNextWord() dim s as integer s=doc.SelStart+doc.SelLength doc.SelLength=0 doc.SelStart=s End Sub
Sub StartSpelling() p=spell.spellingPanel p.Show doc.sellength=0 doc.selstart=0 ContinueCheck End Sub
Property Protected currentword As string
Property offset As integer
Property Protected p As NSPanelMBS
Property spell As myNSSpellCheckerMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu2 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu1 = "-"
MenuItem EditSpelling = "Spelling..."
MenuItem EditCheckspelling = "Check spelling"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO=false then MsgBox "This example needs a MachO target running on Mac OS X." quit end if End EventHandler
End Class
Class MyNSSpellCheckerMBS Inherits NSSpellCheckerMBS
EventHandler Sub Correct() System.DebugLog "Correct" t.CorrectWord End EventHandler
EventHandler Sub FindNext() System.DebugLog "Findnext" t.ContinueCheck End EventHandler
EventHandler Sub Ignore() System.DebugLog "Ignore" t.IgnoreWord End EventHandler
Property t As MainWindow
End Class
End Project

See also:

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...