mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-04-26 05:26:43 +02:00
alpha version
This commit is contained in:
parent
fca268070f
commit
086756621e
@ -1,5 +1,5 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var Book, Booklet, BookletChapter, BookletEntry, BookletFile, BookletFolder, BookletSection;
|
var Booklet, BookletBook, BookletChapter, BookletEntry, BookletFile, BookletFolder, BookletSection, NS;
|
||||||
|
|
||||||
Booklet = class Booklet extends this.OS.GUI.BaseApplication {
|
Booklet = class Booklet extends this.OS.GUI.BaseApplication {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
@ -11,13 +11,20 @@
|
|||||||
me = this;
|
me = this;
|
||||||
this.tree = this.find("toc-ui");
|
this.tree = this.find("toc-ui");
|
||||||
this.currentToc = void 0;
|
this.currentToc = void 0;
|
||||||
|
this.dirty = false;
|
||||||
this.emux = false;
|
this.emux = false;
|
||||||
this.on("treeselect", function(e) {
|
this.on("treeselect", function(e) {
|
||||||
console.log(e.treepath);
|
|
||||||
if ((me.currentToc === e) || (e === void 0) || (e.treepath === 0)) {
|
if ((me.currentToc === e) || (e === void 0) || (e.treepath === 0)) {
|
||||||
return me.reloadEditor();
|
return me.reloadEditor();
|
||||||
}
|
}
|
||||||
|
e.treepath = e.path;
|
||||||
|
return me.load(e).then(function() {
|
||||||
return me.open(e);
|
return me.open(e);
|
||||||
|
}).catch(function(msg) {
|
||||||
|
e.loaded = true;
|
||||||
|
me.open(e);
|
||||||
|
return me.error(__("Error when loading '{0}': {1}", e.name, msg));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
this.initEditor();
|
this.initEditor();
|
||||||
this.resizeContent();
|
this.resizeContent();
|
||||||
@ -40,13 +47,14 @@
|
|||||||
if (!me.currentToc) {
|
if (!me.currentToc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return me.currentToc.descFile.dirty = true;
|
me.currentToc.descFile.dirty = true;
|
||||||
|
return me.dirty = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
newChapter() {
|
newChapter() {
|
||||||
var ch;
|
var ch;
|
||||||
if (!(this.currentToc && this.currentToc.type === "book")) {
|
if (!(this.currentToc && this.currentToc.type === "Book")) {
|
||||||
return this.error(__("No book selected"));
|
return this.error(__("No book selected"));
|
||||||
}
|
}
|
||||||
ch = new BookletChapter(this.book);
|
ch = new BookletChapter(this.book);
|
||||||
@ -56,7 +64,7 @@
|
|||||||
|
|
||||||
newSection() {
|
newSection() {
|
||||||
var sec;
|
var sec;
|
||||||
if (!(this.currentToc && this.currentToc.type === "chapter")) {
|
if (!(this.currentToc && this.currentToc.type === "Chapter")) {
|
||||||
return this.error(__("No chapter selected"));
|
return this.error(__("No chapter selected"));
|
||||||
}
|
}
|
||||||
sec = new BookletSection(this.currentToc);
|
sec = new BookletSection(this.currentToc);
|
||||||
@ -66,7 +74,7 @@
|
|||||||
|
|
||||||
newFile() {
|
newFile() {
|
||||||
var file;
|
var file;
|
||||||
if (!(this.currentToc && this.currentToc.type === "section")) {
|
if (!(this.currentToc && this.currentToc.type === "Section")) {
|
||||||
return this.error(__("No section selected"));
|
return this.error(__("No section selected"));
|
||||||
}
|
}
|
||||||
file = new BookletFile(this.currentToc);
|
file = new BookletFile(this.currentToc);
|
||||||
@ -94,12 +102,33 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load(entry) {
|
||||||
|
var me;
|
||||||
|
me = this;
|
||||||
|
return new Promise(function(r, e) {
|
||||||
|
if (entry.loaded) {
|
||||||
|
return r();
|
||||||
|
}
|
||||||
|
return entry.descFile.meta(function(d) {
|
||||||
|
if (d.error) {
|
||||||
|
return e(d.error);
|
||||||
|
}
|
||||||
|
return entry.descFile.read(function(data) {
|
||||||
|
entry.descFile.cache = data;
|
||||||
|
entry.loaded = true;
|
||||||
|
entry.descFile.dirty = false;
|
||||||
|
return r();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
contextMenu() {
|
contextMenu() {
|
||||||
if (!this.currentToc) {
|
if (!this.currentToc) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
switch (this.currentToc.type) {
|
switch (this.currentToc.type) {
|
||||||
case "book":
|
case "Book":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
text: __("New chapter"),
|
text: __("New chapter"),
|
||||||
@ -110,7 +139,7 @@
|
|||||||
dataid: "delete"
|
dataid: "delete"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
case "chapter":
|
case "Chapter":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
text: __("New section"),
|
text: __("New section"),
|
||||||
@ -121,7 +150,7 @@
|
|||||||
dataid: "delete"
|
dataid: "delete"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
case "section":
|
case "Section":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
text: __("New file"),
|
text: __("New file"),
|
||||||
@ -132,7 +161,7 @@
|
|||||||
dataid: "delete"
|
dataid: "delete"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
case "file":
|
case "File":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
text: __("Delete file"),
|
text: __("Delete file"),
|
||||||
@ -267,10 +296,20 @@
|
|||||||
me = this;
|
me = this;
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case `${this.name}-Open`:
|
case `${this.name}-Open`:
|
||||||
return this.openDialog("FileDiaLog", function(d, f) {
|
return this.checkForDirty(function() {
|
||||||
return console.log(`${d}/${f}`.asFileHandler());
|
return me.openDialog("FileDiaLog", function(d, f) {
|
||||||
|
me.book = new BookletBook(d);
|
||||||
|
return me.book.read(d).then(function() {
|
||||||
|
me.book.treepath = me.book.path;
|
||||||
|
me.tree.set("selectedItem", void 0);
|
||||||
|
me.displayToc();
|
||||||
|
return me.notify(__("Book loaded"));
|
||||||
|
}).catch(function(msg) {
|
||||||
|
return me.error(__("Cannot load book: {0}", msg));
|
||||||
|
});
|
||||||
}, __("Open file"), {
|
}, __("Open file"), {
|
||||||
mimes: me.meta().mimes
|
mimes: ['dir']
|
||||||
|
});
|
||||||
});
|
});
|
||||||
case `${this.name}-New`:
|
case `${this.name}-New`:
|
||||||
return this.openDialog("FileDiaLog", function(d, f) {
|
return this.openDialog("FileDiaLog", function(d, f) {
|
||||||
@ -290,6 +329,7 @@
|
|||||||
}
|
}
|
||||||
me.displayToc();
|
me.displayToc();
|
||||||
return me.book.save().then(function() {
|
return me.book.save().then(function() {
|
||||||
|
me.dirty = false;
|
||||||
return me.notify(__("Book saved"));
|
return me.notify(__("Book saved"));
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
return me.error(__("Can't save the book : {0}", e));
|
return me.error(__("Can't save the book : {0}", e));
|
||||||
@ -297,18 +337,36 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open(toc) {
|
checkForDirty(f) {
|
||||||
this.emux = true;
|
if (!this.dirty) {
|
||||||
this.saveContext();
|
return f();
|
||||||
this.currentToc = toc;
|
|
||||||
this.reloadEditor();
|
|
||||||
this.displayToc();
|
|
||||||
return this.emux = false;
|
|
||||||
}
|
}
|
||||||
|
return this._gui.openDialog("YesNoDialog", function(d) {
|
||||||
|
console.log(d);
|
||||||
|
if (d) {
|
||||||
|
return f();
|
||||||
|
}
|
||||||
|
}, __("Continue ?"), {
|
||||||
|
text: __("Book is unsaved, you want to continue ?")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
open(toc) {
|
||||||
|
var me;
|
||||||
|
me = this;
|
||||||
|
me.emux = true;
|
||||||
|
me.saveContext();
|
||||||
|
me.currentToc = toc;
|
||||||
|
me.reloadEditor();
|
||||||
|
me.displayToc();
|
||||||
|
return me.emux = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
openBook(metaFile) {}
|
||||||
|
|
||||||
newAt(folder) {
|
newAt(folder) {
|
||||||
this.tree.set("selectedItem", false);
|
this.tree.set("selectedItem", false);
|
||||||
this.book = new Book(folder);
|
this.book = new BookletBook(folder);
|
||||||
this.book.treepath = this.book.path;
|
this.book.treepath = this.book.path;
|
||||||
this.currentToc = void 0;
|
this.currentToc = void 0;
|
||||||
this.reloadEditor();
|
this.reloadEditor();
|
||||||
@ -327,8 +385,9 @@
|
|||||||
this.OS.register("Booklet", Booklet);
|
this.OS.register("Booklet", Booklet);
|
||||||
|
|
||||||
BookletEntry = class BookletEntry {
|
BookletEntry = class BookletEntry {
|
||||||
constructor() {
|
constructor(name) {
|
||||||
this.name = "Untitled";
|
this.name = name;
|
||||||
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {}
|
save() {}
|
||||||
@ -346,6 +405,12 @@
|
|||||||
if (!(t && t.length === 2)) {
|
if (!(t && t.length === 2)) {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
if (this.hasMeta && this.metaFile) {
|
||||||
|
this.metaFile.dirty = true;
|
||||||
|
}
|
||||||
|
if (this.parent && this.parent.hasMeta && this.parent.metaFile) {
|
||||||
|
this.parent.metaFile.dirty = true;
|
||||||
|
}
|
||||||
return this.name = t[1].trim();
|
return this.name = t[1].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,16 +453,20 @@
|
|||||||
|
|
||||||
BookletFolder = class BookletFolder extends BookletEntry {
|
BookletFolder = class BookletFolder extends BookletEntry {
|
||||||
constructor(type, path1, hasMeta) {
|
constructor(type, path1, hasMeta) {
|
||||||
super();
|
super("Untitle");
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.path = path1;
|
this.path = path1;
|
||||||
this.hasMeta = hasMeta;
|
this.hasMeta = hasMeta;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
this.cnt = 0;
|
this.cnt = 0;
|
||||||
this.nodes = [];
|
this.nodes = [];
|
||||||
if (this.hasMeta) {
|
if (this.hasMeta) {
|
||||||
this.metaFile = `${this.path}/meta.json`.asFileHandler();
|
this.metaFile = `${this.path}/meta.json`.asFileHandler();
|
||||||
}
|
}
|
||||||
this.descFile = `${this.path}/INTRO.md`.asFileHandler();
|
return this.descFile = `${this.path}/INTRO.md`.asFileHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
add(chap) {
|
add(chap) {
|
||||||
@ -431,6 +500,49 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read(folderPath) {
|
||||||
|
var me;
|
||||||
|
me = this;
|
||||||
|
return new Promise(function(r, e) {
|
||||||
|
me.path = folderPath;
|
||||||
|
me.init();
|
||||||
|
me.loaded = false;
|
||||||
|
return me.metaFile.meta(function(d) {
|
||||||
|
if (d.error) {
|
||||||
|
return e(d.error);
|
||||||
|
}
|
||||||
|
return me.metaFile.read(function(data) {
|
||||||
|
var fn, i, j, len, list, ref, v;
|
||||||
|
// load all child
|
||||||
|
me.name = data.name;
|
||||||
|
list = [];
|
||||||
|
ref = data.entries;
|
||||||
|
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
||||||
|
v = ref[i];
|
||||||
|
list[i] = v;
|
||||||
|
}
|
||||||
|
fn = function(l) {
|
||||||
|
var el, obj;
|
||||||
|
if (l.length === 0) {
|
||||||
|
me.cnt = data.cnt;
|
||||||
|
return r();
|
||||||
|
}
|
||||||
|
el = (l.splice(0, 1))[0];
|
||||||
|
console.log("create", el.type);
|
||||||
|
obj = new NS[el.type](me);
|
||||||
|
obj.name = el.name;
|
||||||
|
return obj.read(el.path).then(function() {
|
||||||
|
return fn(l);
|
||||||
|
}).catch(function(msg) {
|
||||||
|
return fn(l);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return fn(list);
|
||||||
|
}, "json");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
size() {
|
size() {
|
||||||
return this.nodes.length;
|
return this.nodes.length;
|
||||||
}
|
}
|
||||||
@ -464,7 +576,7 @@
|
|||||||
return new Promise(function(r, e) {
|
return new Promise(function(r, e) {
|
||||||
var i, j, len, list, ref, v;
|
var i, j, len, list, ref, v;
|
||||||
list = [];
|
list = [];
|
||||||
if (me.type !== 'section') {
|
if (me.type !== 'Section') {
|
||||||
ref = me.nodes;
|
ref = me.nodes;
|
||||||
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
||||||
v = ref[i];
|
v = ref[i];
|
||||||
@ -496,7 +608,7 @@
|
|||||||
var me;
|
var me;
|
||||||
me = this;
|
me = this;
|
||||||
return new Promise(function(r, e) {
|
return new Promise(function(r, e) {
|
||||||
var entries, i, j, len, ref, v;
|
var data, entries, i, j, len, ref, v;
|
||||||
if (!me.metaFile.dirty) {
|
if (!me.metaFile.dirty) {
|
||||||
return r();
|
return r();
|
||||||
}
|
}
|
||||||
@ -504,9 +616,19 @@
|
|||||||
ref = me.nodes;
|
ref = me.nodes;
|
||||||
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
||||||
v = ref[i];
|
v = ref[i];
|
||||||
entries[i] = v.path;
|
entries[i] = {
|
||||||
|
name: v.name,
|
||||||
|
path: v.path,
|
||||||
|
type: v.type
|
||||||
|
};
|
||||||
}
|
}
|
||||||
me.metaFile.cache = entries;
|
data = {
|
||||||
|
name: me.name,
|
||||||
|
entries: entries,
|
||||||
|
cnt: me.cnt,
|
||||||
|
meta: me.hasMeta
|
||||||
|
};
|
||||||
|
me.metaFile.cache = data;
|
||||||
return me.metaFile.write("object", function(d) {
|
return me.metaFile.write("object", function(d) {
|
||||||
if (d.error) {
|
if (d.error) {
|
||||||
return e(d.error);
|
return e(d.error);
|
||||||
@ -585,9 +707,9 @@
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Book = class Book extends BookletFolder {
|
BookletBook = class BookletBook extends BookletFolder {
|
||||||
constructor(path) {
|
constructor(path) {
|
||||||
super('book', path, true);
|
super('Book', path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
@ -612,7 +734,7 @@
|
|||||||
constructor(book) {
|
constructor(book) {
|
||||||
var path;
|
var path;
|
||||||
path = `${book.path}/c_${book.cnt}`;
|
path = `${book.path}/c_${book.cnt}`;
|
||||||
super('chapter', path, true);
|
super('Chapter', path, true);
|
||||||
book.add(this);
|
book.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +744,7 @@
|
|||||||
constructor(chapter) {
|
constructor(chapter) {
|
||||||
var path;
|
var path;
|
||||||
path = `${chapter.path}/s_${chapter.cnt}`;
|
path = `${chapter.path}/s_${chapter.cnt}`;
|
||||||
super("section", path, true);
|
super("Section", path, true);
|
||||||
chapter.add(this);
|
chapter.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,10 +752,10 @@
|
|||||||
|
|
||||||
BookletFile = class BookletFile extends BookletEntry {
|
BookletFile = class BookletFile extends BookletEntry {
|
||||||
constructor(section) {
|
constructor(section) {
|
||||||
super();
|
super("Untitle file");
|
||||||
this.section = section;
|
this.section = section;
|
||||||
this.hasMeta = false;
|
this.hasMeta = false;
|
||||||
this.type = "file";
|
this.type = "File";
|
||||||
this.path = `${this.section.path}/f_${this.section.cnt}.md`;
|
this.path = `${this.section.path}/f_${this.section.cnt}.md`;
|
||||||
this.descFile = this.path.asFileHandler();
|
this.descFile = this.path.asFileHandler();
|
||||||
this.section.add(this);
|
this.section.add(this);
|
||||||
@ -657,6 +779,16 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read(p) {
|
||||||
|
var me;
|
||||||
|
me = this;
|
||||||
|
return new Promise(function(r, e) {
|
||||||
|
me.loaded = false;
|
||||||
|
me.treepath = p;
|
||||||
|
return r();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
toc() {
|
toc() {
|
||||||
this.updateName();
|
this.updateName();
|
||||||
return this;
|
return this;
|
||||||
@ -664,4 +796,11 @@
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NS = {
|
||||||
|
Book: BookletBook,
|
||||||
|
Chapter: BookletChapter,
|
||||||
|
Section: BookletSection,
|
||||||
|
File: BookletFile
|
||||||
|
};
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
@ -9,5 +9,5 @@
|
|||||||
"version":"0.0.1-a",
|
"version":"0.0.1-a",
|
||||||
"category":"Other",
|
"category":"Other",
|
||||||
"iconclass":"fa fa-adn",
|
"iconclass":"fa fa-adn",
|
||||||
"mimes":["application/json"]
|
"mimes":["dir"]
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
class BookletEntry
|
class BookletEntry
|
||||||
constructor: () ->
|
constructor: (@name) ->
|
||||||
@name = "Untitled"
|
@loaded = true
|
||||||
|
|
||||||
save: () ->
|
save: () ->
|
||||||
|
|
||||||
@ -13,6 +14,8 @@ class BookletEntry
|
|||||||
return @name unless @descFile.dirty
|
return @name unless @descFile.dirty
|
||||||
t = (new RegExp "^\s*#+(.*)\n", "g").exec @descFile.cache
|
t = (new RegExp "^\s*#+(.*)\n", "g").exec @descFile.cache
|
||||||
return @name unless t and t.length is 2
|
return @name unless t and t.length is 2
|
||||||
|
@metaFile.dirty = true if @hasMeta and @metaFile
|
||||||
|
@parent.metaFile.dirty = true if @parent and @parent.hasMeta and @parent.metaFile
|
||||||
@name = t[1].trim()
|
@name = t[1].trim()
|
||||||
|
|
||||||
remove: () ->
|
remove: () ->
|
||||||
@ -35,7 +38,10 @@ class BookletEntry
|
|||||||
|
|
||||||
class BookletFolder extends BookletEntry
|
class BookletFolder extends BookletEntry
|
||||||
constructor: (@type, @path, @hasMeta) ->
|
constructor: (@type, @path, @hasMeta) ->
|
||||||
super()
|
super "Untitle"
|
||||||
|
@init()
|
||||||
|
|
||||||
|
init: () ->
|
||||||
@cnt = 0
|
@cnt = 0
|
||||||
@nodes = []
|
@nodes = []
|
||||||
@metaFile = "#{@path}/meta.json".asFileHandler() if @hasMeta
|
@metaFile = "#{@path}/meta.json".asFileHandler() if @hasMeta
|
||||||
@ -60,7 +66,34 @@ class BookletFolder extends BookletEntry
|
|||||||
r()
|
r()
|
||||||
.catch (msg) ->
|
.catch (msg) ->
|
||||||
e msg
|
e msg
|
||||||
|
read: (folderPath) ->
|
||||||
|
me = @
|
||||||
|
return new Promise (r, e) ->
|
||||||
|
me.path = folderPath
|
||||||
|
me.init()
|
||||||
|
me.loaded = false
|
||||||
|
me.metaFile.meta (d) ->
|
||||||
|
return e d.error if d.error
|
||||||
|
me.metaFile.read (data) ->
|
||||||
|
# load all child
|
||||||
|
me.name = data.name
|
||||||
|
list = []
|
||||||
|
list[i] = v for v,i in data.entries
|
||||||
|
fn = (l) ->
|
||||||
|
if l.length is 0
|
||||||
|
me.cnt = data.cnt
|
||||||
|
return r()
|
||||||
|
el = (l.splice 0, 1)[0]
|
||||||
|
#console.log "create", el.type
|
||||||
|
obj = new NS[el.type]( me )
|
||||||
|
obj.name = el.name
|
||||||
|
obj.read(el.path).then () ->
|
||||||
|
fn l
|
||||||
|
.catch (msg) ->
|
||||||
|
fn l
|
||||||
|
|
||||||
|
return fn list
|
||||||
|
, "json"
|
||||||
|
|
||||||
size: () ->
|
size: () ->
|
||||||
return @nodes.length
|
return @nodes.length
|
||||||
@ -81,7 +114,7 @@ class BookletFolder extends BookletEntry
|
|||||||
me = @
|
me = @
|
||||||
return new Promise (r, e) ->
|
return new Promise (r, e) ->
|
||||||
list = []
|
list = []
|
||||||
list[i] = v for v, i in me.nodes if me.type isnt 'section'
|
list[i] = v for v, i in me.nodes if me.type isnt 'Section'
|
||||||
me.mkdir().then () ->
|
me.mkdir().then () ->
|
||||||
fn = (l) ->
|
fn = (l) ->
|
||||||
return r() if l.length is 0
|
return r() if l.length is 0
|
||||||
@ -98,12 +131,18 @@ class BookletFolder extends BookletEntry
|
|||||||
return new Promise (r, e) ->
|
return new Promise (r, e) ->
|
||||||
return r() unless me.metaFile.dirty
|
return r() unless me.metaFile.dirty
|
||||||
entries = []
|
entries = []
|
||||||
entries[i] = v.path for v,i in me.nodes
|
entries[i] = {name: v.name, path:v.path, type:v.type} for v,i in me.nodes
|
||||||
me.metaFile.cache = entries
|
data = {
|
||||||
|
name: me.name,
|
||||||
|
entries: entries,
|
||||||
|
cnt: me.cnt,
|
||||||
|
meta: me.hasMeta
|
||||||
|
}
|
||||||
|
me.metaFile.cache = data
|
||||||
me.metaFile.write "object", (d) ->
|
me.metaFile.write "object", (d) ->
|
||||||
return e d.error if d.error
|
return e d.error if d.error
|
||||||
me.metaFile.dirty = false
|
me.metaFile.dirty = false
|
||||||
console.log "saved " + me.metaFile.path
|
#console.log "saved " + me.metaFile.path
|
||||||
r()
|
r()
|
||||||
|
|
||||||
|
|
||||||
@ -115,7 +154,7 @@ class BookletFolder extends BookletEntry
|
|||||||
me.descFile.write "text/plain", (d) ->
|
me.descFile.write "text/plain", (d) ->
|
||||||
return e d.error if d.error
|
return e d.error if d.error
|
||||||
me.descFile.dirty = false
|
me.descFile.dirty = false
|
||||||
console.log "saved " + me.descFile.path
|
#console.log "saved " + me.descFile.path
|
||||||
r()
|
r()
|
||||||
.catch (msg) -> e msg
|
.catch (msg) -> e msg
|
||||||
|
|
||||||
@ -141,9 +180,9 @@ class BookletFolder extends BookletEntry
|
|||||||
@
|
@
|
||||||
|
|
||||||
|
|
||||||
class Book extends BookletFolder
|
class BookletBook extends BookletFolder
|
||||||
constructor: (path) ->
|
constructor: (path) ->
|
||||||
super 'book', path, true
|
super 'Book', path, true
|
||||||
|
|
||||||
save:() ->
|
save:() ->
|
||||||
me = @
|
me = @
|
||||||
@ -158,22 +197,22 @@ class Book extends BookletFolder
|
|||||||
class BookletChapter extends BookletFolder
|
class BookletChapter extends BookletFolder
|
||||||
constructor: (book) ->
|
constructor: (book) ->
|
||||||
path = "#{book.path}/c_#{book.cnt}"
|
path = "#{book.path}/c_#{book.cnt}"
|
||||||
super 'chapter', path, true
|
super 'Chapter', path, true
|
||||||
book.add @
|
book.add @
|
||||||
|
|
||||||
|
|
||||||
class BookletSection extends BookletFolder
|
class BookletSection extends BookletFolder
|
||||||
constructor: (chapter) ->
|
constructor: (chapter) ->
|
||||||
path = "#{chapter.path}/s_#{chapter.cnt}"
|
path = "#{chapter.path}/s_#{chapter.cnt}"
|
||||||
super "section", path, true
|
super "Section", path, true
|
||||||
chapter.add @
|
chapter.add @
|
||||||
|
|
||||||
|
|
||||||
class BookletFile extends BookletEntry
|
class BookletFile extends BookletEntry
|
||||||
constructor: (@section) ->
|
constructor: (@section) ->
|
||||||
super()
|
super "Untitle file"
|
||||||
@hasMeta = false
|
@hasMeta = false
|
||||||
@type = "file"
|
@type = "File"
|
||||||
@path = "#{@section.path}/f_#{@section.cnt}.md"
|
@path = "#{@section.path}/f_#{@section.cnt}.md"
|
||||||
@descFile = @path.asFileHandler()
|
@descFile = @path.asFileHandler()
|
||||||
@section.add @
|
@section.add @
|
||||||
@ -185,9 +224,22 @@ class BookletFile extends BookletEntry
|
|||||||
me.descFile.write "text/plain", (d) ->
|
me.descFile.write "text/plain", (d) ->
|
||||||
return e d.error if d.error
|
return e d.error if d.error
|
||||||
me.descFile.dirty = false
|
me.descFile.dirty = false
|
||||||
console.log "saved" + me.descFile.path
|
#console.log "saved" + me.descFile.path
|
||||||
|
r()
|
||||||
|
|
||||||
|
read: (p) ->
|
||||||
|
me = @
|
||||||
|
return new Promise (r, e) ->
|
||||||
|
me.loaded = false
|
||||||
|
me.treepath = p
|
||||||
r()
|
r()
|
||||||
|
|
||||||
toc: () ->
|
toc: () ->
|
||||||
@updateName()
|
@updateName()
|
||||||
@
|
@
|
||||||
|
|
||||||
|
NS =
|
||||||
|
Book: BookletBook
|
||||||
|
Chapter: BookletChapter
|
||||||
|
Section: BookletSection
|
||||||
|
File: BookletFile
|
@ -6,10 +6,17 @@ class Booklet extends this.OS.GUI.BaseApplication
|
|||||||
me = @
|
me = @
|
||||||
@tree = @find "toc-ui"
|
@tree = @find "toc-ui"
|
||||||
@currentToc = undefined
|
@currentToc = undefined
|
||||||
|
@dirty = false
|
||||||
@emux = false
|
@emux = false
|
||||||
@on "treeselect", (e) ->
|
@on "treeselect", (e) ->
|
||||||
return me.reloadEditor() if (me.currentToc is e) or (e is undefined) or (e.treepath is 0)
|
return me.reloadEditor() if (me.currentToc is e) or (e is undefined) or (e.treepath is 0)
|
||||||
|
e.treepath = e.path
|
||||||
|
me.load(e).then ()->
|
||||||
me.open e
|
me.open e
|
||||||
|
.catch (msg) ->
|
||||||
|
e.loaded = true
|
||||||
|
me.open e
|
||||||
|
me.error __("Error when loading '{0}': {1}", e.name, msg)
|
||||||
|
|
||||||
@initEditor()
|
@initEditor()
|
||||||
@resizeContent()
|
@resizeContent()
|
||||||
@ -24,21 +31,22 @@ class Booklet extends this.OS.GUI.BaseApplication
|
|||||||
return if me.emux
|
return if me.emux
|
||||||
return unless me.currentToc
|
return unless me.currentToc
|
||||||
me.currentToc.descFile.dirty = true
|
me.currentToc.descFile.dirty = true
|
||||||
|
me.dirty = true
|
||||||
|
|
||||||
newChapter: () ->
|
newChapter: () ->
|
||||||
return @error __("No book selected") unless @currentToc and @currentToc.type is "book"
|
return @error __("No book selected") unless @currentToc and @currentToc.type is "Book"
|
||||||
ch = new BookletChapter(@book)
|
ch = new BookletChapter(@book)
|
||||||
@displayToc()
|
@displayToc()
|
||||||
ch.treepath = ch.path
|
ch.treepath = ch.path
|
||||||
|
|
||||||
newSection: () ->
|
newSection: () ->
|
||||||
return @error __("No chapter selected") unless @currentToc and @currentToc.type is "chapter"
|
return @error __("No chapter selected") unless @currentToc and @currentToc.type is "Chapter"
|
||||||
sec = new BookletSection(@currentToc)
|
sec = new BookletSection(@currentToc)
|
||||||
@displayToc()
|
@displayToc()
|
||||||
sec.treepath = sec.path
|
sec.treepath = sec.path
|
||||||
|
|
||||||
newFile: () ->
|
newFile: () ->
|
||||||
return @error __("No section selected") unless @currentToc and @currentToc.type is "section"
|
return @error __("No section selected") unless @currentToc and @currentToc.type is "Section"
|
||||||
file = new BookletFile(@currentToc)
|
file = new BookletFile(@currentToc)
|
||||||
@displayToc()
|
@displayToc()
|
||||||
file.treepath = file.path
|
file.treepath = file.path
|
||||||
@ -57,25 +65,37 @@ class Booklet extends this.OS.GUI.BaseApplication
|
|||||||
me.error e
|
me.error e
|
||||||
fn()
|
fn()
|
||||||
|
|
||||||
|
load: (entry) ->
|
||||||
|
me = @
|
||||||
|
return new Promise (r, e) ->
|
||||||
|
return r() if entry.loaded
|
||||||
|
entry.descFile.meta (d) ->
|
||||||
|
return e d.error if d.error
|
||||||
|
entry.descFile.read (data) ->
|
||||||
|
entry.descFile.cache = data
|
||||||
|
entry.loaded = true
|
||||||
|
entry.descFile.dirty = false
|
||||||
|
r()
|
||||||
|
|
||||||
contextMenu: () ->
|
contextMenu: () ->
|
||||||
return undefined unless @currentToc
|
return undefined unless @currentToc
|
||||||
switch @currentToc.type
|
switch @currentToc.type
|
||||||
when "book"
|
when "Book"
|
||||||
return [
|
return [
|
||||||
{ text: __("New chapter"), dataid: "newChapter" },
|
{ text: __("New chapter"), dataid: "newChapter" },
|
||||||
{ text: __("Delete book"), dataid: "delete" }
|
{ text: __("Delete book"), dataid: "delete" }
|
||||||
]
|
]
|
||||||
when "chapter"
|
when "Chapter"
|
||||||
return [
|
return [
|
||||||
{ text: __("New section"), dataid: "newSection" },
|
{ text: __("New section"), dataid: "newSection" },
|
||||||
{ text: __("Delete chapter"), dataid: "delete" }
|
{ text: __("Delete chapter"), dataid: "delete" }
|
||||||
]
|
]
|
||||||
when "section"
|
when "Section"
|
||||||
return [
|
return [
|
||||||
{ text: __("New file"), dataid: "newFile" },
|
{ text: __("New file"), dataid: "newFile" },
|
||||||
{ text: __("Delete section"), dataid: "delete" }
|
{ text: __("Delete section"), dataid: "delete" }
|
||||||
]
|
]
|
||||||
when "file"
|
when "File"
|
||||||
return [
|
return [
|
||||||
{ text: __("Delete file"), dataid: "delete" }
|
{ text: __("Delete file"), dataid: "delete" }
|
||||||
]
|
]
|
||||||
@ -157,9 +177,17 @@ class Booklet extends this.OS.GUI.BaseApplication
|
|||||||
me = @
|
me = @
|
||||||
switch e
|
switch e
|
||||||
when "#{@name}-Open"
|
when "#{@name}-Open"
|
||||||
@openDialog "FileDiaLog", ( d, f ) ->
|
@checkForDirty () ->
|
||||||
console.log "#{d}/#{f}".asFileHandler()
|
me.openDialog "FileDiaLog", ( d, f ) ->
|
||||||
, __("Open file"), { mimes: me.meta().mimes }
|
me.book = new BookletBook(d)
|
||||||
|
me.book.read(d).then () ->
|
||||||
|
me.book.treepath = me.book.path
|
||||||
|
me.tree.set "selectedItem", undefined
|
||||||
|
me.displayToc()
|
||||||
|
me.notify __("Book loaded")
|
||||||
|
.catch (msg) ->
|
||||||
|
me.error __("Cannot load book: {0}", msg)
|
||||||
|
, __("Open file"), { mimes: ['dir'] }
|
||||||
when "#{@name}-New"
|
when "#{@name}-New"
|
||||||
@openDialog "FileDiaLog", ( d, f ) ->
|
@openDialog "FileDiaLog", ( d, f ) ->
|
||||||
me.newAt "#{d}/#{f}"
|
me.newAt "#{d}/#{f}"
|
||||||
@ -169,24 +197,34 @@ class Booklet extends this.OS.GUI.BaseApplication
|
|||||||
me.saveContext() if me.currentToc
|
me.saveContext() if me.currentToc
|
||||||
me.displayToc()
|
me.displayToc()
|
||||||
me.book.save().then () ->
|
me.book.save().then () ->
|
||||||
|
me.dirty = false
|
||||||
me.notify __("Book saved")
|
me.notify __("Book saved")
|
||||||
.catch (e) ->
|
.catch (e) ->
|
||||||
me.error __("Can't save the book : {0}", e)
|
me.error __("Can't save the book : {0}", e)
|
||||||
|
|
||||||
|
checkForDirty: (f) ->
|
||||||
|
return f() unless @dirty
|
||||||
|
@_gui.openDialog "YesNoDialog", (d) ->
|
||||||
|
# console.log d
|
||||||
|
if d
|
||||||
|
f()
|
||||||
|
, __("Continue ?"), { text: __("Book is unsaved, you want to continue ?") }
|
||||||
|
|
||||||
open: (toc) ->
|
open: (toc) ->
|
||||||
@emux = true
|
me = @
|
||||||
@saveContext()
|
me.emux = true
|
||||||
@currentToc = toc
|
me.saveContext()
|
||||||
@reloadEditor()
|
me.currentToc = toc
|
||||||
@displayToc()
|
me.reloadEditor()
|
||||||
@emux = false
|
me.displayToc()
|
||||||
|
me.emux = false
|
||||||
|
|
||||||
openBook: (metaFile) ->
|
openBook: (metaFile) ->
|
||||||
|
|
||||||
|
|
||||||
newAt: (folder) ->
|
newAt: (folder) ->
|
||||||
@tree.set "selectedItem", false
|
@tree.set "selectedItem", false
|
||||||
@book = new Book(folder)
|
@book = new BookletBook(folder)
|
||||||
@book.treepath = @book.path
|
@book.treepath = @book.path
|
||||||
@currentToc = undefined
|
@currentToc = undefined
|
||||||
@reloadEditor()
|
@reloadEditor()
|
||||||
|
@ -9,5 +9,5 @@
|
|||||||
"version":"0.0.1-a",
|
"version":"0.0.1-a",
|
||||||
"category":"Other",
|
"category":"Other",
|
||||||
"iconclass":"fa fa-adn",
|
"iconclass":"fa fa-adn",
|
||||||
"mimes":["application/json"]
|
"mimes":["dir"]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user