From 56cf8ea770ab5ee7c56aaa0f0d90e6476483724c Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Mon, 12 Mar 2018 22:47:23 +0100 Subject: [PATCH] fix File bug --- src/core/api.coffee | 31 ++++++++++++++++++++++++++++++- src/core/tags/afx-switch.tag | 5 ++--- src/packages/Files/main.coffee | 15 ++++++++------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/core/api.coffee b/src/core/api.coffee index dd421c5..69809fd 100644 --- a/src/core/api.coffee +++ b/src/core/api.coffee @@ -310,4 +310,33 @@ self.OS.API = catch e err = e return "" if not err - return err \ No newline at end of file + return err +# utilities functioncs + switcher: () -> + o = {} + p = {} + p[arguments[i]] = false for i in [0..arguments.length - 1 ] + Object.defineProperty o, "__p", { + enumerable: false, + value: p + } + fn = (o, v) -> + Object.defineProperty o, v, { + enumerable: true, + set: (value) -> + for k,l of @__p + @__p[k] = false + o.__p[v] = value + , get: () -> + return o.__p[v] + } + for k, v of o.__p + fn o, k + Object.defineProperty o, "selected", { + configurable: true, + enumerable: false, + get: () -> + for k,v of o.__p + return k if v + } + return o \ No newline at end of file diff --git a/src/core/tags/afx-switch.tag b/src/core/tags/afx-switch.tag index 153b32b..feb3901 100644 --- a/src/core/tags/afx-switch.tag +++ b/src/core/tags/afx-switch.tag @@ -32,11 +32,10 @@ self.update() } /*this.on("mount", function(){ - self.root.observable = (self.parent && self.parent.root && self.parent.root.observable) || opts.observable || riot.observable() + })*/ this.on("update", function(e){ - self.swon = opts.swon - self.onchange = opts.onchange + self.swon = typeof opts.swon == "function"?opts.swon():opts.swon }) toggle(e) { diff --git a/src/packages/Files/main.coffee b/src/packages/Files/main.coffee index e0ba38e..8a839bf 100644 --- a/src/packages/Files/main.coffee +++ b/src/packages/Files/main.coffee @@ -11,7 +11,8 @@ class Files extends this.OS.GUI.BaseApplication @currdir = if @args and @args.length > 0 then @args[0].asFileHandler() else "home://".asFileHandler() @favo = @find "favouri" @clipboard = undefined - + @viewType = @_api.switcher "icon", "list", "tree" + @viewType.list = true @apps = [] @view.contextmenuHandler = (e, m) -> @@ -79,10 +80,10 @@ class Files extends this.OS.GUI.BaseApplication (@find "btgrid").set "onbtclick", (e) -> me.view.set 'view', "icon" - me.setting.view = "icon" + me.viewType.icon = true (@find "btlist").set "onbtclick", (e) -> me.view.set 'view', "list" - me.setting.view = "list" + me.viewType.list = true @chdir null applySetting: (k) -> @@ -153,12 +154,12 @@ class Files extends this.OS.GUI.BaseApplication { text: "__(Navigation bar)", switch: true, checked: @setting.nav, dataid: "#{@name}-nav" }, { text: "__(Hidden files)", switch: true, checked: @setting.showhidden, dataid: "#{@name}-hidden" }, { text: "__(Type)", child: [ - { text: "__(Icon view)", radio: true, checked: @setting.view is 'icon', dataid: "#{@name}-icon", type: 'icon' }, - { text: "__(List view)", radio:true, checked: @setting.view is 'list' or not @setting.view, dataid: "#{@name}-list", type: 'list' }, - { text: "__(Tree view)", radio:true, checked: @setting.view is 'tree', dataid: "#{@name}-tree", type: 'tree' } + { text: "__(Icon view)", radio: true, checked: (() -> me.viewType.icon), dataid: "#{@name}-icon", type: 'icon' }, + { text: "__(List view)", radio:true, checked: (() -> me.viewType.list), dataid: "#{@name}-list", type: 'list' }, + { text: "__(Tree view)", radio:true, checked: (() -> me.viewType.tree), dataid: "#{@name}-tree", type: 'tree' } ], onmenuselect: (e) -> me.view.set 'view', e.item.data.type - me.setting.view = e.item.data.type + me.viewType[e.item.data.type] = true }, ], onmenuselect: (e) -> me.actionView e },