Move disabledKeymaps observer into package manager

This commit is contained in:
Tom Munro
2015-07-29 11:59:32 -07:00
parent 90ec8df3e6
commit b57d2e1dd0
3 changed files with 22 additions and 7 deletions

View File

@@ -455,6 +455,7 @@ describe "PackageManager", ->
describe "when the package's keymaps are disabled and re-enabled after it is activated", ->
it "removes and re-adds the keymaps", ->
element1 = $$ -> @div class: 'test-1'
atom.packages.observeDisabledKeymaps()
waitsForPromise ->
atom.packages.activatePackage("package-with-keymaps-manifest")

View File

@@ -310,6 +310,19 @@ class PackageManager
@activatePackage(packageName) for packageName in packagesToEnable
null
unobserveDisabledKeymaps: ->
@disabledKeymapsSubscription?.dispose()
@disabledKeymapsSubscription = null
observeDisabledKeymaps: ->
@disabledKeymapsSubscription ?= atom.config.onDidChange 'core.disabledKeymaps', ({newValue, oldValue}) =>
keymapsToEnable = _.difference(oldValue, newValue)
keymapsToDisable = _.difference(newValue, oldValue)
@getLoadedPackage(packageName).deactivateKeymaps() for packageName in keymapsToDisable when not @isPackageDisabled(packageName)
@getLoadedPackage(packageName).activateKeymaps() for packageName in keymapsToEnable when not @isPackageDisabled(packageName)
null
loadPackages: ->
# Ensure atom exports is already in the require cache so the load time
# of the first package isn't skewed by being the first to require atom
@@ -396,6 +409,7 @@ class PackageManager
promises.push(promise) unless pack.hasActivationCommands()
return
@observeDisabledPackages()
@observeDisabledKeymaps()
promises
# Activate a single package by name
@@ -424,6 +438,7 @@ class PackageManager
@deactivatePackage(pack.name) for pack in @getLoadedPackages()
return
@unobserveDisabledPackages()
@unobserveDisabledKeymaps()
# Deactivate the package with the given name
deactivatePackage: (name) ->

View File

@@ -201,12 +201,11 @@ class Package
activateResources: ->
@activationDisposables = new CompositeDisposable
@activationDisposables.add atom.config.observe "core.disabledKeymaps", {}, (map) =>
value = not _.include(map ? [], @name)
if value
@activateKeymaps()
else if not value
@deactivateKeymaps()
value = not _.include(atom.config.get("core.disabledKeymaps") ? [], @name)
if value
@activateKeymaps()
else if not value
@deactivateKeymaps()
for [menuPath, map] in @menus when map['context-menu']?
try
@@ -260,7 +259,7 @@ class Package
for [path, map] in @keymaps
if map.length > 0
return true
false
activateServices: ->