       callbacks:
         change: @onScriptsChanged
         select: @onScriptSelected
+        addChild: @onNewScriptAdded
+        removeChild: @onScriptDeleted
       nodeClasses:
+        array: ScriptsNode
         object: ScriptNode
       view: @
     @scriptsTreema = @$el.find('#scripts-treema').treema treemaOptions

  getThangIDs: ->
    (t.id for t in @level.get('thangs') when t.id isnt 'Interface')

  onScriptChanged: =>
    @scriptsTreema.set(@selectedScriptPath, @scriptTreema.data)

  undo: ->
    if @scriptTreema.canUndo() then @scriptTreema.undo() else @scriptsTreema.undo()
  
  redo: ->
    if @scriptTreema.canRedo() then @scriptTreema.redo() else @scriptsTreema.redo()

  showUndoDescription: ->
    return

  showRedoDescription: ->
    return

class ScriptNode extends TreemaObjectNode
  valueClass: 'treema-script'


  onScriptsChanged: (e) =>
    @level.set 'scripts', @scriptsTreema.data

  onScriptSelected: (e, selected) =>
    selected = if selected.length > 1 then selected[0].getLastSelectedTreema() else selected[0]
