Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit a7a79ad

Browse files
Update DevTools extension
1 parent 3436a83 commit a7a79ad

35 files changed

+92
-113
lines changed

_locales/tr/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"extensionName":{"message":"Scratch 3 Geliştirici Araçları"}}
1+
{"extensionName":{"message":"Scratch 3 Geliştirici Araçları"},"extensionDescription":{"message":"https://scratch.mit.edu' da Scratch Düzenleme Deneyiminizi geliştirmek için Scratch 3 Geliştirici Araçları"}}

addon/DevTools.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ export default class DevTools {
3838
async init() {
3939
this.addContextMenus();
4040
while (true) {
41-
const root = await this.addon.tab.waitForElement("ul[class*=gui_tab-list_]", { markAsSeen: true });
41+
const root = await this.addon.tab.waitForElement("ul[class*=gui_tab-list_]", {
42+
markAsSeen: true,
43+
reduxEvents: [
44+
"scratch-gui/mode/SET_PLAYER",
45+
"fontsLoaded/SET_FONTS_LOADED",
46+
"scratch-gui/locales/SELECT_LOCALE",
47+
],
48+
reduxCondition: (state) => !state.scratchGui.mode.isPlayerOnly,
49+
});
4250
this.initInner(root);
4351
}
4452
}
@@ -231,7 +239,7 @@ export default class DevTools {
231239
let myBlocks = [];
232240
let myBlocksByProcCode = {};
233241

234-
// todo - get blockyly from an svg???
242+
// todo - get blockly from an svg???
235243

236244
let wksp = this.utils.getWorkspace();
237245
let topBlocks = wksp.getTopBlocks();
@@ -272,14 +280,18 @@ export default class DevTools {
272280

273281
for (const root of topBlocks) {
274282
if (root.type === "procedures_definition") {
275-
let fields = root.inputList[0];
276-
let typeDesc = fields.fieldRow[0].getText();
277-
let label = root.getChildren()[0];
278-
let procCode = label.getProcCode();
283+
const label = root.getChildren()[0];
284+
const procCode = label.getProcCode();
279285
if (!procCode) {
280286
continue;
281287
}
282-
addBlock("define", typeDesc + " " + procCode, root);
288+
const indexOfLabel = root.inputList.findIndex((i) => i.fieldRow.length > 0);
289+
if (indexOfLabel === -1) {
290+
continue;
291+
}
292+
const translatedDefine = root.inputList[indexOfLabel].fieldRow[0].getText();
293+
const message = indexOfLabel === 0 ? `${translatedDefine} ${procCode}` : `${procCode} ${translatedDefine}`;
294+
addBlock("define", message, root);
283295
continue;
284296
}
285297

@@ -618,7 +630,7 @@ export default class DevTools {
618630
}
619631

620632
/**
621-
* Badly Ophaned - might want to delete these!
633+
* Badly Orphaned - might want to delete these!
622634
* @param topBlock
623635
* @returns {boolean}
624636
*/
@@ -808,7 +820,7 @@ export default class DevTools {
808820
}
809821

810822
/**
811-
* Find all the evern broadcasters.
823+
* Find all the event broadcasters.
812824
* @return {[{eventName:string, block:Block}]} Array of event names and blocks.
813825
*/
814826
getCallsToEvents() {
@@ -1501,8 +1513,18 @@ export default class DevTools {
15011513
}
15021514

15031515
if (this.floatInp && !e.target.closest("#s3devIDDOut")) {
1504-
// If we click outside the dropdown, then instigate the hide code...
1505-
this.hideFloatDropDown();
1516+
if (
1517+
!e.shiftKey ||
1518+
// Clicking on the code area should always make multi-inject work
1519+
(!document.getElementsByClassName("injectionDiv")[0].contains(e.target) &&
1520+
// Focused inputs are not part of the injectionDiv, but to the user they are part of the code area so make multi-inject work there
1521+
!e.target.classList.contains("blocklyHtmlInput")) ||
1522+
// This selector targets workspace buttons (Make a Block etc.) and the extension (!) buttons, which most commonly trigger a popup window so always close the dropdown
1523+
e.target.matches(".blocklyFlyoutButton, .blocklyFlyoutButton *, .blocklyTouchTargetBackground")
1524+
) {
1525+
// If we click outside the dropdown, then instigate the hide code...
1526+
this.hideFloatDropDown();
1527+
}
15061528
}
15071529

15081530
if (e.button === 1 || e.shiftKey) {
@@ -2033,13 +2055,20 @@ export default class DevTools {
20332055
} else {
20342056
field.innerText = option.option[1]; // griffpatch - oops! option.option[1] not 0?
20352057
}
2058+
2059+
// Handle "stop other scripts in sprite"
2060+
if (option.option[1] === "other scripts in sprite") {
2061+
option.dom.querySelector("mutation").setAttribute("hasnext", "true");
2062+
}
20362063
}
20372064

20382065
x.appendChild(option.dom);
20392066

20402067
let ids = Blockly.Xml.domToWorkspace(x, wksp);
20412068

2042-
this.reallyHideFloatDropDown(true);
2069+
if (!e.shiftKey) {
2070+
this.reallyHideFloatDropDown(true);
2071+
}
20432072

20442073
let block = wksp.getBlockById(ids[0]);
20452074

@@ -2053,7 +2082,11 @@ export default class DevTools {
20532082
}
20542083
}
20552084

2056-
this.domHelpers.triggerDragAndDrop(block.svgPath_, null, { x: this.mouseXY.x, y: this.mouseXY.y });
2085+
this.domHelpers.triggerDragAndDrop(block.svgPath_, null, { x: this.mouseXY.x, y: this.mouseXY.y }, e.shiftKey);
2086+
2087+
if (e.shiftKey) {
2088+
document.getElementById("s3devIInp").focus();
2089+
}
20572090

20582091
this.blockCursor = block;
20592092
}

addon/DomHelpers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ export default class DomHelpers {
1313
* @param selectorDrag
1414
* @param selectorDrop
1515
* @param mouseXY
16+
* @param [shiftKey=false]
1617
* @returns {boolean}
1718
*/
18-
triggerDragAndDrop(selectorDrag, selectorDrop, mouseXY) {
19+
triggerDragAndDrop(selectorDrag, selectorDrop, mouseXY, shiftKey) {
1920
// function for triggering mouse events
21+
shiftKey = shiftKey || false;
2022
let fireMouseEvent = function (type, elem, centerX, centerY) {
2123
let evt = document.createEvent("MouseEvents");
22-
evt.initMouseEvent(type, true, true, window, 1, 1, 1, centerX, centerY, false, false, false, false, 0, elem);
24+
evt.initMouseEvent(type, true, true, window, 1, 1, 1, centerX, centerY, shiftKey, false, false, false, 0, elem);
2325
elem.dispatchEvent(evt);
2426
};
2527

addon/blockly/Utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import BlockFlasher from "./BlockFlasher.js";
66
export default class Utils {
77
constructor(addon) {
88
this.addon = addon;
9+
this.addon.tab.traps.getBlockly().then((blockly) => {
10+
this.blockly = blockly;
11+
});
912
/**
1013
* Scratch Virtual Machine
1114
* @type {null|*}
@@ -56,9 +59,8 @@ export default class Utils {
5659
/**
5760
* Based on wksp.centerOnBlock(li.data.labelID);
5861
* @param blockOrId {Blockly.Block|{id}|BlockInstance} A Blockly Block, a block id, or a BlockInstance
59-
* @param [force] {boolean} if true, the view always moves, otherwise only move if the selected element is not entirely visible
6062
*/
61-
scrollBlockIntoView(blockOrId, force) {
63+
scrollBlockIntoView(blockOrId) {
6264
let workspace = this.getWorkspace();
6365
/** @type {Blockly.Block} */
6466
let block; // or is it really a Blockly.BlockSvg?
@@ -106,6 +108,7 @@ export default class Utils {
106108
workspace.scrollbar.set(sx, sy);
107109
this.navigationHistory.storeView({ left: sx, top: sy }, 64);
108110
}
111+
this.blockly?.hideChaff();
109112
BlockFlasher.flash(block);
110113
}
111114

addon/show-broadcast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class ShowBroadcast {
7171
elem = document.querySelector('div[class*="stage-selector_header"]');
7272
} else if (target.isOriginal) {
7373
// This is one of the most ridiculous code I've ever written.
74-
// This essentially comparses sprite names to textContent so that we can add CSS.
74+
// This essentially compares sprite names to textContent so that we can add CSS.
7575
const possibleElements = document.querySelectorAll('div[class*="sprite-selector-item_sprite-name"]');
7676
const spriteNameElem = Array.prototype.find.call(
7777
possibleElements,

addon/userscript.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ div.s3devDDOut.vis ul.s3devDD {
440440
border-radius: 4px;
441441
box-shadow: rgba(0, 0, 0, 0.3) 0 0 3px, rgba(0, 0, 0, 0.2) 0 3px 10px;
442442

443-
z-index: 1000001;
443+
z-index: 999;
444444
}
445445

446446
#s3devInsertLabel {

addon/userscript.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default async function ({ addon, global, console, msg, safeMsg: m }) {
44
// noinspection JSUnresolvedVariable
55
if (!addon.self._isDevtoolsExtension && window.initGUI) {
66
console.log("Extension running, stopping addon");
7+
window._devtoolsAddonEnabled = true;
8+
window.dispatchEvent(new CustomEvent("scratchAddonsDevtoolsAddonStopped"));
79
return;
810
}
911

l10n/de/_general.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"_locale":"de","_locale_name":"Deutsch","thumb-success":"Thumbnail hochgeladen.","thumb-error":"Fehler beim Hochladen des Thumbnails.","thumb-error-413":"Die Datei ist zu groß.","thumb-error-503":"Der Thumbnail-Server hat ein Problem. Bitte versuche es später erneut."}
1+
{"_locale":"de","_locale_name":"Deutsch"}

0 commit comments

Comments
 (0)