/**
 * Copyright: (c) 2017 Max Klein
 * License: MIT
 */

define([
	'lib/EventEmitter',
	'lib/extend'
], function (EventEmitter, extend) {
	var TOOL_SELECT = 0;
	var TOOL_CONNECT = 1;
	var TOOL_PAN = 2;

	function EditorTools(app) {
		EventEmitter.call(this);

		this.app = app;

		this.currentTool = TOOL_SELECT;
		this.running = false;

		this.$run = document.getElementById('toolbar-run');
		this.$stop = document.getElementById('toolbar-stop');
		this.$pause = document.getElementById('toolbar-pause');

		this.registerListeners();
	}

	extend(EditorTools, EventEmitter);

	EditorTools.prototype.registerListeners = function () {
		var self = this;

		this.$run.addEventListener('click', function () {
			if(self.running) {
				self.$run.disabled = true;
				self.$pause.disabled = false;

				self.emit('resume');
			} else {
				self.running = true;

				self.$run.disabled = true;
				self.$stop.disabled = false;
				self.$pause.disabled = false;

				self.emit('run');
			}
		});

		this.$stop.addEventListener('click', function () {
			self.running = false;

			self.$run.disabled = false;
			self.$pause.disabled = true;
			self.$stop.disabled = true;

			self.emit('stop');
		});

		this.$pause.addEventListener('click', function () {
			self.$run.disabled = false;
			self.$pause.disabled = true;

			self.emit('pause');
		});

		document.getElementById('toolbar-tool-select').addEventListener('click', function (evt) {
			self.setTool(TOOL_SELECT);
		});

		document.getElementById('toolbar-tool-connect').addEventListener('click', function (evt) {
			if(!self.running) {
				self.setTool(TOOL_CONNECT);
			}
		});

		document.getElementById('toolbar-tool-pan').addEventListener('click', function (evt) {
			if(!self.running) {
				self.setTool(TOOL_PAN);
			}
		});

		document.getElementById('toolbar-action-delete').addEventListener('click', function () {
			self.emit('action-delete');
		});
	};

	EditorTools.prototype.setTool = function (tool) {
		if(this.currentTool !== tool) {
			var prev = this.currentTool;
			this.currentTool = tool;
			this.emit('tool-changed', tool, prev);
		}
	};

	EditorTools.TOOL_SELECT = TOOL_SELECT;
	EditorTools.TOOL_CONNECT = TOOL_CONNECT;
	EditorTools.TOOL_PAN = TOOL_PAN;

	return EditorTools;
});

@@ -499,16 +499,292 @@
 pause');
+%0A%09%09this.$toolSelect = document.getElementById('toolbar-tool-select');%0A%09%09this.$toolConnect = document.getElementById('toolbar-tool-connect');%0A%09%09this.$toolPan = document.getElementById('toolbar-tool-pan');%0A%09%09this.$actionDelete = document.getElementById('toolbar-action-delete');
 %0A%0A%09%09this
@@ -1217,32 +1217,185 @@
 abled = false;%0A%0A
+%09%09%09%09self.$toolSelect.disabled = true;%0A%09%09%09%09self.$toolConnect.disabled = true;%0A%09%09%09%09self.$toolPan.disabled = true;%0A%09%09%09%09self.$actionDelete.disabled = true;%0A%0A
 %09%09%09%09self.emit('r
@@ -1578,32 +1578,185 @@
 sabled = true;%0A%0A
+%09%09%09self.$toolSelect.disabled = false;%0A%09%09%09self.$toolConnect.disabled = false;%0A%09%09%09self.$toolPan.disabled = false;%0A%09%09%09self.$actionDelete.disabled = false;%0A%0A
 %09%09%09self.emit('st
@@ -1922,54 +1922,24 @@
 %0A%0A%09%09
-document.getElementById('toolbar-
+this.$
 tool
--s
+S
 elect
-')
 .add
@@ -2021,55 +2021,25 @@
 %0A%0A%09%09
-document.getElementById('toolbar-tool-c
+this.$toolC
 onnect
-')
 .add
@@ -2082,32 +2082,8 @@
 ) %7B%0A
-%09%09%09if(!self.running) %7B%0A%09
 %09%09%09s
@@ -2109,21 +2109,16 @@
 NNECT);%0A
-%09%09%09%7D%0A
 %09%09%7D);%0A%0A%09
@@ -2122,51 +2122,21 @@
 %0A%0A%09%09
-document.getElementById('toolbar-tool-pan')
+this.$toolPan
 .add
@@ -2179,32 +2179,8 @@
 ) %7B%0A
-%09%09%09if(!self.running) %7B%0A%09
 %09%09%09s
@@ -2202,21 +2202,16 @@
 L_PAN);%0A
-%09%09%09%7D%0A
 %09%09%7D);%0A%0A%09
@@ -2215,56 +2215,26 @@
 %0A%0A%09%09
-document.getElementById('toolbar-
+this.$
 action
--d
+D
 elete
-')
 .add

Disable tool and action buttons when starting simulation