diff --git a/Makefile b/Makefile index 31c6a1c..15b3130 100644 --- a/Makefile +++ b/Makefile @@ -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)/ diff --git a/src/packages/NotePad/Makefile b/src/packages/NotePad/Makefile new file mode 100644 index 0000000..1eb8714 --- /dev/null +++ b/src/packages/NotePad/Makefile @@ -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 \ No newline at end of file diff --git a/src/packages/NotePad/README.md b/src/packages/NotePad/README.md new file mode 100644 index 0000000..704f80b --- /dev/null +++ b/src/packages/NotePad/README.md @@ -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 diff --git a/src/packages/NotePad/build.json b/src/packages/NotePad/build.json new file mode 100644 index 0000000..c6f0532 --- /dev/null +++ b/src/packages/NotePad/build.json @@ -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" + } + } + ] + } + } +} \ No newline at end of file diff --git a/src/packages/NotePad/main.css b/src/packages/NotePad/main.css new file mode 100644 index 0000000..8017c6f --- /dev/null +++ b/src/packages/NotePad/main.css @@ -0,0 +1,7 @@ +afx-app-window[data-id="NotePad"] textarea[data-id="editor"] +{ + margin: 0; + padding:10px; + border: 0; + background-color: transparent; +} \ No newline at end of file diff --git a/src/packages/NotePad/main.ts b/src/packages/NotePad/main.ts new file mode 100644 index 0000000..cf766e1 --- /dev/null +++ b/src/packages/NotePad/main.ts @@ -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); + }); + } + } + } +} diff --git a/src/packages/NotePad/package.json b/src/packages/NotePad/package.json new file mode 100644 index 0000000..116667d --- /dev/null +++ b/src/packages/NotePad/package.json @@ -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}" + } + } +} \ No newline at end of file diff --git a/src/packages/NotePad/scheme.html b/src/packages/NotePad/scheme.html new file mode 100644 index 0000000..3012e38 --- /dev/null +++ b/src/packages/NotePad/scheme.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file