New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preference setting to pick the language #2

Open
wants to merge 1 commit into
base: master
from
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+256 −3
Diff settings

Always

Just for now

Copy path View file
@@ -13,6 +13,8 @@ ipm install spell-checker

## Version history

* NEXT
* Add preference to choose dictionary language
* 0.3.0
* Ignore non-alphabetical words
* 0.2.2
Copy path View file
@@ -0,0 +1,109 @@
'use strict';
'use babel';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;

var _inkdrop = require('inkdrop');

let LanguageChooser = class LanguageChooser extends _inkdrop.React.Component {
constructor(props) {
super(props);

let languages = inkdrop.config.get('plugins.spell-checker.languages');
if (!languages) {
languages = ['en_US'];
}
let language = inkdrop.config.get('plugins.spell-checker.language');
if (!language) {
language = 'en_US';
}
this.state = {
languages,
language
};

this.handleChange = this.handleChange.bind(this);
}

componentWillMount() {
this.subscriptions = new _inkdrop.CompositeDisposable();
this.subscriptions.add(inkdrop.commands.add(document.body, {
'spell-checker:choose': () => this.choose()
}));
}

componentWillUnmount() {
this.subscriptions.dispose();
}

handleChange(event) {
const language = event.target.value;

this.setState({ language });
inkdrop.config.set('plugins.spell-checker.language', language);

event.preventDefault();
}

render() {
const { MessageDialog } = inkdrop.components.classes;

return _inkdrop.React.createElement(
MessageDialog,
{ className: 'spellCheck', ref: 'dialog', title: 'Choose Language' },
_inkdrop.React.createElement(
'div',
null,
_inkdrop.React.createElement(
'p',
null,
'Select a language for spell checking'
)
),
_inkdrop.React.createElement('br', null),
_inkdrop.React.createElement(
'div',
{ className: 'ui form' },
_inkdrop.React.createElement(
'select',
{ onChange: this.handleChange, value: this.state.language },
this.state.languages.map((item, index) => _inkdrop.React.createElement(
'option',
{ key: index, value: item },
item
))
)
),
_inkdrop.React.createElement('br', null),
_inkdrop.React.createElement(
'div',
null,
_inkdrop.React.createElement(
'p',
null,
_inkdrop.React.createElement(
'strong',
null,
'Note: You will need to restart for this change to take effect'
)
)
)
);
}

choose() {
console.log('Language Selection!');

const { dialog } = this.refs;

if (!dialog.isShown) {
dialog.showDialog();
} else {
dialog.dismissDialog();
}
}
};
exports.default = LanguageChooser;
Copy path View file
@@ -4,20 +4,39 @@ var _codemirrorSpellCheckerInkdrop = require('codemirror-spell-checker-inkdrop')

var _codemirrorSpellCheckerInkdrop2 = _interopRequireDefault(_codemirrorSpellCheckerInkdrop);

var _spellCheckerDisplay = require('./spell-checker-display');

var _spellCheckerDisplay2 = _interopRequireDefault(_spellCheckerDisplay);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = {

activate() {
const { CodeMirror } = require('inkdrop');
let language = inkdrop.config.get('plugins.spell-checker.language');
if (!language) {
language = 'en_US';
}

// Store the latest languages
inkdrop.config.set('plugins.spell-checker.languages', _codemirrorSpellCheckerInkdrop2.default.languages);

(0, _codemirrorSpellCheckerInkdrop2.default)({
codeMirrorInstance: CodeMirror,
ignoreCodeBlocks: true
ignoreCodeBlocks: true,
language: language
});
global.inkdrop.on('editor:init', this.handleEditorInit.bind(this));

inkdrop.components.registerClass(_spellCheckerDisplay2.default);
inkdrop.layouts.addComponentToLayout('modals', 'LanguageChooser');
},

deactivate() {
inkdrop.layouts.removeComponentFromLayout('modals', 'LanguageChooser');
inkdrop.components.deleteClass(_spellCheckerDisplay2.default);

const editor = global.inkdrop.getActiveEditor();
if (editor && editor.codeMirror && this.originalMode) {
editor.codeMirror.setOption('mode', this.originalMode);
Copy path View file
@@ -0,0 +1,18 @@
{
"menu": [
{
"label": "Plugins",
"submenu": [
{
"label": "spell-checker",
"submenu": [
{
"label": "Language",
"command": "spell-checker:choose"
}
]
}
]
}
]
}
Copy path View file
@@ -0,0 +1,84 @@
'use babel'

import { React, CompositeDisposable } from 'inkdrop'

export default class LanguageChooser extends React.Component {
constructor (props) {
super(props)

let languages = inkdrop.config.get('plugins.spell-checker.languages')
if (!languages) {
languages = ['en_US']
}
let language = inkdrop.config.get('plugins.spell-checker.language')
if (!language) {
language = 'en_US'
}
this.state = {
languages,
language
}

this.handleChange = this.handleChange.bind(this)
}

componentWillMount () {
this.subscriptions = new CompositeDisposable()
this.subscriptions.add(inkdrop.commands.add(document.body, {
'spell-checker:choose': () => this.choose()
}))
}

componentWillUnmount () {
this.subscriptions.dispose()
}

handleChange (event) {
const language = event.target.value

this.setState({language})
inkdrop.config.set('plugins.spell-checker.language', language)

event.preventDefault()
}

render () {
const { MessageDialog } = inkdrop.components.classes

return (
<MessageDialog className="spellCheck" ref='dialog' title='Choose Language'>
<div>
<p>Select a language for spell checking</p>
</div>
<br />
<div className="ui form">
<select onChange={this.handleChange} value={this.state.language}>
{
this.state.languages.map((item, index) => (
<option key={index} value={item}>{item}</option>
))
}
</select>
</div>
<br />
<div>
<p>
<strong>Note: You will need to restart for this change to take effect</strong>
</p>
</div>
</MessageDialog>
)
}

choose () {
console.log('Language Selection!')

const { dialog } = this.refs

if (!dialog.isShown) {
dialog.showDialog()
} else {
dialog.dismissDialog()
}
}
}
Copy path View file
@@ -1,17 +1,34 @@
import CodeMirrorSpellChecker from 'codemirror-spell-checker-inkdrop'

import LanguageChooser from './spell-checker-display'

module.exports = {

activate () {
const { CodeMirror } = require('inkdrop')
let language = inkdrop.config.get('plugins.spell-checker.language')
if (!language) {
language = 'en_US'
}

// Store the latest languages
inkdrop.config.set('plugins.spell-checker.languages', CodeMirrorSpellChecker.languages)

CodeMirrorSpellChecker({
codeMirrorInstance: CodeMirror,
ignoreCodeBlocks: true
ignoreCodeBlocks: true,
language: language
})
global.inkdrop.on('editor:init', ::this.handleEditorInit)

inkdrop.components.registerClass(LanguageChooser)
inkdrop.layouts.addComponentToLayout('modals', 'LanguageChooser')
},

deactivate () {
inkdrop.layouts.removeComponentFromLayout('modals', 'LanguageChooser')
inkdrop.components.deleteClass(LanguageChooser)

const editor = global.inkdrop.getActiveEditor()
if (editor && editor.codeMirror && this.originalMode) {
editor.codeMirror.setOption('mode', this.originalMode)
@@ -24,4 +41,4 @@ module.exports = {
cm.setOption('backdrop', this.originalMode)
cm.setOption('mode', 'spell-checker')
}
};
}
Copy path View file
@@ -1,3 +1,7 @@
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment):not(.cm-tag):not(.cm-word):not(.cm-link) {
border-bottom: 1px dotted red;
}

.spellCheck div {
margin-bottom: 5px;
}
ProTip! Use n and p to navigate between commits in a pull request.