From 7cac6865e65380b292d48ad7731840f429ab0a72 Mon Sep 17 00:00:00 2001 From: deadprogrammer Date: Wed, 2 Feb 2011 10:44:47 -0800 Subject: [PATCH 1/2] Add editor open and save functions --- app/widgets/main.rb | 42 +++++++++++++++++++++++++++++++++++++++++- public/css/master.css | 14 ++++++++++++++ public/index.html | 2 ++ public/js/app.js | 35 +++++++++++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 3 deletions(-) diff --git a/app/widgets/main.rb b/app/widgets/main.rb index f40985f..1b194a0 100644 --- a/app/widgets/main.rb +++ b/app/widgets/main.rb @@ -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) @@ -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 diff --git a/public/css/master.css b/public/css/master.css index 1650c31..34a9a35 100644 --- a/public/css/master.css +++ b/public/css/master.css @@ -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; diff --git a/public/index.html b/public/index.html index 0c9d66e..dc832cc 100644 --- a/public/index.html +++ b/public/index.html @@ -23,6 +23,8 @@ # Type in your code just below here: + +