Commit 3082d5bd authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Implement a flag to control whitespace in Blockly XML

Change-Id: I11033332060ba9f9dee29fc41dd661a1e48f7081
parent 68089664
......@@ -700,7 +700,7 @@ public class BlocklyPanel extends HTMLPanel {
*/
public native String getBlocksContent() /*-{
return this.@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::workspace
.saveBlocksFile();
.saveBlocksFile(@com.google.appinventor.common.version.AppInventorFeatures::doPrettifyXml()());
}-*/;
/**
......
......@@ -67,13 +67,17 @@ Blockly.SaveFile.load = function(preUpgradeFormJson, blocksContent) {
* get is called prior to writing out. Original ai2 apps had no versions in them
* so now we write out every time
*
* @param {boolean} prettify Specify true if the workspace should be pretty printed.
* @param {?Blockly.WorkspaceSvg} opt_workspace The workspace to serialize. If none is given,
* Blockly.mainWorkspace will be serialized.
* @return {string} XML serialization of the workspace
*/
Blockly.SaveFile.get = function(opt_workspace) {
Blockly.SaveFile.get = function(prettify, opt_workspace) {
var workspace = opt_workspace || Blockly.mainWorkspace;
var xml = Blockly.Xml.workspaceToDom(workspace, false);
var element = goog.dom.createElement('yacodeblocks');
element.setAttribute('ya-version',top.YA_VERSION);
element.setAttribute('language-version',top.BLOCKS_VERSION);
xml.appendChild(element);
return Blockly.Xml.domToPrettyText(xml);
return prettify ? Blockly.Xml.domToPrettyText(xml) : Blockly.Xml.domToText(xml);
};
......@@ -511,10 +511,11 @@ Blockly.WorkspaceSvg.prototype.verifyAllBlocks = function() {
* Saves the workspace as an XML file and returns the contents as a
* string.
*
* @param {boolean} prettify Specify true if the resulting workspace should be pretty-printed.
* @returns {string} XML serialization of the workspace's blocks.
*/
Blockly.WorkspaceSvg.prototype.saveBlocksFile = function() {
return Blockly.SaveFile.get(this);
Blockly.WorkspaceSvg.prototype.saveBlocksFile = function(prettify) {
return Blockly.SaveFile.get(prettify, this);
};
/**
......
......@@ -124,4 +124,11 @@ public final class AppInventorFeatures {
return false;
}
/**
* If set to true, the Blockly XML will be prettified for human readability.
* If false, the XML is serialized to a more compact form with minimal whitespace.
*/
public static boolean doPrettifyXml() {
return false;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment