Commit d888fd19 authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Merge branch...

Merge branch '5-create-in-blockly-a-block-that-allows-easy-replacement-of-variables-like-the-string-format-in-java' into 'develop'

Resolve "Create in Blockly a block that allows easy replacement of variables like the String.format in Java"

See merge request !3
parents 4fa3dd80 5ea1a4f4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@
                              
              <block type="literal_text"></block>   
              <block type="literal_text_multiline"></block>    
              <block type="text_format_multi"></block>    
              <block type="variable_declare_string"></block>  
              <block type="variable_get_string"></block>  
              <block type="variable_set_string"></block>  
+16 −0
Original line number Diff line number Diff line
@@ -610,6 +610,22 @@ export class ServiceRuleDesignComponent implements OnInit {
      };
      

      Blockly.Java['text_format_multi'] = function(block: { getFieldValue: (arg0: string) => any; }) {
          // Text value.

          var atext = Blockly.Java.valueToCode(block, 'TEXT', Blockly.Java.ORDER_NONE) || '""';
          //atext = '"""\n' +  block.getFieldValue('TEXT') + '\n"""\n';

          var objects = Blockly.Java.valueToCode(block, 'VARIABLES', Blockly.Java.ORDER_NONE)  || null;

          objects = objects.replace('[', ' ,');
          objects = objects.replace(']', ' ');


          var code = 'String.format(' +  atext + objects + ')';
          return [code, Blockly.Java.ORDER_ATOMIC];
      };
  
      Blockly.Java['changecharacteristicvalue'] = function (block: any) {
        // Print statement.
        var argument0 = Blockly.Java.valueToCode(block, 'spec',
+38 −0
Original line number Diff line number Diff line
@@ -82,6 +82,44 @@ Blockly.defineBlocksWithJsonArray([
    }
  };



  Blockly.Blocks['text_format_multi'] = {
    /**
     * Block for text value.
     * @this Blockly.Block
     */
    init: function() {
  
      this.appendValueInput("TEXT")
        .setCheck("String")
        .setAlign(Blockly.ALIGN_RIGHT)
        .appendField("Input(String)");
      this.appendValueInput("VARIABLES")
          .setCheck("Array")
          .setAlign(Blockly.ALIGN_RIGHT)
          .appendField("Variables(Array)");

      this.setOutput(true, 'String');
      this.setColour(160);
      this.setTooltip("A formatted text replacing variables from a list\n %s for Strings\n %n for Numbers, etc");
    },
    /**
     * Create an image of an open or closed quote.
     * @param {boolean} open True if open quote, false if closed.
     * @return {!Blockly.FieldImage} The field image of the quote.
     * @private
     */
    newQuote_: function(open) {
      if (open == Blockly.RTL) {
        var file = 'quote1.png';
      } else {
        var file = 'quote0.png';
      }
      return new Blockly.FieldImage(Blockly.pathToMedia + file, 12, 12, '"');
    }
  };
  
  /*************************************************************************** 
  *
  *   Number RELATED