From 33eab1d30a44daba3747381c2aabcda97a71b6cc Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Tue, 19 May 2020 23:29:31 +0200 Subject: [PATCH] support drag and drop in file --- src/core/core.coffee | 2 +- src/core/tags/FileViewTag.coffee | 2 ++ src/core/tags/ListViewTag.coffee | 41 ++++++++++++++++++++++++++ src/core/tags/TreeViewTag.coffee | 1 - src/packages/CoreServices/package.json | 3 +- src/packages/Files/main.coffee | 13 ++++++++ src/packages/MarketPlace/main.coffee | 11 +++++-- 7 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/core/core.coffee b/src/core/core.coffee index 6743d52..bd3be92 100644 --- a/src/core/core.coffee +++ b/src/core/core.coffee @@ -33,7 +33,7 @@ Ant.OS or= system: {} register: (name, x) -> if x.type is 3 then Ant.OS.GUI.subwindows[name] = x else Ant.OS.APP[name] = x - + # import proprety from an App diff --git a/src/core/tags/FileViewTag.coffee b/src/core/tags/FileViewTag.coffee index d736515..e07a746 100644 --- a/src/core/tags/FileViewTag.coffee +++ b/src/core/tags/FileViewTag.coffee @@ -50,6 +50,7 @@ class FileViewTag extends Ant.OS.GUI.BaseTag __ondragndrop__: (v) -> @refs.treeview.set "ondragndrop", v + @refs.listview.set "ondragndrop", v sortByType: (a, b) -> if a.type < b.type @@ -187,6 +188,7 @@ class FileViewTag extends Ant.OS.GUI.BaseTag .catch (e) -> reject e @refs.gridview.set "header", @header @refs.treeview.set "dragndrop", true + @refs.listview.set "dragndrop", true # even handles @refs.listview.set "onlistselect", (e) => @fileselect e.data.item.get("data") diff --git a/src/core/tags/ListViewTag.coffee b/src/core/tags/ListViewTag.coffee index 0d74a1d..c7fbf91 100644 --- a/src/core/tags/ListViewTag.coffee +++ b/src/core/tags/ListViewTag.coffee @@ -21,6 +21,7 @@ class ListViewItemTag extends Ant.OS.GUI.BaseTag @get("onselect")({ item: @root }) mount: () -> + $(@refs.item).attr "dataref", "afx-list-item" $(@refs.item).contextmenu (e) => e.item = @root @get("oncontextmenu")(e) @@ -73,6 +74,7 @@ class ListViewTag extends Ant.OS.GUI.BaseTag super r, o @setopt "onlistselect", () -> @setopt "onlistdbclick", () -> + @setopt "ondragndrop", () -> @setopt "onitemclose", () -> true @setopt "buttons", [] @setopt "data", [] @@ -82,6 +84,7 @@ class ListViewTag extends Ant.OS.GUI.BaseTag @setopt "selectedItem", undefined @setopt "selectedItems", [] @setopt "selected", -1 + @setopt "dragndrop", false $(@root) .css "display", "flex" .css "flex-direction", "column" @@ -173,6 +176,9 @@ class ListViewTag extends Ant.OS.GUI.BaseTag $( @refs.mlist).empty() for item in data @push item, false + $(@refs.container).off "mousedown", @onmousedown + if @__("dragndrop") and not @__("dropdown") + $(@refs.container).on "mousedown", @onmousedown unselect: () -> @@ -223,6 +229,41 @@ class ListViewTag extends Ant.OS.GUI.BaseTag @observable.trigger "listselect", evt mount: () -> + @dnd = {} + @onmousedown = (e) => + el = $(e.target).closest("li[dataref='afx-list-item']") + return if el.length is 0 + el = el.parent()[0] + @dnd.from = el + @dnd.to = undefined + $(window).on "mouseup", @onmouseup + $(window).on "mousemove", @onmousemove + + @onmouseup = (e) => + $(window).off "mouseup", @onmouseup + $(window).off "mousemove", @onmousemove + ($ "#systooltip").hide() + el = $(e.target).closest("li[dataref='afx-list-item']") + return if el.length is 0 + el = el.parent()[0] + return if el is @dnd.from + @dnd.to = el + @__("ondragndrop") { id: @aid(), data: @dnd } + @dnd = {} + + @onmousemove = (e) => + return unless e + return unless @dnd.from + data = @dnd.from.get("data") + $label = $("#systooltip") + top = e.clientY + 5 + left = e.clientX + 5 + $label.show() + $label[0].set "*", data + $label + .css "top", top + "px" + .css "left", left + "px" + $(@refs.btlist).hide() @observable.on "resize", (e) => @calibrate() @calibrate() diff --git a/src/core/tags/TreeViewTag.coffee b/src/core/tags/TreeViewTag.coffee index 38ba7ad..212d2b0 100644 --- a/src/core/tags/TreeViewTag.coffee +++ b/src/core/tags/TreeViewTag.coffee @@ -220,7 +220,6 @@ class TreeViewTag extends Ant.OS.GUI.BaseTag return if el.length is 0 el = el[0] return if el is @root - e.source = el @dnd.from = el @dnd.to = undefined $(window).on "mouseup", @treemouseup diff --git a/src/packages/CoreServices/package.json b/src/packages/CoreServices/package.json index dbcbc5e..078e818 100644 --- a/src/packages/CoreServices/package.json +++ b/src/packages/CoreServices/package.json @@ -1,7 +1,8 @@ { "app":null, + "className": "CoreServices", "services": [ "Calendar", "PushNotification" ], - "name":"CoreServices", + "name": "Core services", "description":"This is the core services", "info":{ "author": "Xuan Sang LE", diff --git a/src/packages/Files/main.coffee b/src/packages/Files/main.coffee index fd56f1a..128c483 100644 --- a/src/packages/Files/main.coffee +++ b/src/packages/Files/main.coffee @@ -83,6 +83,19 @@ class Files extends this.OS.GUI.BaseApplication resolve d.result .catch (e) -> reject e + @view.set "ondragndrop", (e) => + return unless e + src = e.data.from.get("data") + des = e.data.to.get("data") + return if des.type is "file" + file = src.path.asFileHandle() + file.move "#{des.path}/#{file.basename}" + .then () => + @view.set "path", @view.get("path") + @view.update file.parent().path + @view.update des.path + .catch (e) => @error __("Unable to move: {0} -> {1}", src.path, des.path), e + @setting.sidebar = true if @setting.sidebar is undefined @setting.nav = true if @setting.nav is undefined @setting.showhidden = false if @setting.showhidden is undefined diff --git a/src/packages/MarketPlace/main.coffee b/src/packages/MarketPlace/main.coffee index 56d8e81..3558adf 100644 --- a/src/packages/MarketPlace/main.coffee +++ b/src/packages/MarketPlace/main.coffee @@ -54,7 +54,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication @btinstall.set "onbtclick", (e) => if @btinstall.get "dirty" - return @update() + return @updatePackage() .then () => @notify __("Package updated") .catch (e) => @error e.toString(), e @remoteInstall() @@ -108,7 +108,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication list = [] for k, v of pkgcache list.push { - className: v.app, + className: if v.app then v.app else v.className, name: v.name, text: v.name, icon: v.icon, @@ -293,6 +293,11 @@ class MarketPlace extends this.OS.GUI.BaseApplication if r.error return reject @_api.throwe __("Cannot uninstall package: {0}", r.error) @notify __("Package uninstalled") + # stop all the services if any + if app.services + for srv in app.services + @_gui.unloadApp srv + delete @systemsetting.system.packages[name] @_gui.unloadApp name if sel.download @@ -304,7 +309,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication .catch (e) -> reject e .catch (e) -> reject e - update: () -> + updatePackage: () -> new Promise (resolve, reject) => @uninstall().then () => @remoteInstall()