Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 15, 2022
1 parent c572bca commit 2bfa288
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
15 changes: 12 additions & 3 deletions packages/project-editor/core/objectAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,17 +1197,26 @@ export class TreeAdapter implements ITreeAdapter {
}

onDragStart(item: ITreeObjectAdapter, event: any) {
const projectEditorStore = getDocumentStore(this.rootItem.object);

event.dataTransfer.effectAllowed = "copyMove";
setClipboardData(event, objectToClipboardData(item.object));
setClipboardData(
event,
objectToClipboardData(projectEditorStore, item.object)
);
event.dataTransfer.setDragImage(
DragAndDropManager.blankDragImage,
0,
0
);

// postpone render, otherwise we can receive onDragEnd immediatelly
const projectEditorStore = getDocumentStore(this.rootItem.object);
setTimeout(() => {
DragAndDropManager.start(event, item.object as any, projectEditorStore);
DragAndDropManager.start(
event,
item.object as any,
projectEditorStore
);
});
}

Expand Down
5 changes: 4 additions & 1 deletion packages/project-editor/flow/editor/ComponentsPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ const PaletteItem = observer(
object.height = 0;
}

setClipboardData(event, objectToClipboardData(object));
setClipboardData(
event,
objectToClipboardData(this.context, object)
);

event.dataTransfer.effectAllowed = "copy";

Expand Down
24 changes: 16 additions & 8 deletions packages/project-editor/store/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
getChildOfObject,
getClass,
getClassInfo,
getDocumentStore,
isArray,
isObject,
objectToJson,
Expand All @@ -28,9 +27,10 @@ import {

const CLIPOARD_DATA_ID = "application/eez-studio-project-editor-data";

export function cloneObjectWithNewObjIds(object: IEezObject) {
const projectEditorStore = getDocumentStore(object);

export function cloneObjectWithNewObjIds(
projectEditorStore: ProjectEditorStore,
object: IEezObject
) {
const clonedObject = createObject(
projectEditorStore,
toJS(object) as any,
Expand All @@ -42,10 +42,13 @@ export function cloneObjectWithNewObjIds(object: IEezObject) {
return objectToJson(clonedObject);
}

export function objectToClipboardData(object: IEezObject): string {
export function objectToClipboardData(
projectEditorStore: ProjectEditorStore,
object: IEezObject
): string {
return JSON.stringify({
objectClassName: getClass(object).name,
object: cloneObjectWithNewObjIds(object)
object: cloneObjectWithNewObjIds(projectEditorStore, object)
});
}

Expand All @@ -58,10 +61,15 @@ export function objectToClipboardDataWithoutNewObjIds(
});
}

export function objectsToClipboardData(objects: IEezObject[]): string {
export function objectsToClipboardData(
projectEditorStore: ProjectEditorStore,
objects: IEezObject[]
): string {
return JSON.stringify({
objectClassName: getClass(objects[0]).name,
objects: objects.map(object => cloneObjectWithNewObjIds(object))
objects: objects.map(object =>
cloneObjectWithNewObjIds(projectEditorStore, object)
)
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/project-editor/store/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,15 @@ export function deleteItem(object: IEezObject) {
}

export function cutItem(object: IEezObject) {
let clipboardText = objectToClipboardData(object);
let clipboardText = objectToClipboardData(getDocumentStore(object), object);

deleteItems([object], () => {
copyToClipboard(clipboardText);
});
}

export function copyItem(object: IEezObject) {
copyToClipboard(objectToClipboardData(object));
copyToClipboard(objectToClipboardData(getDocumentStore(object), object));
}

function duplicateItem(object: IEezObject) {
Expand Down
2 changes: 1 addition & 1 deletion packages/project-editor/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ export class ProjectEditorStore {
if (classInfo.objectsToClipboardData) {
return classInfo.objectsToClipboardData(objects);
}
return objectsToClipboardData(objects);
return objectsToClipboardData(this, objects);
}

setRuntimeMode(isDebuggerActive: boolean) {
Expand Down

0 comments on commit 2bfa288

Please sign in to comment.