class library: implement openTextFile via openDocument
[supercollider.git] / SCClassLibrary / Common / GUI / PlusGUI / Collections / StringPlusGUI.sc
blob2b4280f1119a81f4f1b1474e1dfc67b974b88f96
1 + String {
2         newTextWindow { arg title="Untitled", makeListener=false;
3                 Document.new(title, this, makeListener);
4         }
6         openHTMLFile{ arg selectionStart=0, selectionLength=0;
7                 if (Platform.openHTMLFileAction.notNil) {
8                         Platform.openHTMLFileAction.value(this, selectionStart, selectionLength)
9                 } {
10                         this.openDocument(selectionStart, selectionLength)
11                 }
12         }
14         openDocument { arg selectionStart=0, selectionLength=0;
15                 var ideClass;
16                 if(Document.implementationClass.notNil) {
17                         Document.open(this, selectionStart, selectionLength);
18                         ^this
19                 };
21                 ideClass = \ScIDE.asClass;
22                 if ( ideClass.notNil ) {
23                         if ( this.endsWith(".sc") || this.endsWith(".scd") ) {
24                                 ideClass.open(this, selectionStart);
25                                 ^this
26                         }
27                 };
29                 this.openOS
30         }
32 //      *fromUser { arg prompt="Enter string :", default="";
33 //              _GetStringFromUser
34 //              ^this.primitiveFailed
35 //      }
38         draw {
39                 this.drawAtPoint(Point(0,0), Font.default, Color.black);
40         }
41         drawAtPoint { arg point, font, color;
42                 if(GUI.id === \cocoa)
43                         { this.prDrawAtPoint( point, font, color ) }
44                         { Pen.stringAtPoint( this, point, font, color ) }
45         }
46         drawInRect { arg rect, font, color;
47                 if(GUI.id === \cocoa)
48                         { this.prDrawInRect( rect, font, color ) }
49                         { Pen.stringInRect( this, rect, font, color ) }
50         }
51         prDrawAtPoint { arg point, font, color;
52                 _String_DrawAtPoint
53                 ^this.primitiveFailed
54         }
55         prDrawInRect { arg rect, font, color;
56                 _String_DrawInRect
57                 ^this.primitiveFailed
58         }
59         drawCenteredIn { arg rect, font, color;
60                 if(GUI.id === \cocoa)
61                         { this.drawAtPoint(this.bounds( font ).centerIn(rect), font, color) }
62                         { Pen.stringCenteredIn( this, rect, font, color ) }
63         }
64         drawLeftJustIn { arg rect, font, color;
65                 var pos, bounds;
66                 if(GUI.id === \cocoa)
67                         {
68                                 bounds = this.bounds( font );
69                                 pos = bounds.centerIn(rect);
70                                 pos.x = rect.left + 2;
71                                 this.drawAtPoint(pos, font, color);
72                         }
73                         { Pen.stringLeftJustIn( this, rect, font, color ) }
74         }
75         drawRightJustIn { arg rect, font, color;
76                 var pos, bounds;
77                 if(GUI.id === \cocoa)
78                         {
79                                 bounds = this.bounds( font );
80                                 pos = bounds.centerIn(rect);
81                                 pos.x = rect.right - 2 - bounds.width;
82                                 this.drawAtPoint(pos, font, color);
83                         }
84                         { Pen.stringRightJustIn( this, rect, font, color ) }
85         }
87         bounds { arg font;
88                 if(GUI.id === \swing,{
89                         // since Swing is not in svn and can't be easily updated
90                         // let's put this temporary hack/if-statement here
91                         // rather than pollute everybody else's code with hacks/if-statements
92                         font = font ?? { Font.default };
93                         ^Rect(0, 0, this.size * font.size * 0.52146, font.size * 1.25)
94                         // width in Helvetica approx = string size * font size * 0.52146
95                         // 0.52146 is average of all 32-127 ascii characters widths
96                 },{
97                         ^GUI.stringBounds(this, font)
98                 });
99         }
100         prBounds { arg rect, font;
101                 _String_GetBounds
102                 ^this.primitiveFailed
103         }
106         findHelpFile {
107                 ^SCDoc.findHelpFile(this);
108         }
110         findHelpFileOrElse {
111                 this.findHelpFile;
112         }
114         help {
115                 if (Platform.openHelpFileAction.notNil) {
116                         Platform.openHelpFileAction.value(this)
117                 } {
118                         HelpBrowser.openHelpFor(this);
119                 }
120         }
123 + Symbol {
124         openDocument { arg selectionStart=0, selectionLength=0;
125                 ^this.asString.openDocument(selectionStart, selectionLength)
126         }