mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	feat(touchbar): basic implementation for modal buttons
This commit is contained in:
		| @@ -15,6 +15,7 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|     nativeImage: typeof import("electron").nativeImage; |     nativeImage: typeof import("electron").nativeImage; | ||||||
|     remote: typeof import("@electron/remote"); |     remote: typeof import("@electron/remote"); | ||||||
|     lastFocusedComponent?: Component; |     lastFocusedComponent?: Component; | ||||||
|  |     private $activeModal: JQuery<HTMLElement>; | ||||||
|  |  | ||||||
|     constructor() { |     constructor() { | ||||||
|         super(); |         super(); | ||||||
| @@ -23,8 +24,10 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|         this.$widget = $("<div>"); |         this.$widget = $("<div>"); | ||||||
|  |  | ||||||
|         $(window).on("focusin", async (e) => { |         $(window).on("focusin", async (e) => { | ||||||
|             const target = e.target; |             const $target = $(e.target); | ||||||
|             const parentComponentEl = $(target).closest(".component"); |  | ||||||
|  |             this.$activeModal = $target.closest(".modal-dialog"); | ||||||
|  |             const parentComponentEl = $target.closest(".component"); | ||||||
|             this.lastFocusedComponent = appContext.getComponentByEl(parentComponentEl[0]); |             this.lastFocusedComponent = appContext.getComponentByEl(parentComponentEl[0]); | ||||||
|             this.#refreshTouchBar(); |             this.#refreshTouchBar(); | ||||||
|         }); |         }); | ||||||
| @@ -52,17 +55,42 @@ export default class TouchBarWidget extends NoteContextAwareWidget { | |||||||
|     #refreshTouchBar() { |     #refreshTouchBar() { | ||||||
|         const { TouchBar } = this.remote; |         const { TouchBar } = this.remote; | ||||||
|         const parentComponent = this.lastFocusedComponent; |         const parentComponent = this.lastFocusedComponent; | ||||||
|         if (!parentComponent) { |         let touchBar = null; | ||||||
|             return; |  | ||||||
|  |         if (this.$activeModal.length > 0) { | ||||||
|  |             touchBar = this.#buildModalTouchBar(); | ||||||
|  |         } else if (parentComponent) { | ||||||
|  |             const items = parentComponent.triggerCommand("buildTouchBar", { | ||||||
|  |                 TouchBar, | ||||||
|  |                 buildIcon: this.buildIcon.bind(this) | ||||||
|  |             }) as unknown as TouchBarItem[]; | ||||||
|  |             touchBar = this.#buildTouchBar(items); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         let result = parentComponent.triggerCommand("buildTouchBar", { |         if (touchBar) { | ||||||
|             TouchBar, |             this.remote.getCurrentWindow().setTouchBar(touchBar); | ||||||
|             buildIcon: this.buildIcon.bind(this) |         } | ||||||
|         }) as unknown as TouchBarItem[]; |     } | ||||||
|  |  | ||||||
|         const touchBar = this.#buildTouchBar(result); |     #buildModalTouchBar() { | ||||||
|         this.remote.getCurrentWindow().setTouchBar(touchBar); |         const { TouchBar } = this.remote; | ||||||
|  |         const { TouchBarButton, TouchBarSpacer } = this.remote.TouchBar; | ||||||
|  |         const items: TouchBarItem[] = []; | ||||||
|  |  | ||||||
|  |         items.push(new TouchBarSpacer({ size: "flexible" })); | ||||||
|  |  | ||||||
|  |         // Look for buttons in the modal. | ||||||
|  |         const $buttons = this.$activeModal.find(".modal-footer button"); | ||||||
|  |         for (const button of $buttons) { | ||||||
|  |             items.push(new TouchBarButton({ | ||||||
|  |                 label: button.innerText, | ||||||
|  |                 click: () => button.click(), | ||||||
|  |                 enabled: !button.hasAttribute("disabled") | ||||||
|  |             })); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         items.push(new TouchBarSpacer({ size: "flexible" })); | ||||||
|  |         return new TouchBar({ items }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     #buildTouchBar(componentSpecificItems?: TouchBarItem[]) { |     #buildTouchBar(componentSpecificItems?: TouchBarItem[]) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user