changeset 1623:c4e990d1dacf

delete key deletes selected notes. Try to fix mem leak in timeline. Ignore-this: c122fe14883cfda925c1bd66c13773b2
author Drew Perttula <drewp@bigasterisk.com>
date Fri, 09 Jun 2017 08:48:29 +0000
parents 96e0e013e28d
children 4a751aaaee52
files light9/web/timeline/adjustable.coffee light9/web/timeline/timeline.coffee
diffstat 2 files changed, 37 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/timeline/adjustable.coffee	Fri Jun 09 08:25:19 2017 +0000
+++ b/light9/web/timeline/adjustable.coffee	Fri Jun 09 08:48:29 2017 +0000
@@ -88,6 +88,7 @@
     @config.observable(newValue)
 
   subscribe: (onChange) ->
+    log('AdjustableFloatObservable subscribe', @config)
     ko.computed =>
       @config.observable()
       onChange()
--- a/light9/web/timeline/timeline.coffee	Fri Jun 09 08:25:19 2017 +0000
+++ b/light9/web/timeline/timeline.coffee	Fri Jun 09 08:48:29 2017 +0000
@@ -17,7 +17,7 @@
 
   for uri in _.difference(childUris, newUris)
     childByUri[uri].detached()
-    childByUri[uri].remove()
+    ko.removeNode(childByUri[uri])
   for uri in _.difference(newUris, childUris)
     parent.appendChild(makeChild(uri))
 
@@ -109,6 +109,7 @@
 
 
   zoomOrLayoutChanged: ->
+    log('zoomOrLayoutChanged')
     # not for cursor updates
 
     window.debug_zoomOrLayoutChangedCount++
@@ -121,7 +122,7 @@
     zoomInX.range([0, @width()])
     @zoomInX = zoomInX
 
-    # todo: these run a lot of work purely for a time change    
+    # todo: these run a lot of work purely for a time change
     @dia.setTimeAxis(@width(), @$.zoomed.$.audio.offsetTop, @zoomInX)
     @$.adjustersCanvas.updateAllCoords()
 
@@ -219,6 +220,10 @@
                       newCenter + visSeconds / 2, zoomAnimSec)
     shortcut.add "L", =>
       @$.adjustersCanvas.updateAllCoords()
+    shortcut.add 'Delete', =>
+      for note in @selection.selected()
+        deleteNote(@graph, @song, note, @selection)
+
 
   makeZoomAdjs: ->
     yMid = => @$.audio.offsetTop + @$.audio.offsetHeight / 2
@@ -278,6 +283,7 @@
     zoomFlattened: { type: Object, notify: true }
   onZoom: ->
     updateZoomFlattened = ->
+      log('updateZoomFlattened')
       @zoomFlattened = ko.toJS(@zoom)
     ko.computed(updateZoomFlattened.bind(@))
   ready: ->
@@ -522,7 +528,7 @@
       }
     if @inlineRect.display != 'none'
       @async =>
-        @querySelector('light9-timeline-note-inline-attrs').displayed()
+        @querySelector('light9-timeline-note-inline-attrs')?.displayed()
 
     if screenPts[screenPts.length - 1].e(1) - screenPts[0].e(1) < 100
       @clearAdjusters()
@@ -600,18 +606,26 @@
     U = (x) => @graph.Uri(x)
     if @colorScale == @colorScaleFromGraph
       return
-      
-    quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: @song}
-    log('ch', ko.toJS(@selection))
-    settingValue = @graph.Literal(@colorScale)
-    if @existingColorScaleSetting
-      @graph.patchObject(@existingColorScaleSetting, U(':value'), settingValue, @song)
+    @editAttr(@song, @uri, U(':colorScale'), @graph.Literal(@colorScale))
+
+  editAttr: (song, note, attr, value) ->
+    U = (x) => @graph.Uri(x)
+    quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: song}
+
+    existingColorScaleSetting = null
+    for setting in @graph.objects(note, U(':setting'))
+      ea = @graph.uriValue(setting, U(':effectAttr'))
+      if ea == attr
+        existingColorScaleSetting = setting
+        
+    if existingColorScaleSetting
+      @graph.patchObject(existingColorScaleSetting, U(':value'), value, song)
     else
-      setting = @graph.nextNumberedResource(@uri + 'set')
+      setting = @graph.nextNumberedResource(note + 'set')
       patch = {delQuads: [], addQuads: [
-        quad(@uri, U(':setting'), setting)
-        quad(setting, U(':effectAttr'), U(':colorScale'))
-        quad(setting, U(':value'), settingValue)
+        quad(note, U(':setting'), setting)
+        quad(setting, U(':effectAttr'), attr)
+        quad(setting, U(':value'), value)
         ]}
       @graph.applyAndSendPatch(patch)
     
@@ -625,27 +639,29 @@
     @effectLabel = @graph.stringValue(@effect, U('rdfs:label')) or (@effect.replace(/.*\//, ''))
     @noteLabel = @uri.replace(/.*\//, '')
 
-    @existingColorScaleSetting = null
+    existingColorScaleSetting = null
     for setting in @graph.objects(@uri, U(':setting'))
       ea = @graph.uriValue(setting, U(':effectAttr'))
       value = @graph.stringValue(setting, U(':value'))
       if ea == U(':colorScale')
         @colorScaleFromGraph = value
         @colorScale = value
-        @existingColorScaleSetting = setting
-    if @existingColorScaleSetting == null
+        existingColorScaleSetting = setting
+    if existingColorScaleSetting == null
       @colorScaleFromGraph = '#ffffff'
       @colorScale = '#ffffff'
     console.timeEnd('attrs update')
 
 
   onDel: ->
-    deleteNote(@graph, @song, @uri)
+    deleteNote(@graph, @song, @uri, @selection)
 
 
-deleteNote = (graph, song, note) ->
+deleteNote = (graph, song, note, selection) ->
   patch = {delQuads: [{subject: song, predicate: graph.Uri(':note'), object: note, graph: song}], addQuads: []}
   graph.applyAndSendPatch(patch)
+  if note in selection.selected()
+    selection.selected(_.without(selection.selected(), note))
   
 
 Polymer
@@ -871,7 +887,7 @@
 
   
 Polymer
-  # note boxes. Page selection.
+  # note boxes. 
   is: 'light9-timeline-diagram-layer'
   properties: {
     selection: {type: Object, notify: true}
@@ -903,7 +919,7 @@
     for suff in suffixes
       elem = @elemById[uri+suff]
       if elem
-        elem.remove()
+        ko.removeNode(elem)
         delete @elemById[uri+suff]
 
   anyPointsInView: (pts) ->