Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Spellcheck/SpellCheck RB


Required plugins for this example: MBS MacBase Plugin, MBS MacCF 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 RB

This example is the version from Sun, 17th Mar 2012.

Project "SpellCheck RB.xojo_binary_project"
Class Window1 Inherits Window
Binding stringBinder
Control Doc Inherits TextArea
ControlInstance Doc Inherits TextArea
End Control
Control CheckButton Inherits PushButton
ControlInstance CheckButton Inherits PushButton
EventHandler Sub Action() spell.Location=0 spell.length=0 doc.sellength=0 doc.selstart=0 offset=0 checkon End EventHandler
End Control
Control IgnoreButton Inherits PushButton
ControlInstance IgnoreButton Inherits PushButton
EventHandler Sub Action() spell.ignoreWord(currentword) checkon End EventHandler
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
Control ReplaceWord Inherits TextField
ControlInstance ReplaceWord Inherits TextField
EventHandler Sub TextChange() if spell<>Nil then spell.WordFieldValue = me.text end if replaceButton.enabled=doc.sellength>0 and ReplaceWord.text<>"" and ReplaceWord.enabled End EventHandler
End Control
Control ReplaceButton Inherits PushButton
ControlInstance ReplaceButton Inherits PushButton
EventHandler Sub Action() doc.seltext=replaceword.text spell.length=doc.sellength checkon End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() ignorelistSheet.init spell if ignorelistSheet.okay then ignorelistSheet.showModal else ignorelistSheet.close end if End EventHandler
End Control
Control Separator1 Inherits Separator
ControlInstance Separator1 Inherits Separator
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim s as CFStringMBS s=NewCFStringMBS(doc.text) msgBox str(spell.CountWordsInString(s,NewCFStringMBS("en"))) End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control lang Inherits TextField
ControlInstance lang Inherits TextField
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() if spell.setLanguage(lang.Text) then 'ok else MsgBox "This language is unknown." end if End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() dim c as CFStringMBS c=spell.language if c<>nil then lang.text=c.str else lang.text="?" end if End EventHandler
End Control
Control GroupBox1 Inherits GroupBox
ControlInstance GroupBox1 Inherits GroupBox
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
EventHandler Sub TextChange() dim a(-1) as string dim i,c as integer dim s as string PopupMenu1.Enabled=False PopupMenu1.DeleteAllRows if me.text<>"" then a=spell.CompletionsForPartialWordRange(0,len(me.Text),me.text,"") if UBound(a)>=0 then for each s in a PopupMenu1.AddRow s next 'PopupMenu1.AddRow str(c) PopupMenu1.Enabled=PopupMenu1.ListCount>0 end if end if End EventHandler
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
End Control
EventHandler Sub Close() SaveIgnoresWords End EventHandler
EventHandler Sub Open() spell=new NSSpellCheckerMBS // For the demo the bundle should be inside the application folder if spell.Tag<>0 then // available? 'ok LoadIgnoresWords else msgBox "Can't load or find the Cocoa Spellchecking stuff." end if End EventHandler
Protected Sub LoadIgnoresWords() dim f as FolderItem dim t as TextInputStream dim words(-1),line as string f=SpecialFolder.Preferences.Child("SpellCheck RB.pref") t=f.OpenAsTextFile if t<>nil and spell<>nil then while not t.eof line=t.ReadLine(encodings.UTF8) if line<>"" then words.Append line end if wend spell.setIgnoredWords words end if End Sub
Protected Sub SaveIgnoresWords() dim f as FolderItem dim i,c as integer dim t as TextOutputStream dim n(-1) as string f=SpecialFolder.Preferences.Child("SpellCheck RB.pref") t=f.CreateTextFile if t<>nil and spell<>nil then n=spell.ignoredWords for each s as string in n t.WriteLine ConvertEncoding(s,encodings.UTF8) next end if End Sub
Sub checkon() dim s as string dim wc as integer dim a(-1) as string dim pos as integer dim r as NSRangeMBS list.deleteAllRows ' 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 ignoreButton.enabled=true list.enabled=true replaceword.enabled=true s=mid(doc.text,spell.Location+1,spell.length) currentword=s replaceword.text=s a=spell.guessesForWord(s) for each s in a List.AddRow s next else ignoreButton.enabled=false list.enabled=false replaceword.enabled=false replaceButton.enabled=False msgBox "Text is okay." end if End Sub
Property Protected currentword As string
Property offset As integer
Property spell As NSSpellCheckerMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class IgnoreListSheet Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() close End EventHandler
End Control
Sub init(s as NSSpellCheckerMBS) dim a(-1) as string dim c as integer dim i as integer a=s.ignoredWords if UBound(a)>=0 then for each t as string in a Listbox1.AddRow t next okay=true else msgBox "no ignore list available." end if End Sub
Property okay As boolean
End Class
Module Util
End Module
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
End Project

See also:

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


The biggest plugin in space...