HelpBrowser: path box becomes a more conventional search box
[supercollider.git] / SCClassLibrary / Platform / Platform.sc
blobe6070f79f19fab08e19a93e97bbd72b27580fa9f
1 Platform
3         var <classLibraryDir, <helpDir, <>recordingsDir, features;
5         var <>devpath;
7         initPlatform {
8                 classLibraryDir = thisMethod.filenameSymbol.asString.dirname.dirname;
9                 helpDir = thisMethod.filenameSymbol.asString.dirname.dirname.dirname ++ "/Help";
10                 features = IdentityDictionary.new;
11                 recordingsDir = this.userAppSupportDir +/+ "Recordings";
12         }
14         name { ^this.subclassResponsibility }
16         recompile { ^this.subclassResponsibility }
17         *case { | ... cases |
18                 ^thisProcess.platform.name.switch(*cases)
19         }
21         // directories
22         *classLibraryDir { ^thisProcess.platform.classLibraryDir }
23         *helpDir { ^thisProcess.platform.helpDir }
25         systemAppSupportDir { _Platform_systemAppSupportDir }
26         *systemAppSupportDir { ^thisProcess.platform.systemAppSupportDir }
28         userAppSupportDir { _Platform_userAppSupportDir }
29         *userAppSupportDir { ^thisProcess.platform.userAppSupportDir }
31         systemExtensionDir { _Platform_systemExtensionDir }
32         *systemExtensionDir { ^thisProcess.platform.systemExtensionDir }
34         userExtensionDir { _Platform_userExtensionDir }
35         *userExtensionDir { ^thisProcess.platform.userExtensionDir }
37         // The "ideName" is for ide-dependent compilation.
38         // From SC.app, the value is "scapp" meaning "scide_scapp" folders will be compiled and other "scide_*" ignored.
39         ideName { _Platform_ideName }
40         *ideName { ^thisProcess.platform.ideName }
42         platformDir { ^this.name.asString }
43         *platformDir { ^thisProcess.platform.platformDir }
45         pathSeparator { ^this.subclassResponsibility }
46         *pathSeparator { ^thisProcess.platform.pathSeparator }
48         isPathSeparator { |char| ^this.subclassResponsibility }
49         *isPathSeparator { |char| ^thisProcess.platform.isPathSeparator(char) }
51         clearMetadata { |path| ^this.subclassResponsibility }
52         *clearMetadata { |path| ^thisProcess.platform.clearMetadata(path) }
54         getMouseCoords { ^this.subclassResponsibility }
55         *getMouseCoords { ^thisProcess.platform.getMouseCoords }
57         // startup/shutdown hooks
58         startup { }
59         shutdown { }
61         startupFiles { ^#[] }
62         loadStartupFiles { this.startupFiles.do{|afile|
63                 afile = afile.standardizePath;
64                 if(File.exists(afile), {afile.load})
65                 }
66         }
68         // features
69         declareFeature { | aFeature |
70                 var str = aFeature.asString;
71                 if (str.first.isUpper) {
72                         Error("cannot declare class name features").throw;
73                 };
74                 if (str.first == $_) {
75                         Error("cannot declare primitive name features").throw;
76                 };
77                 features.put(aFeature, true);
78         }
79         hasFeature { | symbol |
80                 if (features.includesKey(symbol).not) {
81                         features.put(
82                                 symbol,
83                                 symbol.asSymbol.asClass.notNil or: { symbol.isPrimitive }
84                         )
85                 };
86                 ^features.at(symbol)
87         }
88         when { | features, ifFunction, elseFunction |
89                 ^features.asArray.inject(true, { |v,x|
90                         v and: { this.hasFeature(x) }
91                 }).if(ifFunction, elseFunction)
92         }
93         *when {  | features, ifFunction, elseFunction |
94                 ^thisProcess.platform.when(features, ifFunction, elseFunction)
95         }
97         // Prefer qt but fall back to swing if qt not installed.
98         defaultGUIScheme { if (GUI.get(\qt).notNil) {^\qt} {^\swing} }
99         defaultHIDScheme { ^\none }
101         isSleeping { ^false } // unless defined otherwise
103         // used on systems to deduce a svn directory path, if system wide location is used for installed version. (tested on Linux).
104         devLoc{ |inpath|
105                 var outpath;
106                 if ( devpath.isNil ){ ^inpath };
107                 outpath = inpath.copyToEnd( inpath.find( "SuperCollider") );
108                 outpath = outpath.replace( "SuperCollider", devpath );
109                 ^outpath;
110         }
111         
112         // hook for clients to write frontend.css
113         writeClientCSS {}
117 UnixPlatform : Platform
119         pathSeparator { ^$/ }
121         isPathSeparator { |char|
122                 ^(char === this.pathSeparator)
123         }
125         clearMetadata { |path|
126                 "rm -f %\.*meta".format(path.splitext[0].escapeChar($ )).systemCmd;
127         }
129         arch {
130                 var pipe, arch;
131                 pipe = Pipe("arch", "r");
132                 arch = pipe.getLine;
133                 pipe.close;
134                 ^arch.asSymbol;
135         }