Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Support for automatic detection
Browse files Browse the repository at this point in the history
"lib/encoding-list-view.js" is used for the detection.
  • Loading branch information
Umoxfo committed Mar 3, 2018
1 parent 73a6c44 commit d1c45b5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const {CompositeDisposable} = require('atom')

const EncodingListView = require('./encoding-list-view')
const EncodingStatusView = require('./encoding-status-view')

Expand Down Expand Up @@ -166,19 +168,28 @@ const encodings = {

let encodingListView = null
let encodingStatusView = null
let commandSubscription = null
let commandSubscriptions = null

module.exports = {
activate () {
commandSubscription = atom.commands.add('atom-text-editor', 'encoding-selector:show', () => {
commandSubscriptions = new CompositeDisposable()
commandSubscriptions.add(atom.commands.add('atom-text-editor', 'encoding-selector:show', () => {
if (!encodingListView) encodingListView = new EncodingListView(encodings)
encodingListView.toggle()
})
}))

// Auto Detect
if (atom.config.get('encoding-selector.alwaysAutoDetect')) {
// event: open file
commandSubscriptions.add(atom.workspace.observeTextEditors(() => encodingListView.detectEncoding()))
// event: changed active pane
commandSubscriptions.add(atom.workspace.onDidChangeActivePaneItem(() => encodingListView.detectEncoding()))
}
},

deactivate () {
if (commandSubscription) commandSubscription.dispose()
commandSubscription = null
if (commandSubscriptions) commandSubscriptions.dispose()
commandSubscriptions = null

if (encodingStatusView) encodingStatusView.destroy()
encodingStatusView = null
Expand Down
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,38 @@
"jasmine",
"spyOn"
]
},
"configSchema": {
"alwaysAutoDetect": {
"title": "Always auto detect",
"description": "enabled from startup",
"type": "boolean",
"default": false
},
"disallowEncTypes": {
"title": "Disallow some encoding types",
"description": "example: windows1252, iso88591",
"type": "string",
"default": ""
},
"divideSize": {
"title": "Divide Buffer Size",
"description": "The number of the consideration.",
"type": "number",
"default": 1,
"minimum": 1
},
"ignorePattern": {
"title": "Ignore Pattern",
"description": "example: (txt|js)$",
"type": "string",
"default": ""
},
"forceEncTypes": {
"title": "Force some encoding types",
"description": "example: windows1252:windows1251, iso88591:windows1251",
"type": "string",
"default": ""
}
}
}

0 comments on commit d1c45b5

Please sign in to comment.