From 46b048f221495a6a8030d2a6008c64a2b3d8ea03 Mon Sep 17 00:00:00 2001 From: lxsang Date: Tue, 26 Nov 2019 19:23:28 +0000 Subject: [PATCH] add modif --- Booklet/build/debug/main.js | 6 +++--- Booklet/coffees/common.coffee | 20 ++++++++++++++++++-- Booklet/coffees/main.coffee | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Booklet/build/debug/main.js b/Booklet/build/debug/main.js index 15ec096..1cfef02 100644 --- a/Booklet/build/debug/main.js +++ b/Booklet/build/debug/main.js @@ -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) {} diff --git a/Booklet/coffees/common.coffee b/Booklet/coffees/common.coffee index 578a019..47d7c2e 100644 --- a/Booklet/coffees/common.coffee +++ b/Booklet/coffees/common.coffee @@ -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 = @ @@ -33,11 +34,26 @@ 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 } diff --git a/Booklet/coffees/main.coffee b/Booklet/coffees/main.coffee index 8961bb0..2799628 100644 --- a/Booklet/coffees/main.coffee +++ b/Booklet/coffees/main.coffee @@ -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")