Home Reference Source Test Repository
import ContextMenuBuilder from 'electron-spellchecker/src/context-menu-builder.js'
public class | source

ContextMenuBuilder

ContextMenuBuilder creates context menus based on the content clicked - this information is derived from https://github.com/electron/electron/blob/master/docs/api/web-contents.md#event-context-menu, which we use to generate the menu. We also use the spell-check information to generate suggestions.

Static Method Summary

Static Public Methods
public static

Override the default logger for this class.

Constructor Summary

Public Constructor
public

constructor(spellCheckHandler: SpellCheckHandler, windowOrWebView: BrowserWindow | WebView, debugMode: Boolean)

Creates an instance of ContextMenuBuilder

Member Summary

Public Members
public
public

menu: *

public
public

Method Summary

Public Methods
public

addCopy(menu: *, menuInfo: *): *

Adds the Copy menu item.

public

addCut(menu: *, menuInfo: *): *

Adds the Cut menu item

public

addImageItems(menu: *, menuInfo: *): *

Adds "Copy Image" and "Copy Image URL" items when src is valid.

public

addInspectElement(menu: *, menuInfo: *, needsSeparator: boolean): *

Adds the "Inspect Element" menu item.

public

addPaste(menu: *, menuInfo: *): *

Adds the Paste menu item.

public

addSearchItems(menu: *, menuInfo: *): *

Adds search-related menu items.

public

addSeparator(menu: *): *

Adds a separator item.

public

addSpellingItems(menu: *, menuInfo: *): *

Checks if the current text selection contains a single misspelled word and if so, adds suggested spellings as individual menu items.

public

buildMenuForElement(info: *): Menu

Builds a context menu specific to the given info that would be shown immediately by {{showPopupMenu}}.

public

buildMenuForImage(menuInfo: *): Menu

Builds a menu applicable to an image.

public

buildMenuForLink(menuInfo: *): Menu

Builds a menu applicable to a link element.

public

buildMenuForText(menuInfo: *): Menu

Builds a menu applicable to a text field.

public

buildMenuForTextInput(menuInfo: *): Menu

Builds a menu applicable to a text input field.

public

convertImageToBase64(url: String, callback: Function, outputFormat: String)

Converts an image to a base-64 encoded string.

public

showPopupMenu(contextInfo: Object): Promise

Shows a popup menu given the information returned from the context-menu event.

Static Public Methods

public static setLogger(fn: Function) source

Override the default logger for this class. You probably want to use {{setGlobalLogger}} instead

Params:

NameTypeAttributeDescription
fn Function

The function which will operate like console.log

Public Constructors

public constructor(spellCheckHandler: SpellCheckHandler, windowOrWebView: BrowserWindow | WebView, debugMode: Boolean) source

Creates an instance of ContextMenuBuilder

Params:

NameTypeAttributeDescription
spellCheckHandler SpellCheckHandler

The spell checker to generate recommendations for.

windowOrWebView BrowserWindow | WebView

The hosting window/WebView

debugMode Boolean

If true, display the "Inspect Element" menu item.

Public Members

public debugMode: * source

public menu: * source

public spellCheckHandler: * source

public windowOrWebView: * source

Public Methods

public addCopy(menu: *, menuInfo: *): * source

Adds the Copy menu item.

Params:

NameTypeAttributeDescription
menu *
menuInfo *

Return:

*

public addCut(menu: *, menuInfo: *): * source

Adds the Cut menu item

Params:

NameTypeAttributeDescription
menu *
menuInfo *

Return:

*

public addImageItems(menu: *, menuInfo: *): * source

Adds "Copy Image" and "Copy Image URL" items when src is valid.

Params:

NameTypeAttributeDescription
menu *
menuInfo *

Return:

*

public addInspectElement(menu: *, menuInfo: *, needsSeparator: boolean): * source

Adds the "Inspect Element" menu item.

Params:

NameTypeAttributeDescription
menu *
menuInfo *
needsSeparator boolean
  • optional
  • default: true

Return:

*

public addPaste(menu: *, menuInfo: *): * source

Adds the Paste menu item.

Params:

NameTypeAttributeDescription
menu *
menuInfo *

Return:

*

public addSearchItems(menu: *, menuInfo: *): * source

Adds search-related menu items.

Params:

NameTypeAttributeDescription
menu *
menuInfo *

Return:

*

public addSeparator(menu: *): * source

Adds a separator item.

Params:

NameTypeAttributeDescription
menu *

Return:

*

public addSpellingItems(menu: *, menuInfo: *): * source

Checks if the current text selection contains a single misspelled word and if so, adds suggested spellings as individual menu items.

Params:

NameTypeAttributeDescription
menu *
menuInfo *

Return:

*

public buildMenuForElement(info: *): Menu source

Builds a context menu specific to the given info that would be shown immediately by {{showPopupMenu}}. Use this to add your own menu items to the list but use most of the default behavior.

Params:

NameTypeAttributeDescription
info *

Return:

Menu

The newly created Menu

public buildMenuForImage(menuInfo: *): Menu source

Builds a menu applicable to an image.

Params:

NameTypeAttributeDescription
menuInfo *

Return:

Menu

The Menu

Builds a menu applicable to a link element.

Params:

NameTypeAttributeDescription
menuInfo *

Return:

Menu

The Menu

public buildMenuForText(menuInfo: *): Menu source

Builds a menu applicable to a text field.

Params:

NameTypeAttributeDescription
menuInfo *

Return:

Menu

The Menu

public buildMenuForTextInput(menuInfo: *): Menu source

Builds a menu applicable to a text input field.

Params:

NameTypeAttributeDescription
menuInfo *

Return:

Menu

The Menu

public convertImageToBase64(url: String, callback: Function, outputFormat: String) source

Converts an image to a base-64 encoded string.

Params:

NameTypeAttributeDescription
url String

The image URL

callback Function

A callback that will be invoked with the result

outputFormat String

The image format to use, defaults to 'image/png'

public showPopupMenu(contextInfo: Object): Promise source

Shows a popup menu given the information returned from the context-menu event. This is probably the only method you need to call in this class.

Params:

NameTypeAttributeDescription
contextInfo Object

The object returned from the 'context-menu' Electron event.

Return:

Promise

Completion