Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hybridgroup/kidsruby
Browse files Browse the repository at this point in the history
  • Loading branch information
xn committed Feb 2, 2011
2 parents fa774df + 9545157 commit 2ca6eea
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -68,6 +68,7 @@ To summarize:
* make the canvas bigger for the Turtle
* add Gosu libs/classes to KidsRuby OS to make it easy to write games right away
* How to use KidsRuby
* editor save/open

## TODO

Expand All @@ -78,7 +79,6 @@ To summarize:
* make the Run button WAY WAY bigger

### EDITOR
* editor save/open/clear
* paste into editor (copy already works)

### HELP/TUTORIAL
Expand Down
42 changes: 41 additions & 1 deletion app/widgets/main.rb
Expand Up @@ -4,7 +4,7 @@
class MainWidget < Qt::WebView
q_classinfo("D-Bus Interface", "com.kidsruby.Main")

slots 'evaluateRuby(QString)', 'setupQtBridge()', 'alert(const QString&)', 'QString ask(const QString&)'
slots 'evaluateRuby(QString)', 'setupQtBridge()', 'alert(const QString&)', 'QString ask(const QString&)', 'openRubyFile(const QString&)', 'saveRubyFile(const QString&)'

def initialize(parent = nil)
super(parent)
Expand Down Expand Up @@ -35,6 +35,46 @@ def evaluateRuby(code)
runner.run(code)
end

def openRubyFile(nada)
fileName = Qt::FileDialog.getOpenFileName(self,
tr("Open a Ruby File"),
"",
tr("Ruby Files (*.rb)"))
unless fileName.nil?
codeFile = Qt::File.new(fileName)
unless codeFile.open(Qt::File::ReadOnly | Qt::File::Text)
Qt::MessageBox.warning(self, tr("KidsRuby Problem"),
tr("Oh, uh! Cannot open file %s:\n%s" %
[ codeFile.fileName(), codeFile.errorString() ] ) )
return
end
@frame.evaluateJavaScript("clearCode();")

inf = Qt::TextStream.new(codeFile)

while !inf.atEnd()
line = inf.readLine()
@frame.evaluateJavaScript("addCode('#{line}');")
end
end
end

def saveRubyFile(code)
fileName = Qt::FileDialog.getSaveFileName(self, tr("Save Ruby Code"), tr(".rb"))
unless fileName.nil?
file = Qt::File.new(fileName)
unless file.open(Qt::File::WriteOnly | Qt::File::Text)
Qt::MessageBox.warning(self, tr("KidsRuby Problem"),
tr("Cannot write file %s:\n%s." % [fileName, file.errorString]))
return
end

outf = Qt::TextStream.new(file)
outf << code
outf.flush
end
end

def append(text)
current_output.append(text)
end
Expand Down
14 changes: 14 additions & 0 deletions public/css/master.css
Expand Up @@ -53,6 +53,20 @@ body.lesson-set section h1 {
}

button#run {
bottom: 5px;
font-size: 30px;
position: absolute;
right: 150px;
}

button#open {
bottom: 5px;
font-size: 30px;
position: absolute;
right: 50px;
}

button#save {
bottom: 5px;
font-size: 30px;
position: absolute;
Expand Down
2 changes: 2 additions & 0 deletions public/index.html
Expand Up @@ -23,6 +23,8 @@
# Type in your code just below here:
</textarea>
<button id="run">Run</button>
<button id="open">Open</button>
<button id="save">Save</button>
</div>

<aside id="tabs">
Expand Down
35 changes: 33 additions & 2 deletions public/js/app.js
Expand Up @@ -17,6 +17,27 @@ function submitRubyCode(editor) {
QTApi['evaluateRuby(QString)'](ruby);
}

function openRubyCode() {
QTApi['openRubyFile(QString)']("");
}

function saveRubyCode(editor) {
var ruby = editor.getCode();
QTApi['saveRubyFile(QString)'](ruby);
}

function getEditor() {
return $("#rubycode").data("editor");
}

function clearCode() {
getEditor().setCode("");
}

function addCode(code) {
getEditor().setCode(getEditor().getCode() + "\n" + code);
}

function initTurtle() {
var turtle = new Pen("turtle-canvas");
turtle.center();
Expand Down Expand Up @@ -56,14 +77,24 @@ $(document).ready(function() {
iframeClass: 'editor-window',
autoMatchParens: true
});


$("#rubycode").data("editor", editor);

// Set the output width
$("#output").width = docWidth;

$("#input button").click(function(e) {
$("#run").click(function(e) {
clearOutputs();
submitRubyCode(editor);
});

$("#open").click(function(e) {
openRubyCode(editor);
});

$("#save").click(function(e) {
saveRubyCode(editor);
});

initTurtle();

Expand Down

0 comments on commit 2ca6eea

Please sign in to comment.