add new apps

This commit is contained in:
lxsang
2019-11-24 19:33:14 +00:00
parent 96e7662d6e
commit 7c2cc7dc11
21 changed files with 739 additions and 0 deletions

View File

@ -0,0 +1,106 @@
class BookletEntry
constructor: (@name) ->
@markAsDirty()
save: () ->
remove: () ->
markAsDirty: () -> @dirty = true
markAsClean: () -> @dirty = false
toc: () ->
class BookletFolder extends BookletEntry
constructor: (name) ->
super name
save: () ->
remove: () ->
rename: (newname) ->
class Book extends BookletFolder
constructor: (@path, name) ->
super name
@chapters = []
@metaFile = "#{@path}/meta.json".asFileHandler()
addChapter: (chap) ->
chap.book = @
@chapters.push chap
size: () ->
return @chapters.length
toc: () ->
return {
name: @name,
path: @path,
meta: @metaFile.path,
entries: v.toc() for v in @chapters
}
class BookletChapter extends BookletFolder
constructor: (@book, name) ->
super name
@book.addChapter @
@sections = []
@path = "#{@book.path}/#{@book.size()}"
@metaFile = "#{@path}/meta.json".asFileHandler()
@descFile = "#{@path}/chapter.md".asFileHandler()
addSection: (sec) ->
sec.chapter = @
@sections.push sec
size: () ->
return @sections.length
toc: () ->
return {
name: @name,
path: @path,
meta: @metaFile.path,
description: @descFile.path,
entries: v.toc() for v in @sections
}
class BookletSection extends BookletFolder
constructor: (@chapter, name) ->
super name
@chapter.addSection @
@path = "#{@chapter.path}/#{@chapter.size()}"
@files = []
@descFile = "#{@path}/section.md".asFileHandler()
addFile: (file) ->
file.section = @
@files.push file
toc: () ->
return {
name: @name,
path: @path,
description: @descFile.path,
entries: v.toc() for v in @files
}
size: () ->
return @files.length
class BookletFile extends BookletEntry
constructor: (@section) ->
super ""
@section.addFile @
@path = "#{@section.path}/#{@section.size()}.md"
@handle = @path.asFileHandler()
getTitle: () ->
toc: () ->
return {
name: @name,
path: @path
}

102
Booklet/coffees/main.coffee Normal file
View File

@ -0,0 +1,102 @@
class Booklet extends this.OS.GUI.BaseApplication
constructor: ( args ) ->
super "Booklet", args
main: () ->
@initEditor()
@resizeContent()
initEditor: ()->
markarea = @find "markarea"
@container = @find "mycontainer"
@previewOn = false
@currfile = "Untitled".asFileHandler()
@editormux = false
me = @
@editor = new SimpleMDE
element: markarea
autofocus: true
tabSize: 4
indentWithTabs: true
toolbar: [
"bold", "italic", "heading", "|", "quote", "code",
"unordered-list", "ordered-list", "|", "link",
"image", "table", "horizontal-rule", "|",
{
name: "preview",
className: "fa fa-eye no-disable",
action: (e) ->
me.previewOn = !me.previewOn
SimpleMDE.togglePreview e
#if(self.previewOn) toggle the highlight
#{
# var container = self._scheme.find(self,"Text")
# .$element.getElementsByClassName("editor-preview");
# if(container.length == 0) return;
# var codes = container[0].getElementsByTagName('pre');
# codes.forEach(function(el){
# hljs.highlightBlock(el);
# });
# //console.log(code);
#}
}
]
@on "hboxchange", (e) -> me.resizeContent()
@bindKey "ALT-N", () -> me.actionFile "#{me.name}-New"
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
@createBook()
createBook: () ->
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")
sec2 = new BookletSection(c1, "section 2 in c1")
sec3 = new BookletSection(c2, "section 1 in c2")
f1 = new BookletFile(sec1)
f2 = new BookletFile(sec2)
f3 = new BookletFile(sec3)
f4 = new BookletFile(sec1)
console.log(book.toc())
resizeContent: () ->
children = ($ @container).children()
titlebar = (($ @scheme).find ".afx-window-top")[0]
toolbar = children[1]
statusbar = children[4]
cheight = ($ @scheme).height() - ($ titlebar).height() - ($ toolbar).height() - ($ statusbar).height() - 40
($ children[2]).css("height", cheight + "px")
menu: () ->
me = @
menu = [{
text: "__(File)",
child: [
{ text: "__(New booklet)", dataid: "#{@name}-New", shortcut: "A-N" },
{ text: "__(Open a booklet)", dataid: "#{@name}-Open", shortcut: "A-O" }
],
onmenuselect: (e) -> me.actionFile e.item.data.dataid
}]
menu
actionFile: (e) ->
console.log "Action file fired"
###
me = @
switch e
when "#{@name}-Open"
@openDialog "FileDiaLog", ( d, f ) ->
me.open "#{d}/#{f}".asFileHandler()
, __("Open file")
when "#{@name}-New"
@currfile = "Untitled".asFileHandler()
@currfile.cache = ""
@editor.value("")
###
Booklet.dependencies = [ "mde/simplemde.min" ]
this.OS.register "Booklet", Booklet