Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / SCClassLibrary / Platform / osx / AutoComplete / AutocompleteExtensions.sc
blob2e47351427d869bd739dd269853a167d8c38ebd6
1 // class extensions needed for autocomplete
3 + Document {
4         getIdentifierCoordFromEnd { |endPos|
5                 var origpos, pos, chartemp, id;
6                 pos = (origpos = endPos ? this.selectionStart) - 1;
7                 { (pos >= 0) and:
8                         { (chartemp = this.string(pos, 1)[0]).isAlphaNum or: (chartemp == $_) } }
9                         .while({
10                                 pos = pos - 1;
11                         });
12                 ^[pos+1, origpos-pos-1]
13         }
15         *allowAutoComp { ^true }                // maybe you want to turn off the IDE features
17         *autoCompAll {
18                 this.globalKeyDownAction = this.autoCompleteKeyAction;
19         }
21         *autoComplete {
22                 ^Document.new.autoComplete;
23         }
25         autoComplete {  // enable ide for this document
26                 Document.allowAutoComp.if({
27                         keyDownAction = Document.autoCompleteKeyAction;
28                 });
29         }
31         *autoCompleteKeyAction {
32                 ^{ |doc, char, modifiers, keycode|
33                         var     start, size;
34                         char = char.ascii;
35                         (char == 40 and: (modifiers.bitAnd(131072) > 0)).if({
36                                 #start, size = doc.getIdentifierCoordFromEnd;
37                                 AutoCompMethodBrowser(start, size, doc)
38                         }, {
39                                 (char == 46).if({
40                                         #start, size = doc.getIdentifierCoordFromEnd;
41                                         AutoCompClassBrowser(start, size, doc)
42                                 }, {
43                                         (keycode == 15 and: (modifiers.bitAnd(262144) > 0)).if({
44                                                 #start, size = doc.getIdentifierCoordFromEnd;
45                                                 AutoCompClassSearch(start, size, doc)
46                                         });
47                                 });
48                         });
49                 };
50         }
52         *openFileAutoComplete { arg path;               // open a file by path
53                                                         // can use wildcards
54                 path.pathMatch.do({ |p|
55                         Document.open(p).autoComplete;
56                 });
57         }
59         *openAutoComplete {     // open a file by opendialog
60                 File.openDialog("Choose the codefile to open", { |path|
61                         this.openFileAutoComplete(path);
62                 });
63         }
67 + Class {
68         metaclass {
69                 this.isMetaClass.if({ ^this },{ ^this.class });
70         }
73 + Method {
74         argList { arg skipThis = true;
75                 var str;
76                 (skipThis and: (argNames.size <= 1)).not.if({ str = "(" }, { str = "" });
77                 argNames.do({ |a, i|
78                                 // i > 0 if including "this", i > 1 if not
79                         (i > (skipThis.binaryValue)).if({ str = str ++ ", " });
80                         (skipThis.not and: (i == 0)).if({ str = str ++ "a_" ++ ownerClass.name });
81                         (i > 0).if({ str = str ++ a });
82                 });
83                 ^(str.size > 0).if({ str ++ ")" }, { str });
84         }
87 + Nil {
88         isAlphaNum { ^false }   // error protection in getIdCoords
89         ascii {}