Loading files from a local system

Now that you have got the Open File functionality and registered the global keyboard shortcut for it, let's see what it takes to load a file from the local filesystem back into the editor component:

  1. Let's start by updating the menu.js file and registering a second global shortcut for Cmd + O or Ctrl + O, depending on the user's desktop platform:
      globalShortcut.register('CommandOrControl+O', () => {          // show open dialog      });

We have already imported the dialog object from the Electron framework. You can use it to invoke the system's Open dialog as well.

  1. Update the menu.js file according to the following code:
      globalShortcut.register('CommandOrControl+O', () => { const window = BrowserWindow.getFocusedWindow(); ...

Get Electron Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.