Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / SCClassLibrary / Platform / osx / scide_scapp / CocoaDocument.sc
blobb221cb779c9ce0cb6c518d111d1e453f006f4e2b
1 CocoaDocument : Document {
2         classvar <defaultFont;
4         *initClass{
5                 Document.implementationClass = CocoaDocument;
6         }
8         *startup {
9                 var post;
10                 super.startup;
11                 fork({
12                         0.2.wait;
13                         post = this.listener;
14                         if(post.notNil) { post.name_(" post ") }
15                 }, AppClock);
16                 this.setTheme('default');
17         }
19         *new { arg title="Untitled", string="", makeListener=false;
20                 ^super.prBasicNew.initByString(title, string.asString, makeListener);
21         }
23         *defaultFont_{|font|
24                 font = font.asSCFont;
25                 CocoaDocument.prSetDefaultFont(font);
26                 defaultFont = font;
27         }
29         *prSetDefaultFont{|font|
30                 _TextWindow_SetDefaultFont
31         }
33         *prSetSyntaxColorTheme {|textC, classC, stringC, symbolC, commentC, numberC, specialValsC, specialVarsC, declC, puncC, environC|
34                 _TextWindow_SetSyntaxColorTheme
35         }
37         front {
38                 _TextWindow_ToFront
39         }
41         unfocusedFront {
42                 _TextWindow_UnfocusedFront
43         }
45         alwaysOnTop_{|boolean=true|
46                 _TextWindow_AlwaysOnTop
47         }
49         alwaysOnTop{
50                 _TextWindow_IsAlwaysOnTop
51         }
53         syntaxColorize {
54                 _TextWindow_SyntaxColorize
55         }
57         selectRange {arg start=0, length=0;
58                 _TextWindow_SelectRange
59         }
61         editable_{arg abool=true;
62                 editable = abool;
63                 this.prIsEditable_(abool);
64         }
65         removeUndo{
66                 _TextWindow_RemoveUndo
67         }
69         promptToSave_{|bool|
70                 _TextWindow_SetPromptToSave
71         }
73         promptToSave{
74                 _TextWindow_PromptToSave
75         }
77         underlineSelection{
78                 _TextWindow_UnderlineSelection
79         }
81         balanceParens { arg levels = 1;
82                 var prev = this.selectionStart, next;
83                 levels.do {
84                         this.prBalanceParens;
85                         prev = next;
86                         next = this.selectionStart;
87                         if(prev == next) { ^this };
88                 }
89         }
91         *postColor_{ arg color;
92                 _PostWindow_SetTextColor
93         }
95 // state info
96         isEdited {
97                 _TextWindow_IsEdited
98         }
102 //private-----------------------------------
104         *prDefaultUsesAutoInOutdent_{|bool|
105                 _TextWindow_DefaultUsesAutoInOutdent
106         }
108         prUsesAutoInOutdent_{|bool|
109                 _TextWindow_UsesAutoInOutdent
110         }
112         prIsEditable_{arg editable=true;
113                 _TextWindow_SetEditable
114         }
115         prSetTitle { arg argName;
116                 _TextWindow_SetName
117                 ^this.primitiveFailed
118         }
119         prGetTitle {
120                 _TextWindow_GetName
121         }
122         prGetFileName {
123                 _TextWindow_GetFileName
124                 ^this.primitiveFailed
125         }
126         prSetFileName {|apath|
127                 _TextWindow_SetFileName
128         }
129         prGetBounds { arg argBounds;
130                 _TextWindow_GetBounds
131                 ^this.primitiveFailed
132         }
134         prSetBounds { arg argBounds;
135                 _TextWindow_SetBounds
136                 ^this.primitiveFailed
137         }
138         prBalanceParens {
139                 _TextWindow_BalanceParens
140         }
143         //if range is -1 apply to whole doc
144         setFont {arg font, rangeStart= -1, rangeSize=100;
145                 this.prSetFont(font.asSCFont, rangeStart, rangeSize);
146         }
148         prSetFont { arg font, rangeStart, rangeSize;
149                 _TextWindow_SetFont
150                 ^this.primitiveFailed
151         }
153         setTextColor { arg color,  rangeStart = -1, rangeSize = 0;
154                 _TextWindow_SetTextColor
155         }
157         text {
158                 _TextWindow_Text
159         }
160         selectedText {
161                 _TextWindow_SelectedText
162         }
163         selectUnderlinedText { arg clickPos;
164                 _TextWindow_SelectUnderlinedText
165                 ^false
166         }
168         linkAtClickPos { arg clickPos;
169                 _TextWindow_LinkAtClickPos
170                 ^false
171         }
173         rangeText { arg rangestart=0, rangesize=1;
174                 _TextWindow_TextWithRange
175         }
177         prclose {
178                 _TextWindow_Close
179         }
181         prinsertText { arg dataPtr, txt;
182                 _TextWindow_InsertText
183         }
184         insertTextRange { arg string, rangestart, rangesize;
185                 _TextWindow_InsertTextInRange
186                 ^this.primitiveFailed
187         }
193         *prnumberOfOpen {
194                 _NumberOfOpenTextWindows
195         }
196         prinitByIndex { arg idx;
197                 _TextWindow_GetByIndex
198         }
199         prGetLastIndex {
200                 _TextWindow_GetLastIndex
201         }
204         propen { arg path, selectionStart=0, selectionLength=0;
205                 _OpenTextFile
206         }
207         prinitByString { arg title, str, makeListener;
208                 _NewTextWindow
209         }
211         //other private
212         //if -1 whole doc
213         prSetBackgroundColor { arg color;
214                 _TextWindow_SetBackgroundColor
215         }
216         prGetBackgroundColor { arg color;
217                 _TextWindow_GetBackgroundColor
218         }
219         prSetSelectedBackgroundColor { arg color;
220                 _TextWindow_SetSelectedBackgroundColor
221         }
222         prGetSelectedBackgroundColor{ arg color;
223                 _TextWindow_GetSelectedBackgroundColor
224         }
225         selectedRangeLocation {
226                 _TextWindow_GetSelectedRangeLocation
227         }
228         selectedRangeSize {
229                 _TextWindow_GetSelectedRangeLength
230         }
232         prSelectLine { arg line;
233                 _TextWindow_SelectLine;
234                 ^this.primitiveFailed
235         }
237         *prGetIndexOfListener {
238                 _TextWindow_GetIndexOfListener
239         }
241         initLast {
242                 this.prGetLastIndex;
243                 if(dataptr.isNil,{^nil});
244                 this.background_(Color.white);
245                 this.prAdd;
246         }