Skip to content
Browse files

class library: move functionality from Document to CocoaDocument

Signed-off-by: Tim Blechmann <tim@klingt.org>
  • Loading branch information...
1 parent 52b8cc1 commit 6f6113e440b8c565d2c8c431266eec1641e29653 @timblechmann timblechmann committed Sep 15, 2012
View
134 HelpSource/Classes/CocoaDocument.schelp
@@ -15,6 +15,140 @@ ClassMethods::
private::initClass, prSetDefaultFont, prSetSyntaxColorTheme, prDefaultUsesAutoInOutdent_, prnumberOfOpen, prGetIndexOfListener
+method:: postColor
+Get / set the listeners pen color.
+argument:: col
+An instance of link::Classes/Color::.
+discussion::
+code::
+CocoaDocument.postColor; // returns current post color
+CocoaDocument.postColor_(Color.red);
+CocoaDocument.postColor_(Color.green);
+CocoaDocument.postColor_(Color.blue);
+CocoaDocument.postColor_(Color.black);
+(
+r = Routine({
+ 10.do({
+ Document.postColor_(Color.rand);
+ "There is no blue without yellow and without orange.".postln;
+ 0.5.rand.yield;
+ });
+ CocoaDocument.postColor_(Color.black);
+});
+)
+
+r.play;
+r.stop;
+::
+
+method:: setTheme
+Sets the theme for syntax colorization.
+argument:: themeName
+A link::Classes/Symbol::, defining the name of the theme that you've put into code::Document.themes::.
+discussion::
+The Document class has a preset theme called code::'default'::, which is set as follows (default SC colors):
+code::
+themes = (
+ default: (
+ classColor: Color(0, 0, 0.75, 1),
+ textColor: Color(0, 0, 0, 1),
+ stringColor: Color(0.375, 0.375, 0.375, 1),
+ commentColor: Color(0.75, 0, 0, 1),
+ symbolColor: Color(0, 0.45, 0, 1),
+ numberColor: Color(0, 0, 0, 1)
+ )
+);
+::
+If you want to have your own themes for syntax colorization, you need to put your color set into code::CocoaDocument.themes:: first (preferably in startup.rtf file) and call code::setTheme:: by giving it the name of the theme you've added to "themes" earlier:
+code::
+//putting a custom color theme into Document.themes
+CocoaDocument.themes.put
+(\myTheme,
+ (
+ classColor: Color.new255(53, 74, 187),
+ textColor: Color.new255(0, 0, 0),
+ stringColor: Color.new255(96, 129, 158),
+ commentColor: Color.new255(206, 27, 28),
+ symbolColor: Color.new255(57, 154, 20),
+ numberColor: Color.new255(157, 80, 65)
+ )
+);
+
+//and then calling setTheme with the name:
+CocoaDocument.setTheme('myTheme');
+//to see the current theme:
+CocoaDocument.theme;
+::
+You can switch to the default theme anytime by calling:
+code::
+CocoaDocument.setTheme('default');
+::
+Next time you invoke syntaxColorize, the color theme set by setTheme will be used for syntax colorization. If you want to change the background color for the document window and selected text, in order to make them fit with your syntax colorization theme, see the help for the link::Classes/CocoaDocument#background:: and link::Classes/CocoaDocument#selectedBackground:: methods for Document.
+
+
InstanceMethods::
private::prUsesAutoInOutdent_, prIsEditable_, prSetTitle, prGetTitle, prGetFileName, prSetFileName, prGetBounds, prSetBounds, prBalanceParens, prclose, prinsertText, prinitByIndex, prGetLastIndex, propen, prinitByString, prSetBackgroundColor, prGetBackgroundColor, prSetSelectedBackgroundColor, prGetSelectedBackgroundColor, prSelectLine, prSetFont
+
+
+method:: balanceParens
+Starting from the current selection, increase the selection until matching parentheses are selected.
+argument:: level
+Do this as many times to find ever wider brackets. Set to code::inf:: for outmost.
+discussion::
+code::
+((((
+CocoaDocument.current.balanceParens(1);
+CocoaDocument.current.balanceParens(3);
+CocoaDocument.current.balanceParens(inf);
+))))
+::
+
+method:: background
+Get / set the the Document's background color.
+argument:: color
+An instance of link::Classes/Color::.
+discussion::
+code::
+(
+a = Document("background", "'hardly see anything");
+a.background_(Color.blue(alpha:0.8)); // notice that alpha controls the window transparency
+)
+::
+
+method:: stringColor
+Gets or sets the string color of a specific range of already printed text. Default is the whole document. To set the listener text color for posting, see: link::Classes/Document#postColor::.
+argument:: color
+An instance of link::Classes/Color::.
+argument:: rangeStart
+An link::Classes/Integer::. Default is -1.
+argument:: rangeSize
+An link::Classes/Integer::. Default value is 0
+discussion::
+code::
+// Select the following code in parentheses and execute it
+(
+Document.current.stringColor_(Color.rand(0.2, 0.8),
+ Document.current.selectedRangeLocation + 13,
+ 16);
+)
+// Watch me change color
+::
+
+method:: selectedBackground
+Gets or sets the document's background color for selected text. Applies to the whole document instance.
+argument:: color
+An instance of link::Classes/Color::.
+discussion::
+code::
+Document.current.selectedBackground; // returns default color
+(
+w = Document.new("Test", "Here is a selected text...");
+w.selectedBackground_(Color.new255(120, 180, 110));
+w.selectRange(10, 13);
+)
+::
+
+method:: syntaxColorize
+Syntax colorize a document.
+
View
131 HelpSource/Classes/Document.schelp
@@ -117,76 +117,6 @@ The editor implementation specific class which will handle Documents.
argument:: value
A class for implementing Document, e.g. link::Classes/CocoaDocument::.
-method:: postColor
-Get / set the listeners pen color.
-argument:: col
-An instance of link::Classes/Color::.
-discussion::
-code::
-Document.postColor; // returns current post color
-Document.postColor_(Color.red);
-Document.postColor_(Color.green);
-Document.postColor_(Color.blue);
-Document.postColor_(Color.black);
-(
-r = Routine({
- 10.do({
- Document.postColor_(Color.rand);
- "There is no blue without yellow and without orange.".postln;
- 0.5.rand.yield;
- });
- Document.postColor_(Color.black);
-});
-)
-
-r.play;
-r.stop;
-::
-
-method:: setTheme
-Sets the theme for syntax colorization.
-argument:: themeName
-A link::Classes/Symbol::, defining the name of the theme that you've put into code::Document.themes::.
-discussion::
-The Document class has a preset theme called code::'default'::, which is set as follows (default SC colors):
-code::
-themes = (
- default: (
- classColor: Color(0, 0, 0.75, 1),
- textColor: Color(0, 0, 0, 1),
- stringColor: Color(0.375, 0.375, 0.375, 1),
- commentColor: Color(0.75, 0, 0, 1),
- symbolColor: Color(0, 0.45, 0, 1),
- numberColor: Color(0, 0, 0, 1)
- )
-);
-::
-If you want to have your own themes for syntax colorization, you need to put your color set into code::Document.themes:: first (preferably in startup.rtf file) and call code::setTheme:: by giving it the name of the theme you've added to "themes" earlier:
-code::
-//putting a custom color theme into Document.themes
-Document.themes.put
-(\myTheme,
- (
- classColor: Color.new255(53, 74, 187),
- textColor: Color.new255(0, 0, 0),
- stringColor: Color.new255(96, 129, 158),
- commentColor: Color.new255(206, 27, 28),
- symbolColor: Color.new255(57, 154, 20),
- numberColor: Color.new255(157, 80, 65)
- )
-);
-
-//and then calling setTheme with the name:
-Document.setTheme('myTheme');
-//to see the current theme:
-Document.theme;
-::
-You can switch to the default theme anytime by calling:
-code::
-Document.setTheme('default');
-::
-Next time you invoke syntaxColorize, the color theme set by setTheme will be used for syntax colorization. If you want to change the background color for the document window and selected text, in order to make them fit with your syntax colorization theme, see the help for the link::Classes/Document#background:: and link::Classes/Document#selectedBackground:: methods for Document.
-
subsection:: Path Utilities
Utilities and settings for dealing with documents such as super collider code files. By default the document directory is SuperCollider's application directory.
@@ -287,18 +217,6 @@ Get / set the title (same as link::Classes/Document#name::).
argument:: argName
An instance of link::Classes/String::.
-method:: background
-Get / set the the Document's background color.
-argument:: color
-An instance of link::Classes/Color::.
-discussion::
-code::
-(
-a = Document("background", "'hardly see anything");
-a.background_(Color.blue(alpha:0.8)); // notice that alpha controls the window transparency
-)
-::
-
method:: alwaysOnTop
Get/set whether a document is always on top.
argument:: boolean
@@ -480,19 +398,6 @@ Document.current.selectRange(Document.current.selectedRangeLocation + 3, 150);
)
::
-method:: balanceParens
-Starting from the current selection, increase the selection until matching parentheses are selected.
-argument:: level
-Do this as many times to find ever wider brackets. Set to code::inf:: for outmost.
-discussion::
-code::
-((((
-Document.current.balanceParens(1);
-Document.current.balanceParens(3);
-Document.current.balanceParens(inf);
-))))
-::
-
method:: selectionStart
Returns the start of a current selection.
code::
@@ -587,42 +492,6 @@ Document.current.font_(Font("Impact", 14),
// Watch me change font
::
-method:: stringColor
-Gets or sets the string color of a specific range of already printed text. Default is the whole document. To set the listener text color for posting, see: link::Classes/Document#postColor::.
-argument:: color
-An instance of link::Classes/Color::.
-argument:: rangeStart
-An link::Classes/Integer::. Default is -1.
-argument:: rangeSize
-An link::Classes/Integer::. Default value is 0
-discussion::
-code::
-// Select the following code in parentheses and execute it
-(
-Document.current.stringColor_(Color.rand(0.2, 0.8),
- Document.current.selectedRangeLocation + 13,
- 16);
-)
-// Watch me change color
-::
-
-method:: selectedBackground
-Gets or sets the document's background color for selected text. Applies to the whole document instance.
-argument:: color
-An instance of link::Classes/Color::.
-discussion::
-code::
-Document.current.selectedBackground; // returns default color
-(
-w = Document.new("Test", "Here is a selected text...");
-w.selectedBackground_(Color.new255(120, 180, 110));
-w.selectRange(10, 13);
-)
-::
-
-method:: syntaxColorize
-Syntax colorize a document.
-
method:: underlineSelection
Underlines the current selection of a Document.
View
88 SCClassLibrary/Common/GUI/Document.sc
@@ -11,8 +11,6 @@ Document {
classvar <>wikiBrowse = true;
classvar <>implementationClass;
- classvar <postColor;
- classvar <theme, <themes;
//don't change the order of these vars:
var <dataptr, <>keyDownAction, <>keyUpAction, <>mouseUpAction;
@@ -33,23 +31,6 @@ Document {
num.do { | i |
doc = this.newFromIndex(i);
};
- postColor = Color.black;
- themes = (
- default: (
- classColor: Color(0, 0, 0.75, 1),
- textColor: Color(0, 0, 0, 1),
- stringColor: Color(0.375, 0.375, 0.375, 1),
- commentColor: Color(0.75, 0, 0, 1),
- symbolColor: Color(0, 0.45, 0, 1),
- numberColor: Color(0, 0, 0, 1),
- specialValsColor: Color(0.2, 0.2, 0.75, 1), // true false nil inf
- specialVarsColor: Color(0.4, 0.4, 0.75, 1), // super, thisProcess
- declColor: Color(0, 0, 1, 1), // var, const, args
- puncColor: Color(0, 0, 0, 1),
- environColor: Color(1.0, 0.4, 0, 1)
- )
- );
- theme = themes.default;
}
*open { | path, selectionStart=0, selectionLength=0, envir |
@@ -204,36 +185,6 @@ Document {
this.prSetTitle(argName);
}
- background_ { | color |
- this.prSetBackgroundColor(color);
- }
- background {
- var color;
- color = Color.new;
- this.prGetBackgroundColor(color);
- ^color;
- }
-
- selectedBackground_ { | color |
- this.prSetSelectedBackgroundColor(color);
- }
-
- selectedBackground {
- var color;
- color = Color.new;
- this.prGetSelectedBackgroundColor(color);
- ^color;
- }
-
- *postColor_ { | col |
- postColor = col;
- ^Document.implementationClass.postColor_(col);
- }
-
- stringColor_ { | color, rangeStart = -1, rangeSize = 0 |
- stringColor = color;
- this.setTextColor(color,rangeStart, rangeSize);
- }
bounds {
^this.prGetBounds(Rect.new);
}
@@ -242,7 +193,6 @@ Document {
}
// interaction:
-
close {
this.prclose
}
@@ -263,10 +213,6 @@ Document {
^this.subclassResponsibility(thisMethod)
}
- syntaxColorize {
- ^this.subclassResponsibility(thisMethod)
- }
-
selectLine { | line |
this.prSelectLine(line);
}
@@ -295,27 +241,6 @@ Document {
^this.subclassResponsibility(thisMethod)
}
- *setTheme { | themeName |
- theme = themes[themeName];
- if(theme.proto.isNil) {
- theme = theme.copy.parent_(themes[\default]);
- };
- thisProcess.platform.writeClientCSS;
- Document.implementationClass.prSetSyntaxColorTheme(
- theme.textColor,
- theme.classColor,
- theme.stringColor,
- theme.symbolColor,
- theme.commentColor,
- theme.numberColor,
- theme.specialValsColor,
- theme.specialVarsColor,
- theme.declColor,
- theme.puncColor,
- theme.environColor
- );
- }
-
// state info
isEdited {
^this.subclassResponsibility(thisMethod)
@@ -558,19 +483,6 @@ Document {
^this.subclassResponsibility(thisMethod)
}
- *prSetSyntaxColorTheme{ |textC, classC, stringC, symbolC, commentC, numberC, specialValsC, specialVarsC, declC, puncC, environC|
- ^this.subclassResponsibility(thisMethod);
- }
-
- // if range is -1 apply to whole doc
- setFont { | font, rangeStart= -1, rangeSize=100 |
- ^this.subclassResponsibility(thisMethod)
- }
-
- setTextColor { | color, rangeStart = -1, rangeSize = 0 |
- ^this.subclassResponsibility(thisMethod)
- }
-
text {
^this.subclassResponsibility(thisMethod)
}
View
74 SCClassLibrary/Platform/osx/scide_scapp/CocoaDocument.sc
@@ -1,5 +1,7 @@
CocoaDocument : Document {
classvar <defaultFont;
+ classvar <postColor;
+ classvar <theme, <themes;
*initClass{
Document.implementationClass = CocoaDocument;
@@ -8,6 +10,25 @@ CocoaDocument : Document {
*startup {
var post;
super.startup;
+
+ postColor = Color.black;
+ themes = (
+ default: (
+ classColor: Color(0, 0, 0.75, 1),
+ textColor: Color(0, 0, 0, 1),
+ stringColor: Color(0.375, 0.375, 0.375, 1),
+ commentColor: Color(0.75, 0, 0, 1),
+ symbolColor: Color(0, 0.45, 0, 1),
+ numberColor: Color(0, 0, 0, 1),
+ specialValsColor: Color(0.2, 0.2, 0.75, 1), // true false nil inf
+ specialVarsColor: Color(0.4, 0.4, 0.75, 1), // super, thisProcess
+ declColor: Color(0, 0, 1, 1), // var, const, args
+ puncColor: Color(0, 0, 0, 1),
+ environColor: Color(1.0, 0.4, 0, 1)
+ )
+ );
+ theme = themes.default;
+
fork({
0.2.wait;
post = this.listener;
@@ -16,6 +37,59 @@ CocoaDocument : Document {
this.setTheme('default');
}
+ *setTheme { | themeName |
+ theme = themes[themeName];
+ if(theme.proto.isNil) {
+ theme = theme.copy.parent_(themes[\default]);
+ };
+ thisProcess.platform.writeClientCSS;
+ this.prSetSyntaxColorTheme(
+ theme.textColor,
+ theme.classColor,
+ theme.stringColor,
+ theme.symbolColor,
+ theme.commentColor,
+ theme.numberColor,
+ theme.specialValsColor,
+ theme.specialVarsColor,
+ theme.declColor,
+ theme.puncColor,
+ theme.environColor
+ );
+ }
+
+ background_ { | color |
+ this.prSetBackgroundColor(color);
+ }
+ background {
+ var color;
+ color = Color.new;
+ this.prGetBackgroundColor(color);
+ ^color;
+ }
+
+ selectedBackground_ { | color |
+ this.prSetSelectedBackgroundColor(color);
+ }
+
+ selectedBackground {
+ var color;
+ color = Color.new;
+ this.prGetSelectedBackgroundColor(color);
+ ^color;
+ }
+
+ *postColor_ { | col |
+ postColor = col;
+ ^Document.implementationClass.postColor_(col);
+ }
+
+ stringColor_ { | color, rangeStart = -1, rangeSize = 0 |
+ stringColor = color;
+ this.setTextColor(color,rangeStart, rangeSize);
+ }
+
+
*new { arg title="Untitled", string="", makeListener=false;
^super.prBasicNew.initByString(title, string.asString, makeListener);
}
View
63 SCClassLibrary/deprecated/deprecated-3.7.sc
@@ -37,3 +37,66 @@
^this.openDocument(selectionStart, selectionLength)
}
}
+
+// Document: themes are cocoa-specific
++ Document {
+ *theme_ { |...args|
+ this.deprecated(thisMethod);
+ this.implementationClass.tryPerform(\theme_, args)
+ }
+
+ *theme {
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\theme)
+ }
+
+ *postColor {
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\postColor)
+ }
+
+ *postColor_ {|...args|
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\postColor_, args)
+ }
+
+ *background {
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\background)
+ }
+
+ *background_ {|...args|
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\background_, args)
+ }
+
+ *selectedBackground {
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\selectedBackground)
+ }
+
+ *selectedBackground_ {|...args|
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\selectedBackground_, args)
+ }
+
+ *stringColor_ {|...args|
+ this.deprecated(thisMethod);
+ ^this.implementationClass.tryPerform(\stringColor_, args)
+ }
+
+ setFont { | ...args |
+ this.deprecated(thisMethod);
+ ^this.subclassResponsibility(thisMethod)
+ }
+
+ setTextColor { | ...args |
+ this.deprecated(thisMethod);
+ ^this.subclassResponsibility(thisMethod)
+ }
+
+ syntaxColorize {
+ this.deprecated(thisMethod);
+ ^this.subclassResponsibility(thisMethod)
+ }
+}
View
41 editors/scvim/extra/VimDocument.sc
@@ -16,23 +16,20 @@ VimDocument : Document {
this.startup;
}
- *startup {
+ *startup {
var post;
- super.startup;
- fork({
- 0.2.wait;
- post = this.listener;
- if(post.notNil) { post.name_(" post ") }
+ super.startup;
+ fork({
+ 0.2.wait;
+ post = this.listener;
+ if(post.notNil) { post.name_(" post ") }
}, AppClock);
- this.setTheme('default');
}
*new { | title="Untitled" string="" makeListener=false |
^super.prBasicNew.initByString(title, string.asString, makeListener);
}
- *postColor_ { }
-
initLast { }
front { }
unfocusedFront { }
@@ -41,20 +38,19 @@ VimDocument : Document {
syntaxColorize { }
removeUndo { }
promptToSave_ { | bool | }
- promptToSave { ^true }
+ promptToSave { ^true }
underlineSelection { }
isEdited { ^true }
-
+
// if range is -1 apply to whole doc
- setFont { | font, rangeStart= -1, rangeSize=100 |
+ setFont { | font, rangeStart= -1, rangeSize=100 |
//XXX this only works for the whole server as that is the way vim works
//only works with graphical vim
- Vim.remote_send(servername, "<Esc>:set guifont=" ++
+ Vim.remote_send(servername, "<Esc>:set guifont=" ++
font.replace(" ", "\\\\\\ ") ++ "<CR>");
}
- setTextColor { | color, rangeStart = -1, rangeSize = 0 | }
-
+
text {
var string
= Vim.remote_expr(servername, "getbufline(bufnr(\"" ++ file ++ "\"), 1, \"$\")");
@@ -65,22 +61,21 @@ VimDocument : Document {
selectUnderlinedText { | clickPos | }
selectedRangeLocation { ^0 }
selectedRangeSize { ^0 }
-
+
rangeText { | rangestart=0, rangesize=1 |
- var string =
- Vim.remote_expr(servername, "getbufline(bufnr(\"" ++ file ++ "\"), " ++
+ var string =
+ Vim.remote_expr(servername, "getbufline(bufnr(\"" ++ file ++ "\"), " ++
(rangestart + 1) ++ ", " ++
(rangestart + rangesize) ++ ")");
^string.copyRange(0, (string.size - 2));
}
-
+
insertTextRange { | string, rangestart, rangesize | }
linkAtClickPos { | clickPos | ^nil }
// private //
*prnumberOfOpen { ^0 }
*prGetIndexOfListener { ^0 }
- *prSetSyntaxColorTheme{ |textC, classC, stringC, symbolC, commentC, numberC| }
propen { | path selectionStart=0 selectionLength=0 |
var rcfile = this.prfindRcFile;
@@ -106,7 +101,7 @@ VimDocument : Document {
prGetLastIndex { ^idx }
prIsEditable_{ | editable=true | }
prSetTitle { | argName | title = argName }
- prGetTitle { ^title }
+ prGetTitle { ^title }
prGetFileName { ^nil }
prSetFileName { | apath | }
@@ -115,10 +110,6 @@ VimDocument : Document {
prGetBounds { | argBounds | ^nil }
prSetBounds { | argBounds | }
- prSetBackgroundColor { | color | }
- prGetBackgroundColor { | color | ^nil }
- prSetSelectedBackgroundColor { | color | }
- prGetSelectedBackgroundColor { | color | ^nil }
prGetTmpFile {
var tmp = "/tmp/scvimdocument-tmp" ++ idx ++ ".sc";

0 comments on commit 6f6113e

Please sign in to comment.
Something went wrong with that request. Please try again.