|
|
|
@ -29,6 +29,7 @@ export class ContextMenu {
|
|
|
|
private contextMenuList: IRegisterContextMenu[]
|
|
|
|
private contextMenuList: IRegisterContextMenu[]
|
|
|
|
private contextMenuContainerList: HTMLDivElement[]
|
|
|
|
private contextMenuContainerList: HTMLDivElement[]
|
|
|
|
private contextMenuRelationShip: Map<HTMLDivElement, HTMLDivElement>
|
|
|
|
private contextMenuRelationShip: Map<HTMLDivElement, HTMLDivElement>
|
|
|
|
|
|
|
|
private context: IContextMenuContext | null
|
|
|
|
|
|
|
|
|
|
|
|
constructor(draw: Draw, command: Command) {
|
|
|
|
constructor(draw: Draw, command: Command) {
|
|
|
|
this.draw = draw
|
|
|
|
this.draw = draw
|
|
|
|
@ -36,6 +37,7 @@ export class ContextMenu {
|
|
|
|
this.range = draw.getRange()
|
|
|
|
this.range = draw.getRange()
|
|
|
|
this.position = draw.getPosition()
|
|
|
|
this.position = draw.getPosition()
|
|
|
|
this.container = draw.getContainer()
|
|
|
|
this.container = draw.getContainer()
|
|
|
|
|
|
|
|
this.context = null
|
|
|
|
// 内部菜单
|
|
|
|
// 内部菜单
|
|
|
|
this.contextMenuList = [
|
|
|
|
this.contextMenuList = [
|
|
|
|
...globalMenus,
|
|
|
|
...globalMenus,
|
|
|
|
@ -53,7 +55,7 @@ export class ContextMenu {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _proxyContextMenuEvent(evt: MouseEvent) {
|
|
|
|
private _proxyContextMenuEvent(evt: MouseEvent) {
|
|
|
|
const context = this._getContext()
|
|
|
|
this.context = this._getContext()
|
|
|
|
const renderList: IRegisterContextMenu[] = []
|
|
|
|
const renderList: IRegisterContextMenu[] = []
|
|
|
|
let isRegisterContextMenu = false
|
|
|
|
let isRegisterContextMenu = false
|
|
|
|
for (let c = 0; c < this.contextMenuList.length; c++) {
|
|
|
|
for (let c = 0; c < this.contextMenuList.length; c++) {
|
|
|
|
@ -61,7 +63,7 @@ export class ContextMenu {
|
|
|
|
if (menu.isDivider) {
|
|
|
|
if (menu.isDivider) {
|
|
|
|
renderList.push(menu)
|
|
|
|
renderList.push(menu)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const isMatch = menu.when?.(context)
|
|
|
|
const isMatch = menu.when?.(this.context)
|
|
|
|
if (isMatch) {
|
|
|
|
if (isMatch) {
|
|
|
|
renderList.push(menu)
|
|
|
|
renderList.push(menu)
|
|
|
|
isRegisterContextMenu = true
|
|
|
|
isRegisterContextMenu = true
|
|
|
|
@ -186,8 +188,8 @@ export class ContextMenu {
|
|
|
|
this._setHoverStatus(menuItem, false)
|
|
|
|
this._setHoverStatus(menuItem, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menuItem.onclick = () => {
|
|
|
|
menuItem.onclick = () => {
|
|
|
|
if (menu.callback) {
|
|
|
|
if (menu.callback && this.context) {
|
|
|
|
menu.callback(this.command)
|
|
|
|
menu.callback(this.command, this.context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.dispose()
|
|
|
|
this.dispose()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|