Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
d6b647db
Commit
d6b647db
authored
Feb 12, 2016
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Load XML file will only ask to confirm when blocks are present.
parent
a1aad01d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
39 deletions
+34
-39
ardublockly/ardublockly.js
ardublockly/ardublockly.js
+12
-9
ardublockly/ardublockly_blockly.js
ardublockly/ardublockly_blockly.js
+22
-30
No files found.
ardublockly/ardublockly.js
View file @
d6b647db
...
@@ -319,7 +319,7 @@ Ardublockly.changeIdeButtons = function(value) {
...
@@ -319,7 +319,7 @@ Ardublockly.changeIdeButtons = function(value) {
Ardublockly
.
loadServerXmlFile
=
function
(
xmlFile
)
{
Ardublockly
.
loadServerXmlFile
=
function
(
xmlFile
)
{
var
loadXmlfileAccepted
=
function
()
{
var
loadXmlfileAccepted
=
function
()
{
// loadXmlBlockFile loads the file asynchronously and needs a callback
// loadXmlBlockFile loads the file asynchronously and needs a callback
var
loadXmlC
allback
=
function
(
sucess
)
{
var
loadXmlC
b
=
function
(
sucess
)
{
if
(
sucess
)
{
if
(
sucess
)
{
Ardublockly
.
renderContent
();
Ardublockly
.
renderContent
();
}
else
{
}
else
{
...
@@ -330,18 +330,21 @@ Ardublockly.loadServerXmlFile = function(xmlFile) {
...
@@ -330,18 +330,21 @@ Ardublockly.loadServerXmlFile = function(xmlFile) {
false
);
false
);
}
}
};
};
var
c
allbackConnectionError
=
function
()
{
var
c
onnectionErrorCb
=
function
()
{
Ardublockly
.
openNotConnectedModal
();
Ardublockly
.
openNotConnectedModal
();
};
};
Ardublockly
.
loadXmlBlockFile
(
Ardublockly
.
loadXmlBlockFile
(
xmlFile
,
loadXmlCb
,
connectionErrorCb
);
xmlFile
,
loadXmlCallback
,
callbackConnectionError
);
};
};
if
(
Ardublockly
.
isWorkspaceEmpty
())
{
loadXmlfileAccepted
();
}
else
{
Ardublockly
.
alertMessage
(
Ardublockly
.
alertMessage
(
'
Load new blocks?
'
,
'
Load new blocks?
'
,
'
Loading a new XML file will replace the current blocks from the
'
+
'
Loading a new XML file will replace the current blocks from the
'
+
'
workspace.
\n
Are you sure you want to proceed?
'
,
'
workspace.
\n
Are you sure you want to proceed?
'
,
true
,
loadXmlfileAccepted
);
true
,
loadXmlfileAccepted
);
}
};
};
/**
/**
...
...
ardublockly/ardublockly_blockly.js
View file @
d6b647db
...
@@ -64,51 +64,38 @@ Ardublockly.bindBlocklyEventListeners = function() {
...
@@ -64,51 +64,38 @@ Ardublockly.bindBlocklyEventListeners = function() {
* Loads an XML file from the server and replaces the current blocks into the
* Loads an XML file from the server and replaces the current blocks into the
* Blockly workspace.
* Blockly workspace.
* @param {!string} xmlFile XML file path in a reachable server (no local path).
* @param {!string} xmlFile XML file path in a reachable server (no local path).
* @param {!function} callbackFileLoaded Function to be called once the file is
* @param {!function} cbSuccess Function to be called once the file is loaded.
* loaded.
* @param {!function} cbError Function to be called if there is a connection
* @param {!function} callbackConectonError Function to be called if there is a
* error to the XML server.
* connection error to the XML server.
*/
*/
Ardublockly
.
loadXmlBlockFile
=
function
(
xmlFile
,
callbackFileLoaded
,
Ardublockly
.
loadXmlBlockFile
=
function
(
xmlFile
,
cbSuccess
,
cbError
)
{
callbackConectonError
)
{
// Create a an XML HTTP request
// Create a an XML HTTP request
var
request
=
Ardublockly
.
ajaxRequest
();
var
request
=
Ardublockly
.
ajaxRequest
();
var
requestCb
=
function
()
{
// If file run locally Internet explorer fails here
if
(
request
.
readyState
==
4
)
{
try
{
if
(
request
.
status
==
200
)
{
request
.
open
(
'
GET
'
,
xmlFile
,
true
);
}
catch
(
e
)
{
callbackConectonError
();
}
// Once file is open, parse the XML into the workspace
request
.
onreadystatechange
=
function
()
{
if
((
request
.
readyState
==
4
)
&&
(
request
.
status
==
200
))
{
var
success
=
Ardublockly
.
replaceBlocksfromXml
(
request
.
responseText
);
var
success
=
Ardublockly
.
replaceBlocksfromXml
(
request
.
responseText
);
callbackFileLoaded
(
success
);
cbSuccess
(
success
);
}
else
{
cbError
();
}
}
}
};
};
// If file run locally Chrome will fail here
try
{
try
{
request
.
open
(
'
GET
'
,
xmlFile
,
true
);
request
.
onreadystatechange
=
requestCb
;
request
.
send
(
null
);
request
.
send
(
null
);
}
catch
(
e
)
{
}
catch
(
e
)
{
c
allbackConecton
Error
();
c
b
Error
();
}
}
};
};
/**
/** @return {!string} Generated Arduino code from the Blockly workspace. */
* Generates the Arduino code from the Blockly workspace.
* @return {!string} Arduino code string.
*/
Ardublockly
.
generateArduino
=
function
()
{
Ardublockly
.
generateArduino
=
function
()
{
return
Blockly
.
Arduino
.
workspaceToCode
(
Ardublockly
.
workspace
);
return
Blockly
.
Arduino
.
workspaceToCode
(
Ardublockly
.
workspace
);
};
};
/**
/** @return {!string} Generated XML code from the Blockly workspace. */
* Generates the XML DOM and returns it as a string.
* @return {!string} XML code string.
*/
Ardublockly
.
generateXml
=
function
()
{
Ardublockly
.
generateXml
=
function
()
{
var
xmlDom
=
Blockly
.
Xml
.
workspaceToDom
(
Ardublockly
.
workspace
);
var
xmlDom
=
Blockly
.
Xml
.
workspaceToDom
(
Ardublockly
.
workspace
);
var
xmlText
=
Blockly
.
Xml
.
domToPrettyText
(
xmlDom
);
var
xmlText
=
Blockly
.
Xml
.
domToPrettyText
(
xmlDom
);
...
@@ -198,6 +185,11 @@ Ardublockly.discardAllBlocks = function() {
...
@@ -198,6 +185,11 @@ Ardublockly.discardAllBlocks = function() {
}
}
};
};
/** @return {!boolean} Indicates if the Blockly workspace has blocks. */
Ardublockly
.
isWorkspaceEmpty
=
function
()
{
return
Ardublockly
.
workspace
.
getAllBlocks
().
length
?
false
:
true
;
};
/**
/**
* Changes the Arduino board profile if different from the currently set one.
* Changes the Arduino board profile if different from the currently set one.
* @param {string} newBoard Name of the new profile to set.
* @param {string} newBoard Name of the new profile to set.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment