From f8de6162d17e9a7689efc3b2420888062799b86c Mon Sep 17 00:00:00 2001 From: tmrdja Date: Sun, 30 Mar 2014 19:38:54 +0200 Subject: [PATCH] Added contextmenu Added contextmenu with Delete and Duplicate button --- app/views/editor/level/thangs_tab_view.coffee | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index e0af8ddc4..f62f8c90a 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -48,6 +48,8 @@ module.exports = class ThangsTabView extends View events: 'click #extant-thangs-filter button': 'onFilterExtantThangs' + 'click #delete': 'onDeleteClicked' + 'click #duplicate': 'onDuplicateClicked' shortcuts: 'esc': 'selectAddThang' @@ -61,6 +63,7 @@ module.exports = class ThangsTabView extends View @thangTypes = @supermodel.getCollection new ThangTypeSearchCollection() # should load depended-on Components, too @thangTypes.once 'sync', @onThangTypesLoaded @thangTypes.fetch() + $(document).bind 'contextmenu', @preventDefaultContextMenu # just loading all Components for now: https://github.com/codecombat/codecombat/issues/405 @componentCollection = @supermodel.getCollection new ComponentsCollection() @@ -419,6 +422,29 @@ module.exports = class ThangsTabView extends View @onThangsChanged() @$el.find('.thangs-column').show() + preventDefaultContextMenu: (e) -> + e.preventDefault() + + onSpriteContextMenu: (e) -> + {clientX, clientY} = e.originalEvent.nativeEvent + if @addThangType + $('#duplicate a').html 'Stop Duplicate' + else + $('#duplicate a').html 'Duplicate' + $('#contextmenu').css { position: 'fixed', left: clientX, top: clientY } + $('#contextmenu').show() + + onDeleteClicked: (e) -> + $('#contextmenu').hide() + @deleteSelectedExtantThang e + + onDuplicateClicked: (e) -> + $('#contextmenu').hide() + if !@addThangType + thang = @selectedExtantThang.spriteName + e.target = $(".add-thang-palette-icon[data-thang-type='" + thang + "']").get 0 + @selectAddThang e + class ThangsNode extends TreemaNode.nodeMap.array valueClass: 'treema-array-replacement'