1- const { h } = require ( 'mutant' )
1+ const { computed , h , map , Value , watch } = require ( 'mutant' )
22const nest = require ( 'depnest' )
33const packageInfo = require ( '../../../../../package.json' )
4+ const ExpanderHook = require ( '../../../../expander-hook' )
45
56const themeNames = Object . keys ( require ( '../../../../../styles' ) )
7+ const electron = require ( 'electron' )
68
79exports . needs = nest ( {
810 'settings.obs.get' : 'first' ,
@@ -13,6 +15,12 @@ exports.needs = nest({
1315
1416exports . gives = nest ( 'page.html.render' )
1517
18+ let availableDictionaries = Value ( [ ] )
19+
20+ electron . ipcRenderer . on ( 'setAvailableDictionaries' , ( ev , langs ) => {
21+ availableDictionaries . set ( langs )
22+ } )
23+
1624exports . create = function ( api ) {
1725 return nest ( 'page.html.render' , function channel ( path ) {
1826 if ( path !== '/settings' ) return
@@ -31,6 +39,12 @@ exports.create = function (api) {
3139
3240 const theme = api . settings . obs . get ( 'patchwork.theme' , 'light' )
3341 const lang = api . settings . obs . get ( 'patchwork.lang' , '' )
42+ const spellcheckLangs = api . settings . obs . get ( 'patchwork.spellcheckLangs' , [ 'en-GB' ] )
43+ const enableSpellCheck = api . settings . obs . get ( 'patchwork.enableSpellCheck' , true )
44+ const spellcheckParams = computed ( [ spellcheckLangs , enableSpellCheck ] , ( langs , enabled ) => ( { langs, enabled } ) )
45+ watch ( spellcheckParams , ( params ) => {
46+ electron . ipcRenderer . invoke ( 'setSpellcheckLangs' , params )
47+ } )
3448 const fontSize = api . settings . obs . get ( 'patchwork.fontSize' , '' )
3549 const fontFamily = api . settings . obs . get ( 'patchwork.fontFamily' , '' )
3650 const includeParticipating = api . settings . obs . get ( 'patchwork.includeParticipating' , false )
@@ -66,7 +80,7 @@ exports.create = function (api) {
6680 ] ) ,
6781
6882 h ( 'section' , [
69- h ( 'h2' , i18n ( 'Language' ) ) ,
83+ h ( 'h2' , i18n ( 'Interface Language' ) ) ,
7084 h ( 'select' , {
7185 style : { 'font-size' : '120%' } ,
7286 value : lang ,
@@ -79,6 +93,30 @@ exports.create = function (api) {
7993 ] )
8094 ] ) ,
8195
96+ h ( 'section' , [
97+ h ( 'h2' , i18n ( 'Spellchecking' ) ) ,
98+ h ( 'div' , [
99+ checkbox ( enableSpellCheck , {
100+ label : i18n ( 'Enable Spellchecking' )
101+ } )
102+ ] ) ,
103+ h ( 'h3' , i18n ( 'Languages to check for (select multiple)' ) ) ,
104+ h ( 'select' , {
105+ disabled : computed ( enableSpellCheck , ( b ) => ! b ) ,
106+ multiple : true ,
107+ size : 10 ,
108+ style : { 'font-size' : '120%' } ,
109+ hooks : [ SpellcheckChangeHook ( spellcheckLangs ) ]
110+ } , [
111+ map ( availableDictionaries , ( code ) => h ( 'option' , {
112+ value : code ,
113+ selected : spellcheckLangs ( ) . indexOf ( code ) !== - 1 ,
114+ } , [
115+ '[' , code , '] ' , getLocaleName ( code )
116+ ] ) )
117+ ] )
118+ ] ) ,
119+
82120 h ( 'section' , [
83121 h ( 'h2' , i18n ( 'Font Size' ) ) ,
84122 h ( 'select' , {
@@ -99,7 +137,7 @@ exports.create = function (api) {
99137 'ev-change' : ( ev ) => fontFamily . set ( ev . target . value )
100138 } , [
101139 h ( 'option' , { value : '' } , i18n ( 'Default' ) ) ,
102- fontFamilies . map ( family => h ( 'option' , { value : family } , family ) )
140+ fontFamilies . map ( family => h ( 'option' , { value : family , } , family ) )
103141 ] )
104142 ] ) ,
105143 h ( 'h2' , i18n ( 'Notification Options' ) ) ,
@@ -159,3 +197,17 @@ function checkbox (param, { label }) {
159197 } ) , ' ' , label
160198 ] )
161199}
200+
201+ function SpellcheckChangeHook ( spellcheckLangs ) {
202+ return function ( element ) {
203+ element . addEventListener ( 'change' , ( ev ) => {
204+ const newLangs = [ ]
205+ for ( const c of ev . target . children ) {
206+ if ( c . selected ) {
207+ newLangs . push ( c . value )
208+ }
209+ }
210+ spellcheckLangs . set ( newLangs )
211+ } )
212+ }
213+ }
0 commit comments