mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Watch user's keycap for changes and apply them
This commit is contained in:
@@ -286,6 +286,7 @@ class Atom extends Model
|
||||
@workspaceView = null
|
||||
@project.destroy()
|
||||
@windowEventHandler?.unsubscribe()
|
||||
@keymap.destroy()
|
||||
@windowState = null
|
||||
|
||||
# Private:
|
||||
|
||||
@@ -4,6 +4,7 @@ fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
CSON = require 'season'
|
||||
KeyBinding = require './key-binding'
|
||||
File = require './file'
|
||||
{Emitter} = require 'emissary'
|
||||
|
||||
Modifiers = ['alt', 'control', 'ctrl', 'shift', 'cmd']
|
||||
@@ -28,6 +29,9 @@ class Keymap
|
||||
constructor: ({@resourcePath, @configDirPath})->
|
||||
@keyBindings = []
|
||||
|
||||
destroy: ->
|
||||
@unwatchUserKeymap()
|
||||
|
||||
# Public: Returns an array of all {KeyBinding}s.
|
||||
getKeyBindings: ->
|
||||
_.clone(@keyBindings)
|
||||
@@ -118,9 +122,20 @@ class Keymap
|
||||
@loadDirectory(path.join(@resourcePath, 'keymaps'))
|
||||
@emit('bundled-keymaps-loaded')
|
||||
|
||||
userKeymapPath: ->
|
||||
CSON.resolve(path.join(@configDirPath, 'keymap'))
|
||||
|
||||
unwatchUserKeymap: ->
|
||||
return unless keymapPath = @userKeymapPath()
|
||||
@remove(keymapPath)
|
||||
@userKeymapFile?.off()
|
||||
|
||||
loadUserKeymap: ->
|
||||
userKeymapPath = CSON.resolve(path.join(@configDirPath, 'keymap'))
|
||||
@load(userKeymapPath) if userKeymapPath
|
||||
return unless keymapPath = @userKeymapPath()
|
||||
@unwatchUserKeymap()
|
||||
@load(keymapPath)
|
||||
@userKeymapFile = new File(keymapPath)
|
||||
@userKeymapFile.on 'contents-changed', => @loadUserKeymap()
|
||||
|
||||
loadDirectory: (directoryPath) ->
|
||||
@load(filePath) for filePath in fs.listSync(directoryPath, ['.cson', '.json'])
|
||||
|
||||
Reference in New Issue
Block a user