From 2656c21cdbb436c698354848a55f8cbbc62fb373 Mon Sep 17 00:00:00 2001 From: lxsang Date: Fri, 21 Feb 2020 17:56:45 +0100 Subject: [PATCH] gui --- Makefile | 10 ++- src/core/Announcerment.coffee | 90 +++++++++++++++++++++++ src/core/core.coffee | 25 ------- src/core/tags/tag.coffee | 9 +++ src/core/tags/window-tag.coffee | 8 ++ src/packages/ShowCase/Makefile | 11 +++ src/packages/ShowCase/assets/scheme.html | 5 ++ src/packages/ShowCase/coffees/main.coffee | 36 +++++++++ src/packages/ShowCase/package.json | 13 ++++ 9 files changed, 178 insertions(+), 29 deletions(-) create mode 100644 src/core/Announcerment.coffee create mode 100644 src/core/tags/tag.coffee create mode 100644 src/core/tags/window-tag.coffee create mode 100644 src/packages/ShowCase/Makefile create mode 100644 src/packages/ShowCase/assets/scheme.html create mode 100644 src/packages/ShowCase/coffees/main.coffee create mode 100644 src/packages/ShowCase/package.json diff --git a/Makefile b/Makefile index 7eae061..26e664d 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ coffees= src/core/core.coffee\ src/core/api.coffee\ src/core/settings.coffee\ src/core/handles/RemoteHandle.coffee\ + src/core/Announcerment.coffee\ src/core/vfs.coffee\ src/core/vfs/GoogleDriveHandle.coffee\ src/core/db.coffee\ @@ -24,12 +25,13 @@ coffees= src/core/core.coffee\ src/core/BaseService.coffee\ src/core/BaseEvent.coffee\ src/core/BaseDialog.coffee\ + src/core/tag.coffee\ src/antos.coffee -packages = CoreServices ActivityMonitor Setting # Files MarkOn MarketPlace Preview NotePad wTerm +packages = CoreServices ActivityMonitor Setting ShowCase # Files MarkOn MarketPlace Preview NotePad wTerm main: initd build_coffees build_tags build_themes schemes libs build_packages languages - cp src/index.html $(BUILDDIR)/ @@ -68,7 +70,7 @@ build_tags: @echo "$(BLUE)Building tag files$(NC)" -mkdir $(BUILDDIR)/resources -rm $(BUILDDIR)/resources/antos_tags.js - for f in src/core/tags/*; do (cat "$${f}"; echo) >> $(BUILDDIR)/resources/antos_tags.js; done + for f in src/core/tags/*.tag; do (cat "$${f}"; echo) >> $(BUILDDIR)/resources/antos_tags.js; done languages: -mkdir $(BUILDDIR)/resources @@ -104,7 +106,7 @@ package: cd src/packages/$$PKG && make;\ cd ../../../;\ test -d $(BUILDDIR)/packages/$$PKG || mkdir -p $(BUILDDIR)/packages/$$PKG;\ - cp -rf src/packages/$$PKG/build/* $(BUILDDIR)/packages/$$PKG/;\ + cp -rfv src/packages/$$PKG/build/* $(BUILDDIR)/packages/$$PKG/;\ test -d src/packages/$$PKG/build && rm -r src/packages/$$PKG/build; pkgar: @@ -142,4 +144,4 @@ uglify: release: main uglify clean: - rm -rf $(BUILDDIR)/* + rm -rf $(BUILDDIR)/{resources,scripts,packages,index.html} diff --git a/src/core/Announcerment.coffee b/src/core/Announcerment.coffee new file mode 100644 index 0000000..0408bbe --- /dev/null +++ b/src/core/Announcerment.coffee @@ -0,0 +1,90 @@ +# Copyright 2017-2018 Xuan Sang LE + +# AnTOS Web desktop is is licensed under the GNU General Public +# License v3.0, see the LICENCE file for more information + +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# 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 Announcer + constructor: () -> + @observable = {} + + on: (evtName, callback) -> + @observable[evtName] = { one: [], many: [] } unless @observable[evtName] + @observable[evtName].many.push callback + + one: (evtName, callback) -> + @observable[evtName] = { one: [], many: [] } unless @observable[evtName] + @observable[evtName].one.push callback + + off: (evtName, callback) -> + me = @ + fn = (evt, cb) -> + return unless me.observable[evt] + if cb + for f, i in me.observable[evt].one + if f == cb + me.observable[evt].one.splice i, 1 + break + + for f, i in me.observable[evt].many + if f == cb + me.observable[evt].many.splice i, 1 + break + else + delete me.observable[evt] if me.observable[evt] + if evtName is "*" then fn k, callback for k, v of me.observable else fn evtName, callback + + trigger: (evtName, data) -> + me = @ + trig = (name, d) -> + names = [name, "*"] + for evt in names + continue unless me.observable[evt] + for f, i in me.observable[evt].one + f data + me.observable[evt].one = [] + for f, i in me.observable[evt].many + f data + + if evtName is "*" + trig k, data for k, v of me.observable when k isnt "*" + else + trig evtName, data + +Ant.OS.API.Announcer = Announcer +Ant.OS.announcer = + observable: new Ant.OS.API.Announcer() + quota: 0 + listeners: {} + on: (e, f, a) -> + Ant.OS.announcer.listeners[a.pid] = [] unless Ant.OS.announcer.listeners[a.pid] + Ant.OS.announcer.listeners[a.pid].push { e: e, f: f } + Ant.OS.announcer.observable.on e, f + trigger: (e, d) -> Ant.OS.announcer.observable.trigger e, d + osfail: (m, e, s) -> + Ant.OS.announcer.ostrigger "fail", { m: m, e: e, s: s } + oserror: (m, e, s) -> + Ant.OS.announcer.ostrigger "error", { m: m, e: e, s: s } + osinfo: (m) -> + Ant.OS.announcer.ostrigger "info", { m: m, e: null, s: null } + ostrigger: (e, d) -> + Ant.OS.announcer.trigger e, { id: 0, data: d, name: "OS" } + unregister: (app) -> + return unless Ant.OS.announcer.listeners[app.pid] and Ant.OS.announcer.listeners[app.pid].length > 0 + Ant.OS.announcer.observable.off i.e, i.f for i in Ant.OS.announcer.listeners[app.pid] + delete Ant.OS.announcer.listeners[app.pid] + # Ant.OS.announcer.listeners[app.pid] + getMID: () -> + Ant.OS.announcer.quota += 1 + Ant.OS.announcer.quota \ No newline at end of file diff --git a/src/core/core.coffee b/src/core/core.coffee index 3aaa089..5a26253 100644 --- a/src/core/core.coffee +++ b/src/core/core.coffee @@ -31,31 +31,6 @@ Ant.OS or= appearance: {} VFS: {} system: {} - announcer: - observable: riot.observable() - quota: 0 - listeners: {} - on: (e, f, a) -> - Ant.OS.announcer.listeners[a.pid] = [] unless Ant.OS.announcer.listeners[a.pid] - Ant.OS.announcer.listeners[a.pid].push { e: e, f: f } - Ant.OS.announcer.observable.on e, f - trigger: (e, d) -> Ant.OS.announcer.observable.trigger e, d - osfail: (m, e, s) -> - Ant.OS.announcer.ostrigger "fail", { m: m, e: e, s: s } - oserror: (m, e, s) -> - Ant.OS.announcer.ostrigger "error", { m: m, e: e, s: s } - osinfo: (m) -> - Ant.OS.announcer.ostrigger "info", { m: m, e: null, s: null } - ostrigger: (e, d) -> - Ant.OS.announcer.trigger e, { id: 0, data: d, name: "OS" } - unregister: (app) -> - return unless Ant.OS.announcer.listeners[app.pid] and Ant.OS.announcer.listeners[app.pid].length > 0 - Ant.OS.announcer.observable.off i.e, i.f for i in Ant.OS.announcer.listeners[app.pid] - delete Ant.OS.announcer.listeners[app.pid] - # Ant.OS.announcer.listeners[app.pid] - getMID: () -> - Ant.OS.announcer.quota += 1 - Ant.OS.announcer.quota register: (name, x) -> if x.type is 3 then Ant.OS.GUI.subwindows[name] = x else Ant.OS.APP[name] = x diff --git a/src/core/tags/tag.coffee b/src/core/tags/tag.coffee new file mode 100644 index 0000000..ac159f6 --- /dev/null +++ b/src/core/tags/tag.coffee @@ -0,0 +1,9 @@ +Ant.OS.GUI.tag = {} + +Element.prototype.mount = () -> + Ant.OS.GUI.tag[@tagName](@) if RegExp('afx-*').test(@tagName) and Ant.OS.GUI.tag[@tagName] + +Ant.OS.GUI.tag.define = (name, fn) -> + Ant.OS.GUI.tag[name] = fn + +Ant.OS.GUI.tag.mount = (obj) -> diff --git a/src/core/tags/window-tag.coffee b/src/core/tags/window-tag.coffee new file mode 100644 index 0000000..8ae4838 --- /dev/null +++ b/src/core/tags/window-tag.coffee @@ -0,0 +1,8 @@ + +Ant.OS.GUI.tag.define "afx-window", (tag) -> + childen = $(tag).childen() + @(tag).empty() + $(tag).append( + $("
") + .addClass("afx-window-wrapper") + .append()) \ No newline at end of file diff --git a/src/packages/ShowCase/Makefile b/src/packages/ShowCase/Makefile new file mode 100644 index 0000000..03af4c6 --- /dev/null +++ b/src/packages/ShowCase/Makefile @@ -0,0 +1,11 @@ +coffee_files = coffees/main.coffee + +jsfiles = + +cssfiles = + +copyfiles = assets/scheme.html package.json + + +PKG_NAME=ShowCase +include ../pkg.mk \ No newline at end of file diff --git a/src/packages/ShowCase/assets/scheme.html b/src/packages/ShowCase/assets/scheme.html new file mode 100644 index 0000000..1e844c5 --- /dev/null +++ b/src/packages/ShowCase/assets/scheme.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/packages/ShowCase/coffees/main.coffee b/src/packages/ShowCase/coffees/main.coffee new file mode 100644 index 0000000..99ccccf --- /dev/null +++ b/src/packages/ShowCase/coffees/main.coffee @@ -0,0 +1,36 @@ +Ant = this +class ShowCase extends this.OS.GUI.BaseApplication + constructor: (args) -> + super "ShowCase", args + + main:() -> + me = @ + @announcer = new Ant.OS.API.Announcer() + @announcer.on "evt1", (data) -> + console.log "evt1", data + @announcer.on "evt1", (data) -> + console.log "evt1 fn1: ", data + fn = (data) -> + console.log "evt1 fn2: ", data + @announcer.on "evt1", fn + @announcer.on "evt2", (data) -> + console.log "evt2", data + @announcer.one "evt1", (data) -> + console.log "evt1 only one", data + @announcer.one "*", (data) -> + console.log "evt1 only one*", data + @announcer.on "*", fn + + console.log me.announcer + @on "btclick", (e) -> + me.announcer.trigger("evt1", "Hello 1") + me.announcer.off("*") + me.announcer.trigger("evt2", "Hello 2") + console.log me.announcer + me.notify "Hello" + tag = new Ant.OS.GUI.tags["afx-window"]() + console.log tag + + +ShowCase.singleton = false +this.OS.register "ShowCase", ShowCase \ No newline at end of file diff --git a/src/packages/ShowCase/package.json b/src/packages/ShowCase/package.json new file mode 100644 index 0000000..b6a19df --- /dev/null +++ b/src/packages/ShowCase/package.json @@ -0,0 +1,13 @@ +{ + "app":"ShowCase", + "name": "ShowCase", + "description":"AntOS 1.1.0a features showcase", + "info":{ + "author": "Xuan Sang LE", + "email": "xsang.le@gmail.com", + "licences": "GPLv3" + }, + "version":"0.0.1-a", + "category":"Other", + "mimes":["none"] +} \ No newline at end of file