From ce6aa806796a36068c0a81b9baecfdaffb4e4aa1 Mon Sep 17 00:00:00 2001
From: Max <m.giller.dev@gmail.com>
Date: Thu, 15 Jul 2021 13:11:34 +0200
Subject: [PATCH] Implemented activate and deactivate events

---
 editor/js/state.js      |  4 ++++
 editor/js/tools/tool.js | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/editor/js/state.js b/editor/js/state.js
index 4d46c5e..9e36c27 100644
--- a/editor/js/state.js
+++ b/editor/js/state.js
@@ -34,9 +34,13 @@ class State extends Tool {
             return;
         }
 
+        this.tool.onToolDeactivate(tool);
+
         this.previousTool = this.tool;
         this.tool = tool;
         this.display.setSelectedTool(tool);
+
+        this.tool.onToolActivate();
     }
 
     setSelectedItem(item) {
diff --git a/editor/js/tools/tool.js b/editor/js/tools/tool.js
index babede8..76b9ea6 100644
--- a/editor/js/tools/tool.js
+++ b/editor/js/tools/tool.js
@@ -18,6 +18,18 @@ class Tool {
         return this.icon;
     }
 
+    onToolActivate() {
+        if (this.warnings) {
+            console.warn('Method "onToolActivate" not implemented.');
+        }
+    }
+
+    onToolDeactivate(nextTool) {
+        if (this.warnings) {
+            console.warn('Method "onToolDeactivate" not implemented.');
+        }
+    }
+
     onNodeClick(node) {
         if (this.warnings) {
             console.warn('Method "onNodeClick" not implemented.');
-- 
GitLab