mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	chore(client/ts): port menus/electron_context_menu
This commit is contained in:
		
							parent
							
								
									6480ce9aaf
								
							
						
					
					
						commit
						eb9a55bf4f
					
				@ -15,17 +15,18 @@ interface MenuSeparatorItem {
 | 
				
			|||||||
export interface MenuCommandItem {
 | 
					export interface MenuCommandItem {
 | 
				
			||||||
    title: string;
 | 
					    title: string;
 | 
				
			||||||
    command?: string;
 | 
					    command?: string;
 | 
				
			||||||
    type: string;
 | 
					    type?: string;
 | 
				
			||||||
    uiIcon: string;
 | 
					    uiIcon?: string;
 | 
				
			||||||
    templateNoteId?: string;
 | 
					    templateNoteId?: string;
 | 
				
			||||||
    enabled?: boolean;
 | 
					    enabled?: boolean;
 | 
				
			||||||
    handler?: MenuHandler;
 | 
					    handler?: MenuHandler;
 | 
				
			||||||
    items?: MenuItem[];
 | 
					    items?: MenuItem[];
 | 
				
			||||||
    shortcut?: string;
 | 
					    shortcut?: string;
 | 
				
			||||||
 | 
					    spellingSuggestion?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type MenuItem = MenuCommandItem | MenuSeparatorItem;
 | 
					export type MenuItem = MenuCommandItem | MenuSeparatorItem;
 | 
				
			||||||
export type MenuHandler = (item: MenuItem, e: JQuery.MouseDownEvent<HTMLElement, undefined, HTMLElement, HTMLElement>) => void;
 | 
					export type MenuHandler = (item: MenuCommandItem, e: JQuery.MouseDownEvent<HTMLElement, undefined, HTMLElement, HTMLElement>) => void;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ContextMenu {
 | 
					class ContextMenu {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,12 +3,14 @@ import options from "../services/options.js";
 | 
				
			|||||||
import zoomService from "../components/zoom.js";
 | 
					import zoomService from "../components/zoom.js";
 | 
				
			||||||
import contextMenu from "./context_menu.js";
 | 
					import contextMenu from "./context_menu.js";
 | 
				
			||||||
import { t } from "../services/i18n.js";
 | 
					import { t } from "../services/i18n.js";
 | 
				
			||||||
 | 
					import type { BrowserWindow } from "electron";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setupContextMenu() {
 | 
					function setupContextMenu() {
 | 
				
			||||||
    const electron = utils.dynamicRequire('electron');
 | 
					    const electron = utils.dynamicRequire('electron');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const remote = utils.dynamicRequire('@electron/remote');
 | 
					    const remote = utils.dynamicRequire('@electron/remote');
 | 
				
			||||||
    const {webContents} = remote.getCurrentWindow();
 | 
					    // FIXME: Remove typecast once Electron is properly integrated.
 | 
				
			||||||
 | 
					    const {webContents} = remote.getCurrentWindow() as BrowserWindow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    webContents.on('context-menu', (event, params) => {
 | 
					    webContents.on('context-menu', (event, params) => {
 | 
				
			||||||
        const {editFlags} = params;
 | 
					        const {editFlags} = params;
 | 
				
			||||||
@ -97,7 +99,7 @@ function setupContextMenu() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            // Read the search engine from the options and fallback to DuckDuckGo if the option is not set.
 | 
					            // Read the search engine from the options and fallback to DuckDuckGo if the option is not set.
 | 
				
			||||||
            const customSearchEngineName = options.get("customSearchEngineName");
 | 
					            const customSearchEngineName = options.get("customSearchEngineName");
 | 
				
			||||||
            const customSearchEngineUrl = options.get("customSearchEngineUrl");
 | 
					            const customSearchEngineUrl = options.get("customSearchEngineUrl") as string;
 | 
				
			||||||
            let searchEngineName;
 | 
					            let searchEngineName;
 | 
				
			||||||
            let searchEngineUrl;
 | 
					            let searchEngineUrl;
 | 
				
			||||||
            if (customSearchEngineName && customSearchEngineUrl) {
 | 
					            if (customSearchEngineName && customSearchEngineUrl) {
 | 
				
			||||||
@ -132,7 +134,7 @@ function setupContextMenu() {
 | 
				
			|||||||
            y: params.y / zoomLevel,
 | 
					            y: params.y / zoomLevel,
 | 
				
			||||||
            items,
 | 
					            items,
 | 
				
			||||||
            selectMenuItemHandler: ({command, spellingSuggestion}) => {
 | 
					            selectMenuItemHandler: ({command, spellingSuggestion}) => {
 | 
				
			||||||
                if (command === 'replaceMisspelling') {
 | 
					                if (command === 'replaceMisspelling' && spellingSuggestion) {
 | 
				
			||||||
                    webContents.insertText(spellingSuggestion);
 | 
					                    webContents.insertText(spellingSuggestion);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -131,9 +131,9 @@ export default class NoteTypeChooserDialog extends BasicWidget {
 | 
				
			|||||||
                const commandItem = (noteType as MenuCommandItem)
 | 
					                const commandItem = (noteType as MenuCommandItem)
 | 
				
			||||||
                this.$noteTypeDropdown.append(
 | 
					                this.$noteTypeDropdown.append(
 | 
				
			||||||
                    $('<a class="dropdown-item" tabindex="0">')
 | 
					                    $('<a class="dropdown-item" tabindex="0">')
 | 
				
			||||||
                        .attr("data-note-type", commandItem.type)
 | 
					                        .attr("data-note-type", commandItem.type || "")
 | 
				
			||||||
                        .attr("data-template-note-id", commandItem.templateNoteId || "")
 | 
					                        .attr("data-template-note-id", commandItem.templateNoteId || "")
 | 
				
			||||||
                        .append($("<span>").addClass(commandItem.uiIcon))
 | 
					                        .append($("<span>").addClass(commandItem.uiIcon || ""))
 | 
				
			||||||
                        .append(` ${noteType.title}`)
 | 
					                        .append(` ${noteType.title}`)
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user