Igor 5 vuotta sitten
vanhempi
commit
3a3a1c8ea7

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

@@ -271,7 +271,8 @@ div.buttons_manage_columns {
 .ui.comment span {
 	font-style: italic;
 }
-.ui.comment, .ui.reader, .ui.writer, .ui.attribution, .ui.iftrue, .ui.repeatNtimes, .ui.whiletrue, .ui.dowhiletrue, .ui.switch, .ui.functioncall {
+.ui.comment, .ui.reader, .ui.writer, .ui.attribution, .ui.iftrue, .ui.repeatNtimes, .ui.whiletrue, .ui.dowhiletrue, .ui.switch, .ui.functioncall,
+.ui.return {
 	border: 1px solid gray;
 	padding: 5px;
 	border-radius: 5px;

+ 2 - 0
i18n/en/ui.json

@@ -47,6 +47,8 @@
   "text_iftrue": "If true then",
   "text_receives": "receives",
   "text_repeatNtimes": "Repeat N times",
+  "text_return":"return",
+  "text_btn_return":"Return",
   "text_whiletrue": "While true",
   "text_dowhiletrue": "Do while true",
   "text_switch": "Switch",

+ 2 - 0
i18n/es/ui.json

@@ -37,6 +37,8 @@
   "text_if":"if",
   "text_break":"break",
   "text_else":"else",
+  "text_return":"return",
+  "text_btn_return":"Return",
   "text_for":"for",
   "text_code_while":"while",
   "text_code_do":"do",

+ 2 - 0
i18n/pt/ui.json

@@ -32,6 +32,8 @@
   "text_write_var": "Escrita de dados",
   "text_command_read":"leia",
   "text_command_write":"escreva",
+  "text_return":"retorne",
+  "text_btn_return":"Retorno",
   "text_comment": "Comentário",
   "join_or": "ou",
   "text_attribution": "Atribuição",

+ 1 - 0
index.html

@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <html>
   <head>
+    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <title></title>
     <link rel="stylesheet" type="text/css" href="js/semantic/semantic.min.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-visual-1.0.css">

+ 22 - 0
js/visualUI/algorithm.js

@@ -0,0 +1,22 @@
+import $ from 'jquery';
+import { Types } from './types';
+import * as Models from './ivprog_elements';
+import { LocalizedStrings } from './../services/localizedStringsService';
+import * as GlobalsManagement from './globals';
+import * as VariablesManagement from './variables';
+import * as CommandsManagement from './commands';
+import * as CodeManagement from './code_generator';
+import * as VariableValueMenu from './commands/variable_value_menu';
+import * as FunctionsManagement from './functions';
+import { DOMConsole } from './../io/domConsole';
+import { IVProgParser } from './../ast/ivprogParser';
+import { IVProgProcessor } from './../processor/ivprogProcessor';
+import { LanguageService } from '../services/languageService';
+
+export function renderAlgorithm () {
+	$('.all_functions').empty();
+
+	for (var i = 0; i < window.program_obj.functions.length; i++) {
+		FunctionsManagement.renderFunction(window.program_obj.functions[i]);
+	}
+}

+ 21 - 0
js/visualUI/code_generator.js

@@ -149,9 +149,30 @@ function commandsCode (command_obj, indentation = 2) {
 
 		case Models.COMMAND_TYPES.switch:
 			return switchsCode(command_obj, indentation);
+
+		case Models.COMMAND_TYPES.return:
+			return returnsCode(command_obj, indentation);
 	}
 }
 
+function returnsCode(command_obj, indentation) {
+	var ret = '\n';
+
+	for (var i = 0; i < indentation; i++) {
+		ret += '\t';
+	}
+
+	ret += LocalizedStrings.getUI('text_return');
+
+	if (command_obj.variable_value_menu) {
+		try {
+			ret += ' ' + variableValueMenuCode(command_obj.variable_value_menu);
+		} catch(err) {}
+	}
+
+	return ret;
+}
+
 function breaksCode(command_obj, indentation) {
 	var ret = '\n';
 

+ 12 - 0
js/visualUI/commands.js

@@ -16,6 +16,7 @@ import * as SwitchesManagement from './commands/switch';
 import * as FunctioncallsManagement from './commands/functioncall';
 import * as VariableValueMenuManagement from './commands/variable_value_menu';
 import * as BreaksManagement from './commands/break';
+import * as ReturnsManagement from './commands/return';
 
 var has_element_created_draged = false;
 var which_element_is_draged = null;
@@ -113,6 +114,10 @@ export function createFloatingCommand (function_obj, function_container, command
 		case Models.COMMAND_TYPES.functioncall:
 			floatingObject = FunctioncallsManagement.createFloatingCommand();
 			break;
+
+		case Models.COMMAND_TYPES.return:
+			floatingObject = ReturnsManagement.createFloatingCommand();
+			break;
 	}
 
 	floatingObject.draggable().appendTo("body");
@@ -177,6 +182,10 @@ export function renderCommand (command, element_reference, before_after_inside,
 			createdElement = SwitchesManagement.renderCommand(command, function_obj);
 			break;
 
+		case Models.COMMAND_TYPES.return:
+			createdElement = ReturnsManagement.renderCommand(command, function_obj);
+			break;
+
 	}
 
 	switch (before_after_inside) {
@@ -237,6 +246,9 @@ export function genericCreateCommand (command_type) {
 			var sc = [new Models.SwitchCase(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true))];
 
 			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));
 	}
 }
 

+ 32 - 0
js/visualUI/commands/return.js

@@ -0,0 +1,32 @@
+import $ from 'jquery';
+import { Types } from '../types';
+import * as Models from '../ivprog_elements';
+import { LocalizedStrings } from '../../services/localizedStringsService';
+import * as GlobalsManagement from '../globals';
+import * as VariablesManagement from '../variables';
+import * as VariableValueMenu from './variable_value_menu';
+import * as CommandsManagement from '../commands';
+
+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"></i> <i class="ui icon times red button_remove_command"></i> <span> '+LocalizedStrings.getUI('text_return')+' </span>  <div class="var_value_menu_div"></div></div>');
+	el.data('command', command);
+
+	addHandlers(command, function_obj, el);
+
+	VariableValueMenu.renderMenu(command, command.variable_value_menu, el.find('.var_value_menu_div'), function_obj);
+
+	return el;
+}
+
+function addHandlers (command, function_obj, return_dom) {
+
+	return_dom.find('.button_remove_command').on('click', function() {
+		if (CommandsManagement.removeCommand(command, function_obj, return_dom)) {
+			return_dom.remove();
+		}
+	});
+}

+ 11 - 1
js/visualUI/commands/variable_value_menu.js

@@ -12,7 +12,7 @@ export const VAR_OR_VALUE_TYPES = Object.freeze({only_variable: 1, only_value: 2
 	value_and_function: 6, all: 7});
 
 export function renderMenu (command, ref_object, dom_object, function_obj, size_field = 2, expression_element) {
-	var menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
+	var menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom" data-algo="12"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
 
 	if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_function) {
 
@@ -75,6 +75,16 @@ export function renderMenu (command, ref_object, dom_object, function_obj, size_
     if (ref_object.content || ref_object.function_called) {
     	renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
     }
+
+}
+
+export function refreshMenu (menu_var_or_value_dom) {
+	console.log('\n\n');
+	console.log(menu_var_or_value_dom);
+	console.log("olá, fui chamado! note alguns DATAS recuperados: ");
+	console.log(menu_var_or_value_dom.data());
+	console.log('\n\n\n');
+
 }
 
 function renderPreviousContent (function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element) {

+ 2 - 9
js/visualUI/functions.js

@@ -177,7 +177,7 @@ function renderFunctionReturn (function_obj, function_element) {
 }
 
 
-function renderFunction (function_obj) {
+export function renderFunction (function_obj) {
 
   var appender = '<div class="ui secondary segment function_div list-group-item">';
 
@@ -203,6 +203,7 @@ function renderFunction (function_obj) {
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.whiletrue+'"><i class="sync icon"></i> '+LocalizedStrings.getUI('text_whiletrue')+'</a>'
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.dowhiletrue+'"><i class="sync icon"></i> '+LocalizedStrings.getUI('text_dowhiletrue')+'</a>'
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.switch+'"><i class="list icon"></i> '+LocalizedStrings.getUI('text_switch')+'</a>'
+        + '<a class="item" data-command="'+Models.COMMAND_TYPES.return+'"><i class="reply icon"></i> '+LocalizedStrings.getUI('text_btn_return')+'</a>'
         + '</div></div></div>';
 
   appender += '<div class="function_signature_div">'+LocalizedStrings.getUI("function")+' ';
@@ -225,14 +226,6 @@ function renderFunction (function_obj) {
     + '</div>'
     + '<div class="ui bottom attached segment commands_list_div" id="function_drag_cmd_">';
 
-
-  if (function_obj.commands) {
-    for (var l = 0; l < function_obj.commands.length; l++) {
-      //appender += renderElementCommandGeneric(programa.funcoes[sequence].comandos[l], sequence, l, -1, l);
-      
-    }
-  }
-
   appender += '</div>';
 
   appender += '<div class="function_close_div">}</div>'

+ 15 - 1
js/visualUI/ivprog_elements.js

@@ -1,8 +1,11 @@
+import * as VariableValueMenuManagement from './commands/variable_value_menu';
 import { Types } from './../ast/types';
 import WatchJS from 'melanke-watchjs';
+import * as AlgorithmManagement from './algorithm';
 
 export const COMMAND_TYPES = Object.freeze({function:"function", comment:"comment", reader:"reader", writer:"writer", attribution:"attribution", iftrue:"iftrue",
- repeatNtimes:"repeatNtimes", whiletrue:"whiletrue", dowhiletrue:"dowhiletrue", switch:"switch", switchcase:"switchcase", functioncall:"functioncall", break:"break"});
+ repeatNtimes:"repeatNtimes", whiletrue:"whiletrue", dowhiletrue:"dowhiletrue", switch:"switch", switchcase:"switchcase", functioncall:"functioncall", break:"break",
+ return:"return"});
 
 export const ARITHMETIC_TYPES = Object.freeze({plus:"plus", minus:"minus", multiplication:"multiplication", division:"division", module:"module", none:"none"});
 
@@ -170,6 +173,14 @@ export class Switch {
   }
 }
 
+export class Return {
+
+ constructor (variable_value_menu) {
+    this.type = COMMAND_TYPES.return;
+    this.variable_value_menu = variable_value_menu;
+  } 
+}
+
 export class SwitchCase {
 
  constructor (variable_value_menu, commands_block = []) {
@@ -226,6 +237,9 @@ export class Program {
     WatchJS.watch(function_to_add.variables_list, function(){
       console.log("as variáveis da função abaixo foram alteradas: ");
       console.log(function_to_add);
+
+      AlgorithmManagement.renderAlgorithm();
+
     }, 1);
 
     this.functions.push(function_to_add);