mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-08-28 14:52:45 +02:00
correct more app
This commit is contained in:
@@ -1,24 +1,3 @@
|
||||
# TinyEditor
|
||||
This is the example project for the tutorial: [https://blog.lxsang.me/post/id/20](https://blog.lxsang.me/post/id/20)
|
||||
|
||||
## 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**
|
||||
|
@@ -1,24 +1,3 @@
|
||||
# TinyEditor
|
||||
This is the example project for the tutorial: [https://blog.lxsang.me/post/id/20](https://blog.lxsang.me/post/id/20)
|
||||
|
||||
## 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**
|
||||
|
@@ -1,8 +1,6 @@
|
||||
|
||||
afx-app-window[data-id="TinyEditor"] textarea[data-id="editor"]
|
||||
{
|
||||
background-color: #272822;
|
||||
color:white;
|
||||
margin: 0;
|
||||
padding:10px;
|
||||
border: 0;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
void 0;
|
||||
var TinyEditor;
|
||||
|
||||
TinyEditor = class TinyEditor extends this.OS.GUI.BaseApplication {
|
||||
@@ -7,32 +8,29 @@
|
||||
}
|
||||
|
||||
main() {
|
||||
var me;
|
||||
me = this;
|
||||
this.editor = this.find("editor");
|
||||
this.bindKey("ALT-N", function() {
|
||||
return me.newFile();
|
||||
this.bindKey("ALT-N", () => {
|
||||
return this.newFile();
|
||||
});
|
||||
this.bindKey("ALT-O", function() {
|
||||
return me.openFile();
|
||||
this.bindKey("ALT-O", () => {
|
||||
return this.openFile();
|
||||
});
|
||||
this.bindKey("CTRL-S", function() {
|
||||
return me.saveFile();
|
||||
this.bindKey("CTRL-S", () => {
|
||||
return this.saveFile();
|
||||
});
|
||||
this.filehandler = this.args && this.args.length > 0 ? this.args[0].asFileHandler() : null;
|
||||
$(this.editor).on('input', function(e) {
|
||||
if (me.filehandler.dirty === true) {
|
||||
this.filehandle = this.args && this.args.length > 0 ? this.args[0].asFileHandle() : null;
|
||||
$(this.editor).on('input', (e) => {
|
||||
if (this.filehandle.dirty === true) {
|
||||
return;
|
||||
}
|
||||
me.filehandler.dirty = true;
|
||||
return me.scheme.set("apptitle", `${me.filehandler.path}*`);
|
||||
this.filehandle.dirty = true;
|
||||
return this.scheme.set("apptitle", `${this.filehandle.path}*`);
|
||||
});
|
||||
return this.read();
|
||||
}
|
||||
|
||||
menu() {
|
||||
var m, me;
|
||||
me = this;
|
||||
var m;
|
||||
m = [
|
||||
{
|
||||
text: "__(File)",
|
||||
@@ -53,14 +51,14 @@
|
||||
shortcut: 'C-S'
|
||||
}
|
||||
],
|
||||
onmenuselect: function(e) {
|
||||
switch (e.item.data.dataid) {
|
||||
onchildselect: (e) => {
|
||||
switch (e.data.item.get("data").dataid) {
|
||||
case "new":
|
||||
return me.newFile();
|
||||
return this.newFile();
|
||||
case "open":
|
||||
return me.openFile();
|
||||
return this.openFile();
|
||||
case "save":
|
||||
return me.saveFile();
|
||||
return this.saveFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,71 +67,73 @@
|
||||
}
|
||||
|
||||
newFile() {
|
||||
this.filehandler = null;
|
||||
this.filehandle = null;
|
||||
return this.read();
|
||||
}
|
||||
|
||||
openFile() {
|
||||
var me;
|
||||
me = this;
|
||||
return this.openDialog("FileDiaLog", function(dir, fname, d) {
|
||||
me.filehandler = `${dir}/${fname}`.asFileHandler();
|
||||
return me.read();
|
||||
}, __("Open file"));
|
||||
return this.openDialog("FileDialog", {
|
||||
title: __("Open file")
|
||||
}).then((d) => {
|
||||
this.filehandle = d.file.path.asFileHandle();
|
||||
return this.read();
|
||||
});
|
||||
}
|
||||
|
||||
saveFile() {
|
||||
var me;
|
||||
me = this;
|
||||
this.filehandler.cache = this.editor.value;
|
||||
if (this.filehandler.path !== "Untitled") {
|
||||
this.filehandle.cache = this.editor.value;
|
||||
if (this.filehandle.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
|
||||
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() {
|
||||
var me;
|
||||
me = this;
|
||||
this.editor.value = "";
|
||||
if (this.filehandler === null) {
|
||||
this.filehandler = "Untitled".asFileHandler();
|
||||
if (this.filehandle === null) {
|
||||
this.filehandle = "Untitled".asFileHandle();
|
||||
this.scheme.set("apptitle", "Untitled");
|
||||
return;
|
||||
}
|
||||
return this.filehandler.read(function(d) {
|
||||
me.scheme.set("apptitle", me.filehandler.path);
|
||||
return me.editor.value = d;
|
||||
return this.filehandle.read().then((d) => {
|
||||
this.scheme.set("apptitle", this.filehandle.path);
|
||||
return this.editor.value = d;
|
||||
}).catch((e) => {
|
||||
return this.error(__("Unable to read file content"));
|
||||
});
|
||||
}
|
||||
|
||||
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}`);
|
||||
return this.filehandle.write("text/plain").then((d) => {
|
||||
this.filehandle.dirty = false;
|
||||
return this.scheme.set("apptitle", `${this.filehandle.path}`);
|
||||
}).catch((e) => {
|
||||
return this.error(__("Error saving file {0}", this.filehandle.path), e);
|
||||
});
|
||||
}
|
||||
|
||||
cleanup(e) {
|
||||
var me;
|
||||
if (!this.filehandler.dirty) {
|
||||
if (!this.filehandle.dirty) {
|
||||
return;
|
||||
}
|
||||
me = this;
|
||||
e.preventDefault();
|
||||
return this.ask("__(Quit)", "__(Quit without saving?)", function() {
|
||||
me.filehandler.dirty = false;
|
||||
return me.quit();
|
||||
return this.ask({
|
||||
title: "__(Quit)",
|
||||
text: "__(Quit without saving?)"
|
||||
}).then(() => {
|
||||
this.filehandle.dirty = false;
|
||||
return this.quit();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"app":"TinyEditor",
|
||||
"name":"TinyEditor",
|
||||
"description":"",
|
||||
"name":"Tiny editor",
|
||||
"description":"Basic plain text file editor",
|
||||
"info":{
|
||||
"author": "",
|
||||
"email": ""
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version":"0.0.1-a",
|
||||
"category":"Other",
|
||||
|
BIN
TinyEditor/build/release/TinyEditor.zip
Normal file
BIN
TinyEditor/build/release/TinyEditor.zip
Normal file
Binary file not shown.
@@ -3,20 +3,18 @@ class TinyEditor extends this.OS.GUI.BaseApplication
|
||||
super "TinyEditor", args
|
||||
|
||||
main: () ->
|
||||
me = @
|
||||
@editor = @find "editor"
|
||||
@bindKey "ALT-N", () -> me.newFile()
|
||||
@bindKey "ALT-O", () -> me.openFile()
|
||||
@bindKey "CTRL-S", () -> me.saveFile()
|
||||
@filehandler = if @args and @args.length > 0 then @args[0].asFileHandler() else null
|
||||
$(@editor).on 'input', (e) ->
|
||||
return if me.filehandler.dirty is true
|
||||
me.filehandler.dirty = true
|
||||
me.scheme.set "apptitle", "#{me.filehandler.path}*"
|
||||
@bindKey "ALT-N", () => @newFile()
|
||||
@bindKey "ALT-O", () => @openFile()
|
||||
@bindKey "CTRL-S", () => @saveFile()
|
||||
@filehandle = if @args and @args.length > 0 then @args[0].asFileHandle() else null
|
||||
$(@editor).on 'input', (e) =>
|
||||
return if @filehandle.dirty is true
|
||||
@filehandle.dirty = true
|
||||
@scheme.set "apptitle", "#{@filehandle.path}*"
|
||||
@read()
|
||||
|
||||
menu: () ->
|
||||
me = @
|
||||
m = [
|
||||
{
|
||||
text: "__(File)",
|
||||
@@ -25,60 +23,62 @@ class TinyEditor extends this.OS.GUI.BaseApplication
|
||||
{ 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()
|
||||
onchildselect: (e) =>
|
||||
switch e.data.item.get("data").dataid
|
||||
when "new" then @newFile()
|
||||
when "open" then @openFile()
|
||||
when "save" then @saveFile()
|
||||
}
|
||||
]
|
||||
m
|
||||
|
||||
newFile: () ->
|
||||
@filehandler = null
|
||||
@filehandle = null
|
||||
@read()
|
||||
|
||||
openFile: () ->
|
||||
me = @
|
||||
@openDialog "FileDiaLog", ( dir, fname, d ) ->
|
||||
me.filehandler = "#{dir}/#{fname}".asFileHandler()
|
||||
me.read()
|
||||
, __("Open file")
|
||||
@openDialog "FileDialog", { title: __("Open file") }
|
||||
.then (d) =>
|
||||
@filehandle = d.file.path.asFileHandle()
|
||||
@read()
|
||||
,
|
||||
|
||||
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 }
|
||||
@filehandle.cache = @editor.value
|
||||
return @write() unless @filehandle.path is "Untitled"
|
||||
@openDialog("FileDialog", {
|
||||
title: __("Save as"),
|
||||
file: @filehandle
|
||||
}).then (f) =>
|
||||
d = f.file.path.asFileHandle()
|
||||
d = d.parent() if f.file.type is "file"
|
||||
@filehandle.setPath "#{d.path}/#{f.name}"
|
||||
@write()
|
||||
|
||||
read: () ->
|
||||
me = @
|
||||
@editor.value = ""
|
||||
if @filehandler is null
|
||||
@filehandler = "Untitled".asFileHandler()
|
||||
if @filehandle is null
|
||||
@filehandle = "Untitled".asFileHandle()
|
||||
@scheme.set "apptitle", "Untitled"
|
||||
return
|
||||
@filehandler.read (d) ->
|
||||
me.scheme.set "apptitle", me.filehandler.path
|
||||
me.editor.value = d
|
||||
@filehandle.read().then (d) =>
|
||||
@scheme.set "apptitle", @filehandle.path
|
||||
@editor.value = d
|
||||
.catch (e) => @error __("Unable to read file content")
|
||||
|
||||
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}"
|
||||
@filehandle.write("text/plain").then (d) =>
|
||||
@filehandle.dirty = false
|
||||
@scheme.set "apptitle", "#{@filehandle.path}"
|
||||
.catch (e) => @error __("Error saving file {0}", @filehandle.path), e
|
||||
|
||||
|
||||
cleanup: (e) ->
|
||||
return unless @filehandler.dirty
|
||||
me = @
|
||||
return unless @filehandle.dirty
|
||||
e.preventDefault()
|
||||
@ask "__(Quit)", "__(Quit without saving?)", () ->
|
||||
me.filehandler.dirty = false
|
||||
me.quit()
|
||||
@ask { title: "__(Quit)", text: "__(Quit without saving?)" }
|
||||
.then () =>
|
||||
@filehandle.dirty = false
|
||||
@quit()
|
||||
|
||||
this.OS.register "TinyEditor", TinyEditor
|
@@ -1,7 +1,5 @@
|
||||
afx-app-window[data-id="TinyEditor"] textarea[data-id="editor"]
|
||||
{
|
||||
background-color: #272822;
|
||||
color:white;
|
||||
margin: 0;
|
||||
padding:10px;
|
||||
border: 0;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"app":"TinyEditor",
|
||||
"name":"TinyEditor",
|
||||
"description":"",
|
||||
"name":"Tiny editor",
|
||||
"description":"Basic plain text file editor",
|
||||
"info":{
|
||||
"author": "",
|
||||
"email": ""
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version":"0.0.1-a",
|
||||
"category":"Other",
|
||||
|
@@ -1 +0,0 @@
|
||||
{"name":"TinyEditor","root":"home://workspace/TinyEditor","css":["css/main.css"],"javascripts":[],"coffees":["coffees/main.coffee"],"copies":["assets/scheme.html","package.json","README.md"]}
|
8
TinyEditor/project.json
Normal file
8
TinyEditor/project.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "TinyEditor",
|
||||
"root": "home://workspace/antosdk-apps/TinyEditor",
|
||||
"css": ["css/main.css"],
|
||||
"javascripts": [],
|
||||
"coffees": ["coffees/main.coffee"],
|
||||
"copies": ["assets/scheme.html", "package.json", "README.md"]
|
||||
}
|
Reference in New Issue
Block a user