I am using NSTextView for the user to type their response. I have turned on continuous spell check and the incorrect words have a red line under them. I have a shared SpellChecker which I am using. But I want the user to do a right click and correct the spelling. I have the following questions -
In Text edit, as soon as you do a right click, it highlights the word, how can I achieve the same ?. I am planning to get the selectedrange and pass it to the spellchecker.
Once the spellcheck suggestions are added to the context menu, it still shows up when I go to the next word, so should I always clear the context menu before adding any new item ?.
I am using Monobjc, and when I execute the following code, I get an exception -
var t = Menu.ItemArray;
foreach(var s in t)
{
var menuItem = s.CastAs<NSMenuItem>(); //exception
}
I am basically try to get individual NSMenuItem to check if it spelling suggestions or something else.
EDIT - Added stacktrace
System.InvalidCastException: Cannot cast from source type to destination type.
at example.test.MacOS.UI.HTML.ESView.MenuForEvent (Monobjc.Cocoa.NSEvent theEvent) [0x00000] in <filename unknown>:0
at Monobjc.Dynamic.Proxies.example.test.MacOS.UI.HTML.ESView.MenuForEvent_Monobjc_Cocoa_NSEvent (IntPtr receiver, IntPtr selector, IntPtr ) [0x00000] in <filename unknown>:0
at (wrapper native-to-managed) Monobjc.Dynamic.Proxies.example.test.MacOS.UI.HTML.ESView:MenuForEvent_Monobjc_Cocoa_NSEvent (intptr,intptr,intptr)
at (wrapper managed-to-native) E5EEC20A:pinvoke (intptr,intptr,intptr)
at E5EEC20A.objc_msgSendSuper (IntPtr receiver, IntPtr selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Monobjc.Bridge.Generators.DynamicMessagingGenerator.SendMessage (System.String message, IntPtr receiver, IntPtr selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Monobjc.ObjectiveCRuntime.SendMessageSuper (IManagedWrapper receiver, Monobjc.Class cls, System.String selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Monobjc.Id.SendMessageSuper (Monobjc.Class cls, System.String selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at example.test.MacOS.UI.App.Application.SendEvent (Monobjc.Cocoa.NSEvent theEvent) [0x00000] in <filename unknown>:0
at Monobjc.Dynamic.Proxies.example.test.MacOS.UI.App.Application.SendEvent_Monobjc_Cocoa_NSEvent (IntPtr receiver, IntPtr selector, IntPtr ) [0x00000] in <filename unknown>:0
at (wrapper native-to-managed) Monobjc.Dynamic.Proxies.example.test.MacOS.UI.App.Application:SendEvent_Monobjc_Cocoa_NSEvent (intptr,intptr,intptr)
at (wrapper managed-to-native) Monobjc.ObjectiveCRuntime:objc_msgSend (intptr,intptr)
at Monobjc.ObjectiveCRuntime.SendMessage (IManagedWrapper receiver, System.String selector) [0x00000] in <filename unknown>:0
at Monobjc.Cocoa.NSApplication.Run () [0x00000] in <filename unknown>:0
at example.test.MacOS.UI.App.Application.RunApplication () [0x00000] in <filename unknown>:0
at example.test.MacOS.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
EDIT - Step 3
Question 3 worked based on Laurent's suggestion.