Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Drag and drop views that share data
name
code content
SharedDndData { var <value; *new { arg val; ^super.newCopyArgs(val) } value_ { arg val; value = val; this.changed(\value); } asString { ^value.asString; } } DndView : QDragView { var views; *new { arg parent, bounds, type = \both; var view = super.new(parent, bounds); view.onClose = { view.object.removeDependant(view) }; if (type === \source or: (type === \both)) { view.beginDragAction = { view.object }; }; if (type === \sink or: (type === \both)) { view.canReceiveDragHandler = true; view.receiveDragHandler = { view.object = View.currentDrag } }; ^view; } object_ { arg new_obj; object.removeDependant(this); object = new_obj; object.addDependant(this); this.string = object.asString; } value { ^this.object.value } value_ { arg new_val; if (this.object.isNil) { this.object = SharedDndData(new_val); }{ this.object.value = new_val; } } update { arg caller; if (caller === object) { this.string = this.object.asString } } }
code description
The DndView is a subclass of QDragView, implementing additional functionality. When a drag-and-drop is performed between two such views, setting one's value will update the other's as well. Use the 'value' method to get or set the value of a view. When creating a new instance of the view, you can pass in the 'type' argument, which can be \source, \sink, or \both, defining what will be the role of the view.
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change