 
   activate: (state) ->
     # Require modules on activation
-    StatusView ?= require './views/status-bar-view'
-    SettingsHelper ?= require './utils/settings-helper'
-    MenuManager ?= require './utils/menu-manager'
+    @StatusView ?= require './views/status-bar-view'
+    @SettingsHelper ?= require './utils/settings-helper'
+    @MenuManager ?= require './utils/menu-manager'
 
     # Initialize views
-    @statusView = new StatusView()
+    @statusView = new @StatusView()
 
     # Hooking up commands
     atom.workspaceView.command 'spark-ide:login', => @login()


    atom.confirm
      message: 'Removal confirmation'
      detailedMessage: 'Do you really want to remove ' + SettingsHelper.get('current_core_name') + '?'
      buttons: buttons

  claimCore: ->
    ClaimCoreView ?= require './views/claim-core-view'

    if !SettingsHelper.isLoggedIn()
      return

    @claimCoreView ?= new ClaimCoreView()
    @claimCoreView.attach()

  identifyCore: (port=null) ->
    ListeningModeView ?= require './views/listening-mode-view'
    SerialHelper = require './utils/serial-helper'

    if !SettingsHelper.isLoggedIn()
      return

    @listPortsPromise = SerialHelper.listPorts()
    @listPortsPromise.done (ports) =>
      @listPortsPromise = null
      if ports.length == 0
        @listeningModeView ?= new ListeningModeView()
        @listeningModeView.show()
      else if (ports.length == 1) || (!!port)
        if !port
          port = ports[0].comName

        promise = SerialHelper.askForCoreID port
        promise.done (coreID) =>
          IdentifyCoreView ?= require './views/identify-core-view'
          @identifyCoreView ?= new IdentifyCoreView coreID
          @identifyCoreView.attach()
        , (e) =>
          @statusView.setStatus e, 'error'
          @statusView.clearAfter 5000
      else
        SelectPortView ?= require './views/select-port-view'
        @selectPortView ?= new SelectPortView()

        @selectPortView.show()


        @compileCloudPromise = null

  showCompileErrors: ->
    @CompileErrorsView = require './views/compile-errors-view'
    @compileErrorsView ?= new @CompileErrorsView
    @compileErrorsView.show()

  toggleCloudVariablesAndFunctions: ->
    # TODO: Implement
    @CloudVariablesAndFunctions ?= require './views/cloud-variables-and-functions-view'
    @cloudVariablesAndFunctions ?= new @CloudVariablesAndFunctions
