Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1432 from ssbc/spellcheck-options
Browse files Browse the repository at this point in the history
Allow selection of multiple or no spellchecker languages.
  • Loading branch information
black-puppydog committed Mar 21, 2021
2 parents 1ba77b6 + 1b789e6 commit 2c11a9d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
5 changes: 5 additions & 0 deletions index.js
Expand Up @@ -170,6 +170,11 @@ electron.app.on('ready', () => {
});
})

electron.ipcMain.handle('setSpellcheckLangs', (ev, params) => {
if (!windows.main) { return }
const { langs, enabled } = params
windows.main.webContents.session.setSpellCheckerLanguages(enabled ? langs : []);
})
electron.ipcMain.handle('consoleLog', (ev, o) => console.log(o))
electron.ipcMain.handle('consoleError', (ev, o) => console.error(o))
electron.ipcMain.handle('badgeCount', (ev, count) => {
Expand Down
58 changes: 55 additions & 3 deletions lib/depject/page/html/render/settings.js
@@ -1,8 +1,10 @@
const { h } = require('mutant')
const { computed, h, map, Value, watch } = require('mutant')
const nest = require('depnest')
const packageInfo = require('../../../../../package.json')
const ExpanderHook = require('../../../../expander-hook')

const themeNames = Object.keys(require('../../../../../styles'))
const electron = require('electron')

exports.needs = nest({
'settings.obs.get': 'first',
Expand All @@ -13,6 +15,12 @@ exports.needs = nest({

exports.gives = nest('page.html.render')

let availableDictionaries = Value([])

electron.ipcRenderer.on('setAvailableDictionaries', (ev, langs) => {
availableDictionaries.set(langs)
})

exports.create = function (api) {
return nest('page.html.render', function channel (path) {
if (path !== '/settings') return
Expand All @@ -31,6 +39,12 @@ exports.create = function (api) {

const theme = api.settings.obs.get('patchwork.theme', 'light')
const lang = api.settings.obs.get('patchwork.lang', '')
const spellcheckLangs = api.settings.obs.get('patchwork.spellcheckLangs', ['en-GB'])
const enableSpellCheck = api.settings.obs.get('patchwork.enableSpellCheck', true)
const spellcheckParams = computed([spellcheckLangs, enableSpellCheck], (langs, enabled) => ({ langs, enabled }))
watch(spellcheckParams, (params) => {
electron.ipcRenderer.invoke('setSpellcheckLangs', params)
})
const fontSize = api.settings.obs.get('patchwork.fontSize', '')
const fontFamily = api.settings.obs.get('patchwork.fontFamily', '')
const includeParticipating = api.settings.obs.get('patchwork.includeParticipating', false)
Expand Down Expand Up @@ -66,7 +80,7 @@ exports.create = function (api) {
]),

h('section', [
h('h2', i18n('Language')),
h('h2', i18n('Interface Language')),
h('select', {
style: { 'font-size': '120%' },
value: lang,
Expand All @@ -79,6 +93,30 @@ exports.create = function (api) {
])
]),

h('section', [
h('h2', i18n('Spellchecking')),
h('div', [
checkbox(enableSpellCheck, {
label: i18n('Enable Spellchecking')
})
]),
h('h3', i18n('Languages to check for (select multiple)')),
h('select', {
disabled: computed(enableSpellCheck, (b) => !b),
multiple: true,
size: 10,
style: { 'font-size': '120%' },
hooks: [SpellcheckChangeHook(spellcheckLangs)]
}, [
map(availableDictionaries, (code) => h('option', {
value: code,
selected: spellcheckLangs().indexOf(code) !== -1,
}, [
'[', code, '] ', getLocaleName(code)
]))
])
]),

h('section', [
h('h2', i18n('Font Size')),
h('select', {
Expand All @@ -99,7 +137,7 @@ exports.create = function (api) {
'ev-change': (ev) => fontFamily.set(ev.target.value)
}, [
h('option', { value: '' }, i18n('Default')),
fontFamilies.map(family => h('option', { value: family }, family))
fontFamilies.map(family => h('option', { value: family, }, family))
])
]),
h('h2', i18n('Notification Options')),
Expand Down Expand Up @@ -159,3 +197,17 @@ function checkbox (param, { label }) {
}), ' ', label
])
}

function SpellcheckChangeHook (spellcheckLangs) {
return function (element) {
element.addEventListener('change', (ev) => {
const newLangs = []
for (const c of ev.target.children) {
if (c.selected) {
newLangs.push(c.value)
}
}
spellcheckLangs.set(newLangs)
})
}
}
2 changes: 2 additions & 0 deletions lib/window.js
Expand Up @@ -29,6 +29,8 @@ module.exports = function Window (config, path, opts, serverDevToolsCallback, na
data: opts.data || '',
title: opts.title || 'Patchwork',
})
const availableLangs = window.webContents.session.availableSpellCheckerLanguages
window.webContents.send('setAvailableDictionaries', availableLangs)
})

// setTimeout(function () {
Expand Down
46 changes: 45 additions & 1 deletion locales/en.json
Expand Up @@ -306,5 +306,49 @@
"nl": "nl",
"Last activity": "Last activity",
"Status": "Status",
"Indexes": "Indexes"
"Indexes": "Indexes",
"Interface Language": "Interface Language",
"fa": "fa",
"Spellchecking": "Spellchecking",
"Enable Spellchecking": "Enable Spellchecking",
"Languages to check for (select multiple)": "Languages to check for (select multiple)",
"af": "af",
"bg": "bg",
"ca": "ca",
"cs": "cs",
"cy": "cy",
"da": "da",
"en-AU": "en-AU",
"en-CA": "en-CA",
"en-GB": "en-GB",
"en-GB-oxendict": "en-GB-oxendict",
"en-US": "en-US",
"es-419": "es-419",
"es-AR": "es-AR",
"es-ES": "es-ES",
"es-MX": "es-MX",
"es-US": "es-US",
"et": "et",
"fo": "fo",
"he": "he",
"hi": "hi",
"hr": "hr",
"hu": "hu",
"hy": "hy",
"id": "id",
"it": "it",
"ko": "ko",
"lt": "lt",
"lv": "lv",
"nb": "nb",
"pt-PT": "pt-PT",
"ro": "ro",
"sh": "sh",
"sq": "sq",
"sr": "sr",
"sv": "sv",
"ta": "ta",
"tg": "tg",
"tr": "tr",
"vi": "vi"
}

0 comments on commit 2c11a9d

Please sign in to comment.