Skip to content

Commit e9094c4

Browse files
committed
Merge branch 'dev' of github.com:atom-minimap/atom-minimap into dev
2 parents f5fe36b + 4442ee2 commit e9094c4

File tree

2 files changed

+59
-31
lines changed

2 files changed

+59
-31
lines changed

lib/mixins/plugin-management.coffee

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ class PluginManagement extends Mixin
2222
# settings name as well as the key to unregister the module.
2323
# plugin - The plugin {Object} to register.
2424
registerPlugin: (name, plugin) ->
25+
settingsKey = "minimap.plugins.#{name}"
26+
2527
@configDefaults.plugins[name] = true
26-
unless atom.config.get("minimap.plugins.#{name}")?
27-
atom.config.set "minimap.plugins.#{name}", true
28+
atom.config.set(settingsKey, true) unless atom.config.get(settingsKey)?
2829

2930
@plugins[name] = plugin
3031

3132
@emit('plugin:added', {name, plugin})
32-
atom.config.observe "minimap.plugins.#{name}", =>
33+
34+
atom.config.observe settingsKey, =>
35+
@updatesPluginActivationState(name)
36+
37+
atom.workspaceView.command "minimap:toggle-#{name}", =>
38+
atom.config.set settingsKey, not atom.config.get(settingsKey)
3339
@updatesPluginActivationState(name)
3440

3541
@updatesPluginActivationState(name)
@@ -39,6 +45,7 @@ class PluginManagement extends Mixin
3945
# name - The identifying name of the plugin to unregister.
4046
unregisterPlugin: (name) ->
4147
atom.config.unobserve "minimap.plugins.#{name}"
48+
atom.workspaceView.off "minimap:toggle-#{name}"
4249
plugin = @plugins[name]
4350
delete @configDefaults.plugins[name]
4451
delete @plugins[name]
@@ -49,9 +56,12 @@ class PluginManagement extends Mixin
4956
updatesPluginActivationState: (name) ->
5057
plugin = @plugins[name]
5158

52-
if atom.config.get("minimap.plugins.#{name}")
59+
pluginActive = plugin.isActive()
60+
settingActive = atom.config.get("minimap.plugins.#{name}")
61+
62+
if settingActive and not pluginActive
5363
plugin.activatePlugin()
5464
@emit('plugin:activated', {name, plugin})
55-
else
65+
else if pluginActive and not settingActive
5666
plugin.deactivatePlugin()
5767
@emit('plugin:deactivated', {name, plugin})

spec/minimap-plugins-spec.coffee

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,45 @@ describe "Minimap Plugins", ->
1111
atom.workspaceView.attachToDom()
1212
editorView = atom.workspaceView.getActiveView()
1313

14+
atom.config.set 'minimap.plugins.dummy', undefined
15+
1416
@plugin =
15-
activatePlugin: ->
16-
deactivatePlugin: ->
17+
active: false
18+
activatePlugin: -> @active = true
19+
deactivatePlugin: -> @active = false
20+
isActive: -> @active
21+
22+
spyOn(@plugin, 'activatePlugin').andCallThrough()
23+
spyOn(@plugin, 'deactivatePlugin').andCallThrough()
1724

18-
spyOn @plugin, 'activatePlugin'
19-
spyOn @plugin, 'deactivatePlugin'
25+
@registerHandler = jasmine.createSpy('register handler')
26+
@unregisterHandler = jasmine.createSpy('unregister handler')
2027

2128
describe 'registered before activation', ->
2229

2330
beforeEach ->
31+
Minimap.on 'plugin:added', @registerHandler
2432
Minimap.registerPlugin 'dummy', @plugin
2533

2634
it 'should be available in the minimap', ->
2735
expect(Minimap.plugins['dummy']).toBe(@plugin)
2836

37+
it 'should have emit an event', ->
38+
expect(@registerHandler).toHaveBeenCalled()
39+
2940
it 'should have created a default config for the plugin', ->
3041
expect(Minimap.configDefaults.plugins.dummy).toBeDefined()
3142

3243
it 'should have set the corresponding config', ->
3344
expect(atom.config.get 'minimap.plugins.dummy').toBeDefined()
3445

46+
describe 'triggering the corresponding plugin command', ->
47+
beforeEach ->
48+
atom.workspaceView.trigger 'minimap:toggle-dummy'
49+
50+
it 'should have received a deactivation call', ->
51+
expect(@plugin.deactivatePlugin).toHaveBeenCalled()
52+
3553
describe 'and then unregistered', ->
3654
beforeEach ->
3755
Minimap.unregisterPlugin 'dummy'
@@ -46,31 +64,31 @@ describe "Minimap Plugins", ->
4664
it 'should not receive an activation call', ->
4765
expect(@plugin.deactivatePlugin).not.toHaveBeenCalled()
4866

49-
describe 'the registered plugin', ->
50-
it 'should have received an activation call', ->
51-
Minimap.registerPlugin 'dummy', @plugin
52-
expect(@plugin.activatePlugin).toHaveBeenCalled()
67+
describe 'the registered plugin', ->
68+
it 'should have received an activation call', ->
69+
Minimap.registerPlugin 'dummy', @plugin
70+
expect(@plugin.activatePlugin).toHaveBeenCalled()
5371

54-
describe 'when the config for it is false', ->
55-
beforeEach ->
56-
atom.config.set 'minimap.plugins.dummy', false
57-
Minimap.registerPlugin 'dummy', @plugin
72+
describe 'when the config for it is false', ->
73+
beforeEach ->
74+
atom.config.set 'minimap.plugins.dummy', false
75+
Minimap.registerPlugin 'dummy', @plugin
5876

59-
it 'should have received a deactivation call', ->
60-
expect(@plugin.deactivatePlugin).toHaveBeenCalled()
77+
it 'should not have received an activation call', ->
78+
expect(@plugin.activatePlugin).not.toHaveBeenCalled()
6179

62-
describe 'when the config is modified after registration', ->
63-
beforeEach ->
64-
Minimap.registerPlugin 'dummy', @plugin
65-
atom.config.set 'minimap.plugins.dummy', false
80+
describe 'when the config is modified after registration', ->
81+
beforeEach ->
82+
Minimap.registerPlugin 'dummy', @plugin
83+
atom.config.set 'minimap.plugins.dummy', false
6684

67-
it 'should have received a deactivation call', ->
85+
it 'should have received a deactivation call', ->
6886
expect(@plugin.deactivatePlugin).toHaveBeenCalled()
6987

70-
describe 'on minimap activation', ->
71-
beforeEach ->
72-
waitsForPromise ->
73-
promise = atom.packages.activatePackage('minimap')
74-
expect(atom.workspaceView.find('.minimap')).not.toExist()
75-
atom.workspaceView.trigger 'minimap:toggle'
76-
promise
88+
describe 'on minimap activation', ->
89+
beforeEach ->
90+
waitsForPromise ->
91+
promise = atom.packages.activatePackage('minimap')
92+
expect(atom.workspaceView.find('.minimap')).not.toExist()
93+
atom.workspaceView.trigger 'minimap:toggle'
94+
promise

0 commit comments

Comments
 (0)