diff --git a/Makefile b/Makefile
index 2c43d7a..c36eca3 100644
--- a/Makefile
+++ b/Makefile
@@ -49,10 +49,7 @@ coffees= src/core/core.coffee \
src/core/tags/SystemPanelTag.coffee \
src/antos.coffee
-
-
-
-packages = CoreServices Files Setting CodePad
+packages = CoreServices Files Setting CodePad MarketPlace
main: initd build_coffees build_themes libs build_packages languages
- cp src/index.html $(BUILDDIR)/
diff --git a/src/core/BaseDialog.coffee b/src/core/BaseDialog.coffee
index fcbd5da..e30ac20 100644
--- a/src/core/BaseDialog.coffee
+++ b/src/core/BaseDialog.coffee
@@ -290,7 +290,7 @@ SelectionDialog.scheme = """
-
+
diff --git a/src/core/api.coffee b/src/core/api.coffee
index 2e15b53..0c73baa 100644
--- a/src/core/api.coffee
+++ b/src/core/api.coffee
@@ -208,14 +208,14 @@ Ant.OS.API =
r.responseType = "arraybuffer"
r.onload = (e) ->
if @status is 200 and @readyState is 4
- resolve @response
Ant.OS.API.loaded q, p, "OK"
+ resolve @response
else
- reject e, @
Ant.OS.API.loaded q, p, "FAIL"
+ reject Ant.OS.API.throwe __("Unable to get blob: {0}", p)
Ant.OS.API.loading q, p
r.send()
-
+
upload: (p, d) ->
new Promise (resolve, reject) ->
q = Ant.OS.announcer.getMID()
diff --git a/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl b/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl
index 357c70d..d853cbe 100644
--- a/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl
+++ b/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl
@@ -1,7 +1,7 @@
{
"app":"{0}",
"name":"{0}",
- "description":"",
+ "description":"{0}",
"info":{
"author": "",
"email": ""
diff --git a/src/packages/MarketPlace/dialog.coffee b/src/packages/MarketPlace/dialog.coffee
index b53417c..db62344 100644
--- a/src/packages/MarketPlace/dialog.coffee
+++ b/src/packages/MarketPlace/dialog.coffee
@@ -16,78 +16,67 @@
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
-class RepositoryDialog extends this.OS.GUI.BaseDialog
+class RepositoryDialog extends this.OS.GUI.subwindows.SelectionDialog
constructor: () ->
- super "RepositoryDialog"
-
- init: () ->
- @_gui.htmlToScheme RepositoryDialog.scheme, @, @host
- #@render "#{@meta().path}/repositorydia.html"
-
+ super()
main: () ->
- me = @
- @list = @find "repo-list"
- @list.set "onlistdbclick", (e) ->
- selidx = me.list.get "selidx"
- return unless selidx >= 0
- sel = me.systemsetting.system.repositories[selidx]
- me.openDialog "PromptDialog", (e) ->
- m = e.match /\[([^\]]*)\]\s*(.*)/
- return me.error "Wrong format: it should be [name] url" if not m or m.length isnt 3
- sel.name = m[1]
- sel.text = sel.name
- sel.url = m[2]
- me.refreshList()
- , __("Edit repository"), { label: __("Format : [name] url"), value: "[#{e.data.text}] #{e.data.url}" }
-
+ @list = @find "list"
+ $((@find "btnOk")).hide()
@list.set "buttons", [
{
text: "+",
- onbtclick: () ->
- me.openDialog "PromptDialog", (e) ->
- m = e.match /\[([^\]]*)\]\s*(.*)/
- return me.error __("Wrong format: it should be [name] url") if not m or m.length isnt 3
- me.systemsetting.system.repositories.push {
- name: m[1],
+ onbtclick: () =>
+ @openDialog("PromptDialog", {
+ title: __("Add repository"),
+ label: __("Format : [name] url")
+ }).then (e) =>
+ m = e.match /\[([^\]]*)\]\s*(.+)/
+ if not m or m.length isnt 3
+ return @error __("Wrong format: it should be [name] url")
+ repo = {
url: m[2],
- text: m[1],
- i: me.systemsetting.system.repositories.length
+ text: m[1]
}
- me.refreshList()
- , __("Add repository"), { label: __("Format : [name] url") }
+ @systemsetting.system.repositories.push repo
+ @list.push repo
},
{
text: "-",
- onbtclick: () ->
- selidx = me.list.get "selidx"
+ onbtclick: () =>
+ el = @list.get "selectedItem"
+ return unless el
+ selidx = $(el).index()
return unless selidx >= 0
- me.systemsetting.system.repositories.splice selidx, selidx
- me.refreshList()
+ @systemsetting.system.repositories.splice selidx, selidx
+ @list.remove el
+ },
+ {
+ iconclass: "fa fa-pencil",
+ onbtclick: () => @editRepo()
}
]
- (@find "btquit").set "onbtclick", (e) -> me.quit()
- @refreshList()
- refreshList: () ->
- ls = ({
- text: v.name,
- iconclass: "fa fa-link",
- url: v.url,
- complex: true,
- detail: [{ text: v.url }]
- } for v in @systemsetting.system.repositories)
- @list.set "items", ls
+ editRepo: () ->
+ el = @list.get "selectedItem"
+ return unless el
+ selidx = $(el).index()
+ return unless selidx >= 0
+ data = el.get "data"
+ sel = @systemsetting.system.repositories[selidx]
+ @openDialog("PromptDialog", {
+ title: __("Edit repository"),
+ label: __("Format : [name] url"),
+ value: "[#{data.text}] #{data.url}"
+ }).then (e) =>
+ m = e.match /\[([^\]]*)\]\s*(.+)/
+ if not m or m.length isnt 3
+ return @error __("Wrong format: it should be [name] url")
+ data.text = m[1]
+ data.url = m[2]
+ @list.update()
+ @list.unselect()
+
onexit: (e) ->
- @parent.repo.set "items", @systemsetting.system.repositories
- @parent.dialog = undefined if @parent
-RepositoryDialog.scheme = """
-
-
-
-
-
-
-"""
\ No newline at end of file
+ @parent.refreshRepoList()
+ super.onexit e
\ No newline at end of file
diff --git a/src/packages/MarketPlace/main.coffee b/src/packages/MarketPlace/main.coffee
index de03c63..56d8e81 100644
--- a/src/packages/MarketPlace/main.coffee
+++ b/src/packages/MarketPlace/main.coffee
@@ -16,25 +16,27 @@
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
-self = this
class MarketPlace extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "MarketPlace", args
main: () ->
- me = @
@installdir = @systemsetting.system.pkgpaths.user
# test repository
+ @apps_meta = []
@repo = @find "repo"
- @repo.set "onlistselect", (e) ->
- return unless e.data
- me.fetchApps e.data.url
- @repo.set "items", @systemsetting.system.repositories
+ @repo.set "onlistselect", (e) =>
+ data = e.data.item.get("data")
+ return unless data
+ @fetchApps data
+
+ @refreshRepoList()
@applist = @find "applist"
- @applist.set "onlistselect", (e) ->
- return unless e.data
- me.appDetail e.data
+ @applist.set "onlistselect", (e) =>
+ data = e.data.item.get("data")
+ @appDetail data
+
@container = @find "container"
@appname = @find "appname"
@appdesc = @find "app-desc"
@@ -42,39 +44,105 @@ class MarketPlace extends this.OS.GUI.BaseApplication
@btinstall = @find "bt-install"
@btremove = @find "bt-remove"
@btexec = @find "bt-exec"
- ($ @container ).css "visibility", "hidden"
- @btexec.set "onbtclick", (e) ->
- app = me.applist.get "selected"
- return unless app
- me._gui.launch app.className if app.className
- @btinstall.set "onbtclick", (e) ->
- return me.update() if me.btinstall.get "dirty"
- me.install()
- @btremove.set "onbtclick", (e) ->
- me.uninstall()
- @bindKey "CTRL-R", () ->
- me.openDialog new RepositoryDialog()
- fetchApps: (url) ->
- me = @
- @_api.get url, ( d ) ->
- for v in d
- v.text = v.name
- v.iconclass = "fa fa-adn"
- me.applist.set "items", d
- , (e, s) ->
- me.error __("Fail to fetch packages list from: {0}", url)
+ @searchbox = @find "searchbox"
+ ($ @container).css "visibility", "hidden"
+ @btexec.set "onbtclick", (e) =>
+ el = @applist.get "selectedItem"
+ return unless el
+ app = el.get("data")
+ @_gui.launch app.className if app.className
+
+ @btinstall.set "onbtclick", (e) =>
+ if @btinstall.get "dirty"
+ return @update()
+ .then () => @notify __("Package updated")
+ .catch (e) => @error e.toString(), e
+ @remoteInstall()
+ .then () => @notify __("Package installed")
+ .catch (e) => @error e.toString(), e
+
+ @btremove.set "onbtclick", (e) =>
+ @uninstall()
+ .then () => @notify __("Packaged uninstalled")
+ .catch (e) => @error e.toString(), e
+
+ @bindKey "CTRL-R", () =>
+ @menuOptionsHandle "repos"
+
+ $(@searchbox).keyup (e) => @search e
+
+ refreshRepoList: () ->
+ list = (v for v in @systemsetting.system.repositories)
+ list.unshift {
+ text: "Installed"
+ }
+ @repo.set "data", list
+
+ search: (e) ->
+ switch e.which
+ when 37
+ e.preventDefault()
+ when 38
+ @applist.selectPrev()
+ e.preventDefault()
+ when 39
+ e.preventDefault()
+ when 40
+ @applist.selectNext()
+ e.preventDefault()
+ when 13
+ e.preventDefault()
+ else
+ text = @searchbox.value
+ @applist.set "data", (v for v in @apps_meta) if text.length is 2
+ return if text.length < 3
+ result = []
+ term = new RegExp text, 'i'
+ result.push v for v in @apps_meta when v.text.match term
+ @applist.set "data", result
+
+
+ fetchApps: (data) ->
+ if not data.url
+ pkgcache = @systemsetting.system.packages
+ list = []
+ for k, v of pkgcache
+ list.push {
+ className: v.app,
+ name: v.name,
+ text: v.name,
+ icon: v.icon,
+ iconclass: v.iconclass,
+ category: v.category,
+ author: v.info.author,
+ version: v.version,
+ description: "#{v.path}/REAME.md"
+ }
+ @apps_meta = list
+ @applist.set "data", list
+ return
+
+ @_api.get data.url
+ .then ( d ) =>
+ for v in d
+ v.text = v.name
+ v.iconclass = "fa fa-adn"
+ @apps_meta = d
+ @applist.set "data", d
+ .catch (e) ->
+ @error __("Fail to fetch packages list from: {0}", data.url), e
appDetail: (d) ->
- me = @
($ @container).css "visibility", "visible"
( $ @appname ).html d.name
(@find "vstat").set "text", ""
if d.description
- d.description.asFileHandler().read (text) ->
+ d.description.asFileHandle().read().then (text) =>
converter = new showdown.Converter()
- ($ me.appdesc).html converter.makeHtml text
+ ($ @appdesc).html(converter.makeHtml text)
+ .catch (e) => @notify __("Unable to read package description")
else
- ($ me.appdesc).empty()
+ ($ @appdesc).empty()
pkgcache = @systemsetting.system.packages
@btinstall.set "text", "__(Install)"
@btinstall.set "dirty", false
@@ -89,7 +157,8 @@ class MarketPlace extends this.OS.GUI.BaseApplication
@btinstall.set "dirty", true
@btinstall.set "text", "__(Update)"
($ @btinstall).show()
- (@find "vstat").set "text", __("Your application version is older ({0} < {1})", vs, ovs)
+ (@find "vstat").set "text",
+ __("Your application version is older ({0} < {1})", vs, ovs)
($ @btremove).show()
($ @btexec).show()
else
@@ -98,111 +167,185 @@ class MarketPlace extends this.OS.GUI.BaseApplication
($ @btexec).hide()
($ @appdetail).empty()
- for k, v of d when k isnt "name" and k isnt "description"
- ($ @appdetail).append $("").append(($ "