forked from scztt/Connection.quark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewActionUpdater.sc
More file actions
44 lines (39 loc) · 1.24 KB
/
ViewActionUpdater.sc
File metadata and controls
44 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
ViewActionUpdater {
classvar funcs, onCloseFunc;
*initClass {
funcs = MultiLevelIdentityDictionary();
onCloseFunc = {
|view, actionName, func|
ViewActionUpdater.disable(view, actionName, func);
};
}
*actionFunc {
|propertyName\value, signalName=\value|
var func = funcs.at(propertyName, signalName);
if (func.isNil) {
func = "{ |view ...args| view.changed('%', view.%) }".format(signalName, propertyName).interpret;
funcs.put(propertyName, signalName, func);
};
^func;
}
*isConnected {
|view, actionName, actionFunc|
var isConnected = (view.perform(actionName) == actionFunc);
if (view.perform(actionName).isKindOf(FunctionList)) {
isConnected = isConnected || view.perform(actionName).array.includes(actionFunc);
};
^isConnected;
}
*enable {
|view, actionName=\action, propertyName=\value, signalName=\value|
var func = this.actionFunc(propertyName, signalName);
if (this.isConnected(view, actionName, func).not) {
view.perform(actionName.asSetter, view.perform(actionName).addFunc(func));
{ view.onClose = view.onClose.addFunc(onCloseFunc.value(_, actionName, func)) }.defer;
}
}
*disable {
|view, actionName, func|
view.perform(actionName.asSetter, view.perform(actionName).removeFunc(func));
}
}