deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / Collections / Environment.sc
blobad208c6191cf324bc0e785f256e594fe0d75dbf1
1 Environment : IdentityDictionary {
2         classvar <>stack;
4         *make { arg function;
5                 ^this.new.make(function)
6         }
7         *use { arg function;
8                 ^this.new.use(function)
9         }
11         make { arg function;
12                 // pushes the Envir, executes function, returns the Envir
13                 // usually used to create an environment by adding new variables to it.
14                 var result, saveEnvir;
16                 saveEnvir = currentEnvironment;
17                 currentEnvironment = this;
18                 protect {
19                         function.value(this);
20                 }{
21                         currentEnvironment = saveEnvir;
22                 };
23         }
24         use { arg function;
25                 // temporarily replaces the currentEnvironment with this,
26                 // executes function, returns the result of the function
27                 var result, saveEnvir;
29                 saveEnvir = currentEnvironment;
30                 currentEnvironment = this;
31                 protect {
32                         result = function.value(this);
33                 }{
34                         currentEnvironment = saveEnvir;
35                 };
36                 ^result
37         }
39         eventAt { arg key; ^this.at(key) }
40         composeEvents { arg event; ^this.copy.putAll(event) }
42         *pop {
43                 if(stack.notNil and: { stack.notEmpty }) { currentEnvironment = stack.pop };
44         }
45         *push { arg envir;
46                 stack = stack.add(currentEnvironment);
47                 currentEnvironment = envir;
48         }
49         pop { ^this.class.pop }
50         push { this.class.push(this) }
52         linkDoc { arg doc, pushNow = true;
53         doc = doc ? Document.current;
54         doc.envir_(this);
55         if(pushNow and: { currentEnvironment !== this }) { this.push };
56      }
58      unlinkDoc { arg doc, popNow = false;
59         doc = doc ? Document.current;
60         if(doc.envir === this) { doc.envir_(nil) };
61         if(popNow and:  { currentEnvironment === this }) { this.pop };
62      }