diff --git a/lib/sb-atom-sonic-pi-view.js b/lib/sb-atom-sonic-pi-view.js new file mode 100644 index 0000000..a1b8233 --- /dev/null +++ b/lib/sb-atom-sonic-pi-view.js @@ -0,0 +1,31 @@ +'use babel'; + +export default class sbAtomSonicPiView { + + constructor(serializedState) { + console.log('creating element'); + // Create root element + this.element = document.createElement('div'); + this.element.classList.add('sb-atom-sonic-pi'); + + // Create message element + const message = document.createElement('div'); + message.textContent = 'The sb-atom-sonic-pi package is Alive! It\'s ALIVE!'; + message.classList.add('message'); + this.element.appendChild(message); + } + + // Returns an object that can be retrieved when package is activated + serialize() {} + + // Tear down any state and detach + destroy() { + console.log('removing element'); + this.element.remove(); + } + + getElement() { + return this.element; + } + +} diff --git a/lib/sb-atom-sonic-pi.coffee b/lib/sb-atom-sonic-pi.coffee index 747881c..9ad41f4 100644 --- a/lib/sb-atom-sonic-pi.coffee +++ b/lib/sb-atom-sonic-pi.coffee @@ -1,48 +1,78 @@ -{CompositeDisposable} = require 'atom' -osc = require 'node-osc' -provider = require './sb-atom-sonic-pi-autocomplete' +'use babel'; + +{CompositeDisposable} = require 'atom'; +osc = require 'node-osc'; +provider = require './sb-atom-sonic-pi-autocomplete'; +sbAtomSonicPiView = require './sb-atom-sonic-pi-view'; module.exports = sbAtomSonicPi = config: sendMessagesToGUI: - title: 'Send Messages To GUI' - type: 'boolean' + title: 'Send Messages To GUI', + type: 'boolean', default: false - subscriptions: null - provide: -> provider + sbAtomSonicPiView: null, + subscriptions: null, + modalPanel: null, + provide: -> provider; activate: (state) -> - @subscriptions = new CompositeDisposable + @sbAtomSonicPiView = new sbAtomSonicPiView(state.sbAtomSonicPiViewState); + @modalPanel = atom.workspace.addModalPanel( + item: this.sbAtomSonicPiView.getElement(), + visible: false + ); + + @subscriptions = new CompositeDisposable; @subscriptions.add(atom.commands.add 'atom-workspace', 'sb-atom-sonic-pi:play-file': => @play('getText'), 'sb-atom-sonic-pi:save-and-play-file':=> @saveAndPlay(), 'sb-atom-sonic-pi:play-selection': => @play('getSelectedText'), - 'sb-atom-sonic-pi:stop': => @stop()) + 'sb-atom-sonic-pi:stop': => @stop(), + 'sb-atom-sonic-pi:toggle-tutorial': => @toggleTutorial(), + 'sb-atom-sonic-pi:test_toggle': => @test_toggle() + ); deactivate: -> - @subscriptions.dispose() + @modalPanel.destroy(); + @subscriptions.dispose(); + @sbAtomSonicPiView.destroy(); + + serialize: -> + return sbAtomSonicPiViewState: this.sbAtomSonicPiView.serialize(); play: (selector) -> - editor = atom.workspace.getActiveTextEditor() - source = editor[selector]() - @send '/run-code', 'atom', source - atom.notifications.addSuccess "Sent source code to Sonic Pi. :)" + editor = atom.workspace.getActiveTextEditor(); + source = editor[selector](); + @send('/run-code', 'atom', source); + atom.notifications.addSuccess("Sent source code to Sonic Pi. :)"); saveAndPlay: -> - editor = atom.workspace.getActiveTextEditor() + editor = atom.workspace.getActiveTextEditor(); editor.save(); - fullPath = editor.getPath() - title = editor.getTitle() - @send '/run-code', 'atom', "run_file \"" + fullPath + "\"" - atom.notifications.addSuccess "Saved file and told Sonic Pi to start playing. :)" + fullPath = editor.getPath().replace(/\\/g,"/"); + title = editor.getTitle(); + @send('/run-code', 'atom', "run_file \"" + fullPath + "\""); + atom.notifications.addSuccess("Saved file and told Sonic Pi to start playing. :)"); stop: -> - @send '/stop-all-jobs' - atom.notifications.addInfo "Told Sonic Pi to stop playing." + @send('/stop-all-jobs'); + atom.notifications.addInfo("Told Sonic Pi to stop playing."); send: (args...) -> if atom.config.get('sb-atom-sonic-pi.sendMessagesToGUI') == true - sp_gui = new osc.Client('localhost', 4559) - sp_gui.send args..., -> sp_gui.kill() - sp_server = new osc.Client('127.0.0.1', 4557) - sp_server.send args..., -> sp_server.kill() + sp_gui = new osc.Client('localhost', 4559); + sp_gui.send args..., -> sp_gui.kill(); + sp_server = new osc.Client('127.0.0.1', 4557); + sp_server.send args..., -> sp_server.kill(); + + test_toggle: -> + console.log('sb-atom-sonic-pi was toggled!'); + return ( + if this.modalPanel.isVisible() + console.log('sb-atom-sonic-pi: hiding panel'); + this.modalPanel.hide() + else + console.log('sb-atom-sonic-pi: showing panel'); + this.modalPanel.show() + ) diff --git a/package.json b/package.json index 786e58e..dc0e388 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,13 @@ } } }, + "consumedServices": { + "tree-view": { + "versions": { + "^1.0.0": "consumeTreeView" + } + } + }, "repository": "https://github.com/sunderb/sb-atom-sonic-pi", "license": "MIT", "engines": { diff --git a/spec/sb-atom-sonic-pi-spec.coffee b/spec/sb-atom-sonic-pi-spec.coffee index eeb7d5e..9b89a21 100644 --- a/spec/sb-atom-sonic-pi-spec.coffee +++ b/spec/sb-atom-sonic-pi-spec.coffee @@ -12,20 +12,22 @@ describe "sbAtomSonicPi", -> workspaceElement = atom.views.getView(atom.workspace) activationPromise = atom.packages.activatePackage('sb-atom-sonic-pi') - describe "when the sb-atom-sonic-pi:toggle event is triggered", -> + describe "when the sb-atom-sonic-pi:test_toggle event is triggered", -> it "hides and shows the modal panel", -> # Before the activation event the view is not on the DOM, and no panel # has been created + console.log('sb-atom-sonic-pi: test 1'); expect(workspaceElement.querySelector('.sb-atom-sonic-pi')).not.toExist() # This is an activation event, triggering it will cause the package to be # activated. - atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:toggle' + atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:test_toggle' waitsForPromise -> activationPromise runs -> + console.log('sb-atom-sonic-pi: test 2'); expect(workspaceElement.querySelector('.sb-atom-sonic-pi')).toExist() sbAtomSonicPiElement = workspaceElement.querySelector('.sb-atom-sonic-pi') @@ -33,10 +35,11 @@ describe "sbAtomSonicPi", -> sbAtomSonicPiPanel = atom.workspace.panelForItem(sbAtomSonicPiElement) expect(sbAtomSonicPiPanel.isVisible()).toBe true - atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:toggle' + atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:test_toggle' expect(sbAtomSonicPiPanel.isVisible()).toBe false it "hides and shows the view", -> + console.log('sb-atom-sonic-pi: next set of tests'); # This test shows you an integration test testing at the view level. # Attaching the workspaceElement to the DOM is required to allow the @@ -44,19 +47,20 @@ describe "sbAtomSonicPi", -> # requires that the workspaceElement is on the DOM. Tests that attach the # workspaceElement to the DOM are generally slower than those off DOM. jasmine.attachToDOM(workspaceElement) - + console.log('sb-atom-sonic-pi: test 3'); expect(workspaceElement.querySelector('.sb-atom-sonic-pi')).not.toExist() # This is an activation event, triggering it causes the package to be # activated. - atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:toggle' + atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:test_toggle' waitsForPromise -> activationPromise runs -> + console.log('sb-atom-sonic-pi: test 4'); # Now we can test for view visibility sbAtomSonicPiElement = workspaceElement.querySelector('.sb-atom-sonic-pi') expect(sbAtomSonicPiElement).toBeVisible() - atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:toggle' + atom.commands.dispatch workspaceElement, 'sb-atom-sonic-pi:test_toggle' expect(sbAtomSonicPiElement).not.toBeVisible() diff --git a/spec/sb-atom-sonic-pi-view-spec.coffee b/spec/sb-atom-sonic-pi-view-spec.coffee index 7c9686f..da5675b 100644 --- a/spec/sb-atom-sonic-pi-view-spec.coffee +++ b/spec/sb-atom-sonic-pi-view-spec.coffee @@ -1,6 +1,6 @@ -sbAtomSonicView = require '../lib/sb-atom-sonic-pi-view' +sbAtomSonicPiView = require '../lib/sb-atom-sonic-pi-view' -describe "sbAtomSonicView", -> +describe "sbAtomSonicPiView", -> it "has one valid test", -> expect("life").toBe "easy" # I'm not sure why this test is here, but OK...