Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 15, 2024
1 parent f107b18 commit 22d919d
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 129 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"request": "^2.88.2",
"request-promise-native": "^1.0.5",
"run-script-os": "^1.1.6",
"typescript": "^5.3.3",
"typescript": "^5.5.3",
"wpapi": "^1.2.2"
},
"dependencies": {
Expand Down Expand Up @@ -184,4 +184,4 @@
"xterm": "^4.14.1",
"xterm-addon-fit": "^0.5.0"
}
}
}
5 changes: 5 additions & 0 deletions packages/project-editor/core/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,15 @@ export type InheritedValue =

export interface SerializedData {
originProjectFilePath: string;

objectClassName: string;
classInfo?: ClassInfo;

object?: EezObject;
objectParentPath?: string;

objects?: EezObject[];
objectsParentPath?: string[];
}

interface LVGLClassInfoProperties {
Expand Down
158 changes: 85 additions & 73 deletions packages/project-editor/flow/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
PropertyInfo,
PropertyType,
registerClass,
SerializedData
SerializedData,
setParent
} from "project-editor/core/object";
import { visitObjects } from "project-editor/core/search";
import {
Expand Down Expand Up @@ -185,6 +186,7 @@ export abstract class Flow extends EezObject {
objectsToClipboardData(objects: IEezObject[]) {
const flowFragment = new FlowFragment();
flowFragment.addObjects(this, objects);
setParent(flowFragment, this);
return objectToClipboardData(
ProjectEditor.getProjectStore(this),
flowFragment
Expand Down Expand Up @@ -324,103 +326,113 @@ export class FlowFragment extends EezObject {
const flow = ProjectEditor.getFlow(clipboardData.pastePlace);
const pasteFlowFragment = clipboardData.serializedData
.object as FlowFragment;

const projectStore = getProjectStore(flow);

const flowFragment = createObject(
return FlowFragment.paste(
projectStore,
flow,
pasteFlowFragment,
FlowFragment,
undefined,
false
object
);
}
};

let closeCombineCommands = false;
if (!projectStore.undoManager.combineCommands) {
projectStore.undoManager.setCombineCommands(true);
closeCombineCommands = true;
}
static paste(
projectStore: ProjectStore,
flow: Flow,
pasteFlowFragment: FlowFragment,
object: IEezObject
) {
const flowFragment = createObject(
projectStore,
pasteFlowFragment,
FlowFragment,
undefined,
false
);

let components: EezObject[] = [];
let closeCombineCommands = false;
if (!projectStore.undoManager.combineCommands) {
projectStore.undoManager.setCombineCommands(true);
closeCombineCommands = true;
}

if (flowFragment.connectionLines.length > 0) {
flowFragment.connectionLines.forEach(connectionLine =>
projectStore.addObject(flow.connectionLines, connectionLine)
);
let components: EezObject[] = [];

flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(flow.components, component)
);
});
} else {
if (
(object instanceof Widget ||
object instanceof ProjectEditor.LVGLWidgetClass) &&
flowFragment.components.every(
component => component instanceof Widget
)
) {
let containerAncestor:
| ContainerWidget
| SelectWidget
| LVGLWidget
| undefined = getAncestorOfType(
getParent(getParent(object)),
ContainerWidget.classInfo
) as ContainerWidget | undefined;
if (flowFragment.connectionLines.length > 0) {
flowFragment.connectionLines.forEach(connectionLine =>
projectStore.addObject(flow.connectionLines, connectionLine)
);

flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(flow.components, component)
);
});
} else {
if (
(object instanceof Widget ||
object instanceof ProjectEditor.LVGLWidgetClass) &&
flowFragment.components.every(
component => component instanceof Widget
)
) {
let containerAncestor:
| ContainerWidget
| SelectWidget
| LVGLWidget
| undefined = getAncestorOfType(
getParent(getParent(object)),
ContainerWidget.classInfo
) as ContainerWidget | undefined;

if (!containerAncestor) {
containerAncestor = getAncestorOfType(
getParent(getParent(object)),
SelectWidget.classInfo
) as SelectWidget | undefined;
if (!containerAncestor) {
containerAncestor = getAncestorOfType(
getParent(getParent(object)),
SelectWidget.classInfo
) as SelectWidget | undefined;
if (!containerAncestor) {
containerAncestor = getAncestorOfType(
getParent(getParent(object)),
ProjectEditor.LVGLWidgetClass.classInfo
) as LVGLWidget | undefined;
}
ProjectEditor.LVGLWidgetClass.classInfo
) as LVGLWidget | undefined;
}
}

if (containerAncestor) {
const parent =
containerAncestor instanceof
ProjectEditor.LVGLWidgetClass
? containerAncestor.children
: containerAncestor.widgets;

flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(parent, component)
);
});
} else {
flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(
flow.components,
component
)
);
});
}
if (containerAncestor) {
const parent =
containerAncestor instanceof
ProjectEditor.LVGLWidgetClass
? containerAncestor.children
: containerAncestor.widgets;

flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(parent, component)
);
});
} else {
flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(flow.components, component)
);
});
}
} else {
flowFragment.components.forEach(component => {
components.push(
projectStore.addObject(flow.components, component)
);
});
}
}

if (closeCombineCommands) {
projectStore.undoManager.setCombineCommands(false);
}

return components;
if (closeCombineCommands) {
projectStore.undoManager.setCombineCommands(false);
}
};

return components;
}

addObjects(flow: Flow, objects: IEezObject[]) {
this.components = [];
Expand Down
7 changes: 5 additions & 2 deletions packages/project-editor/project-editor-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
LVGLLedWidget
} from "project-editor/lvgl/widgets";

import { getBitmapData } from "project-editor/features/bitmap/bitmap";
import { Bitmap, getBitmapData } from "project-editor/features/bitmap/bitmap";
import {
migrateProjectVersion,
migrateProjectType
Expand Down Expand Up @@ -117,6 +117,7 @@ import { ConditionalStyle, Style } from "project-editor/features/style/style";
import { PropertyType } from "project-editor/core/object";
import { evalProperty } from "project-editor/flow/helper";
import { migrateLvglVersion } from "./lvgl/migrate";
import { FlowTabState } from "project-editor/flow/flow-tab-state";

export const conditionalStyleConditionProperty = makeExpressionProperty(
{
Expand Down Expand Up @@ -180,6 +181,7 @@ export async function createProjectEditor(
ScpiCommandClass: ScpiCommand,
ScpiSubsystemClass: ScpiSubsystem,
StyleClass: Style,
BitmapClass: Bitmap,
LVGLWidgetClass: LVGLWidget,
LVGLScreenWidgetClass: LVGLScreenWidget,
LVGLPanelWidgetClass: LVGLPanelWidget,
Expand Down Expand Up @@ -220,7 +222,8 @@ export async function createProjectEditor(
createActionComponentClass,
makeExpressionProperty,
evalProperty,
conditionalStyleConditionProperty
conditionalStyleConditionProperty,
FlowTabStateClass: FlowTabState
};

ConditionalStyle.classInfo.properties.push(
Expand Down
8 changes: 7 additions & 1 deletion packages/project-editor/project-editor-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ import type {
ScpiSubsystem
} from "project-editor/features/scpi/scpi";
import type { getObjectVariableTypeFromType } from "project-editor/features/variable/value-type";
import type { getBitmapData } from "project-editor/features/bitmap/bitmap";
import type {
Bitmap,
getBitmapData
} from "project-editor/features/bitmap/bitmap";
import type {
migrateProjectVersion,
migrateProjectType
Expand Down Expand Up @@ -94,6 +97,7 @@ import type { Style } from "project-editor/features/style/style";
import type { evalProperty } from "project-editor/flow/helper";
import type { PropertyInfo } from "project-editor/core/object";
import type { migrateLvglVersion } from "project-editor/lvgl/migrate";
import type { FlowTabState } from "project-editor/flow/flow-tab-state";

export interface IProjectEditor {
homeTabs?: Tabs;
Expand Down Expand Up @@ -129,6 +133,7 @@ export interface IProjectEditor {
ScpiCommandClass: typeof ScpiCommand;
ScpiSubsystemClass: typeof ScpiSubsystem;
StyleClass: typeof Style;
BitmapClass: typeof Bitmap;
LVGLWidgetClass: typeof LVGLWidget;
LVGLScreenWidgetClass: typeof LVGLScreenWidget;
LVGLPanelWidgetClass: typeof LVGLPanelWidget;
Expand Down Expand Up @@ -170,6 +175,7 @@ export interface IProjectEditor {
makeExpressionProperty: typeof makeExpressionProperty;
evalProperty: typeof evalProperty;
conditionalStyleConditionProperty: PropertyInfo;
FlowTabStateClass: typeof FlowTabState;
}

export const ProjectEditor: IProjectEditor = {} as any;
11 changes: 8 additions & 3 deletions packages/project-editor/store/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
ProjectStore,
rewireBegin,
rewireEnd,
canContain
canContain,
getObjectPathAsString
} from "project-editor/store";

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -33,7 +34,7 @@ const CLIPOARD_DATA_ID = "application/eez-studio-project-editor-data";

////////////////////////////////////////////////////////////////////////////////

function cloneObjectWithNewObjIds(
export function cloneObjectWithNewObjIds(
projectStore: ProjectStore,
object: IEezObject
) {
Expand All @@ -59,7 +60,8 @@ export function objectToClipboardData(
const serializeData: SerializedData = {
originProjectFilePath: projectStore.filePath!,
objectClassName: getClass(object).name,
object: objectToJson(clonedObject) as any as EezObject
object: objectToJson(clonedObject) as any as EezObject,
objectParentPath: getObjectPathAsString(getParent(object))
};

return JSON.stringify(serializeData);
Expand All @@ -80,6 +82,9 @@ export function objectsToClipboardData(
objectClassName: getClass(objects[0]).name,
objects: clonedObjects.map(
clonedObject => objectToJson(clonedObject) as any as EezObject
),
objectsParentPath: objects.map(object =>
getObjectPathAsString(getParent(object))
)
};

Expand Down
Loading

0 comments on commit 22d919d

Please sign in to comment.