Browse Source

Implement new expressions

Igor 5 years ago
parent
commit
888097a8ca

+ 1 - 1
.ima_version.json

@@ -1 +1 @@
-{ "version":"2019_04_29 13_09" }
+{ "version":"2019_05_09 14_16" }

File diff suppressed because it is too large
+ 305 - 139
build/ivprog.bundle.js


File diff suppressed because it is too large
+ 1 - 1
build/ivprog.bundle.js.map


+ 39 - 2
css/ivprog-visual-1.0.css

@@ -884,7 +884,7 @@ div.ui.checkbox.transition.visible {
 }
 
 .add_parentheses {
-	margin-left: 40px;
+	margin-left: 20px;
 }
 
 .temp_class {
@@ -945,7 +945,6 @@ div.ui.checkbox.transition.visible {
 	min-height: 10px;
 
     position: absolute;
-    z-index: 99;
     margin-left: -10px;
     margin-top: -5px;
     padding-left: 5px;
@@ -955,4 +954,42 @@ div.ui.checkbox.transition.visible {
     border: 2px solid green !important;
     box-shadow: #8f8f8f 2px 2px !important;
     background: #d8ffd8 !important;
+}
+
+.ui.button.green.add_expression {
+	padding: 2px;
+    padding-top: 5px;
+    padding-bottom: 5px;
+    margin-left: 5px;
+    padding-left: 10px;
+}
+.ui.button.green.add_expression i {
+	font-size: 110%;
+}
+.simple_add {
+	display: inline;
+}
+.lixeira {
+	position: absolute;
+	top: 300px;
+	left: 200px;
+	height: 100px;
+	background-image: url('../img/trash-icon.png');
+	width: 125px !important;
+    background-position: 0;
+    background-repeat: no-repeat;
+    display: none;
+}
+.lixeira .trash {
+	font-size: 3em;
+}
+.color_test {
+	background-color: green;
+}
+.parentheses_fixed {
+	background-color: #617063 !important;
+	color: white !important;
+}
+.parentheses_in_expression {
+	cursor: pointer;
 }

BIN
img/trash-icon.png


+ 32 - 12
js/visualUI/code_generator.js

@@ -165,7 +165,8 @@ function returnsCode (command_obj, indentation) {
 
 	if (command_obj.variable_value_menu) {
 		try {
-			ret += ' ' + variableValueMenuCode(command_obj.variable_value_menu, true);
+			ret += ' ' + elementExpressionCode(command_obj.variable_value_menu);
+			//ret += ' ' + variableValueMenuCode(command_obj.variable_value_menu, true);
 		} catch(err) {}
 	}
 
@@ -251,14 +252,16 @@ function repeatNtimesCode (command_obj, indentation) {
 
 
 	if (command_obj.expression2) {
-		switch (command_obj.expression2.expression.type) {
+		/*switch (command_obj.expression2.expression.type) {
 			case Models.EXPRESSION_TYPES.exp_logic:
 				ret += logicExpressionCode(command_obj.expression2.expression);
 				break;
 			case Models.EXPRESSION_TYPES.exp_arithmetic:
 				ret += arithmeticExpressionCode(command_obj.expression2.expression);
 				break;
-		}
+		}*/
+
+		ret += elementExpressionCode(command_obj.expression2);
 	}
 
 	ret += ' ; ';
@@ -315,18 +318,22 @@ function iftruesCode (command_obj, indentation) {
 
 	ret += LocalizedStrings.getUI('text_if');
 
-	if (!command_obj.expression.expression) {
+	if (!command_obj.expression) {
 		Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI('inform_valid_expression'));
+	} else {
+		ret += ' ( ';
+		ret += elementExpressionCode(command_obj.expression);
+		ret += ' ) ';
 	}
 
-	switch (command_obj.expression.expression.type) {
+	/*switch (command_obj.expression.expression.type) {
 		case Models.EXPRESSION_TYPES.exp_logic:
 			ret += logicExpressionCode(command_obj.expression.expression);
 			break;
 		case Models.EXPRESSION_TYPES.exp_arithmetic:
 			ret += arithmeticExpressionCode(command_obj.expression.expression);
 			break;
-	}
+	}*/
 
 	ret += ' { ';
 
@@ -382,17 +389,23 @@ function doWhilesCode (command_obj, indentation) {
 
 	ret += '} ' + LocalizedStrings.getUI('text_code_while');
 
-	if (!command_obj.expression.expression) {
+	if (!command_obj.expression) {
 		Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI('inform_valid_expression'));
 	}
 
-	switch (command_obj.expression.expression.type) {
+	/*switch (command_obj.expression.expression.type) {
 		case Models.EXPRESSION_TYPES.exp_logic:
 			ret += logicExpressionCode(command_obj.expression.expression);
 			break;
 		case Models.EXPRESSION_TYPES.exp_arithmetic:
 			ret += arithmeticExpressionCode(command_obj.expression.expression);
 			break;
+	}*/
+
+	if (command_obj.expression) {
+		ret += ' ( ';
+		ret += elementExpressionCode(command_obj.expression);
+		ret += ' ) ';
 	}
 
 	return ret;
@@ -408,17 +421,22 @@ function whiletruesCode (command_obj, indentation) {
 
 	ret += LocalizedStrings.getUI('text_code_while');
 
-	if (!command_obj.expression.expression) {
+	if (!command_obj.expression) {
 		Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI('inform_valid_expression'));
 	}
 
-	switch (command_obj.expression.expression.type) {
+	/*switch (command_obj.expression.expression.type) {
 		case Models.EXPRESSION_TYPES.exp_logic:
 			ret += logicExpressionCode(command_obj.expression.expression);
 			break;
 		case Models.EXPRESSION_TYPES.exp_arithmetic:
 			ret += arithmeticExpressionCode(command_obj.expression.expression);
 			break;
+	}*/
+	if (command_obj.expression) {
+		ret += ' ( ';
+		ret += elementExpressionCode(command_obj.expression);
+		ret += ' ) ';
 	}
 
 	ret += ' { ';
@@ -714,13 +732,15 @@ function writersCode (command_obj, indentation) {
 	
 	ret += LocalizedStrings.getUI('text_command_write') + ' ( ';
 
-	for (var i = 0; i < command_obj.content.length; i++) {
+	/*for (var i = 0; i < command_obj.content.length; i++) {
 		ret += variableValueMenuCode(command_obj.content[i]);
 
 		if ((i + 1) < command_obj.content.length) {
 			ret += ' + ';
 		}
-	}
+	}*/
+
+	ret += elementExpressionCode(command_obj.content);
 
 	ret += ' ) ';
 	return ret;

+ 5 - 5
js/visualUI/commands.js

@@ -482,18 +482,18 @@ export function genericCreateCommand (command_type) {
 			return new Models.FunctionCall(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false), null);
 
 		case Models.COMMAND_TYPES.iftrue:
-			return new Models.IfTrue(new Models.ConditionalExpression(null), null, null);
+			return new Models.IfTrue([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)]);
 
 		case Models.COMMAND_TYPES.repeatNtimes:
 			return new Models.RepeatNTimes(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false), 
 											new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),
-										     null, new Models.ConditionalExpression(null), null, null);
+										     null, [new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)], null, null);
 
 		case Models.COMMAND_TYPES.whiletrue:
-			return new Models.WhileTrue(new Models.ConditionalExpression(null), null);
+			return new Models.WhileTrue([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)], null);
 
 		case Models.COMMAND_TYPES.dowhiletrue:
-			return new Models.DoWhileTrue(new Models.ConditionalExpression(null), null);
+			return new Models.DoWhileTrue([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)], null);
 
 		case Models.COMMAND_TYPES.switch:
 
@@ -502,7 +502,7 @@ export function genericCreateCommand (command_type) {
 			return new Models.Switch(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.variable_and_function, null, null, null, true), sc);
 
 		case Models.COMMAND_TYPES.return:
-			return new Models.Return(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
+			return new Models.Return([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)]);
 	}
 }
 

+ 6 - 1
js/visualUI/commands/dowhiletrue.js

@@ -7,6 +7,7 @@ import * as VariablesManagement from '../variables';
 import * as CommandsManagement from '../commands';
 import * as ConditionalExpressionManagement from './conditional_expression';
 import * as ContextualizedMenu from './contextualized_menu';
+import * as GenericExpressionManagement from './generic_expression';
 
 export function createFloatingCommand () {
 	return $('<div class="ui dowhiletrue created_element"> <i class="ui icon small sync"></i> <span> '+ LocalizedStrings.getUI('text_command_do') +' <br> ' + LocalizedStrings.getUI('text_code_while') +'(x < 10) </span></div>');
@@ -28,7 +29,11 @@ export function renderCommand (command, function_obj) {
 
 	ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el);
 
-	ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
+	//ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
+
+	if (command.expression) {
+		GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression);
+	}
 
 	if (command.commands_block) {
 		for (var j = 0; j < command.commands_block.length; j++) {

+ 195 - 59
js/visualUI/commands/generic_expression.js

@@ -40,6 +40,12 @@ export function renderExpression (command, function_obj, div_to_render, expressi
 		} else {
 			div_to_render.text(LocalizedStrings.getUI('var_menu_select_var').toLowerCase());
 		}
+	} else {
+		var types_included = [];
+		types_included.push(Models.EXPRESSION_TYPES.exp_conditional);
+		types_included.push(Models.EXPRESSION_TYPES.exp_logic);
+		types_included.push(Models.EXPRESSION_TYPES.exp_arithmetic);
+		renderElements(command, function_obj, div_to_render, expression_array, types_included);
 	}
 
 	div_to_render.children('.mouse_distance').addClass('mouse_distance_hidden');
@@ -55,49 +61,147 @@ export function renderExpression (command, function_obj, div_to_render, expressi
 			$(this).children('.mouse_distance').css('opacity', '0');
 		}
 	});
+	var lixeira = $('<div class="lixeira" draggable="true"></div>');
 
-	/*var allfilhos = div_to_render.children('.mouse_distance');
-	console.log(allfilhos);
-	var boudings = [];
-	for (var i = 0; i < allfilhos.length; i++) {
-		boudings.push(allfilhos.get(i).getBoundingClientRect());
-	}
-
-	div_to_render.children('.mouse_distance').addClass('mouse_distance_hidden');
+	div_to_render.find('.single_element_expression').on('mousedown', function (evt) {
+		window.posX = evt.clientX;
+		window.posY = evt.clientY;
+	});
 	
-	div_to_render.on('mousemove mouseenter', function(evt) {
-		if (!window.open_or_close && command.variable.content) {
-
-			
-			var leftDistances = [];
-			var rightDistances = [];
-
-			for (var i = 0; i < allfilhos.length; i++) {
-				var leftD = Math.abs(boudings[i].left - evt.clientX);
-				leftDistances.push(leftD);
-				var rightD = Math.abs(boudings[i].right - evt.clientX);
-				rightDistances.push(rightD);
-			}
+	Sortable.create(div_to_render[0], {
+	    animation: 100,
+	    ghostClass: 'ghost',
+	    group: {
+	        name: 'shared',
+	        put: false // Do not allow items to be put into this list
+	    },
+	    draggable: '.single_element_expression',
+	    sort: false,
+	    filter: '.not_allowed',
+	    
+	    onStart: function(event) {
+	    	$('body').append(lixeira);
+	    	lixeira.css('display', 'block');
+			lixeira.css('top', window.posY + 70, '!important');
+			lixeira.css('left', window.posX - 20, '!important');
+	    },
+	    onMove: function(event) {
+	    	lixeira.addClass('color_test');
+	    },
+	    onEnd: function(event) {
+	    	lixeira.remove();
+	    	div_to_render.find('.ghost').removeClass('ghost');
+	    }
+  	});
+  	new Sortable(lixeira[0], {
+	    group: 'shared',
+	    animation: 150,
+	    onAdd: function (evt) {
+	       lixeira.css('display', 'none');
+	       lixeira.find('.single_element_expression').remove();
+	       lixeira.css('background-color', '');
+	       lixeira.remove();
+	       removeElement(evt, expression_array);
+	       renderExpression(command, function_obj, div_to_render, expression_array);
+	    }
+	});
+}
 
-			div_to_render.children('.mouse_distance').removeClass('mouse_distance_except');
-			div_to_render.children('.mouse_distance').addClass('mouse_distance_hidden');
-			
-			var menorLeft = Math.min.apply(null, leftDistances);
-			var indiceLeft = leftDistances.indexOf(menorLeft);
+function removeElement (event, expression_array) {
+	var indice = $(event.item).data('index');
+	var first = expression_array[0];
+	console.log('indice: ', indice);
+	if (expression_array[indice].type) {
+		// if is alone in expression:
+		if (expression_array.length == 1) {
+			//function_obj.commands.splice(function_obj.commands.indexOf(command), 1);
+			expression_array.splice(0, 1);
+		} else if (expression_array.length > 1) {
+			if (indice > 0 && expression_array[indice - 1].type_op) {
+				if (indice < (expression_array.length) 
+					&& expression_array[indice - 2] == '('
+					&& expression_array[indice + 1].type_op) {
+					expression_array.splice(indice + 1, 1);
+				}
+				expression_array.splice(indice, 1);
+				expression_array.splice(indice - 1, 1);
+				if (indice - 2 < (expression_array.length) 
+					&& expression_array[indice - 2] == '('
+					&& expression_array[indice - 1] == ')') {
+					expression_array.splice(indice - 1, 1);
+					expression_array.splice(indice - 2, 1);
+					if (indice - 3 >= 0 && indice - 3 < expression_array.length
+						&& expression_array[indice - 3].type_op ) {
+						expression_array.splice(indice - 3, 1);
+					}
+				}
+			} else if (indice < (expression_array.length - 1) &&  expression_array[indice + 1].type_op) {
+				expression_array.splice(indice + 1, 1);
+				expression_array.splice(indice, 1);
+			} else if (indice < (expression_array.length - 1) && indice > 0 
+				&& expression_array[indice -1] == '(' && expression_array[indice +1] == ')') {
+				if (indice > 1
+					&& expression_array[indice - 2].type_op) {
+					expression_array.splice(indice + 1, 1);
+					expression_array.splice(indice, 1);
+					expression_array.splice(indice - 1, 1);
+					expression_array.splice(indice - 2, 1);
+
+				} else if (indice < (expression_array.length - 2) 
+					&& expression_array[indice + 2].type_op) {
+					expression_array.splice(indice + 1, 1);
+					expression_array.splice(indice, 1);
+					expression_array.splice(indice - 1, 1);
 
-			var menorRight = Math.min.apply(null, rightDistances);
-			var indiceRight = rightDistances.indexOf(menorRight);
+				} else {
+					expression_array.splice(indice + 1, 1);
+					expression_array.splice(indice, 1);
+					expression_array.splice(indice - 1, 1);
+				}
+			}
+		}
 
-			if (menorRight < menorLeft) {
-				$(allfilhos.get(indiceRight)).removeClass('mouse_distance_hidden');
-				$(allfilhos.get(indiceRight)).addClass('mouse_distance_except');
-			} else {
-				$(allfilhos.get(indiceLeft)).removeClass('mouse_distance_hidden');
-				$(allfilhos.get(indiceLeft)).addClass('mouse_distance_except');
+	} else if (expression_array[indice].type_op) {
+		// iVProg doesn't support operator remove
+	} else {
+		
+		var opening = -1;
+		var closing = -1;
+
+		if (expression_array[indice] == '(') {
+			opening = indice;
+			for (var i = indice + 1; i < expression_array.length; i++) {
+				if (expression_array[i] == ')') {
+					closing = i;
+					break;
+				}
+			}
+		} else {
+			closing = indice;
+			for (var i = indice - 1; i >= 0; i--) {
+				if (expression_array[i] == '(') {
+					opening = i;
+					break;
+				}
 			}
 		}
-	});*/
 
+		if (expression_array[opening + 1].type_op) {
+			expression_array.splice(closing, 1);
+			expression_array.splice(opening + 1, 1);
+			expression_array.splice(opening, 1);
+		} else {
+			expression_array.splice(closing, 1);
+			expression_array.splice(opening, 1);
+		}
+	}
+	// if expression is empty, add a new var value:
+	if (expression_array.length == 0) {
+		expression_array.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
+	}
+	if (first != expression_array[0] && expression_array[0].type_op) {
+		expression_array.splice(0, 1);
+	}
 }
 
 function renderElements (command, function_obj, div_to_render, expression_array, types_included) {
@@ -132,11 +236,16 @@ function renderElements (command, function_obj, div_to_render, expression_array,
 			}
 
 		} else {
+			if (i == 0) {
+				console.log("NEGAÇÃO NO PRIMEIRO ELEMENTO");
+			} else if (expression_array[i - 1] == '(') {
+				console.log("NEGAÇÃO APÓS O PARÊNTESES");
+			}
 			renderOperatorMenu(command, function_obj, div_to_render, expression_array[i], types_included, i, expression_array);
 		}
 	}
 
-	renderFinalAddElements(div_to_render, types_included, expression_array, command, function_obj, i);
+	renderFinalAddElements(div_to_render, types_included, expression_array, command, function_obj, i, true);
 
 	renderAddParenthesis(command, function_obj, div_to_render, expression_array, types_included);
 
@@ -145,7 +254,7 @@ function renderElements (command, function_obj, div_to_render, expression_array,
 window.parentheses_activate = false;
 window.open_or_close = null;
 function renderAddParenthesis (command, function_obj, div_to_render, expression_array, types_included) {
-	var addParentheses = $('<div class="single_element_expression add_parentheses"><i class="icons"><b style="font-style: normal;">( )</b><i class="corner add icon blue" style="font-size: .6em;right: -3px;bottom: -2px;"></i></i></div>');
+	var addParentheses = $('<div class="single_element_expression add_parentheses not_allowed"><i class="icons"><b style="font-style: normal;">( )</b><i class="corner add icon blue" style="font-size: .6em;right: -3px;bottom: -2px;"></i></i></div>');
 	div_to_render.append(addParentheses);
 	addParentheses.popup({
 	    content : "Adicionar parênteses",
@@ -235,6 +344,9 @@ function renderAddParenthesis (command, function_obj, div_to_render, expression_
 					return;
 				}
 
+
+				window.open_parentheses.addClass('parentheses_fixed');
+
 				floating = $('<div class="floating_parenthesis"> ) </div>');
 				floating.draggable().appendTo("body");
 				floating.css("position", "absolute");
@@ -249,6 +361,8 @@ function renderAddParenthesis (command, function_obj, div_to_render, expression_
 			} else {
 
 				floating.remove();
+
+				window.open_parentheses.removeClass('parentheses_fixed');
 				
 				div_to_render.off('mousemove');
 				div_to_render.off('mouseleave');
@@ -484,7 +598,7 @@ function renderGhostParentheses (actual_target, command, function_obj, div_to_re
 }
 
 function renderParenthesis (div_to_render, expression_content, command, function_obj, position, expression_array) {
-	var ghost_parenthesis = $('<div class="single_element_expression" data-index="'+position+'">'+expression_content+'</div>');
+	var ghost_parenthesis = $('<div class="single_element_expression parentheses_in_expression" data-index="'+position+'">'+expression_content+'</div>');
 	div_to_render.append(ghost_parenthesis);
 }
 
@@ -528,24 +642,26 @@ function renderStartAddOperator (div_to_render, types_included, expression_array
 	menu_final.dropdown('set selected', Models.ARITHMETIC_TYPES.minus);
 
 	div_temp.on('click', function() {
-		var sera = position;
+		if (!window.open_or_close) {
+			var sera = position;
+
+			if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_arithmetic) >= 0) {
+				console.log('p1');
+				expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_arithmetic,Models.ARITHMETIC_TYPES.minus));
+			} else if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_logic) >= 0) {
+				console.log('p2');
+				expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_logic,Models.LOGIC_COMPARISON.equals_to));
+			} else if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_conditional) >= 0) {
+				console.log('p3');
+				expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_conditional,Models.ARITHMETIC_COMPARISON.greater_than));
+			}
 
-		if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_arithmetic) >= 0) {
-			console.log('p1');
-			expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_arithmetic,Models.ARITHMETIC_TYPES.minus));
-		} else if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_logic) >= 0) {
-			console.log('p2');
-			expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_logic,Models.LOGIC_COMPARISON.equals_to));
-		} else if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_conditional) >= 0) {
-			console.log('p3');
-			expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_conditional,Models.ARITHMETIC_COMPARISON.greater_than));
+			renderExpression(command, function_obj, div_to_render, expression_array);
 		}
-
-		renderExpression(command, function_obj, div_to_render, expression_array);
 	});
 }
 
-function renderFinalAddElements (div_to_render, types_included, expression_array, command, function_obj, position) {
+function renderFinalAddElements (div_to_render, types_included, expression_array, command, function_obj, position, is_last = false) {
 
 	var menu_final = '<div class="ui dropdown disabled usepointer"><div class="text"> + </div><i class="dropdown icon"></i><div class="menu">';
 	if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_arithmetic) >= 0) {
@@ -578,26 +694,46 @@ function renderFinalAddElements (div_to_render, types_included, expression_array
 	menu_final += '</div></div>';
 
 	menu_final = $(menu_final);
-	var div_temp = $('<div class="single_element_expression ghost_element mouse_distance"></div>');
-
+	var div_temp = $('<div class="simple_add mouse_distance"></div>');
 	var div_higher = $('<div class="higher_element"></div>');
-	div_higher.append(div_temp);
-	div_to_render.append(div_higher);
-	div_temp.append(menu_final);
-	//div_to_render.append(div_temp);
+
+	var button = $('<button class="ui button green add_expression"><i class="plus circle inverted icon"></i></button>');
+	div_temp.append(button);
+
+	if (!is_last) {
+		div_higher.append(div_temp);
+		div_to_render.append(div_higher);
+		//div_temp.append(menu_final);
+		div_temp.css('opacity', '0', '!important');
+	} else {
+		div_temp.removeClass('mouse_distance');
+		div_temp.css('opacity', '1', '!important');
+		//div_temp.append(menu_final);
+		div_to_render.append(div_temp);
+	}
+	
+
 	menu_final.dropdown('set selected', Models.ARITHMETIC_TYPES.plus);
 
 	div_temp.on('click', function() {
 		var sera = position;
 
+		if (expression_array[sera] == ')' && expression_array[sera - 1] == '(') {
+			expression_array.splice(sera, 0, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
+			renderExpression(command, function_obj, div_to_render, expression_array);
+			return;
+		}
+
 		if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_arithmetic) >= 0) {
 			expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_arithmetic,Models.ARITHMETIC_TYPES.plus));
+			expression_array.splice(sera + 1, 0, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
 		} else if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_logic) >= 0) {
 			expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_logic,Models.LOGIC_COMPARISON.equals_to));
+			expression_array.splice(sera + 1, 0, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
 		} else if (types_included.indexOf(Models.EXPRESSION_TYPES.exp_conditional) >= 0) {
 			expression_array.splice(sera, 0, new Models.ExpressionOperator(Models.EXPRESSION_TYPES.exp_conditional,Models.ARITHMETIC_COMPARISON.greater_than));
+			expression_array.splice(sera + 1, 0, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
 		}
-		expression_array.splice(sera + 1, 0, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
 
 		renderExpression(command, function_obj, div_to_render, expression_array);
 	});
@@ -636,7 +772,7 @@ function renderOperatorMenu (command, function_obj, div_to_render, expression_el
 	menu_final += '</div></div>';
 
 	menu_final = $(menu_final);
-	var div_temp = $('<div class="single_element_expression" data-index="'+position+'"></div>');
+	var div_temp = $('<div class="single_element_expression not_allowed" data-index="'+position+'"></div>');
 	div_temp.append(menu_final);
 	div_to_render.append(div_temp);
 	menu_final.dropdown({

+ 4 - 1
js/visualUI/commands/iftrue.js

@@ -6,6 +6,7 @@ import * as GlobalsManagement from '../globals';
 import * as VariablesManagement from '../variables';
 import * as CommandsManagement from '../commands';
 import * as ConditionalExpressionManagement from './conditional_expression';
+import * as GenericExpressionManagement from './generic_expression';
 
 export function createFloatingCommand () {
 	return $('<div class="ui iftrue created_element"> <i class="ui icon small random"></i> <span> if (x < 1) { } </span></div>');
@@ -34,7 +35,9 @@ export function renderCommand (command, function_obj) {
 
 	addHandlers(command, function_obj, el);
 
-	ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
+	//ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
+
+	GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression);
 
 	if (command.commands_block) {
 		for (var j = 0; j < command.commands_block.length; j++) {

+ 4 - 1
js/visualUI/commands/repeatNtimes.js

@@ -8,6 +8,7 @@ import * as CommandsManagement from '../commands';
 import * as ConditionalExpressionManagement from './conditional_expression';
 import * as VariableValueMenu from './variable_value_menu';
 import * as ContextualizedMenu from './contextualized_menu';
+import * as GenericExpressionManagement from './generic_expression';
 
 export function createFloatingCommand () {
 	return $('<div class="ui repeatNtimes created_element"> <i class="ui icon small sync"></i> <span> para (x = 0; x < 10; x ++) <br> </span></div>');
@@ -30,7 +31,9 @@ export function renderCommand (command, function_obj) {
 
 	VariableValueMenu.renderMenu(command, command.var_attribution, el.find('.variable_attribution'), function_obj);
 
-	ConditionalExpressionManagement.renderExpression(command, command.expression2, function_obj, el.find('.conditional_expression'));
+	//ConditionalExpressionManagement.renderExpression(command, command.expression2, function_obj, el.find('.conditional_expression'));
+
+	GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression2);
 
 	VariableValueMenu.renderMenu(command, command.var_incrementation, el.find('.incrementation_variable'), function_obj);	
 

+ 6 - 5
js/visualUI/commands/return.js

@@ -6,25 +6,26 @@ import * as GlobalsManagement from '../globals';
 import * as VariablesManagement from '../variables';
 import * as VariableValueMenu from './variable_value_menu';
 import * as CommandsManagement from '../commands';
+import * as GenericExpressionManagement from './generic_expression';
 
 export function createFloatingCommand () {
 	return $('<div class="ui return created_element"> <i class="ui icon small reply"></i> <span> '+LocalizedStrings.getUI('text_return')+' </span></div>');
 }
 
 export function renderCommand (command, function_obj) {
-	var el = $('<div class="ui return command_container"> <i class="ui icon small reply command_drag"></i> <i class="ui icon times red button_remove_command"></i> <span class="span_command_spec"> '+LocalizedStrings.getUI('text_return')+' </span>  <div class="var_value_menu_div"></div></div>');
+	var el = $('<div class="ui return command_container"> <i class="ui icon small reply command_drag"></i> <i class="ui icon times red button_remove_command"></i> <span class="span_command_spec"> '+LocalizedStrings.getUI('text_return')+' </span>  <div class="expression_elements"></div></div>');
 	el.data('command', command);
 
 	addHandlers(command, function_obj, el);
 
 	if (function_obj.return_type != Types.VOID) {
-		VariableValueMenu.renderMenu(command, command.variable_value_menu, el.find('.var_value_menu_div'), function_obj);
+		//VariableValueMenu.renderMenu(command, command.variable_value_menu, el.find('.var_value_menu_div'), function_obj);
+		GenericExpressionManagement.renderExpression(command, function_obj, el.find('.expression_elements'), command.variable_value_menu);
 	} else {
-		el.find('.var_value_menu_div').remove();
+		el.find('.expression_elements').remove();
 		command.variable_value_menu = null;
 	}
-
-
+	
 	return el;
 }
 

+ 4 - 1
js/visualUI/commands/whiletrue.js

@@ -7,6 +7,7 @@ import * as VariablesManagement from '../variables';
 import * as CommandsManagement from '../commands';
 import * as ConditionalExpressionManagement from './conditional_expression';
 import * as ContextualizedMenu from './contextualized_menu';
+import * as GenericExpressionManagement from './generic_expression';
 
 export function createFloatingCommand () {
 	return $('<div class="ui whiletrue created_element"> <i class="ui icon small sync"></i> <span> ' + LocalizedStrings.getUI('text_code_while') + ' ( x < 10 ) <br> </span></div>');
@@ -30,7 +31,9 @@ export function renderCommand (command, function_obj) {
 
 	ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el);
 
-	ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
+	//ConditionalExpressionManagement.renderExpression(command, command.expression, function_obj, el.find('.conditional_expression'));
+
+	GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression);
 
 	if (command.commands_block) {
 		for (var j = 0; j < command.commands_block.length; j++) {

+ 7 - 2
js/visualUI/commands/writer.js

@@ -7,6 +7,7 @@ import * as VariablesManagement from '../variables';
 import * as VariableValueMenu from './variable_value_menu';
 import * as VariableValueMenuManagement from './variable_value_menu';
 import * as CommandsManagement from '../commands';
+import * as GenericExpressionManagement from './generic_expression';
 
 import '../../Sortable.js';
 
@@ -21,7 +22,11 @@ export function renderCommand (command, function_obj) {
 	var el = $(ret);
 	el.data('command', command);
 
-	for (var i = 0; i < command.content.length; i ++) {
+	//renderExpression (command, function_obj, div_to_render, expression_array)
+
+	GenericExpressionManagement.renderExpression(command, function_obj, el.find('.all_elements_write'), command.content);
+
+	/*for (var i = 0; i < command.content.length; i ++) {
 		var new_div_item = $( '<div class="var_value_menu_div"></div>' );
 		var div_parent_with_handler = $( '<div class="div_parent_handler"></div>' );
 		div_parent_with_handler.append($('<i class="ui icon ellipsis vertical inverted handler"></i>'));
@@ -38,7 +43,7 @@ export function renderCommand (command, function_obj) {
 
 	if (command.content.length == 0) {
 		addHandlerIconAdd(el.find('.all_elements_write'), command, function_obj);
-	}
+	}*/
 
 	addHandlers(command, function_obj, el);
 	return el;