git ssb

1+

Daan Patchwork / patchwork



Commit 1b789e63aa59f5d3e5539a4432c8b3c466977a0e

Allow selection of multiple or no spellchecker languages.

Daan Wynen committed on 3/21/2021, 12:58:30 AM
Parent: 1ba77b6b13b6ff3be4180dc4de6c449ba4570d90

Files changed

index.jschanged
lib/depject/page/html/render/settings.jschanged
lib/window.jschanged
locales/en.jsonchanged
index.jsView
@@ -169,8 +169,13 @@
169169 y: Math.round(y * factor) + 4,
170170 });
171171 })
172172
173 + electron.ipcMain.handle('setSpellcheckLangs', (ev, params) => {
174 + if (!windows.main) { return }
175 + const { langs, enabled } = params
176 + windows.main.webContents.session.setSpellCheckerLanguages(enabled ? langs : []);
177 + })
173178 electron.ipcMain.handle('consoleLog', (ev, o) => console.log(o))
174179 electron.ipcMain.handle('consoleError', (ev, o) => console.error(o))
175180 electron.ipcMain.handle('badgeCount', (ev, count) => {
176181 electron.app.badgeCount = count;
lib/depject/page/html/render/settings.jsView
@@ -1,9 +1,11 @@
1-const { h } = require('mutant')
1 +const { computed, h, map, Value, watch } = require('mutant')
22 const nest = require('depnest')
33 const packageInfo = require('../../../../../package.json')
4 +const ExpanderHook = require('../../../../expander-hook')
45
56 const themeNames = Object.keys(require('../../../../../styles'))
7 +const electron = require('electron')
68
79 exports.needs = nest({
810 'settings.obs.get': 'first',
911 'intl.sync.locales': 'first',
@@ -12,8 +14,14 @@
1214 })
1315
1416 exports.gives = nest('page.html.render')
1517
18 +let availableDictionaries = Value([])
19 +
20 +electron.ipcRenderer.on('setAvailableDictionaries', (ev, langs) => {
21 + availableDictionaries.set(langs)
22 +})
23 +
1624 exports.create = function (api) {
1725 return nest('page.html.render', function channel (path) {
1826 if (path !== '/settings') return
1927 const i18n = api.intl.sync.i18n
@@ -30,8 +38,14 @@
3038 ]
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)
3751 const autoDeleteBlocked = api.settings.obs.get('patchwork.autoDeleteBlocked', false)
@@ -65,9 +79,9 @@
6579 ])
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,
7387 'ev-change': (ev) => lang.set(ev.target.value)
@@ -79,8 +93,32 @@
7993 ])
8094 ]),
8195
8296 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 +
120 + h('section', [
83121 h('h2', i18n('Font Size')),
84122 h('select', {
85123 style: { 'font-size': '120%' },
86124 value: fontSize,
@@ -98,9 +136,9 @@
98136 value: fontFamily,
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')),
106144
@@ -158,4 +196,18 @@
158196 'ev-change': (ev) => param.set(ev.target.checked)
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 +}
lib/window.jsView
@@ -28,8 +28,10 @@
2828 config: config,
2929 data: opts.data || '',
3030 title: opts.title || 'Patchwork',
3131 })
32 + const availableLangs = window.webContents.session.availableSpellCheckerLanguages
33 + window.webContents.send('setAvailableDictionaries', availableLangs)
3234 })
3335
3436 // setTimeout(function () {
3537 // window.show()
locales/en.jsonView
@@ -305,6 +305,50 @@
305305 "In order to share with users on the internet, you need to be invited to a pub server or a room server.": "In order to share with users on the internet, you need to be invited to a pub server or a room server.",
306306 "nl": "nl",
307307 "Last activity": "Last activity",
308308 "Status": "Status",
309- "Indexes": "Indexes"
309 + "Indexes": "Indexes",
310 + "Interface Language": "Interface Language",
311 + "fa": "fa",
312 + "Spellchecking": "Spellchecking",
313 + "Enable Spellchecking": "Enable Spellchecking",
314 + "Languages to check for (select multiple)": "Languages to check for (select multiple)",
315 + "af": "af",
316 + "bg": "bg",
317 + "ca": "ca",
318 + "cs": "cs",
319 + "cy": "cy",
320 + "da": "da",
321 + "en-AU": "en-AU",
322 + "en-CA": "en-CA",
323 + "en-GB": "en-GB",
324 + "en-GB-oxendict": "en-GB-oxendict",
325 + "en-US": "en-US",
326 + "es-419": "es-419",
327 + "es-AR": "es-AR",
328 + "es-ES": "es-ES",
329 + "es-MX": "es-MX",
330 + "es-US": "es-US",
331 + "et": "et",
332 + "fo": "fo",
333 + "he": "he",
334 + "hi": "hi",
335 + "hr": "hr",
336 + "hu": "hu",
337 + "hy": "hy",
338 + "id": "id",
339 + "it": "it",
340 + "ko": "ko",
341 + "lt": "lt",
342 + "lv": "lv",
343 + "nb": "nb",
344 + "pt-PT": "pt-PT",
345 + "ro": "ro",
346 + "sh": "sh",
347 + "sq": "sq",
348 + "sr": "sr",
349 + "sv": "sv",
350 + "ta": "ta",
351 + "tg": "tg",
352 + "tr": "tr",
353 + "vi": "vi"
310354 }

Built with git-ssb-web