Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/microsoft/pxt into thspar…
Browse files Browse the repository at this point in the history
…ks/theme_order
  • Loading branch information
thsparks committed Feb 26, 2025
2 parents 2531462 + 071ea30 commit 266a670
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pxt-core",
"version": "11.3.21",
"version": "11.3.25",
"description": "Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors",
"keywords": [
"TypeScript",
Expand Down
6 changes: 4 additions & 2 deletions pxtblocks/builtins/loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export function initLoops() {
{
"type": "field_variable",
"name": "VAR",
"variable": controlsSimpleForDef.block["variable"]
"variable": controlsSimpleForDef.block["variable"],
"variableTypes": [""],
// Please note that most multilingual characters
// cannot be used as variable name at this point.
// Translate or decide the default variable name
Expand Down Expand Up @@ -328,7 +329,8 @@ export function initLoops() {
{
"type": "field_variable",
"name": "VAR",
"variable": controlsForOfDef.block["variable"]
"variable": controlsForOfDef.block["variable"],
"variableTypes": [""],
// Please note that most multilingual characters
// cannot be used as variable name at this point.
// Translate or decide the default variable name
Expand Down
66 changes: 57 additions & 9 deletions pxtblocks/builtins/variables.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import * as Blockly from "blockly";
import { createFlyoutGroupLabel, createFlyoutHeadingLabel, mkVariableFieldBlock } from "../toolbox";
import { installBuiltinHelpInfo, setBuiltinHelpInfo } from "../help";
import { provider } from "../constants";

export function initVariables() {
// We only give types to "special" variables like enum members and we don't
// want those showing up in the variable dropdown so filter the variables
// that show up to only ones that have an empty type
(Blockly.FieldVariable.prototype as any).getVariableTypes_ = () => [""];

let varname = lf("{id:var}item");
Blockly.Variables.flyoutCategory = function (workspace: Blockly.WorkspaceSvg) {
let xmlList: HTMLElement[] = [];
Expand Down Expand Up @@ -103,7 +97,31 @@ export function initVariables() {
const variablesGetId = "variables_get";
const variablesGetDef = pxt.blocks.getBlockDefinition(variablesGetId);
msg.VARIABLES_GET_CREATE_SET = variablesGetDef.block["VARIABLES_GET_CREATE_SET"];
installBuiltinHelpInfo(variablesGetId);
Blockly.Blocks[variablesGetId] = {
init: function() {
this.jsonInit(
{
"type": "variables_get",
"message0": "%1",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
"variableTypes": [""],
},
],
"output": null,
"style": "variable_blocks",
"helpUrl": "%{BKY_VARIABLES_GET_HELPURL}",
"tooltip": "%{BKY_VARIABLES_GET_TOOLTIP}",
"extensions": ["contextMenu_variableSetterGetter"],
}
);

setBuiltinHelpInfo(this, variablesGetId);
}
};

const variablesReporterGetId = "variables_get_reporter";
installBuiltinHelpInfo(variablesReporterGetId);
Expand All @@ -120,7 +138,36 @@ export function initVariables() {
msg.VARIABLES_SET = variablesSetDef.block["VARIABLES_SET"];
msg.VARIABLES_DEFAULT_NAME = varname;
msg.VARIABLES_SET_CREATE_GET = lf("Create 'get %1'");
installBuiltinHelpInfo(variablesSetId);
Blockly.Blocks[variablesSetId] = {
init: function() {
this.jsonInit(
{
"type": "variables_set",
"message0": "%{BKY_VARIABLES_SET}",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
"variableTypes": [""],
},
{
"type": "input_value",
"name": "VALUE",
},
],
"previousStatement": null,
"nextStatement": null,
"style": "variable_blocks",
"tooltip": "%{BKY_VARIABLES_SET_TOOLTIP}",
"helpUrl": "%{BKY_VARIABLES_SET_HELPURL}",
"extensions": ["contextMenu_variableSetterGetter"],
}
);

setBuiltinHelpInfo(this, variablesSetId);
}
};

// pxt variables_change
const variablesChangeId = "variables_change";
Expand All @@ -133,7 +180,8 @@ export function initVariables() {
{
"type": "field_variable",
"name": "VAR",
"variable": varname
"variable": varname,
"variableTypes": [""]
},
{
"type": "input_value",
Expand Down
1 change: 0 additions & 1 deletion pxtblocks/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function installHelpResources(id: string, name: string, tooltip: any, url

block.init = function () {
old.call(this);
let block = this;
setHelpResources(this, id, name, tooltip, url, colour, colourSecondary, colourTertiary);
}
}
Expand Down
3 changes: 2 additions & 1 deletion pxtblocks/plugins/duplicateOnDrag/variablesGetReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Blockly.defineBlocksWithJsonArray([
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}"
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
"variableTypes": [""],
}
],
"output": null,
Expand Down
2 changes: 2 additions & 0 deletions pxtlib/spriteutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ namespace pxt.sprite {
}

export function bitmapEquals(a: pxt.sprite.BitmapData, b: pxt.sprite.BitmapData) {
if (a === b) return true;
else if (!a && b || !b && a) return false;
return pxt.sprite.Bitmap.fromData(a).equals(pxt.sprite.Bitmap.fromData(b));
}

Expand Down
22 changes: 22 additions & 0 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6278,6 +6278,28 @@ document.addEventListener("DOMContentLoaded", async () => {
socketbridge.tryInit();
electron.initElectron(theEditor);
})
.then(() => {
// Load theme colors
let initialTheme = data.getData<string>(auth.THEMEID);
if (!initialTheme) {
initialTheme = pxt.appTarget?.appTheme?.defaultColorTheme;
}

// We have a legacy preference stored if the user has enabled high contrast.
// Respect it here by switching to the hc color theme.
const hcEnabled = data.getData<boolean>(auth.HIGHCONTRAST);
if (hcEnabled) {
initialTheme = pxt.appTarget?.appTheme?.highContrastColorTheme;
}

if (initialTheme) {
const themeManager = ThemeManager.getInstance(document);
if (initialTheme !== themeManager.getCurrentColorTheme()?.id) {
return themeManager.switchColorTheme(initialTheme);
}
}
return Promise.resolve();
})
.then(() => {
const showHome = theEditor.shouldShowHomeScreen();
if (!showHome) {
Expand Down
9 changes: 9 additions & 0 deletions webapp/src/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class Editor extends toolboxeditor.ToolboxEditor {
showCategories: boolean = true;
breakpointsByBlock: pxt.Map<number>; // Map block id --> breakpoint ID
breakpointsSet: number[]; // the IDs of the breakpoints set.
currentFlyoutKey: string;

private errorChangesListeners: pxt.Map<(errors: pxtblockly.BlockDiagnostic[]) => void> = {};
protected intersectionObserver: IntersectionObserver;
Expand Down Expand Up @@ -667,6 +668,13 @@ export class Editor extends toolboxeditor.ToolboxEditor {
this.hideFlyout();
}

if (ev.type === "var_create") {
if (this.currentFlyoutKey === "variables" && this.editor.getFlyout()?.isVisible()) {
// refresh the flyout when a new variable is created
this.showVariablesFlyout();
}
}

if ((ignoredChanges.indexOf(ev.type) === -1)
|| this.markIncomplete) {
this.changeCallback();
Expand Down Expand Up @@ -1696,6 +1704,7 @@ export class Editor extends toolboxeditor.ToolboxEditor {
}

private showFlyoutInternal_(xmlList: Element[], flyoutName: string = "default") {
this.currentFlyoutKey = flyoutName;
const flyout = this.editor.getFlyout() as pxtblockly.VerticalFlyout;
flyout.show(xmlList, flyoutName);
flyout.scrollToStart();
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/blocksSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function cachedBuiltinCategories(): pxt.Map<BuiltinCategoryDefinition> {
</value>
<value name="LIST">
<block type="variables_get">
<field name="VAR">list</field>
<field name="VAR">${lf("{id:var}list")}</field>
</block>
</value>
</block>`
Expand Down
9 changes: 8 additions & 1 deletion webapp/src/components/ImageEditor/ImageCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple
if (document.activeElement instanceof HTMLElement && document.activeElement !== this.refs["canvas-bounds"]) {
document.activeElement.blur();
}
(this.refs["canvas-bounds"] as HTMLDivElement).focus();
this.focus();

if (this.isColorSelect()) {
this.selectCanvasColor(coord, isRightClick);
Expand All @@ -230,6 +230,7 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple

onDragStart(coord: ClientCoordinates, isRightClick?: boolean): void {
this.hasInteracted = true
this.focus();
if (this.touchesResize(coord.clientX, coord.clientY)) {
this.isResizing = true;
}
Expand All @@ -243,10 +244,12 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple
else {
this.updateCursorLocation(coord);
this.startEdit(!!isRightClick);
this.updateEdit(this.cursorLocation[0], this.cursorLocation[1]);
}
}

onDragMove(coord: ClientCoordinates): void {
this.focus();
if (this.isPanning() && this.lastPanX != undefined && this.lastPanY != undefined) {
this.panX += this.lastPanX - coord.clientX;
this.panY += this.lastPanY - coord.clientY;
Expand Down Expand Up @@ -1091,6 +1094,10 @@ export class ImageCanvasImpl extends React.Component<ImageCanvasProps, {}> imple

this.props.dispatchImageEdit(this.editState.toImageState());
}

protected focus() {
(this.refs["canvas-bounds"] as HTMLDivElement).focus();
}
}

function mapStateToProps({ store: { present }, editor }: ImageEditorStore, ownProps: any) {
Expand Down

0 comments on commit 266a670

Please sign in to comment.