AntOSDK first working version, now application can be built from browser

This commit is contained in:
Xuan Sang LE 2018-03-20 13:07:23 +01:00
parent 09f72fd436
commit f89c71e2b3
13 changed files with 187 additions and 43 deletions

View File

@ -71,12 +71,12 @@ class BasicDialog extends BaseDialog
init: () -> init: () ->
@title = @name if not @title @title = @name if not @title
html = "<afx-app-window data-id = 'dia-window' width='#{@conf.width}' height='#{@conf.height}'> html = "<afx-app-window data-id = '#{@name}' width='#{@conf.width}' height='#{@conf.height}'>"
<afx-vbox>" html += "<afx-hbox><div data-width='7'></div><afx-vbox><div data-height='5'></div>"
html += "<#{v.tag} #{v.att} style = 'margin-left:5px; margin-right:5px;' data-id = 'content#{k}'></#{v.tag}>" for k,v of @conf.tags html += "<#{v.tag} #{v.att} data-id = 'content#{k}'></#{v.tag}>" for k,v of @conf.tags
html += "<div data-height = '35' style=' text-align:right;padding-top:3px;'>" html += "<div data-height = '35' style=' text-align:right;padding-top:3px;'>"
html += "<afx-button data-id = 'bt#{k}' text = '#{v.label}' style='margin-right:5px;'></afx-button>" for k,v of @conf.buttons html += "<afx-button data-id = 'bt#{k}' text = '#{v.label}' style='margin-left:5px;'></afx-button>" for k,v of @conf.buttons
html += "</div><div data-height='5'></div></afx-vbox></afx-app-window>" html += "</div><div data-height='5'></div></afx-vbox><div data-width='7'></div></afx-hbox></afx-app-window>"
#render the html #render the html
_GUI.htmlToScheme html, @, @host _GUI.htmlToScheme html, @, @host
@ -200,7 +200,7 @@ this.OS.register "InfoDialog", InfoDialog
class YesNoDialog extends BasicDialog class YesNoDialog extends BasicDialog
constructor: () -> constructor: () ->
super "YesNoDialog", { super "YesNoDialog", {
tags: [{ tag: "afx-label", att: "style = 'padding-left:10px;'" }], tags: [{ tag: "afx-label" }],
width: 300, width: 300,
height: 100, height: 100,
resizable: true, resizable: true,
@ -290,20 +290,28 @@ class FileDiaLog extends BaseDialog
e.child.path.asFileHandler().read (d) -> e.child.path.asFileHandler().read (d) ->
return me.error __("Resource not found: {0}", e.child.path) if d.error return me.error __("Resource not found: {0}", e.child.path) if d.error
f d.result f d.result
location.set "onlistselect", (e) -> setroot = (path) ->
return unless e and e.data.path path.asFileHandler().read (d) ->
e.data.path.asFileHandler().read (d) ->
if(d.error) if(d.error)
return me.error __("Resource not found: {0}", e.data.path) return me.error __("Resource not found: {0}", path)
fileview.set "path", e.data.path fileview.set "path", path
fileview.set "data", d.result fileview.set "data", d.result
location.set "items", ( i for i in @systemsetting.VFS.mountpoints when i.type isnt "app" ) if not @data or not @data.root
location.set "selected", 0 unless location.get "selected" location.set "onlistselect", (e) ->
return unless e and e.data.path
setroot e.data.path
location.set "items", ( i for i in @systemsetting.VFS.mountpoints when i.type isnt "app" )
location.set "selected", 0 unless location.get "selected"
else
$(location).hide()
@trigger "calibrate"
setroot @data.root
fileview.set "onfileselect", (f) -> fileview.set "onfileselect", (f) ->
($ filename).val f.filename if f.type is "file" ($ filename).val f.filename if f.type is "file"
(@find "bt-ok").set "onbtclick", (e) -> (@find "bt-ok").set "onbtclick", (e) ->
f = fileview.get "selectedFile" f = fileview.get "selectedFile"
return me.notify __("Please select a file") unless f return me.notify __("Please select a file/fofler") unless f
return me.notify __("Please select {0} only", me.data.type) if me.data and me.data.type and me.data.type isnt f.type
if me.data and me.data.mimes if me.data and me.data.mimes
#verify the mime #verify the mime
m = false m = false

View File

@ -25,7 +25,7 @@ class FormatedString
__: () -> __: () ->
me = @ me = @
return @fs.l().replace /{(\d+)}/g, (match, number) -> return @fs.l().replace /{(\d+)}/g, (match, number) ->
return if typeof me.values[number] != 'undefined' then me.values[number] else match return if typeof me.values[number] != 'undefined' then me.values[number].__() else match
hash: () -> hash: () ->
@__().hash() @__().hash()
@ -80,7 +80,7 @@ if not String.prototype.format
String.prototype.format = () -> String.prototype.format = () ->
args = arguments args = arguments
return @replace /{(\d+)}/g, (match, number) -> return @replace /{(\d+)}/g, (match, number) ->
return if typeof args[number] != 'undefined' then args[number] else match return if typeof args[number] != 'undefined' then args[number].__() else match
String.prototype.f = () -> String.prototype.f = () ->
args = arguments args = arguments

View File

@ -68,11 +68,12 @@ class BaseFileHandler
return -1 unless @path return -1 unless @path
return @path.hash() return @path.hash()
sendB64: (m, f) -> sendB64: (p, f) ->
me = @ me = @
m = if p is "object" then "text/plain" else p
return f "" unless @cache return f "" unless @cache
if typeof @cache is "string" if p is "object" or typeof @cache is "string"
b64 = @cache.asBase64() b64 = if p is "object" then (JSON.stringify @cache).asBase64() else @cache.asBase64()
b64 = "data:#{m};base64,#{b64}" b64 = "data:#{m};base64,#{b64}"
f(b64) f(b64)
else else

View File

@ -1,4 +1,4 @@
coffee_files = main.coffee coffee_files = main.coffee dialog.coffee
jsfiles = coffeescript.js jsfiles = coffeescript.js

View File

@ -0,0 +1,109 @@
class BuildDialog extends this.OS.GUI.BasicDialog
constructor: () ->
super "BuildDialog", {
tags: [
{ tag: "afx-label", att: 'text="__(Coffees)" data-height="23" class="header"' },
{ tag: "afx-list-view" }
{ tag: "afx-label", att: 'text="__(Javascripts)" data-height="23" class="header"' },
{ tag: "afx-list-view" }
{ tag: "afx-label", att: 'text="__(Css)" data-height="23" class="header"' },
{ tag: "afx-list-view" }
{ tag: "afx-label", att: 'text="__(Copied files)" data-height="23" class="header"' },
{ tag: "afx-list-view" }
{ tag: "div", att: ' data-height="5"' }
],
width: 350,
height: 450,
resizable: true,
buttons: [
{
label: "__(Save)", onclick: (d) ->
data =
coffees: (v.text for v in (d.find "content1").get "items")
javascripts: (v.text for v in (d.find "content3").get "items")
css: (v.text for v in (d.find "content5").get "items")
copies: (v.text for v in (d.find "content7").get "items")
d.handler data if d.handler
d.quit()
},
{ label: "__(Cancel)", onclick: (d) -> d.quit() }
],
filldata: (d) ->
lv = d.find "content1"
lv.set "items", ({ text: v } for v in d.parent.prjfile.cache.coffees)
lv.set "buttons", [
{
text: "+",
onbtclick: (e) ->
d.selectFile ["text/coffeescript"], (f) ->
lv.push { text: f }, true if f
},
{
text: "-",
onbtclick: (e) ->
sel = lv.get "selected"
return unless sel
lv.remove sel, true
}
]
lv1 = d.find "content3"
lv1.set "items", ({ text: v } for v in d.parent.prjfile.cache.javascripts)
lv1.set "buttons", [
{
text: "+",
onbtclick: (e) ->
d.selectFile ["application/javascript"], (f) ->
lv1.push { text: f }, true if f
},
{
text: "-",
onbtclick: (e) ->
sel = lv1.get "selected"
return unless sel
lv1.remove sel, true
}
]
lv2 = d.find "content5"
lv2.set "items", ({ text: v } for v in d.parent.prjfile.cache.css)
lv2.set "buttons", [
{
text: "+",
onbtclick: (e) ->
d.selectFile ["text/css"], (f) ->
lv2.push { text: f }, true if f
},
{
text: "-",
onbtclick: (e) ->
sel = lv2.get "selected"
return unless sel
lv2.remove sel, true
}
]
lv3 = d.find "content7"
lv3.set "items", ({ text: v } for v in d.parent.prjfile.cache.copies)
lv3.set "buttons", [
{
text: "+",
onbtclick: (e) ->
d.selectFile [".*"], (f) ->
lv3.push { text: f }, true if f
},
{
text: "-",
onbtclick: (e) ->
sel = lv3.get "selected"
return unless sel
lv3.remove sel, true
}
]
}
selectFile: (mimes, f) ->
me = @
@openDialog "FileDiaLog", (d, n, p) ->
f p.replace me.parent.prjfile.cache.root + "/", ""
, "__(Select a file)", { mimes: mimes, type: "file", root: @parent.prjfile.cache.root }

View File

@ -145,8 +145,10 @@ class AntOSDK extends this.OS.GUI.BaseApplication
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save" @bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas" @bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
@bindKey "CTRL-R", () -> me.bnR() @bindKey "CTRL-R", () -> me.bnR()
@bindKey "ALT-B", () -> me.actionBuild "#{me.name}-Build" @bindKey "ALT-C", () -> me.actionBuild "#{me.name}-Build"
@bindKey "ALT-P", () -> me.buildAndRelease() @bindKey "ALT-P", () -> me.buildAndRelease()
@bindKey "ALT-Y", () ->
me.actionBuild "#{me.name}-Options"
@openProject @prjfile if @prjfile @openProject @prjfile if @prjfile
@trigger "calibrate" @trigger "calibrate"
@ -428,8 +430,8 @@ class AntOSDK extends this.OS.GUI.BaseApplication
child: [ child: [
{ text: "__(Build and Run)", dataid: "#{@name}-Run", shortcut: "C-R" }, { text: "__(Build and Run)", dataid: "#{@name}-Run", shortcut: "C-R" },
{ text: "__(Build release)", dataid: "#{@name}-Release", shortcut: "A-P" }, { text: "__(Build release)", dataid: "#{@name}-Release", shortcut: "A-P" },
{ text: "__(Build)", dataid: "#{@name}-Build", shortcut: "A-B" }, { text: "__(Build)", dataid: "#{@name}-Build", shortcut: "A-C" },
{ text: "__(Build Options)", dataid: "#{@name}-Options", shortcut: "A-C" } { text: "__(Build Options)", dataid: "#{@name}-Options", shortcut: "A-Y" }
], ],
onmenuselect: (e) -> me.actionBuild e.item.data.dataid onmenuselect: (e) -> me.actionBuild e.item.data.dataid
} }
@ -438,6 +440,7 @@ class AntOSDK extends this.OS.GUI.BaseApplication
actionFile: (e) -> actionFile: (e) ->
me = @ me = @
return unless @prjfile
saveas = () -> saveas = () ->
me.openDialog "FileDiaLog", (d, n) -> me.openDialog "FileDiaLog", (d, n) ->
file = "#{d}/#{n}".asFileHandler() file = "#{d}/#{n}".asFileHandler()
@ -487,10 +490,17 @@ class AntOSDK extends this.OS.GUI.BaseApplication
return fn() unless @isDirty() return fn() unless @isDirty()
@ask "__(Unsaved project)", "__(Ignore unsaved project ?)", () -> @ask "__(Unsaved project)", "__(Ignore unsaved project ?)", () ->
fn() fn()
when "#{@name}-Save"
return unless @prjfile
@prjfile.write "object", (r) ->
return me.error __("Cannot save project: {0}", r.error) if r.error
me.notify __("project saved")
me.prjfile.dirty = false
actionBuild: (e) -> actionBuild: (e) ->
me = @ me = @
return unless @prjfile
switch e switch e
when "#{@name}-Run" then me.bnR() when "#{@name}-Run" then me.bnR()
when "#{@name}-Build" when "#{@name}-Build"
@ -498,7 +508,11 @@ class AntOSDK extends this.OS.GUI.BaseApplication
me.log "ERROR", ex.toString() me.log "ERROR", ex.toString()
when "#{@name}-Release" when "#{@name}-Release"
me.buildAndRelease() me.buildAndRelease()
when "#{@name}-Options"
me.openDialog new BuildDialog(), (d) ->
me.prjfile.cache[k] = v for k, v of d
me.prjfile.dirty = true
, "__(Add files to build target)"
isDirty: () -> isDirty: () ->
return false unless @tabarea return false unless @tabarea
@ -512,9 +526,10 @@ class AntOSDK extends this.OS.GUI.BaseApplication
me = @ me = @
evt.preventDefault() evt.preventDefault()
dirties = ( v for v in @tabarea.get "items" when v.dirty ) dirties = ( v for v in @tabarea.get "items" when v.dirty )
@ask "__(Quit)", __("Ignore all {0} unsaved files ?", dirties.length), () -> m = __("Ignore: {0} unsaved files {1}?", dirties.length, if @prjfile.dirty then "__(and unsaved project)" else "")
@ask "__(Quit)", m, () ->
v.dirty = false for v in dirties v.dirty = false for v in dirties
@prjfile.dirty = false me.prjfile.dirty = false
me.quit() me.quit()
log: (t, m) -> log: (t, m) ->

View File

@ -110,4 +110,11 @@ afx-tab-bar[data-id="tabarea"] afx-list-view{
afx-tab-bar[data-id="tabarea"] afx-list-view > div.list-container > ul > li.selected { afx-tab-bar[data-id="tabarea"] afx-list-view > div.list-container > ul > li.selected {
background-color: #f6F6F6; background-color: #f6F6F6;
border-radius: 0; border-radius: 0;
}
afx-app-window[data-id="BuildDialog"] afx-label.header {
font-weight: bold;
margin: 0;
}
afx-app-window[data-id="BuildDialog"] afx-list-view {
border: 1px solid #a6A6A6;
} }

View File

@ -60,9 +60,6 @@ class BloggerCategoryDialog extends this.OS.GUI.BasicDialog
(d.find "bt0").trigger() if e.which is 13 (d.find "bt0").trigger() if e.which is 13
} }
this.OS.register "BloggerCategoryDialog", BloggerCategoryDialog
# This dialog is use for cv section editing # This dialog is use for cv section editing
class BloggerCVSectionDiaglog extends this.OS.GUI.BaseDialog class BloggerCVSectionDiaglog extends this.OS.GUI.BaseDialog
@ -102,5 +99,4 @@ class BloggerCVSectionDiaglog extends this.OS.GUI.BaseDialog
container = @find "editor-container" container = @find "editor-container"
children = ($ container).children() children = ($ container).children()
cheight = ($ container).height() - 30 cheight = ($ container).height() - 30
($ children[1]).css("height", cheight + "px") ($ children[1]).css("height", cheight + "px")
this.OS.register "BloggerCVSectionDiaglog", BloggerCVSectionDiaglog

View File

@ -52,7 +52,7 @@ class Blogger extends this.OS.GUI.BaseApplication
me.saveUser() me.saveUser()
(@find "cv-cat-add").set "onbtclick", (e) -> (@find "cv-cat-add").set "onbtclick", (e) ->
me.openDialog "BloggerCategoryDialog", me.openDialog new BloggerCategoryDialog(),
(d) -> (d) ->
c = c =
name: d.value, name: d.value,
@ -68,7 +68,7 @@ class Blogger extends this.OS.GUI.BaseApplication
(@find "cv-cat-edit").set "onbtclick", (e) -> (@find "cv-cat-edit").set "onbtclick", (e) ->
cat = me.cvlist.get "selectedItem" cat = me.cvlist.get "selectedItem"
return unless cat return unless cat
me.openDialog "BloggerCategoryDialog", (d) -> me.openDialog new BloggerCategoryDialog(), (d) ->
c = c =
id: cat.id, id: cat.id,
publish: cat.publish, publish: cat.publish,
@ -93,7 +93,7 @@ class Blogger extends this.OS.GUI.BaseApplication
(@find "cv-sec-add").set "onbtclick", (e) -> (@find "cv-sec-add").set "onbtclick", (e) ->
cat = me.cvlist.get "selectedItem" cat = me.cvlist.get "selectedItem"
return me.notify __("Please select a category") unless cat and cat.id isnt 0 return me.notify __("Please select a category") unless cat and cat.id isnt 0
me.openDialog "BloggerCVSectionDiaglog", (d) -> me.openDialog new BloggerCVSectionDiaglog(), (d) ->
d.cid = Number cat.id d.cid = Number cat.id
d.start = Number d.start d.start = Number d.start
d.end = Number d.end d.end = Number d.end
@ -108,7 +108,7 @@ class Blogger extends this.OS.GUI.BaseApplication
sec = (me.find "cv-sec-list").get "selected" sec = (me.find "cv-sec-list").get "selected"
return me.notify __("Please select a section to move") unless sec return me.notify __("Please select a section to move") unless sec
me.openDialog "BloggerCategoryDialog", (d) -> me.openDialog new BloggerCategoryDialog(), (d) ->
c = c =
id: sec.id, id: sec.id,
cid: d.p.id cid: d.p.id
@ -123,7 +123,7 @@ class Blogger extends this.OS.GUI.BaseApplication
sec = (me.find "cv-sec-list").get "selected" sec = (me.find "cv-sec-list").get "selected"
return me.notify __("Please select a section to edit") unless sec return me.notify __("Please select a section to edit") unless sec
me.openDialog "BloggerCVSectionDiaglog", (d) -> me.openDialog new BloggerCVSectionDiaglog(), (d) ->
d.cid = Number sec.cid d.cid = Number sec.cid
d.start = Number d.start d.start = Number d.start
d.end = Number d.end d.end = Number d.end

View File

@ -62,6 +62,9 @@ afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] >
background-color: transparent; background-color: transparent;
border-radius: 5px; border-radius: 5px;
} }
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > div.list-container > ul > li.selected ul.complex-content li{
color: #414339;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .cv-content{ afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .cv-content{
text-align: justify; text-align: justify;
} }

View File

@ -242,7 +242,7 @@ class Files extends this.OS.GUI.BaseApplication
@notify __("File {0} cut", file.filename) @notify __("File {0} cut", file.filename)
when "#{@name}-copy" when "#{@name}-copy"
return unless file return unless file or file.type is "dir"
@clipboard = @clipboard =
cut: false cut: false
file: file.path.asFileHandler() file: file.path.asFileHandler()
@ -257,8 +257,14 @@ class Files extends this.OS.GUI.BaseApplication
me.clipboard = undefined me.clipboard = undefined
me.error __("Fail to paste: {0}", r.error) if r.error me.error __("Fail to paste: {0}", r.error) if r.error
else else
@notify __("Copy not yet implemented") @clipboard.file.read (d) ->
@clipboard = undefined blob = new Blob [d], { type: me.clipboard.file.info.mime }
fp = "#{me.currdir.path}/#{me.clipboard.file.basename}".asFileHandler()
fp.cache = blob
fp.write me.clipboard.file.info.mime, (r) ->
me.clipboard = undefined
me.error __("Fail to paste: {0}", r.error) if r.error
, "binary"
else else
@_api.handler.setting() @_api.handler.setting()

View File

@ -90,5 +90,4 @@ RepositoryDialog.scheme = """
</div> </div>
</afx-vbox> </afx-vbox>
</afx-app-window> </afx-app-window>
""" """
this.OS.register "RepositoryDialog", RepositoryDialog

View File

@ -52,7 +52,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication
@btremove.set "onbtclick", (e) -> @btremove.set "onbtclick", (e) ->
me.uninstall e me.uninstall e
@bindKey "CTRL-R", () -> @bindKey "CTRL-R", () ->
me.openDialog "RepositoryDialog" me.openDialog new RepositoryDialog()
fetchApps: (url) -> fetchApps: (url) ->
me = @ me = @
@_api.get url, ( d ) -> @_api.get url, ( d ) ->
@ -93,7 +93,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication
{ text: "__(Options)", child: [ { text: "__(Options)", child: [
{ text: "__(Repositories)", shortcut: "C-R" } { text: "__(Repositories)", shortcut: "C-R" }
] , onmenuselect: (e) -> ] , onmenuselect: (e) ->
me.openDialog "RepositoryDialog" me.openDialog new RepositoryDialog()
} }
] ]