update generic client

This commit is contained in:
lxsang 2021-11-22 14:59:09 +01:00
parent e1ac72f12e
commit afade6884e
2 changed files with 227 additions and 0 deletions

81
GPClient/build.json Normal file
View File

@ -0,0 +1,81 @@
{
"name": "GPClient",
"targets": {
"init": {
"jobs": [
{
"name": "vfs-mkdir",
"data": [
"build",
"build/debug",
"build/release"
]
}
]
},
"coffee": {
"require": [
"coffee"
],
"jobs": [
{
"name": "coffee-compile",
"data": {
"src": [
"coffees/main.coffee"
],
"dest": "build/debug/main.js"
}
}
]
},
"uglify": {
"require": [
"terser"
],
"jobs": [
{
"name": "terser-uglify",
"data": [
"build/debug/main.js"
]
}
]
},
"copy": {
"jobs": [
{
"name": "vfs-cp",
"data": {
"src": [
"assets/scheme.html",
"package.json",
"README.md"
],
"dest": "build/debug"
}
}
]
},
"release": {
"require": [
"zip"
],
"depend": [
"init",
"coffee",
"uglify",
"copy"
],
"jobs": [
{
"name": "zip-mk",
"data": {
"src": "build/debug",
"dest": "build/release/GPClient.zip"
}
}
]
}
}
}

View File

@ -0,0 +1,146 @@
(function() {
var TinyEditor;
TinyEditor = class TinyEditor extends this.OS.application.BaseApplication {
constructor(args) {
super("TinyEditor", args);
}
main() {
this.editor = this.find("editor");
this.bindKey("ALT-N", () => {
return this.newFile();
});
this.bindKey("ALT-O", () => {
return this.openFile();
});
this.bindKey("CTRL-S", () => {
return this.saveFile();
});
this.filehandle = this.args && this.args.length > 0 ? this.args[0].path.asFileHandle() : null;
$(this.editor).on('input', (e) => {
if (this.filehandle.dirty === true) {
return;
}
this.filehandle.dirty = true;
return this.scheme.apptitle = `${this.filehandle.path}*`;
});
return this.read();
}
menu() {
var m;
m = [
{
text: "__(File)",
nodes: [
{
text: "__(New)",
dataid: "new",
shortcut: 'A-N'
},
{
text: "__(Open)",
dataid: "open",
shortcut: 'A-O'
},
{
text: "__(Save)",
dataid: "save",
shortcut: 'C-S'
}
],
onchildselect: (e) => {
switch (e.data.item.data.dataid) {
case "new":
return this.newFile();
case "open":
return this.openFile();
case "save":
return this.saveFile();
}
}
}
];
return m;
}
newFile() {
this.filehandle = null;
return this.read();
}
openFile() {
return this.openDialog("FileDialog", {
title: __("Open file")
}).then((d) => {
this.filehandle = d.file.path.asFileHandle();
return this.read();
});
}
saveFile() {
this.filehandle.cache = this.editor.value;
if (this.filehandle.path !== "Untitled") {
return this.write();
}
return this.openDialog("FileDialog", {
title: __("Save as"),
file: this.filehandle
}).then((f) => {
var d;
d = f.file.path.asFileHandle();
if (f.file.type === "file") {
d = d.parent();
}
this.filehandle.setPath(`${d.path}/${f.name}`);
return this.write();
});
}
read() {
this.editor.value = "";
if (this.filehandle === null) {
this.filehandle = "Untitled".asFileHandle();
this.scheme.apptitle = "Untitled";
return;
}
return this.filehandle.read().then((d) => {
this.scheme.apptitle = this.filehandle.path;
return this.editor.value = d;
}).catch((e) => {
return this.error(__("Unable to read file content"));
});
}
write() {
return this.filehandle.write("text/plain").then((d) => {
this.filehandle.dirty = false;
return this.scheme.apptitle = `${this.filehandle.path}`;
}).catch((e) => {
return this.error(__("Error saving file {0}", this.filehandle.path), e);
});
}
cleanup(e) {
if (!this.filehandle.dirty) {
return;
}
e.preventDefault();
return this.ask({
title: "__(Quit)",
text: "__(Quit without saving?)"
}).then((d) => {
if (!d) {
return;
}
this.filehandle.dirty = false;
return this.quit();
});
}
};
this.OS.register("TinyEditor", TinyEditor);
}).call(this);