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
Hide 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) {
Ardublockly
.
loadServerXmlFile
=
function
(
xmlFile
)
{
var
loadXmlfileAccepted
=
function
()
{
// loadXmlBlockFile loads the file asynchronously and needs a callback
var
loadXmlC
allback
=
function
(
sucess
)
{
var
loadXmlC
b
=
function
(
sucess
)
{
if
(
sucess
)
{
Ardublockly
.
renderContent
();
}
else
{
...
...
@@ -330,18 +330,21 @@ Ardublockly.loadServerXmlFile = function(xmlFile) {
false
);
}
};
var
c
allbackConnectionError
=
function
()
{
var
c
onnectionErrorCb
=
function
()
{
Ardublockly
.
openNotConnectedModal
();
};
Ardublockly
.
loadXmlBlockFile
(
xmlFile
,
loadXmlCallback
,
callbackConnectionError
);
Ardublockly
.
loadXmlBlockFile
(
xmlFile
,
loadXmlCb
,
connectionErrorCb
);
};
Ardublockly
.
alertMessage
(
'
Load new blocks?
'
,
'
Loading a new XML file will replace the current blocks from the
'
+
'
workspace.
\n
Are you sure you want to proceed?
'
,
true
,
loadXmlfileAccepted
);
if
(
Ardublockly
.
isWorkspaceEmpty
())
{
loadXmlfileAccepted
();
}
else
{
Ardublockly
.
alertMessage
(
'
Load new blocks?
'
,
'
Loading a new XML file will replace the current blocks from the
'
+
'
workspace.
\n
Are you sure you want to proceed?
'
,
true
,
loadXmlfileAccepted
);
}
};
/**
...
...
ardublockly/ardublockly_blockly.js
View file @
d6b647db
...
...
@@ -64,51 +64,38 @@ Ardublockly.bindBlocklyEventListeners = function() {
* Loads an XML file from the server and replaces the current blocks into the
* Blockly workspace.
* @param {!string} xmlFile XML file path in a reachable server (no local path).
* @param {!function} callbackFileLoaded Function to be called once the file is
* loaded.
* @param {!function} callbackConectonError Function to be called if there is a
* connection error to the XML server.
* @param {!function} cbSuccess Function to be called once the file is loaded.
* @param {!function} cbError Function to be called if there is a connection
* error to the XML server.
*/
Ardublockly
.
loadXmlBlockFile
=
function
(
xmlFile
,
callbackFileLoaded
,
callbackConectonError
)
{
Ardublockly
.
loadXmlBlockFile
=
function
(
xmlFile
,
cbSuccess
,
cbError
)
{
// Create a an XML HTTP request
var
request
=
Ardublockly
.
ajaxRequest
();
// If file run locally Internet explorer fails here
try
{
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
);
callbackFileLoaded
(
success
);
var
requestCb
=
function
()
{
if
(
request
.
readyState
==
4
)
{
if
(
request
.
status
==
200
)
{
var
success
=
Ardublockly
.
replaceBlocksfromXml
(
request
.
responseText
);
cbSuccess
(
success
);
}
else
{
cbError
();
}
}
};
// If file run locally Chrome will fail here
try
{
request
.
open
(
'
GET
'
,
xmlFile
,
true
);
request
.
onreadystatechange
=
requestCb
;
request
.
send
(
null
);
}
catch
(
e
)
{
c
allbackConecton
Error
();
c
b
Error
();
}
};
/**
* Generates the Arduino code from the Blockly workspace.
* @return {!string} Arduino code string.
*/
/** @return {!string} Generated Arduino code from the Blockly workspace. */
Ardublockly
.
generateArduino
=
function
()
{
return
Blockly
.
Arduino
.
workspaceToCode
(
Ardublockly
.
workspace
);
};
/**
* Generates the XML DOM and returns it as a string.
* @return {!string} XML code string.
*/
/** @return {!string} Generated XML code from the Blockly workspace. */
Ardublockly
.
generateXml
=
function
()
{
var
xmlDom
=
Blockly
.
Xml
.
workspaceToDom
(
Ardublockly
.
workspace
);
var
xmlText
=
Blockly
.
Xml
.
domToPrettyText
(
xmlDom
);
...
...
@@ -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.
* @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