Browse Source

fix(input): give feature full menu for inputs

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
233125f586
  1. 44
      app/menu.js

44
app/menu.js

@ -21,28 +21,48 @@ export default class MenuBuilder {
template = this.buildDefaultTemplate() template = this.buildDefaultTemplate()
} }
this.setupInputTemplate()
const menu = Menu.buildFromTemplate(template) const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu)
return menu return menu
} }
setupDevelopmentEnvironment() { setupInputTemplate() {
this.mainWindow.openDevTools() const selectionMenu = Menu.buildFromTemplate([
{ role: 'copy' },
{ type: 'separator' },
{ role: 'selectall' },
])
const inputMenu = Menu.buildFromTemplate([
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ type: 'separator' },
{ role: 'selectall' },
])
this.mainWindow.webContents.on('context-menu', (e, props) => { this.mainWindow.webContents.on('context-menu', (e, props) => {
const { x, y } = props const { selectionText, isEditable } = props;
Menu if (isEditable) {
.buildFromTemplate([{ inputMenu.popup(this.mainWindow);
label: 'Inspect element', } else if (selectionText && selectionText.trim() !== '') {
click: () => { selectionMenu.popup(this.mainWindow);
this.mainWindow.inspectElement(x, y) }
}
}])
.popup(this.mainWindow)
}) })
} }
setupDevelopmentEnvironment() {
this.mainWindow.openDevTools()
}
buildDarwinTemplate() { buildDarwinTemplate() {
const subMenuAbout = { const subMenuAbout = {
label: 'Electron', label: 'Electron',

Loading…
Cancel
Save