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

@ -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>