Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 8 additions & 8 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"mechanism_delete": "Delete Project",
"mechanism_rename": "Rename Project",
"mechanism_copy": "Copy Project",
"opmode_delete": "Delete Project",
"opmode_rename": "Rename Project",
"opmode_copy": "Copy Project",
"mechanism_delete": "Delete Mechanism",
"mechanism_rename": "Rename Mechanism",
"mechanism_copy": "Copy Mechanism",
"opmode_delete": "Delete OpMode",
"opmode_rename": "Rename OpMode",
"opmode_copy": "Copy OpMode",
"project_delete": "Delete Project",
"project_rename": "Rename Project",
"project_copy": "Copy Project",
"fail_list_modules": "Failed to load the list of modules.",
"fail_list_projects": "Failed to load the list of projects.",
"mechanism": "Mechanism",
"opmode": "OpMode",
"class_rule_description": "No spaces are allowed in the name. Each word in the name should start with a capital letter.",
Expand All @@ -21,4 +21,4 @@
"search": "Search..."

}
}
}
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const App: React.FC = (): React.JSX.Element => {
const createTabItemsFromProject = (projectData: commonStorage.Project): Tabs.TabItem[] => {
const tabs: Tabs.TabItem[] = [
{
key: projectData.modulePath,
key: projectData.robot.modulePath,
title: 'Robot',
type: TabType.ROBOT,
},
Expand Down Expand Up @@ -334,7 +334,7 @@ const App: React.FC = (): React.JSX.Element => {
if (project) {
const tabs = createTabItemsFromProject(project);
setTabItems(tabs);
setActiveTab(project.modulePath);
setActiveTab(project.robot.modulePath);
}
}, [project]);

Expand Down
14 changes: 9 additions & 5 deletions src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { getClassData, getAllowedTypesForSetCheck, getOutputCheck } from './util
import { FunctionData, findSuperFunctionData } from './utils/python_json_types';
import * as value from './utils/value';
import * as variable from './utils/variable';
import { Editor } from '../editor/editor';
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import { createFieldDropdown } from '../fields/FieldDropdown';
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
Expand Down Expand Up @@ -224,9 +223,15 @@ export function addInstanceComponentBlocks(
contents: toolboxItems.ContentsType[]) {

const classData = getClassData(componentType);
if (!classData) {
throw new Error('Could not find classData for ' + componentType);
}
const functions = classData.instanceMethods;

const componentClassData = getClassData('component.Component');
if (!componentClassData) {
throw new Error('Could not find classData for component.Component');
}
const componentFunctions = componentClassData.instanceMethods;

for (const functionData of functions) {
Expand Down Expand Up @@ -331,8 +336,7 @@ type CallPythonFunctionExtraState = {
*/
actualFunctionName?: string,
/**
* True if this blocks refers to an exported function (for example, from a
* user's Project).
* True if this blocks refers to an exported function (for example, from the Robot).
*/
exportedFunction?: boolean,
/**
Expand Down Expand Up @@ -540,7 +544,7 @@ const CALL_PYTHON_FUNCTION = {
case FunctionKind.INSTANCE_COMPONENT: {
// TODO: We need the list of component names for this.mrcComponentClassName so we can
// create a dropdown that has the appropriate component names.
const componentNames = [];
const componentNames: string[] = [];
const componentName = this.getComponentName();
if (!componentNames.includes(componentName)) {
componentNames.push(componentName);
Expand Down Expand Up @@ -679,7 +683,7 @@ export const pythonFromBlock = function(
: block.getFieldValue(FIELD_FUNCTION_NAME);
// Generate the correct code depending on the module type.
switch (generator.getModuleType()) {
case commonStorage.MODULE_TYPE_PROJECT:
case commonStorage.MODULE_TYPE_ROBOT:
case commonStorage.MODULE_TYPE_MECHANISM:
code = 'self.';
break;
Expand Down
3 changes: 1 addition & 2 deletions src/blocks/mrc_get_python_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ type GetPythonVariableExtraState = {
*/
actualVariableName?: string,
/**
* True if this blocks refers to an exported variable (for example, from a
* user's Project).
* True if this blocks refers to an exported variable (for example, from the Robot).
*/
exportedVariable?: boolean,
};
Expand Down
3 changes: 1 addition & 2 deletions src/blocks/mrc_set_python_variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ type SetPythonVariableExtraState = {
*/
actualVariableName?: string,
/**
* True if this blocks refers to an exported variable (for example, from a
* user's Project).
* True if this blocks refers to an exported variable (for example, from the Robot).
*/
exportedVariable?: boolean,
};
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/utils/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author [email protected] (Liz Looney)
*/

import { PythonData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types';
import { ClassData, PythonData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types';
import { robotPyData } from './robotpy_data';
import { externalSamplesData } from './external_samples_data';

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/utils/python_json_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function isSuperFunction(f1: FunctionData, f2: FunctionData): boolean {
return true;
}

export function findSuperFunctionData(functionData: FunctionData, superClassFunctions: FunctionData): FunctionData | null {
export function findSuperFunctionData(functionData: FunctionData, superClassFunctions: FunctionData[]): FunctionData | null {
for (const superClassFunctionData of superClassFunctions) {
if (isSuperFunction(superClassFunctionData, functionData)) {
return superClassFunctionData;
Expand Down
41 changes: 22 additions & 19 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class Editor {
private eventsCategory: EventsCategory;
private currentModule: commonStorage.Module | null = null;
private modulePath: string = '';
private projectPath: string = '';
private robotPath: string = '';
private moduleContent: string = '';
private projectContent: string = '';
private robotContent: string = '';
private bindedOnChange: any = null;
private toolbox: Blockly.utils.toolbox.ToolboxDefinition = EMPTY_TOOLBOX;

Expand All @@ -73,11 +73,11 @@ export class Editor {

// TODO(lizlooney): As blocks are loaded, determine whether any blocks
// are accessing variable or calling functions thar are defined in another
// blocks file (like a Project) and check whether the variable or function
// blocks file (like the Robot) and check whether the variable or function
// definition has changed. This might happen if the user defines a variable
// or function in the Project, uses the variable or function in the
// or function in the Robot, uses the variable or function in the
// OpMode, and then removes or changes the variable or function in the
// Project.
// Robot.

// TODO(lizlooney): We will need a way to identify which variable or
// function, other than by the variable name or function name, because the
Expand All @@ -88,15 +88,15 @@ export class Editor {
// TODO(lizlooney): Look at blocks with type 'mrc_get_python_variable' or
// 'mrc_set_python_variable', and where block.mrcExportedVariable === true.
// Look at block.mrcImportModule and get the exported blocks for that module.
// (It should be the project and we already have the project content.)
// It could be from the Robot (or a Mechanism?) and we already have the Robot content.
// Check whether block.mrcActualVariableName matches any exportedBlock's
// extraState.actualVariableName. If there is no match, put a warning on the
// block.

// TODO(lizlooney): Look at blocks with type 'mrc_call_python_function' and
// where block.mrcExportedFunction === true.
// Look at block.mrcImportModule and get the exported blocks for that module.
// (It should be the project and we already have the project content.)
// It could be from the Robot (or a Mechanism?) and we already have the Robot content.
// Check whether block.mrcActualFunctionName matches any exportedBlock's
// extraState.actualFunctionName. If there is no match, put a warning on the block.
// If there is a match, check whether
Expand Down Expand Up @@ -124,21 +124,23 @@ export class Editor {

if (currentModule) {
this.modulePath = currentModule.modulePath;
this.projectPath = commonStorage.makeProjectPath(currentModule.projectName);
this.robotPath = commonStorage.makeRobotPath(currentModule.projectName);
} else {
this.modulePath = '';
this.projectPath = '';
this.robotPath = '';
}
this.moduleContent = '';
this.projectContent = '';
this.robotContent = '';
this.clearBlocklyWorkspace();

if (currentModule) {
// Fetch the content for the current module and the robot.
// TODO: Also fetch the content for the mechanisms?
const promises: {[key: string]: Promise<string>} = {}; // key is module path, value is promise of module content.
promises[this.modulePath] = this.storage.fetchModuleContent(this.modulePath);
if (this.projectPath !== this.modulePath) {
// Also fetch the project module content. It contains exported blocks that can be used.
promises[this.projectPath] = this.storage.fetchModuleContent(this.projectPath)
if (this.robotPath !== this.modulePath) {
// Also fetch the robot module content. It contains components, etc, that can be used.
promises[this.robotPath] = this.storage.fetchModuleContent(this.robotPath)
}

const moduleContents: {[key: string]: string} = {}; // key is module path, value is module content
Expand All @@ -148,10 +150,10 @@ export class Editor {
})
);
this.moduleContent = moduleContents[this.modulePath];
if (this.projectPath === this.modulePath) {
this.projectContent = this.moduleContent
if (this.robotPath === this.modulePath) {
this.robotContent = this.moduleContent
} else {
this.projectContent = moduleContents[this.projectPath];
this.robotContent = moduleContents[this.robotPath];
}
this.loadBlocksIntoBlocklyWorkspace();
}
Expand Down Expand Up @@ -187,8 +189,8 @@ export class Editor {

public updateToolbox(shownPythonToolboxCategories: Set<string>): void {
if (this.currentModule) {
if (!this.projectContent) {
// The Project content hasn't been fetched yet. Try again in a bit.
if (!this.robotContent) {
// The Robot content hasn't been fetched yet. Try again in a bit.
setTimeout(() => {
this.updateToolbox(shownPythonToolboxCategories)
}, 50);
Expand Down Expand Up @@ -229,7 +231,8 @@ export class Editor {

private getComponents(): commonStorage.Component[] {
const components: commonStorage.Component[] = [];
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_PROJECT) {
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) {
// TODO(lizlooney): Fill the components array.
}
return components;
Expand Down
4 changes: 2 additions & 2 deletions src/editor/extended_python_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export class ExtendedPythonGenerator extends PythonGenerator {
}

getModuleType(): string | null {
if (this.context && this.context.module) {
return this.context.module.moduleType;
if (this.context) {
return this.context.getModuleType();
}
return null;
}
Expand Down
11 changes: 9 additions & 2 deletions src/editor/generator_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export class GeneratorContext {
this.clear();
}

getModuleType(): string | null {
if (this.module) {
return this.module.moduleType;
}
return null;
}

clear(): void {
this.clearExportedBlocks();
this.hasHardware= false;
Expand All @@ -58,7 +65,7 @@ export class GeneratorContext {
if (!this.module) {
throw new Error('getClassName: this.module is null.');
}
if (this.module.moduleType === commonStorage.MODULE_TYPE_PROJECT) {
if (this.module.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
return 'Robot';
}

Expand All @@ -69,7 +76,7 @@ export class GeneratorContext {
if (!this.module) {
throw new Error('getClassParent: this.module is null.');
}
if (this.module.moduleType === commonStorage.MODULE_TYPE_PROJECT) {
if (this.module.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
return 'RobotBase';
}
if (this.module.moduleType === commonStorage.MODULE_TYPE_OPMODE) {
Expand Down
2 changes: 1 addition & 1 deletion src/reactComponents/AddTabDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function AddTabDialog(props: AddTabDialogProps) {
await commonStorage.addModuleToProject(
props.storage, props.project, storageType, trimmedName);

const newModule = commonStorage.getClassInProject(props.project, trimmedName);
const newModule = commonStorage.findModuleByClassName(props.project, trimmedName);
if (newModule) {
const module: Module = {
path: newModule.modulePath,
Expand Down
2 changes: 1 addition & 1 deletion src/reactComponents/FileManageModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default function FileManageModal(props: FileManageModalProps) {
trimmedName
);

const newModule = commonStorage.getClassInProject(props.project, trimmedName);
const newModule = commonStorage.findModuleByClassName(props.project, trimmedName);
if (newModule) {
const module: Module = {
path: newModule.modulePath,
Expand Down
2 changes: 1 addition & 1 deletion src/reactComponents/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function Header(props: HeaderProps): React.JSX.Element {

/** Gets the project name or fallback text. */
const getProjectName = (): string => {
return props.project?.className || 'No Project Selected';
return props.project?.robot.className || 'No Project Selected';
};

return (
Expand Down
Loading