| 9 | } |
| 10 | |
| 11 | export class PriorityContextMenu { |
| 12 | private menu: ContextMenu; |
| 13 | private options: PriorityContextMenuOptions; |
| 14 | private sortedPriorities: PriorityConfig[]; |
| 15 | private targetDoc: Document = activeDocument; |
| 16 | |
| 17 | constructor(options: PriorityContextMenuOptions) { |
| 18 | this.menu = new ContextMenu(); |
| 19 | this.options = options; |
| 20 | this.buildMenu(); |
| 21 | } |
| 22 | |
| 23 | private buildMenu(): void { |
| 24 | // Match the order shown in Priority settings. |
| 25 | this.sortedPriorities = this.options.plugin.priorityManager.getPrioritiesByWeightAsc(); |
| 26 | |
| 27 | this.sortedPriorities.forEach((priority) => { |
| 28 | this.menu.addItem((item) => { |
| 29 | let title = priority.label; |
| 30 | |
| 31 | // Use consistent icon for all items |
| 32 | item.setIcon("star"); |
| 33 | |
| 34 | // Highlight current selection with visual indicator |
| 35 | if (priority.value === this.options.currentValue) { |
| 36 | title = `✓ ${priority.label}`; |
| 37 | } |
| 38 | |
| 39 | item.setTitle(title); |
| 40 | |
| 41 | item.onClick(async () => { |
| 42 | this.options.onSelect(priority.value); |
| 43 | }); |
| 44 | }); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | public show(event: UIEvent): void { |
| 49 | // Store the document reference from the event target to support pop-out windows |
| 50 | // Use cross-window compatible instanceOf check |
| 51 | if ((event.target as Node)?.instanceOf?.(HTMLElement)) { |
| 52 | this.targetDoc = (event.target as HTMLElement).ownerDocument; |
| 53 | } |
| 54 | this.menu.show(event); |
| 55 | |
| 56 | // Apply color styling after menu is shown |
| 57 | window.setTimeout(() => { |
| 58 | this.applyColorStyling(); |
| 59 | }, 10); |
| 60 | } |
| 61 | |
| 62 | public showAtElement(element: HTMLElement): void { |
| 63 | // Store the document reference from the element to support pop-out windows |
| 64 | this.targetDoc = element.ownerDocument; |
| 65 | this.menu.showAtPosition({ |
| 66 | x: element.getBoundingClientRect().left, |
| 67 | y: element.getBoundingClientRect().bottom + 4, |
| 68 | }); |
nothing calls this directly
no outgoing calls
no test coverage detected