add modif

This commit is contained in:
lxsang 2019-11-26 19:23:28 +00:00
parent 7c2cc7dc11
commit 46b048f221
3 changed files with 22 additions and 6 deletions

View File

@ -74,7 +74,7 @@
createBook() {
var book, c1, c2, f1, f2, f3, f4, sec1, sec2, sec3;
book = new Book("home://test");
book = new Book("home://test", "mybook");
c1 = new BookletChapter(book, "Chapter one");
c2 = new BookletChapter(book, "Chapter two");
sec1 = new BookletSection(c1, "section 1 in c1");
@ -173,9 +173,9 @@
super(name);
}
save() {}
save(apif) {}
remove() {}
remove(apif) {}
rename(newname) {}

View File

@ -14,9 +14,9 @@ class BookletFolder extends BookletEntry
constructor: (name) ->
super name
save: () ->
save: (apif) ->
remove: () ->
remove: (apif) ->
rename: (newname) ->
@ -26,6 +26,7 @@ class Book extends BookletFolder
super name
@chapters = []
@metaFile = "#{@path}/meta.json".asFileHandler()
@descFile = "#{@path}/book.md".asFileHandler()
addChapter: (chap) ->
chap.book = @
@ -34,10 +35,25 @@ class Book extends BookletFolder
size: () ->
return @chapters.length
save:(handle) ->
v.save handle for v in @chapters
me = @
if @dirty
if @descFile.dirty
@descFile.write "text/plain", (r) ->
handle.error __("Fail to save file {0}: {1}", me.descFile.path, r.error) if r.error
@metaFile.cache = @toc()
@metaFile.dirty = true
@metaFile.write "object", (r) ->
return handle.error __("Fail to write book meta: {0}", r.error)
me.markAsClean
handle.notify __("Book saved")
toc: () ->
return {
name: @name,
path: @path,
description: @descFile.path,
meta: @metaFile.path,
entries: v.toc() for v in @chapters
}

View File

@ -48,7 +48,7 @@ class Booklet extends this.OS.GUI.BaseApplication
@createBook()
createBook: () ->
book = new Book("home://test", "mybook", @)
book = new Book("home://test", "mybook")
c1 = new BookletChapter(book, "Chapter one")
c2 = new BookletChapter(book, "Chapter two")
sec1 = new BookletSection(c1, "section 1 in c1")