scide: LookupDialog - redo lookup on classes after partial lookup
[supercollider.git] / SCClassLibrary / DefaultLibrary / Main.sc
blob94fa04e9f9cb382880ceb5dd1e58dfcfc46422ba
1 Main : Process {
2         var <platform, argv;
3         var recvOSCfunc, prRecvOSCFunc;
4         var openPorts;
6                 // proof-of-concept: the interpreter can set this variable when executing code in a file
7                 // should be nil most of the time
9         startup {
10             var didWarnOverwrite = false;
11                 // setup the platform first so that class initializers can call platform methods.
12                 // create the platform, then intialize it so that initPlatform can call methods
13                 // that depend on thisProcess.platform methods.
14                 platform = this.platformClass.new;
15                 platform.initPlatform;
17                 super.startup;
19                 // set the 's' interpreter variable to the default server.
20                 interpreter.s = Server.default;
21                 GUI.fromID( this.platform.defaultGUIScheme );
22                 GeneralHID.fromID( this.platform.defaultHIDScheme );
23                 this.platform.startup;
24                 StartUp.run;
25                 openPorts = Set[NetAddr.langPort];
27                 ("Welcome to SuperCollider %.".format(Main.version)
28                         + (Platform.ideName.switch(
29                                 "scvim", {"For help type :SChelp."},
30                                 "scel",  {"For help type C-c C-y."},
31                                 "sced",  {"For help type ctrl-U."},
32                                 "scapp", {"For help type cmd-d."},
33                                 "scqt", {"For help press %.".format(if(this.platform.name==\osx,"Cmd-D","Ctrl-D"))}
34                         ) ?? {
35                                 (
36                                         osx: "For help type cmd-d.",
37                                         linux: "For help type ctrl-c ctrl-h (Emacs) or :SChelp (vim) or ctrl-U (sced/gedit).",
38                                         windows: "For help press F1.",
39                                         iphone: ""
40                                  ).at(platform.name);
42                         })
43                 ).postln;
45                 Main.overwriteMsg.split(Char.nl).drop(-1).collect(_.split(Char.tab)).do {|x|
46                         if(x[2].beginsWith(Platform.classLibraryDir) and: {x[1].contains(""+/+"SystemOverwrites"+/+"").not}
47                         ) {
48                                 warn("Extension in '%' overwrites % in main class library.".format(x[1],x[0]));
49                                 didWarnOverwrite = true;
50                         }
51                 };
52                 if(didWarnOverwrite) {
53                         inform("\nIntentional overwrites must be put in a 'SystemOverwrites' subfolder.")
54                 }
55         }
57         shutdown { // at recompile, quit
58                 Server.quitAll;
59                 this.platform.shutdown;
60                 super.shutdown;
61         }
63         run { // used to be called by command-R, customisation now via CocoaMenuItem
64                 //interpreter.interpretPrintCmdLine;
65         }
67         stop { // called by command-.
68                 CmdPeriod.run;
69         }
71         hardStop { // called by command alt dot
72                 CmdPeriod.hardRun;
73         }
75         recvOSCmessage { arg time, replyAddr, recvPort, msg;
76                 // this method is called when an OSC message is received.
77                 recvOSCfunc.value(time, replyAddr, msg);
78                 prRecvOSCFunc.value(msg, time, replyAddr, recvPort); // same order as OSCFunc
79                 OSCresponder.respond(time, replyAddr, msg);
80         }
82         recvOSCbundle { arg time, replyAddr, recvPort ... msgs;
83                 // this method is called when an OSC bundle is received.
84                 msgs.do({ arg msg;
85                         this.recvOSCmessage(time, replyAddr, recvPort, msg);
86                 });
87         }
89         addOSCRecvFunc { |func| prRecvOSCFunc = prRecvOSCFunc.addFunc(func) }
91         removeOSCRecvFunc { |func| prRecvOSCFunc = prRecvOSCFunc.removeFunc(func) }
93         replaceOSCRecvFunc { |func, newFunc| prRecvOSCFunc = prRecvOSCFunc.replaceFunc(func, newFunc) }
95         openPorts { ^openPorts.copy } // don't allow the Set to be modified from the outside
97         openUDPPort {|portNum|
98                 var result;
99                 if(openPorts.includes(portNum), {^true});
100                 result = this.prOpenUDPPort(portNum);
101                 if(result, { openPorts = openPorts.add(portNum); });
102                 ^result;
103         }
105         prOpenUDPPort {|portNum|
106                 _OpenUDPPort
107                 ^false
108         }
110         newSCWindow {
111                 var win, palette;
112                 win = SCWindow("construction");
113                 win.front;
114                 win.toggleEditMode;
115         }
117 //      override in platform specific extension
119 //      platformClass {
120 //              ^Platform
121 //      }
123         argv {
124                 ^argv ?? { argv = this.prArgv }
125         }
127         showHelpBrowser {
128                 HelpBrowser.openBrowsePage;
129         }
130         showHelpSearch {
131                 HelpBrowser.openSearchPage(this.getCurrentSelection);
132         }
133         showHelp {
134                 HelpBrowser.openHelpFor(this.getCurrentSelection);
135         }
137         showClassBrowser {
138                 var string, class, method, words;
139                 string = interpreter.cmdLine;
140                 class = string.asSymbol.asClass;
141                 (class ? Object).browse;
142         }
144         *version {^[this.scVersionMajor, ".", this.scVersionMinor, this.scVersionPostfix].join}
146         *versionAtLeast { |maj, min|
147                 ^if((maj==this.scVersionMajor) and:{min.notNil}){
148                         this.scVersionMinor >= min
149                 }{
150                         this.scVersionMajor >= maj
151                 };
152         }
154         *versionAtMost { |maj, min|
155                 ^if((maj==this.scVersionMajor) and:{min.notNil}){
156                         this.scVersionMinor <= min
157                 }{
158                         this.scVersionMajor <= maj
159                 };
160         }
162         pid {
163                 _GetPid
164                 ^this.primitiveFailed
165         }
167         // PRIVATE
168         prArgv {
169                 _Argv
170                 ^[]
171         }
173         recompile { platform.recompile }
175         escapeWindow { platform.escapeWindow }
177         exitFullScreen { platform.exitFullScreen }
179         setDeferredTaskInterval { |interval| platform.setDeferredTaskInterval(interval) }
181         *overwriteMsg { _MainOverwriteMsg ^this.primitiveFailed }
185 MethodOverride {
186         var <ownerClass, <selector, <activePath, <overriddenPath;
188         *new { arg ownerClass, selector, activePath, overriddenPath;
189                 ^super.newCopyArgs(ownerClass, selector, activePath, overriddenPath)
190         }
192         *fromLine { arg string;
193                 var parts = string.split(Char.tab);
194                 var class, selector;
195                 #class, selector = parts[0].split($:);
196                 ^this.new(class.asSymbol.asClass, selector, parts[1], parts[2])
197         }
199         openFiles {
200                 var path2 = if(overriddenPath.beginsWith("/Common")) {
201                         Platform.classLibraryDir +/+ overriddenPath
202                         } { overriddenPath };
203                 activePath.openTextFile;
204                 path2.openTextFile;
205         }
207         *simplifyPath { arg path;
208                 var extDir, sysExtDir, quarkDir;
209                 extDir = Platform.userExtensionDir;
210                 sysExtDir = Platform.systemExtensionDir;
211                 quarkDir = LocalQuarks.globalPath;
212                 path = path.replace("'" ++ extDir, "Platform.userExtensionDir ++ '");
213                 path = path.replace("'" ++ sysExtDir, "Platform.systemExtensionDir ++ '");
214                 path = path.replace("'" ++ quarkDir, "LocalQuarks.globalPath ++ '");
215                 ^path
217         }
219         *all {
220                 var msg = Main.overwriteMsg.drop(-1); // drop last newline
221                 var lines = msg.split(Char.nl);
222                 ^lines.collect { |line| this.fromLine(line) };
223         }
225         *printAll { arg simplifyPaths = true;
226                 var all = this.all;
227                 var classes = all.collect(_.ownerClass).as(Set);
228                 if(all.isEmpty) { "There are no overwritten methods in class library".postln; ^this };
229                 ("Overwritten methods in class library:".underlined ++ "\n\n").post;
230                 classes.do { |class|
231                         class.asString.underlined.postln;
232                         all.select { |x| x.ownerClass == class }.do { |x|
233                                 var activePath = x.activePath;
234                                 var overriddenPath = x.overriddenPath;
235                                 if(simplifyPaths) {
236                                         activePath = this.simplifyPath(x.activePath);
237                                         overriddenPath = this.simplifyPath(x.overriddenPath);
238                                 };
239                                 ("\t" ++ x.ownerClass.name ++ ":" ++ x.selector).postln;
240                                 ("\t\t" ++ activePath).postln;
241                                 ("\t\t" ++ overriddenPath).postln;
242                         };
243                         "\n".post;
244                 }
245         }
247         *printAllShort {
248                 var all = this.all;
249                 var classes = all.collect(_.ownerClass).as(Set);
250                 if(all.isEmpty) { "There are no overwritten methods in class library".postln; ^this };
251                 ("Overwritten methods in class library:".underlined ++ "\n").post;
252                 classes.do { |class|
253                         all.select { |x| x.ownerClass == class }.collect { |x| x.selector }.as(Set).do { |x|
254                                 postf("\t%:%\n", class, x);
255                         }
256                 }
257         }