···11-# Keybindings require three things to be fully defined: A selector that is
22-# matched against the focused element, the keystroke and the command to
33-# execute.
44-#
55-# Below is a basic keybinding which registers on all platforms by applying to
66-# the root workspace element.
77-88-# For more detailed documentation see
99-# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
1010-'atom-workspace':
1111- 'ctrl-alt-o': 'language-mzn:toggle'
-22
lib/language-mzn-view.coffee
···11-module.exports =
22-class LanguageMznView
33- constructor: (serializedState) ->
44- # Create root element
55- @element = document.createElement('div')
66- @element.classList.add('language-mzn')
77-88- # Create message element
99- message = document.createElement('div')
1010- message.textContent = "The LanguageMzn package is Alive! It's ALIVE!"
1111- message.classList.add('message')
1212- @element.appendChild(message)
1313-1414- # Returns an object that can be retrieved when package is activated
1515- serialize: ->
1616-1717- # Tear down any state and detach
1818- destroy: ->
1919- @element.remove()
2020-2121- getElement: ->
2222- @element
-33
lib/language-mzn.coffee
···11-LanguageMznView = require './language-mzn-view'
22-{CompositeDisposable} = require 'atom'
33-44-module.exports = LanguageMzn =
55- languageMznView: null
66- modalPanel: null
77- subscriptions: null
88-99- activate: (state) ->
1010- @languageMznView = new LanguageMznView(state.languageMznViewState)
1111- @modalPanel = atom.workspace.addModalPanel(item: @languageMznView.getElement(), visible: false)
1212-1313- # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
1414- @subscriptions = new CompositeDisposable
1515-1616- # Register command that toggles this view
1717- @subscriptions.add atom.commands.add 'atom-workspace', 'language-mzn:toggle': => @toggle()
1818-1919- deactivate: ->
2020- @modalPanel.destroy()
2121- @subscriptions.dispose()
2222- @languageMznView.destroy()
2323-2424- serialize: ->
2525- languageMznViewState: @languageMznView.serialize()
2626-2727- toggle: ->
2828- console.log 'LanguageMzn was toggled!'
2929-3030- if @modalPanel.isVisible()
3131- @modalPanel.hide()
3232- else
3333- @modalPanel.show()
···11-LanguageMzn = require '../lib/language-mzn'
22-33-# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
44-#
55-# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
66-# or `fdescribe`). Remove the `f` to unfocus the block.
77-88-describe "LanguageMzn", ->
99- [workspaceElement, activationPromise] = []
1010-1111- beforeEach ->
1212- workspaceElement = atom.views.getView(atom.workspace)
1313- activationPromise = atom.packages.activatePackage('language-mzn')
1414-1515- describe "when the language-mzn:toggle event is triggered", ->
1616- it "hides and shows the modal panel", ->
1717- # Before the activation event the view is not on the DOM, and no panel
1818- # has been created
1919- expect(workspaceElement.querySelector('.language-mzn')).not.toExist()
2020-2121- # This is an activation event, triggering it will cause the package to be
2222- # activated.
2323- atom.commands.dispatch workspaceElement, 'language-mzn:toggle'
2424-2525- waitsForPromise ->
2626- activationPromise
2727-2828- runs ->
2929- expect(workspaceElement.querySelector('.language-mzn')).toExist()
3030-3131- languageMznElement = workspaceElement.querySelector('.language-mzn')
3232- expect(languageMznElement).toExist()
3333-3434- languageMznPanel = atom.workspace.panelForItem(languageMznElement)
3535- expect(languageMznPanel.isVisible()).toBe true
3636- atom.commands.dispatch workspaceElement, 'language-mzn:toggle'
3737- expect(languageMznPanel.isVisible()).toBe false
3838-3939- it "hides and shows the view", ->
4040- # This test shows you an integration test testing at the view level.
4141-4242- # Attaching the workspaceElement to the DOM is required to allow the
4343- # `toBeVisible()` matchers to work. Anything testing visibility or focus
4444- # requires that the workspaceElement is on the DOM. Tests that attach the
4545- # workspaceElement to the DOM are generally slower than those off DOM.
4646- jasmine.attachToDOM(workspaceElement)
4747-4848- expect(workspaceElement.querySelector('.language-mzn')).not.toExist()
4949-5050- # This is an activation event, triggering it causes the package to be
5151- # activated.
5252- atom.commands.dispatch workspaceElement, 'language-mzn:toggle'
5353-5454- waitsForPromise ->
5555- activationPromise
5656-5757- runs ->
5858- # Now we can test for view visibility
5959- languageMznElement = workspaceElement.querySelector('.language-mzn')
6060- expect(languageMznElement).toBeVisible()
6161- atom.commands.dispatch workspaceElement, 'language-mzn:toggle'
6262- expect(languageMznElement).not.toBeVisible()
-5
spec/language-mzn-view-spec.coffee
···11-LanguageMznView = require '../lib/language-mzn-view'
22-33-describe "LanguageMznView", ->
44- it "has one valid test", ->
55- expect("life").toBe "easy"
-8
styles/language-mzn.less
···11-// The ui-variables file is provided by base themes provided by Atom.
22-//
33-// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less
44-// for a full listing of what's available.
55-@import "ui-variables";
66-77-.language-mzn {
88-}