Bladeren bron

Work in progress

Igor 3 jaren geleden
bovenliggende
commit
0bd258e260

+ 16 - 0
css/ivprog-visual-1.0.css

@@ -1145,4 +1145,20 @@ i.button_alternate_expression {
 .button_write_expression {
 	cursor: pointer;
 	margin-left: 1rem !important;
+}
+
+.input-expression-field {
+	width: 50%;
+}
+
+.expression-edit-confirm {
+	color: #32a852;
+	font-size: 1.2rem !important;
+	cursor: pointer;
+	margin-left: 1rem !important;
+  margin-right: 1rem !important;
+}
+
+.expression-edit-cancel {
+	cursor: pointer;
 }

+ 1 - 0
i18n/ui.csv

@@ -11,6 +11,7 @@ btn_break,Pare,break,break
 btn_case,Caso,Case,Caso
 expression_invalid,Expressão inválida. Verifique a sintáxe antes de continuar.,Invalid expression. Check the syntax before proceeding.,Expresión no válida. Verifique la sintaxis antes de continuar.
 expression_undelcared_variable,Variáveis não declaradas:,Undeclared variables:,Variables no declaradas:
+expression_undeclared_function,Funções não definidas:,Undefined functions:,Funcíon no declaradas:
 start,inicio,main,main
 type_void,vazio,void,void
 type_integer,inteiro,int,int

+ 1 - 1
js/visualUI/code_generator.js

@@ -688,7 +688,7 @@ function readersCode (command_obj, indentation) {
   return ret;
 }
 
-function variableValueMenuCode (variable_obj, is_return = false) {
+export function variableValueMenuCode (variable_obj, is_return = false) {
   let ret = "";
   try {
     if (variable_obj.function_called) {

+ 33 - 14
js/visualUI/commands/attribution.js

@@ -443,34 +443,53 @@ function addHandlers (command, function_obj, attribution_dom) {
 
 		var text = "";
 		if (command.expression) {
-			try {
-				text = CodeGenerator.elementExpressionCode(command.expression);
-			} catch(ex) {
+			if (command.expression.length == 1 && command.expression[0].content == null && !command.expression[0].function_called) {
 				text = "";
+			} else {
+				try {
+					text = CodeGenerator.elementExpressionCode(command.expression);
+				} catch(ex) {
+					text = "";
+				}
 			}
 		}
 
-		var input = $('<input type="text" value="'+text+'" spellcheck="false" autocomplete="off" >');
+		var ok_button = $('<i class="ui icon check circle expression-edit-confirm"></i>');
+		var cancel_button = $('<i class="ui icon undo expression-edit-cancel"></i>');
+		var input = $('<input type="text" spellcheck="false" autocomplete="off" class="input-expression-field" >');
+		input.val(text);
 		
 		input.keyup(function(evt) {
 			if (evt.keyCode == 27) { // esc
-				input.remove();
-				afterWhichElement.css('display', 'inline');
-				lockButton.css('display', 'inline');
-				editButton.css('display', 'inline');
+				cancel_button.click();
 			} 
 			if (evt.keyCode == 13) { // enter
-				var parsed = null;
-				parsed = ExpressionManagement.expressionParserToVisual(input.val(), function_obj, input);
-				if (parsed) {
-					command.expression = parsed;
-					renderAlgorithm();
-				}
+				ok_button.click();
 			}
 		});
 
+		ok_button.click(function() {
+			var parsed = null;
+			parsed = ExpressionManagement.expressionParserToVisual(input.val(), function_obj, input);
+			if (parsed) {
+				command.expression = parsed;
+				renderAlgorithm();
+			}
+		});
+
+		cancel_button.click(function() {
+			input.remove();
+			cancel_button.remove();
+			ok_button.remove();
+			afterWhichElement.css('display', 'inline');
+			lockButton.css('display', 'inline');
+			editButton.css('display', 'inline');
+		});
+
 		input.insertAfter(afterWhichElement);
 		input.focus();
+		cancel_button.insertAfter(input);
+		ok_button.insertAfter(input);
 		var len = text.length; 
 		input[0].setSelectionRange(len, len); 
 

+ 91 - 10
js/visualUI/commands/generic_expression.js

@@ -1372,6 +1372,15 @@ function getVariable (function_obj, search) {
           break;
         }
       }
+    
+    // 3. Procurar na lista de parâmetros: 
+    if (!variavel)
+      for (var j = 0; j < function_obj.parameters_list.length; j++) {
+        if (function_obj.parameters_list[j].name == search.value) {
+          variavel = function_obj.parameters_list[j];
+          break;
+        }
+      }
   }
 
   if (search.instance == "expression"
@@ -1391,27 +1400,68 @@ function getVariable (function_obj, search) {
   if (search.instance == "expression"
     && search.type == "var"
     && search.class == "vector") {
-    /*
-      variable_and_value = 7,
-      content = null,
-      row = null,
-      column = null,
-      include_constant = true,
-      dimensions = 0
-    */
+      
+    var obj = new Models.VariableValueMenu(
+      VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
+      variavel,
+      null,
+      getVariable(function_obj, search.line[0]),
+      true
+    );
+    return obj;
+  }
+
+  if (search.instance == "expression"
+    && search.type == "var"
+    && search.class == "matrix") {
     var obj = new Models.VariableValueMenu(
       VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
       variavel,
+      getVariable(function_obj, search.line[0]),
+      getVariable(function_obj, search.column[0]),
+      true
+    );
+    return obj;
+  }
+
+  if (search.instance == "expression"
+    && search.type == "function") {
+    var obj = new Models.VariableValueMenu(
+      VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
+      null,
       null,
       null,
       true
     );
-    
+    // Procurar a função para referência:
+    for (var i = 0; i < program_obj.functions.length; i++) {
+      if (program_obj.functions[i].name == search.value) {
+        obj.function_called = program_obj.functions[i];
+      }
+    }
+    obj.parameters_list = [];
+
+    for (var i = 0; i < search.params.length; i++) {
+      obj.parameters_list.push(getVariable(function_obj,search.params[i][0]));
+    }
+    return obj;
   }
 }
 
 export function expressionParserToVisual (text, function_obj, input_field) {
+
+  if (text.trim().length == 0) {
+    return [new Models.VariableValueMenu(
+      VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all,
+      null,
+      null,
+      null,
+      true
+    )];
+  }
+
   var var_not_found = [];
+  var fun_not_found = [];
   var parsed;
   try {
     parsed = ivprogCore.parseExpression(text);
@@ -1432,7 +1482,7 @@ export function expressionParserToVisual (text, function_obj, input_field) {
         }
       }
 
-      // 2. Procurar a variável nas gloais: 
+      // 2. Procurar a variável nas globais: 
       if (!variavel)
         for (var j = 0; j < program_obj.globals.length; j++) {
           if (program_obj.globals[j].name == parsed[i].value) {
@@ -1440,10 +1490,41 @@ export function expressionParserToVisual (text, function_obj, input_field) {
             break;
           }
         }
+
+      // 3. Procurar a variável nos parâmetros:
+      if (!variavel)
+        for (var j = 0; j < function_obj.parameters_list.length; j++) {
+          if (function_obj.parameters_list[j].name == parsed[i].value) {
+            variavel = function_obj.parameters_list[j];
+            break;
+          }
+        }
       
       if (!variavel)
         var_not_found.push(parsed[i].value);
     }
+
+    var funcao;
+    if (parsed[i].instance == "expression"
+      && parsed[i].type == "function") {
+    
+      // Procurar a função para referência:
+      for (var j = 0; j < program_obj.functions.length; j++) {
+        if (program_obj.functions[j].name == parsed[i].value) {
+          funcao = program_obj.functions[j];
+        }
+    }
+
+    if (!funcao) {
+      fun_not_found.push(parsed[i].value);
+    }
+  }
+}
+
+  if (fun_not_found.length > 0) {
+    let uniqueWords = [...new Set(fun_not_found)];
+    Utils.renderErrorMessage(input_field,  LocalizedStrings.getUI('expression_undeclared_function') + " " + uniqueWords.join(", "));
+    return null;
   }
 
   if (var_not_found.length > 0) {