From 7f39f086191393f2815e18607dfbfbfc05d37472 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 8 Nov 2020 15:41:45 +0100 Subject: [PATCH] Add animation file context menu to unload file --- js/animations/animation.js | 26 +++++++++++++++++++++++--- lang/en.json | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/js/animations/animation.js b/js/animations/animation.js index 05892231..c85ac27a 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -378,7 +378,7 @@ class Animation { } return this; } - remove(undo) { + remove(undo, remove_from_file = true) { if (undo) { Undo.initEdit({animations: [this]}) } @@ -389,7 +389,7 @@ class Animation { if (undo) { Undo.finishEdit('remove animation', {animations: []}) - if (isApp && this.path && fs.existsSync(this.path)) { + if (isApp && remove_from_file && this.path && fs.existsSync(this.path)) { Blockbench.showMessageBox({ translateKey: 'delete_animation', icon: 'movie', @@ -575,12 +575,29 @@ class Animation { } }, 'duplicate', + 'rename', 'delete', '_', {name: 'menu.animation.properties', icon: 'list', click: function(animation) { animation.propertiesDialog(); }} ]) + Animation.prototype.file_menu = new Menu([ + {name: 'menu.animation_file.unload', icon: 'clear_all', click: function(id) { + let animations_to_remove = []; + Animation.all.forEach(animation => { + if (animation.path == id && animation.saved) { + animations_to_remove.push(animation); + } + }) + if (!animations_to_remove.length) return; + Undo.initEdit({animations: animations_to_remove}) + animations_to_remove.forEach(animation => { + animation.remove(false, false); + }) + Undo.finishEdit('remove animation', {animations: []}) + }} + ]) new Property(Animation, 'boolean', 'saved', {default: true}) new Property(Animation, 'string', 'path') @@ -1800,6 +1817,9 @@ Interface.definePanels(function() { name: other_animation && other_animation.name.replace(/\w+$/, 'new'), path }).add(true).propertiesDialog() + }, + showFileContextMenu(event, id) { + Animation.prototype.file_menu.open(event, id); } }, computed: { @@ -1822,7 +1842,7 @@ Interface.definePanels(function() {