-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #3335: Detect and handle unavailable extensions in dragged PNGs #3354
Fix #3335: Detect and handle unavailable extensions in dragged PNGs #3354
Conversation
Can one of the admins verify this patch? |
3335-2.mov |
Hi @ewpatton and @SusanRatiLane, Could you please review my pull request? |
@AppInventorWorkerBee ok to test |
}); | ||
|
||
if (missingExtensions.length > 0) { | ||
var message = 'This image references the following blocks which require extensions that are not present in the project:\n\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should either be added to the Blockly.Msg object and a corresponding entry in the translation file, or we should add it to OdeMessages.java and figure out how to get it here so that it can be translated into the user's language.
*/ | ||
function validateBlockTypes(blockTypes, workspace) { | ||
if (!blockTypes || blockTypes.length === 0) { | ||
console.warn('No block types provided for validation.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a warning is necessary here. It's logical that the empty set of block types is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove this warning.
} | ||
|
||
var componentDb = workspace.getComponentDatabase(); | ||
if (!componentDb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the component database is allocated during the setup of the workspace, so this should never be true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I will remove this statement
var blocks = xml.getElementsByTagName('block'); | ||
for (var i = 0; i < blocks.length; i++) { | ||
var mutation = blocks[i].getElementsByTagName('mutation')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that getElementsByTagName
gets all descendants, so you could just do xml.getElementsByTagName('mutation')
to get all of the mutations. Otherwise, this code ends up being quadratic in its runtime since for each block you may be looking up mutations on its children, grandchildren, etc. not just its own mutation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments.
Hi @ewpatton, Thank you so much for reviewing my PR. I'll make the requested changes and submit an updated PR soon. |
…ation support in Blockly.Msg
@ewpatton I have made the requested changes. Please review and let me know if anything else is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
General items:
ant tests
passes on my machineIf your code changes how something works on the device (i.e., it affects the companion):
master
master
as the baseFor all other changes:
master
master
as the baseWhat does this PR accomplish?
- To solve the issue of importing blocks from a PNG file that requires extensions not present in the project, I added the following steps:
1. Extract Block Types: created a function extractBlockTypes to extract the block types from the XML data embedded in the PNG file.
2. Validate Block Types: created a function validateBlockTypes to check if the extracted block types are available in the component database of the workspace.
3. Show Missing Extensions Dialog: created a function showMissingExtensionDialog to display an alert dialog listing the missing extensions if any.
4. Modify importPngAsBlock: modified the importPngAsBlock function to:
Fixes #3335