de.sciss.lucre.swing.edit.EditExprMap.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lucreswing_2.13.0-RC2 Show documentation
Show all versions of lucreswing_2.13.0-RC2 Show documentation
Swing support for Lucre, and common views
The newest version!
/*
* EditExprMap.scala
* (LucreSwing)
*
* Copyright (c) 2014-2019 Hanns Holger Rutz. All rights reserved.
*
* This software is published under the GNU Lesser General Public License v2.1+
*
*
* For further information, please contact Hanns Holger Rutz at
* [email protected]
*/
package de.sciss.lucre.swing.edit
import de.sciss.lucre.expr.{Expr, Type}
import de.sciss.lucre.stm.Sys
import de.sciss.lucre.{stm, event => evt}
import javax.swing.undo.UndoableEdit
import scala.language.higherKinds
object EditExprMap {
@deprecated("Try to transition to stm.UndoManager", since = "1.17.0")
def apply[S <: Sys[S], K, A, Ex[~ <: Sys[~]] <: Expr[~, A]](name: String, map: evt.Map.Modifiable[S, K, Ex],
key: K, value: Option[Ex[S]])
(implicit tx: S#Tx, cursor: stm.Cursor[S],
keyType : evt.Map.Key[K],
valueType: Type.Expr[A, Ex]): UndoableEdit = {
val before = map.get(key)
val now: Option[Ex[S]] = (before, value) match {
case (Some(valueType.Var(vr)), Some(v)) => return EditVar.Expr[S, A, Ex](name, vr, v) // current value is variable
case (_, None) | (_, Some(valueType.Var(_))) => value // new value is none or some variable, just put it
case _ => value.map(v => valueType.newVar(v)) // new value is some non-variable, wrap it, then put it
}
import valueType.serializer
val mapH = tx.newHandle(map) // (evt.Map.Modifiable.serializer[S, A, Expr[S, B], Change[B]])
val beforeH = tx.newHandle(before)
val nowH = tx.newHandle(now)
val res = new EditMutableMap.Impl(name, key, mapH, beforeH, nowH)
res.perform()
res
}
}