add TinyEditor package

This commit is contained in:
lxsang 2018-07-24 17:18:07 +00:00
parent 10a0225fbf
commit e54a33605a
14 changed files with 333 additions and 106 deletions

View File

@ -1,105 +0,0 @@
(function() {
var LuaPlayground;
LuaPlayground = class LuaPlayground extends this.OS.GUI.BaseApplication {
constructor(args) {
super("LuaPlayground", args);
}
main() {
var me;
me = this;
this.datarea = this.find("editorea");
this.output = this.find("output");
this.editor = ace.edit(this.datarea);
this.editor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
fontSize: "10pt"
});
this.editor.getSession().setUseWrapMode(true);
this.editor.session.setMode("ace/mode/lua");
this.editor.setTheme("ace/theme/monokai");
this.on("vboxchange", function() {
return me.editor.resize();
});
(this.find("log-clear")).set("onbtclick", function(e) {
return me.log("clean");
});
this.socket = null;
return this.bindKey("CTRL-R", function() {
return me.run();
});
}
menu() {
var me, menu;
me = this;
menu = [
{
text: "__(Code)",
child: [
{
text: "__(Run)",
dataid: `${this.name}-Run`,
shortcut: "C-R"
}
],
onmenuselect: function(e) {
return me.run();
}
}
];
return menu;
}
log(t, m) {
var p;
if (t === "clean") {
return $(this.output).empty();
}
p = ($("<p>")).attr("class", t.toLowerCase())[0];
$(p).html(`${t}: ${m.__()}`);
($(this.output)).append(p);
return ($(this.output)).scrollTop(this.output.scrollHeight);
}
run() {
var me, proto, value;
me = this;
value = this.editor.getValue().trim();
if (!(value && value !== "")) {
return;
}
proto = window.location.protocol === "https:" ? "wss://" : "ws://";
this.socket = new WebSocket(proto + this._api.HOST + "/lua-api/os/apigateway?ws=1");
this.socket.onopen = function() {
//send data to server
return me.socket.send(JSON.stringify({
code: value
}));
};
this.socket.onmessage = function(e) {
if (e.data) {
return me.log("INFO", e.data);
}
};
return this.socket.onclose = function() {
me.socket = null;
return console.log("socket closed");
};
}
cleanup(e) {
if (this.socket) {
return this.socket.close();
}
}
};
this.OS.dependencies = ["ace/ace"];
this.OS.register("LuaPlayground", LuaPlayground);
}).call(this);

View File

@ -57,5 +57,5 @@ class LuaPlayground extends this.OS.GUI.BaseApplication
cleanup: (e)-> cleanup: (e)->
@socket.close() if @socket @socket.close() if @socket
this.OS.dependencies = ["ace/ace"] LuaPlayground.dependencies = ["ace/ace"]
this.OS.register "LuaPlayground", LuaPlayground this.OS.register "LuaPlayground", LuaPlayground

24
TinyEditor/README.md Normal file
View File

@ -0,0 +1,24 @@
# TinyEditor
This is an example project, generated by AntOS Development Kit
## Howto
1. Open the project.apj file with AntOSDK (simply double Click on it)
2. Modify the UI in *assets/scheme.html*
3. Modify application code in *coffees/main.coffee*
4. Modify CSS style in *css/main.css*
5. Other files need to be copied: put in to assets
## Set up build target
Click **Menu> Build > Build Option** or simply hit **ALT-Y**
In the build options dialog, add or remove files that need to be
included into the build
Click **Save**
## Build application
* To build: **Menu > Build > Build** or **ALT-C**
* To build and run: **Menu > Build > Build and Run** or **CTRL-R**
* To release: **Menu > Build > Build release** or **ALT-P**

View File

@ -0,0 +1,5 @@
<afx-app-window apptitle="__(Text Editor)" width="500" height="400" data-id="TinyEditor">
<afx-vbox >
<textarea data-id='editor'></textarea>
</afx-vbox>
</afx-app-window>

View File

@ -0,0 +1,24 @@
# TinyEditor
This is an example project, generated by AntOS Development Kit
## Howto
1. Open the project.apj file with AntOSDK (simply double Click on it)
2. Modify the UI in *assets/scheme.html*
3. Modify application code in *coffees/main.coffee*
4. Modify CSS style in *css/main.css*
5. Other files need to be copied: put in to assets
## Set up build target
Click **Menu> Build > Build Option** or simply hit **ALT-Y**
In the build options dialog, add or remove files that need to be
included into the build
Click **Save**
## Build application
* To build: **Menu > Build > Build** or **ALT-C**
* To build and run: **Menu > Build > Build and Run** or **CTRL-R**
* To release: **Menu > Build > Build release** or **ALT-P**

View File

@ -0,0 +1,9 @@
afx-app-window[data-id="TinyEditor"] textarea[data-id="editor"]
{
background-color: #272822;
color:white;
margin: 0;
padding:10px;
border: 0;
}

View File

@ -0,0 +1,145 @@
(function() {
var TinyEditor;
TinyEditor = class TinyEditor extends this.OS.GUI.BaseApplication {
constructor(args) {
super("TinyEditor", args);
}
main() {
var me;
me = this;
this.editor = this.find("editor");
this.stbar = this.find("statusbar");
this.bindKey("ALT-N", function() {
return me.newFile();
});
this.bindKey("ALT-O", function() {
return me.openFile();
});
this.bindKey("CTRL-S", function() {
return me.saveFile();
});
this.filehandler = null;
$(this.editor).on('input', function(e) {
if (me.filehandler.dirty === true) {
return;
}
me.filehandler.dirty = true;
return me.scheme.set("apptitle", `${me.filehandler.path}*`);
});
return this.read();
}
menu() {
var m, me;
me = this;
m = [
{
text: "__(File)",
child: [
{
text: "__(New)",
dataid: "new",
shortcut: 'A-N'
},
{
text: "__(Open)",
dataid: "open",
shortcut: 'A-O'
},
{
text: "__(Save)",
dataid: "save",
shortcut: 'C-S'
}
],
onmenuselect: function(e) {
switch (e.item.data.dataid) {
case "new":
return me.newFile();
case "open":
return me.openFile();
case "save":
return me.saveFile();
}
}
}
];
return m;
}
newFile() {
this.filehandler = null;
return this.read();
}
openFile(fi) {
var me;
me = this;
return this.openDialog("FileDiaLog", function(dir, fname, d) {
me.filehandler = `${dir}/${fname}`.asFileHandler();
return me.read();
}, __("Open file"));
}
saveFile() {
var me;
me = this;
this.filehandler.cache = this.editor.value;
if (this.filehandler.path !== "Untitled") {
return this.write();
}
return this.openDialog("FileDiaLog", function(dir, fname, d) {
me.filehandler.setPath(`${dir}/${fname}`);
return me.write();
}, __("Save as"), {
file: me.filehandler
});
}
read() {
var me;
me = this;
this.editor.value = "";
if (this.filehandler === null) {
this.filehandler = "Untitled".asFileHandler();
this.scheme.set("apptitle", "Untitled");
return;
}
return this.filehandler.read(function(d) {
me.scheme.set("apptitle", me.filehandler.path);
return me.editor.value = d;
});
}
write() {
var me;
me = this;
return this.filehandler.write("text/plain", function(d) {
if (d.error) {
return me.error(__("Error saving file {0}", me.filehandler.path));
}
me.filehandler.dirty = false;
return me.scheme.set("apptitle", `${me.filehandler.path}`);
});
}
cleanup(e) {
var me;
if (!this.filehandler.dirty) {
return;
}
me = this;
e.preventDefault();
return this.ask("__(Quit)", "__(Quit without saving?)", function() {
me.filehandler.dirty = false;
return me.quit();
});
}
};
this.OS.register("TinyEditor", TinyEditor);
}).call(this);

View File

@ -0,0 +1,13 @@
{
"app":"TinyEditor",
"name":"TinyEditor",
"description":"",
"info":{
"author": "",
"email": ""
},
"version":"0.0.1-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["none"]
}

View File

@ -0,0 +1,5 @@
<afx-app-window apptitle="__(Text Editor)" width="500" height="400" data-id="TinyEditor">
<afx-vbox >
<textarea data-id='editor'></textarea>
</afx-vbox>
</afx-app-window>

Binary file not shown.

View File

@ -0,0 +1,85 @@
class TinyEditor extends this.OS.GUI.BaseApplication
constructor: ( args ) ->
super "TinyEditor", args
main: () ->
me = @
@editor = @find "editor"
@stbar = @find "statusbar"
@bindKey "ALT-N", () -> me.newFile()
@bindKey "ALT-O", () -> me.openFile()
@bindKey "CTRL-S", () -> me.saveFile()
@filehandler = null
$(@editor).on 'input', (e) ->
return if me.filehandler.dirty is true
me.filehandler.dirty = true
me.scheme.set "apptitle", "#{me.filehandler.path}*"
@read()
menu: () ->
me = @
m = [
{
text: "__(File)",
child: [
{ text: "__(New)", dataid :"new", shortcut: 'A-N' },
{ text: "__(Open)", dataid :"open", shortcut: 'A-O' },
{ text: "__(Save)", dataid :"save", shortcut: 'C-S' }
],
onmenuselect: (e) ->
switch e.item.data.dataid
when "new" then me.newFile()
when "open" then me.openFile()
when "save" then me.saveFile()
}
]
m
newFile: () ->
@filehandler = null
@read()
openFile: (fi) ->
me = @
@openDialog "FileDiaLog", ( dir, fname, d ) ->
me.filehandler = "#{dir}/#{fname}".asFileHandler()
me.read()
, __("Open file")
saveFile: () ->
me = @
@filehandler.cache = @editor.value
return @write() unless @filehandler.path is "Untitled"
@openDialog "FileDiaLog", (dir, fname, d) ->
me.filehandler.setPath "#{dir}/#{fname}"
me.write()
, __("Save as"), { file: me.filehandler }
read: () ->
me = @
@editor.value = ""
if @filehandler is null
@filehandler = "Untitled".asFileHandler()
@scheme.set "apptitle", "Untitled"
return
@filehandler.read (d) ->
me.scheme.set "apptitle", me.filehandler.path
me.editor.value = d
write: () ->
me = @
@filehandler.write "text/plain", (d) ->
return me.error __("Error saving file {0}", me.filehandler.path) if d.error
me.filehandler.dirty = false
me.scheme.set "apptitle", "#{me.filehandler.path}"
cleanup: (e) ->
return unless @filehandler.dirty
me = @
e.preventDefault()
@ask "__(Quit)", "__(Quit without saving?)", () ->
me.filehandler.dirty = false
me.quit()
this.OS.register "TinyEditor", TinyEditor

8
TinyEditor/css/main.css Normal file
View File

@ -0,0 +1,8 @@
afx-app-window[data-id="TinyEditor"] textarea[data-id="editor"]
{
background-color: #272822;
color:white;
margin: 0;
padding:10px;
border: 0;
}

13
TinyEditor/package.json Normal file
View File

@ -0,0 +1,13 @@
{
"app":"TinyEditor",
"name":"TinyEditor",
"description":"",
"info":{
"author": "",
"email": ""
},
"version":"0.0.1-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["none"]
}

1
TinyEditor/project.apj Normal file
View File

@ -0,0 +1 @@
{"name":"TinyEditor","root":"home://workspace/TinyEditor","css":["css/main.css"],"javascripts":[],"coffees":["coffees/main.coffee"],"copies":["assets/scheme.html","package.json","README.md"]}