replace CodePad by NotePad

This commit is contained in:
lxsang 2021-05-12 17:43:28 +02:00
parent 99e3e6308c
commit 4c96fac5e5
8 changed files with 307 additions and 1 deletions

View File

@ -54,7 +54,7 @@ javascripts= dist/core/core.js \
antfx = $(tags) \
dist/core/Announcerment.js
packages = Syslog Files MarketPlace Setting
packages = Syslog Files MarketPlace Setting NotePad
main: initd build_javascripts build_themes libs build_packages languages
- cp src/index.html $(BUILDDIR)/

View File

@ -0,0 +1,11 @@
module_files = main.js
libfiles =
cssfiles = main.css
copyfiles = scheme.html package.json README.md
PKG_NAME=NotePad
include ../pkg.mk

View File

@ -0,0 +1,6 @@
# NotePad: A very simple text editor
Defaut text editor which is included in each AntOS release.
It has very barebone features: open/edit/save text file.
Text/Code editor with fancy features can be optionally installed via the Market Place

View File

@ -0,0 +1,102 @@
{
"name": "NotePad",
"targets": {
"init": {
"jobs": [
{
"name": "vfs-mkdir",
"data": [
"build",
"build/debug",
"build/release"
]
}
]
},
"locale": {
"require": ["locale"],
"jobs": [
{
"name":"locale-gen",
"data": {
"src": "",
"exclude": ["build/"],
"locale": "en_GB",
"dest": "package.json"
}
}
]
},
"ts": {
"require": [
"ts"
],
"jobs": [
{
"name": "ts-import",
"data": [
"sdk://core/ts/core.d.ts",
"sdk://core/ts/jquery.d.ts",
"sdk://core/ts/antos.d.ts"
]
},
{
"name": "ts-compile",
"data": {
"src": ["main.ts"],
"dest": "build/debug/main.js"
}
}
]
},
"uglify": {
"require": [
"terser"
],
"jobs": [
{
"name": "terser-uglify",
"data": [
"build/debug/main.js"
]
}
]
},
"copy": {
"jobs": [
{
"name": "vfs-cp",
"data": {
"src": [
"scheme.html",
"package.json",
"README.md",
"main.css"
],
"dest": "build/debug"
}
}
]
},
"release": {
"require": [
"zip"
],
"depend": [
"init",
"ts",
"uglify",
"copy"
],
"jobs": [
{
"name": "zip-mk",
"data": {
"src": "build/debug",
"dest": "build/release/NotePad.zip"
}
}
]
}
}
}

View File

@ -0,0 +1,7 @@
afx-app-window[data-id="NotePad"] textarea[data-id="editor"]
{
margin: 0;
padding:10px;
border: 0;
background-color: transparent;
}

View File

@ -0,0 +1,143 @@
namespace OS {
export namespace application {
export class NotePad extends BaseApplication {
private editor: HTMLTextAreaElement;
private filehandle: API.VFS.BaseFileHandle;
private win: GUI.tag.WindowTag;
constructor(args: AppArgumentsType[]) {
super("NotePad", args);
}
main(): void {
this.win = this.scheme as GUI.tag.WindowTag;
this.editor = this.find("editor") as HTMLTextAreaElement;
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.win.apptitle = `${this.filehandle.path}*`;
});
return this.read();
}
menu() {
return [
{
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();
}
}
}
];
}
newFile() {
this.filehandle = null;
return this.read();
}
openFile() {
return this.openDialog("FileDialog", {
title: __("Open file"),
mimes: this.meta().mimes
}).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.win.apptitle = "Untitled";
return;
}
this.filehandle.read().then((d) => {
this.win.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.win.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(false);
});
}
}
}
}

View File

@ -0,0 +1,32 @@
{
"pkgname": "NotePad",
"name": "Text editor",
"app": "NotePad",
"description": "A very simple text editor",
"info": {
"author": "Xuan Sang LE",
"email": "mrsang@iohub.dev"
},
"version": "0.1.0-b",
"category": "Utility",
"iconclass": "bi bi-pen",
"mimes": [
"text/.*"
],
"dependencies": [],
"locale": {
"en_GB": {
"Text Editor": "Text Editor",
"File": "File",
"New": "New",
"Open": "Open",
"Save": "Save",
"Quit": "Quit",
"Quit without saving?": "Quit without saving?",
"Open file": "Open file",
"Save as": "Save as",
"Unable to read file content": "Unable to read file content",
"Error saving file {0}": "Error saving file {0}"
}
}
}

View File

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