Skip to content
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

A couple of function dialog fixes #10415

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pxtblocks/plugins/functions/fields/fieldArgumentEditor.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import * as Blockly from "blockly";
import { FunctionManager } from "../functionManager";
import { ArgumentEditorBlock } from "../blocks/argumentEditorBlocks";

export interface FieldArgumentEditorConfig extends Blockly.FieldTextInputConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this as a separate interface if it no longer adds something to the Blockly.FieldTextInputConfig?

typeName?: string;
}

export class FieldArgumentEditor extends Blockly.FieldTextInput {
static REMOVE_ARG_URI =
"data:image/svg+xml;charset=UTF-8,%3c?xml version='1.0' encoding='UTF-8' standalone='no'?%3e%3csvg width='20px' height='20px' viewBox='0 0 20 20' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3c!-- Generator: Sketch 48.1 (47250) - http://www.bohemiancoding.com/sketch --%3e%3ctitle%3edelete-argument v2%3c/title%3e%3cdesc%3eCreated with Sketch.%3c/desc%3e%3cdefs%3e%3c/defs%3e%3cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3e%3cg id='delete-argument-v2' stroke='%23FF661A'%3e%3cg id='Group' transform='translate(3.000000, 2.500000)'%3e%3cpath d='M1,3 L13,3 L11.8900496,14.0995037 C11.8389294,14.6107055 11.4087639,15 10.8950124,15 L3.10498756,15 C2.59123611,15 2.16107055,14.6107055 2.10995037,14.0995037 L1,3 Z' id='Rectangle' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M7,11 L7,6' id='Line' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M9.5,11 L9.5,6' id='Line-Copy' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M4.5,11 L4.5,6' id='Line-Copy-2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3crect id='Rectangle-2' fill='%23FF661A' x='0' y='2.5' width='14' height='1' rx='0.5'%3e%3c/rect%3e%3cpath d='M6,0 L8,0 C8.55228475,-1.01453063e-16 9,0.44771525 9,1 L9,3 L5,3 L5,1 C5,0.44771525 5.44771525,1.01453063e-16 6,0 Z' id='Rectangle-3' stroke-width='1.5'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e";

protected typeName?: string;
protected removeButtonMouseWrapper_?: Blockly.browserEvents.Data;

constructor(text: string, opt_validator: Blockly.FieldValidator, config: FieldArgumentEditorConfig) {
super(text, opt_validator, config);

this.typeName = config.typeName;
}

showEditor(e?: Event | undefined): void {
Expand All @@ -34,10 +31,10 @@ export class FieldArgumentEditor extends Blockly.FieldTextInput {
this.removeCallback
);
div.appendChild(removeButton);

if (this.typeName && this.sourceBlock_?.workspace) {
const typeName = (this.sourceBlock_ as ArgumentEditorBlock)?.getTypeName();
if (typeName && this.sourceBlock_?.workspace) {
const iconClass = FunctionManager.getInstance().getIconForType(
this.typeName
typeName
);

if (iconClass) {
Expand Down Expand Up @@ -81,6 +78,7 @@ Blockly.Css.register(`
}

.functioneditor i.argumentEditorTypeIcon {
color: var(--pxt-primary-foreground);
position: absolute;
width: 24px;
height: 24px;
Expand Down
2 changes: 1 addition & 1 deletion pxtblocks/plugins/functions/functionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class FunctionManager {
}

setIconForType(typeName: string, icon: string) {
this.typeIcons[icon] = typeName;
this.typeIcons[typeName] = icon;
}

setArgumentNameForType(typeName: string, name: string) {
Expand Down
8 changes: 3 additions & 5 deletions pxtblocks/plugins/functions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,13 @@ export function createCustomArgumentEditor(typeName: string, ws: Blockly.Workspa
}

function createCustomArgumentBlock(blockType: string, typeName: string, ws: Blockly.Workspace) {
const block = Blockly.utils.xml.createElement("block");
block.setAttribute("type", blockType);

const block = ws.newBlock(blockType);
const mutation = Blockly.utils.xml.createElement("mutation");
mutation.setAttribute("typename", typeName);

block.appendChild(mutation);
block.domToMutation(mutation);

return Blockly.Xml.domToBlock(block, ws);
return block;
}

export function findLegalName(name: string, ws: Blockly.Workspace, block?: CommonFunctionBlock) {
Expand Down