Skip to content

Commit 482c4e9

Browse files
committed
New Blockly Core returns a slightly different empty project XML.
1 parent 8fa22fa commit 482c4e9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/modules/blocklyc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ export const hasCode = () => {
981981
const xml = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
982982
const text = Blockly.Xml.domToText(xml);
983983
const emptyHeader = Project.getTerminatedEmptyProjectCodeHeader();
984-
if (text !== emptyHeader) {
984+
const emptyHeaderV2 = Project.getTerminatedEmptyProjectCodeHeaderV2();
985+
if (! (text === emptyHeader || text === emptyHeaderV2)) {
985986
result = true;
986987
}
987988
}

src/modules/project.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {logConsoleMessage} from './utility';
3535
*/
3636
const EmptyProjectCodeHeader = '<xml xmlns="https://developers.google.com/blockly/xml">';
3737
const TerminatedEmptyProjectCodeHeader = '<xml xmlns="https://developers.google.com/blockly/xml"/>';
38+
const TerminatedEmptyProjectCodeHeaderV2 = `<xml xmlns=\"https://developers.google.com/blockly/xml\"></xml>`;
3839

3940
/**
4041
* Preserve the initial state of the project
@@ -386,6 +387,14 @@ class Project {
386387
return TerminatedEmptyProjectCodeHeader;
387388
}
388389

390+
/**
391+
* Version 2 empty project string
392+
* @return {string}
393+
*/
394+
static getTerminatedEmptyProjectCodeHeaderV2() {
395+
return TerminatedEmptyProjectCodeHeaderV2;
396+
}
397+
389398
/**
390399
* Convert a string project board type
391400
* @param {string} board

src/modules/toolbar_controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import {hasCode} from './blocklyc';
2424
import {getProjectInitialState} from './project.js';
2525
import {clientService, serviceConnectionTypes} from './client_service';
26+
import {logConsoleMessage} from "./utility";
2627

2728

2829
/**
@@ -55,6 +56,9 @@ export function propToolbarButtonController() {
5556
disableButtons(false, isS3boardType);
5657
return;
5758
}
59+
else {
60+
console.log(`Project has code`);
61+
}
5862
}
5963
// The compile button should always be available when a project
6064
// is loaded and there is at least one block defined in the project

0 commit comments

Comments
 (0)