Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
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
appinventor-sources
Commits
737923db
Commit
737923db
authored
Feb 16, 2020
by
Beka Westberg
Committed by
Evan W. Patton
Feb 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scoped variable blocks to typeblock
parent
77d9970b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
appinventor/blocklyeditor/src/typeblock.js
appinventor/blocklyeditor/src/typeblock.js
+57
-0
No files found.
appinventor/blocklyeditor/src/typeblock.js
View file @
737923db
...
...
@@ -260,6 +260,7 @@ Blockly.TypeBlock.prototype.lazyLoadOfOptions_ = function () {
this
.
needsReload
.
components
=
null
;
}
this
.
loadGlobalVariables_
();
this
.
loadLocalVariables_
();
this
.
loadProcedures_
();
this
.
reloadOptionsAfterChanges_
();
};
...
...
@@ -435,6 +436,62 @@ Blockly.TypeBlock.prototype.loadGlobalVariables_ = function () {
}.
bind
(
this
));
};
/**
* Loads all local variables in the scope of the selected block (if one exists).
* This is used lazily from show(). Call 'reloadOptionsAfterChanges_' after
* calling this function. The function lazyLoadOfOptions_ is an example of how
* to call this function.
* @private
*/
Blockly
.
TypeBlock
.
prototype
.
loadLocalVariables_
=
function
()
{
// Remove any local vars from the list so that we can re-add them.
this
.
TBOptions_
=
goog
.
object
.
filter
(
this
.
TBOptions_
,
function
(
option
)
{
return
!
option
.
isLocalVar
;
});
var
selected
=
Blockly
.
selected
;
if
(
!
selected
)
{
return
;
}
var
localVarNames
=
Blockly
.
FieldLexicalVariable
.
getLexicalNamesInScope
(
selected
).
map
(
function
(
varNameArray
)
{
// Index 0 should be the translated name.
return
varNameArray
[
0
];
});
// getLexicalNamesInScope does not include names declared on the block passed.
if
(
selected
.
getVars
)
{
// TODO: This doesn't currently support variable prefixes, but I don't want
// to duplicate all of the logic inside getLexicalNamesInScope(). If the
// suggestion for #2033 gets accepted this will be an easy fix.
localVarNames
=
localVarNames
.
concat
(
selected
.
getVars
().
map
(
function
(
varName
)
{
return
selected
.
workspace
.
getTopWorkspace
().
getComponentDatabase
()
.
getInternationalizedParameterName
(
varName
);
}));
}
goog
.
array
.
forEach
(
localVarNames
,
function
(
varName
)
{
var
translatedGet
=
Blockly
.
Msg
.
LANG_VARIABLES_GET_TITLE_GET
+
'
'
+
varName
;
this
.
TBOptions_
[
translatedGet
]
=
{
canonicName
:
'
lexical_variable_get
'
,
dropDown
:
{
titleName
:
'
VAR
'
,
value
:
varName
},
isLocalVar
:
true
};
var
translatedSet
=
Blockly
.
Msg
.
LANG_VARIABLES_SET_TITLE_SET
+
'
'
+
varName
;
this
.
TBOptions_
[
translatedSet
]
=
{
canonicName
:
'
lexical_variable_set
'
,
dropDown
:
{
titleName
:
'
VAR
'
,
value
:
varName
},
isLocalVar
:
true
}
}.
bind
(
this
));
};
/**
* Creates the auto-complete panel, powered by Google Closure's ac widget
* @private
...
...
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