   getThangIDs: ->
     (t.id for t in @level.get('thangs') when t.id isnt 'Interface')
 
+  onNewScriptAdded: (scriptNode) =>
+    return unless scriptNode
+    if scriptNode.data.id is undefined
+      scriptNode.disableTracking()
+      scriptNode.set '/id', 'Script-' + @scriptsTreema.data.length
+      scriptNode.enableTracking()
+
+  onScriptDeleted: =>
+    for key, treema of @scriptsTreema.childrenTreemas
+      key = parseInt(key)
+      treema.disableTracking()
+      if /Script-[0-9]*/.test treema.data.id
+        existingKey = parseInt(treema.data.id.substr(7))
+        if existingKey isnt key+1
+          treema.set 'id', 'Script-' + (key+1)
+      treema.enableTracking()
+
   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
+    if @scriptTreema.canUndo()
+      undoDescription = @scriptTreema.getUndoDescription()
+    else 
+      undoDescription = @scriptsTreema.getUndoDescription()
+    titleText = $('#undo-button').attr('title', 'Undo ' + undoDescription + ' (Ctrl+Z)')
 
   showRedoDescription: ->
-    return
+    if @scriptTreema.canRedo()
+      redoDescription = @scriptTreema.getRedoDescription()
+    else 
+      redoDescription = @scriptsTreema.getRedoDescription()
+    titleText = $('#redo-button').attr('title', 'Redo ' + redoDescription + ' (Ctrl+Shift+Z)')
+
+class ScriptsNode extends TreemaArrayNode
+  addNewChild: ->
+    newTreema = super()
+    if @callbacks.addChild
+      @callbacks.addChild newTreema
+    newTreema
+
+  getUndoDescription: ->
+    return '' unless @canUndo()
+    trackedActions = @getTrackedActions()
+    currentStateIndex = @getCurrentStateIndex()
+    return @getTrackedActionDescription( trackedActions[currentStateIndex - 1] )
+
+  getRedoDescription: ->
+    return '' unless @canRedo()
+    trackedActions = @getTrackedActions()
+    currentStateIndex = @getCurrentStateIndex()
+    return @getTrackedActionDescription trackedActions[currentStateIndex]
+
+  getTrackedActionDescription: (trackedAction) ->
+    switch trackedAction.action
+      when 'insert'
+        trackedActionDescription = 'Add New Script'
+
+      when 'delete'
+        trackedActionDescription = 'Delete Script'
+
+      when 'edit'
+        path = trackedAction.path.split '/'
+        trackedActionDescription = 'Edit Script'
+
+      else
+        trackedActionDescription = ''
+    trackedActionDescription
 
 class ScriptNode extends TreemaObjectNode
   valueClass: 'treema-script'


  onScriptsChanged: (e) =>
    @level.set 'scripts', @scriptsTreema.data
    lastAction = @scriptsTreema.trackedActions[@scriptsTreema.getCurrentStateIndex() - 1]
    return unless lastAction

    if lastAction.action is 'insert' and lastAction.parentPath is '/'
      newScript = @scriptsTreema.get lastAction.path
      if newScript.id is undefined
        @scriptsTreema.disableTracking()
        @scriptsTreema.set lastAction.path+'/id', 'Script-' + @scriptsTreema.data.length
        @scriptsTreema.enableTracking()
        @scriptTreema.refreshDisplay()

    if lastAction.action is 'delete' and lastAction.parentPath[0] is '/'
      for key, treema of @scriptsTreema.childrenTreemas
        key = parseInt(key)
        treema.disableTracking()
        if /Script-[0-9]*/.test treema.data.id
          existingKey = parseInt(treema.data.id.substr(7))
          if existingKey isnt key+1
            treema.set 'id', 'Script-' + (key+1)
        treema.enableTracking()

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

    @tabToCurrentScript()
    e.preventDefault()

  onDeletePressed: (e) ->
    returnVal = super(e)
    if @callbacks.removeChild
      @callbacks.removeChild() 
    returnVal

  onRightArrowPressed: ->
    @tabToCurrentScript()

