1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-25 11:43:17 +01:00

add context menu to inputs

closes #1217
This commit is contained in:
Mikael Finstad 2023-07-26 10:05:20 +02:00
parent 351b8673ee
commit 999e855254
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
2 changed files with 33 additions and 0 deletions

30
public/contextMenu.js Normal file
View File

@ -0,0 +1,30 @@
const { Menu } = require('electron');
// https://github.com/electron/electron/issues/4068#issuecomment-274159726
module.exports = (window) => {
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' },
]);
window.webContents.on('context-menu', (e, props) => {
const { selectionText, isEditable } = props;
if (isEditable) {
inputMenu.popup(window);
} else if (selectionText && selectionText.trim() !== '') {
selectionMenu.popup(window);
}
});
};

View File

@ -16,6 +16,7 @@ const logger = require('./logger');
const menu = require('./menu'); const menu = require('./menu');
const configStore = require('./configStore'); const configStore = require('./configStore');
const { frontendBuildDir } = require('./util'); const { frontendBuildDir } = require('./util');
const attachContextMenu = require('./contextMenu');
const { checkNewVersion } = require('./update-checker'); const { checkNewVersion } = require('./update-checker');
@ -108,6 +109,8 @@ function createWindow() {
remote.enable(mainWindow.webContents); remote.enable(mainWindow.webContents);
attachContextMenu(mainWindow);
if (isDev) mainWindow.loadURL('http://localhost:3001'); if (isDev) mainWindow.loadURL('http://localhost:3001');
// Need to useloadFile for special characters https://github.com/mifi/lossless-cut/issues/40 // Need to useloadFile for special characters https://github.com/mifi/lossless-cut/issues/40