mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
70 lines
2.6 KiB
JavaScript
70 lines
2.6 KiB
JavaScript
import utils from "../../../services/utils.js";
|
|
import server from "../../../services/server.js";
|
|
import toastService from "../../../services/toast.js";
|
|
|
|
const TPL = `
|
|
<style>
|
|
.disabled-field {
|
|
opacity: 0.5;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|
|
|
|
<div>
|
|
<h4>Spell check</h4>
|
|
|
|
<p>These options apply only for desktop builds, browsers will use their own native spell check. App restart is required after change.</p>
|
|
|
|
<div class="custom-control custom-checkbox">
|
|
<input type="checkbox" class="custom-control-input" id="spell-check-enabled">
|
|
<label class="custom-control-label" for="spell-check-enabled">Enable spellcheck</label>
|
|
</div>
|
|
|
|
<br/>
|
|
|
|
<div class="form-group">
|
|
<label for="spell-check-language-code">Language code(s)</label>
|
|
<input type="text" class="form-control" id="spell-check-language-code" placeholder="for example "en-US", "de-AT"">
|
|
</div>
|
|
|
|
<p>Multiple languages can be separated by comma, e.g. <code>en-US, de-DE, cs</code>. Changes to the spell check options will take effect after application restart.</p>
|
|
|
|
<p><strong>Available language codes: </strong> <span id="available-language-codes"></span></p>
|
|
</div>`;
|
|
|
|
export default class SpellcheckOptions {
|
|
constructor() {
|
|
$("#options-spellcheck").html(TPL);
|
|
|
|
this.$spellCheckEnabled = $("#spell-check-enabled");
|
|
this.$spellCheckLanguageCode = $("#spell-check-language-code");
|
|
|
|
this.$spellCheckEnabled.on('change', () => {
|
|
const opts = { 'spellCheckEnabled': this.$spellCheckEnabled.is(":checked") ? "true" : "false" };
|
|
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
|
|
|
|
return false;
|
|
});
|
|
|
|
this.$spellCheckLanguageCode.on('change', () => {
|
|
const opts = { 'spellCheckLanguageCode': this.$spellCheckLanguageCode.val() };
|
|
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
|
|
|
|
return false;
|
|
});
|
|
|
|
this.$availableLanguageCodes = $("#available-language-codes");
|
|
|
|
if (utils.isElectron()) {
|
|
const { webContents } = utils.dynamicRequire('@electron/remote').getCurrentWindow();
|
|
|
|
this.$availableLanguageCodes.text(webContents.session.availableSpellCheckerLanguages.join(', '));
|
|
}
|
|
}
|
|
|
|
optionsLoaded(options) {
|
|
this.$spellCheckEnabled.prop("checked", options['spellCheckEnabled'] === 'true');
|
|
this.$spellCheckLanguageCode.val(options['spellCheckLanguageCode']);
|
|
}
|
|
}
|