Mercurial Hosting > luan
changeset 1921:2364fc43037a
better spell check
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 20 Apr 2025 12:47:41 -0600 |
parents | 5b15b33c2d9c |
children | 81cd2b1dab52 |
files | classpath.sh scripts/build-luan.sh scripts/install.sh src/luan/modules/editor/SpellCheckerLuan.java src/luan/modules/editor/Spell_checker.luan src/luan/modules/editor/dictionaries/dictionaries.cnf src/luan/modules/editor/dictionaries/dictionary_en.ortho src/luan/modules/editor/menu.luan src/luan/modules/swing/SpellCheckerLuan.java src/luan/modules/swing/Text_component.luan website/src/dictionaries/dictionaries.cnf website/src/dictionaries/dictionary_en.ortho |
diffstat | 12 files changed, 68 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
diff -r 5b15b33c2d9c -r 2364fc43037a classpath.sh --- a/classpath.sh Sat Apr 19 22:01:48 2025 -0600 +++ b/classpath.sh Sun Apr 20 12:47:41 2025 -0600 @@ -8,3 +8,5 @@ done export CLASSPATH + +export LUAN_DICTS=$LUAN_HOME/src/luan/modules/editor/dictionaries/
diff -r 5b15b33c2d9c -r 2364fc43037a scripts/build-luan.sh --- a/scripts/build-luan.sh Sat Apr 19 22:01:48 2025 -0600 +++ b/scripts/build-luan.sh Sun Apr 20 12:47:41 2025 -0600 @@ -26,6 +26,7 @@ #chmod +x build/luan/install.sh cp scripts/uninstall.sh build/luan cp scripts/luan_editor.sh build/luan +cp -r src/luan/modules/editor/dictionaries build/luan cd build VERSION=`java -classpath $CLASSPATH luan.Luan classpath:luan/version.luan`
diff -r 5b15b33c2d9c -r 2364fc43037a scripts/install.sh --- a/scripts/install.sh Sat Apr 19 22:01:48 2025 -0600 +++ b/scripts/install.sh Sun Apr 20 12:47:41 2025 -0600 @@ -12,6 +12,8 @@ for i in `pwd`/jars/* ; do CLASSPATH=\$CLASSPATH:\$i ; done CLASSPATH=\$(echo -n \$CLASSPATH | sed 's/^://') +export LUAN_DICTS=`pwd`/dictionaries/ + java -classpath \$CLASSPATH luan.Luan "\$@" End
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/editor/SpellCheckerLuan.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/editor/SpellCheckerLuan.java Sun Apr 20 12:47:41 2025 -0600 @@ -0,0 +1,36 @@ +package luan.modules.editor; + +import java.net.URL; +import java.net.MalformedURLException; +import javax.swing.text.JTextComponent; +import com.inet.jortho.SpellChecker; +import com.inet.jortho.DefaultMessageHandler; +import luan.LuanException; +import luan.LuanRuntimeException; + + +public class SpellCheckerLuan { + + public static void registerDictionaries( String baseURL, String activeLocale) throws MalformedURLException, LuanException { + SpellChecker.setMessageHandler(new DefaultMessageHandler(null) { + @Override public void handleException(java.lang.Throwable throwable) { + throw new LuanRuntimeException(new LuanException(throwable)); + } + } ); + URL url = new URL(baseURL); + try { + SpellChecker.registerDictionaries( url, activeLocale ); + } catch(LuanRuntimeException e) { + LuanException luanException = (LuanException)e.getCause(); + throw luanException; + } + } + + public static void register(JTextComponent text) { + SpellChecker.register(text); + } + + public static void unregister(JTextComponent text) { + SpellChecker.unregister(text); + } +}
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/editor/Spell_checker.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/editor/Spell_checker.luan Sun Apr 20 12:47:41 2025 -0600 @@ -0,0 +1,22 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +require "java" +local System = require "java:java.lang.System" +local SpellCheckerLuan = require "java:luan.modules.editor.SpellCheckerLuan" + + +local Spell_checker = {} + +local dir = System.getenv("LUAN_DICTS") or error() +SpellCheckerLuan.registerDictionaries( "file:"..dir, "en" ) + +function Spell_checker.spell_check(text_component,spell_check) + local jtext_component = text_component.java + if spell_check then + SpellCheckerLuan.register(jtext_component) + else + SpellCheckerLuan.unregister(jtext_component) + end +end + +return Spell_checker
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/editor/dictionaries/dictionaries.cnf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/editor/dictionaries/dictionaries.cnf Sun Apr 20 12:47:41 2025 -0600 @@ -0,0 +1,2 @@ +extension=.ortho +languages=en
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/editor/dictionaries/dictionary_en.ortho Binary file src/luan/modules/editor/dictionaries/dictionary_en.ortho has changed
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/editor/menu.luan --- a/src/luan/modules/editor/menu.luan Sat Apr 19 22:01:48 2025 -0600 +++ b/src/luan/modules/editor/menu.luan Sun Apr 20 12:47:41 2025 -0600 @@ -11,8 +11,8 @@ local Option_pane = require "luan:swing/Option_pane.luan" local show_message_dialog = Option_pane.show_message_dialog or error() local show_input_dialog = Option_pane.show_input_dialog or error() -local Text_component = require "luan:swing/Text_component.luan" -local has_spell_checker = not not Text_component.has_spell_checker +local Spell_checker = require "luan:editor/Spell_checker.luan" +local spell_check = Spell_checker.spell_check or error() local function action_listener(fn) @@ -177,9 +177,8 @@ new_check_box_menu_item{ text = "Spell Check" accelerator = "meta SEMICOLON" - enabled = has_spell_checker action_listener = function(event) - text_area.spell_check(event.source.state) + spell_check(text_area,event.source.state) end } new_menu_item{
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/swing/SpellCheckerLuan.java --- a/src/luan/modules/swing/SpellCheckerLuan.java Sat Apr 19 22:01:48 2025 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -package luan.modules.swing; - -import java.net.URL; -import java.net.MalformedURLException; -import javax.swing.text.JTextComponent; -import com.inet.jortho.SpellChecker; -import com.inet.jortho.DefaultMessageHandler; -import luan.LuanException; -import luan.LuanRuntimeException; - - -public class SpellCheckerLuan { - - public static void registerDictionaries( String baseURL, String activeLocale) throws MalformedURLException, LuanException { - SpellChecker.setMessageHandler(new DefaultMessageHandler(null) { - @Override public void handleException(java.lang.Throwable throwable) { - throw new LuanRuntimeException(new LuanException(throwable)); - } - } ); - URL url = new URL(baseURL); - try { - SpellChecker.registerDictionaries( url, activeLocale ); - } catch(LuanRuntimeException e) { - LuanException luanException = (LuanException)e.getCause(); - throw luanException; - } - } - - public static void register(JTextComponent text) { - SpellChecker.register(text); - } - - public static void unregister(JTextComponent text) { - SpellChecker.unregister(text); - } -}
diff -r 5b15b33c2d9c -r 2364fc43037a src/luan/modules/swing/Text_component.luan --- a/src/luan/modules/swing/Text_component.luan Sat Apr 19 22:01:48 2025 -0600 +++ b/src/luan/modules/swing/Text_component.luan Sun Apr 20 12:47:41 2025 -0600 @@ -13,21 +13,12 @@ require "java" local SwingLuan = require "java:luan.modules.swing.SwingLuan" local fixTextComponent = SwingLuan.fixTextComponent -local SpellCheckerLuan = require "java:luan.modules.swing.SpellCheckerLuan" local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "swing/Text_component" local Text_component = {} -try - SpellCheckerLuan.registerDictionaries( "https://www.luan.software/dictionaries/", "en" ) - Text_component.has_spell_checker = true -catch e - logger.error("Spell checker disabled: "..e.get_message()) - Text_component.has_spell_checker = false -end - function Text_component.__index(component,key) local rtn = super__index(component,key) if rtn ~= fail then return rtn end @@ -96,14 +87,6 @@ jcomponent.select(start_pos-1,end_pos-1) end component.print = jcomponent.print - function component.spell_check(spell_check) - Text_component.has_spell_checker or error "spell_checker disabled" - if spell_check then - SpellCheckerLuan.register(jcomponent) - else - SpellCheckerLuan.unregister(jcomponent) - end - end return component end