2
私の電子アプリには「ファイルを開く」というボタンがあり、それをクリックすると開いているファイルのダイアログボックスが表示され、ファイルを選択できます。エレクトロン - メニューからファイルを開く
アプリツールバーからメニュー項目をクリックすると、「ファイルを開く」ダイアログボックスを開くことはできますか?
これは、ツールバーメニューのサブメニューで私のラベルです:
label: 'Open',
accelerator: 'CmdOrCtrl+O'
私のような何かをしたい:
label: 'Open',
accelerator: 'CmdOrCtrl+O',
role: 'open'
をしかし、「オープン」というような役割がありません。
オープンファイルダイアログボックスを開くクリックイベントを実装するにはどうすればよいですか?
Main.js開いているファイルのセクション:
const ipc = require('electron').ipcMain
const dialog = require('electron').dialog
ipc.on('open-file-dialog', function (event) {
dialog.showOpenDialog({
properties: ['openFile', 'openDirectory']
}, function (files) {
if (files) event.sender.send('selected-file', files)
})
})
index.js:
const ipc = require('electron').ipcRenderer
const selectDirBtn = document.getElementById('open')
selectDirBtn.addEventListener('click', function (event) {
ipc.send('open-file-dialog')
})
ipc.on('selected-file', function (event, path) {
document.getElementById('selected-file').innerHTML = `► ${path}`
document.getElementById('selected-file2').innerHTML = `${path}`
})