Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(store): cut/copy/paste support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReincarnator committed Dec 13, 2017
1 parent d163bb3 commit 50eb476
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Pattern } from './pattern';
import { Project } from './project';

export class Store {
@MobX.observable private clipboardElement?: PageElement | undefined;
@MobX.observable private currentPage?: Page;
@MobX.observable private patternSearchTerm: string = '';
@MobX.observable private projects: Project[] = [];
Expand All @@ -25,6 +26,10 @@ export class Store {
this.currentPage = undefined;
}

public getClipboardElement(): PageElement | undefined {
return this.clipboardElement;
}

public getCurrentPage(): Page | undefined {
return this.currentPage;
}
Expand Down Expand Up @@ -150,6 +155,10 @@ export class Store {
this.patternSearchTerm = patternSearchTerm;
}

public setClipboardElement(clipboardElement: PageElement): void {
this.clipboardElement = clipboardElement;
}

public setSelectedElement(selectedElement: PageElement): void {
this.selectedElement = selectedElement;
}
Expand Down
11 changes: 11 additions & 0 deletions src/store/page/page_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export class PageElement {
child.setParent(this, index);
}

public clone(): PageElement {
const clone = new PageElement(this.pattern);
this.children.forEach(child => {
clone.addChild(child.clone());
});
this.propertyValues.forEach((value: PropertyValue, id: string) => {
clone.setPropertyValue(id, value);
});
return clone;
}

protected createChildElementOrValue(json: JsonValue, store: Store): PageElement | PropertyValue {
if (json && (json as JsonObject)['_type'] === 'pattern') {
return PageElement.fromJsonObject(json as JsonObject, store, this);
Expand Down

0 comments on commit 50eb476

Please sign in to comment.