This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(menu): add context menu for page elements
fixes #111
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { MenuItemConstructorOptions, remote } from 'electron'; | ||
import { PageElement } from '../store/page/page-element'; | ||
import { Store } from '../store/store'; | ||
const { Menu } = remote; | ||
|
||
export function elementMenu(store: Store, element: PageElement): void { | ||
const clipboardElement: PageElement | undefined = store.getClipboardElement(); | ||
|
||
const template: MenuItemConstructorOptions[] = [ | ||
{ | ||
label: 'Cut Element', | ||
click: () => { | ||
store.setClipboardElement(element); | ||
element.remove(); | ||
} | ||
}, | ||
{ | ||
label: 'Copy Element', | ||
click: () => { | ||
store.setClipboardElement(element); | ||
} | ||
}, | ||
{ | ||
label: 'Delete element', | ||
click: () => { | ||
element.remove(); | ||
} | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
label: 'Paste element below', | ||
enabled: Boolean(clipboardElement), | ||
click: () => { | ||
const newPageElement = clipboardElement && clipboardElement.clone(); | ||
|
||
if (newPageElement) { | ||
element.addSibling(newPageElement); | ||
} | ||
} | ||
}, | ||
{ | ||
label: 'Paste element inside', | ||
enabled: Boolean(clipboardElement), | ||
click: () => { | ||
const newPageElement = clipboardElement && clipboardElement.clone(); | ||
|
||
if (newPageElement) { | ||
element.addChild(newPageElement); | ||
} | ||
} | ||
} | ||
]; | ||
|
||
const menu = Menu.buildFromTemplate(template); | ||
menu.popup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters