Skip to content

Commit b9283e5

Browse files
authored
Merge pull request #175 from arduino/feature/new-toolbar
Feature/new toolbar
2 parents 516d13b + 6602bf5 commit b9283e5

23 files changed

+730
-267
lines changed

backend/menu.js

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
const { app, Menu } = require('electron')
2+
const { shortcuts, disableShortcuts } = require('./shortcuts.js')
23
const path = require('path')
34
const serial = require('./serial/serial.js').sharedInstance
45
const openAboutWindow = require('about-window').default
5-
const shortcuts = require('./shortcuts.js')
6+
67
const { type } = require('os')
78

9+
let appInfoWindow = null
10+
11+
function closeAppInfo(win) {
12+
disableShortcuts(win, false)
13+
appInfoWindow.off('close', () => closeAppInfo(win))
14+
appInfoWindow = null
15+
16+
}
17+
function openAppInfo(win) {
18+
if (appInfoWindow != null) {
19+
appInfoWindow.show()
20+
} else {
21+
appInfoWindow = openAboutWindow({
22+
icon_path: path.resolve(__dirname, '../ui/arduino/media/about_image.png'),
23+
css_path: path.resolve(__dirname, '../ui/arduino/views/about.css'),
24+
copyright: '© Arduino SA 2022',
25+
package_json_dir: path.resolve(__dirname, '..'),
26+
bug_report_url: "https://github.com/arduino/lab-micropython-editor/issues",
27+
bug_link_text: "report an issue",
28+
homepage: "https://labs.arduino.cc",
29+
use_version_info: false,
30+
win_options: {
31+
parent: win,
32+
modal: true,
33+
},
34+
show_close_button: 'Close',
35+
})
36+
appInfoWindow.on('close', () => closeAppInfo(win));
37+
disableShortcuts(win, true)
38+
}
39+
}
40+
841
module.exports = function registerMenu(win, state = {}) {
942
const isMac = process.platform === 'darwin'
1043
const template = [
@@ -22,7 +55,22 @@ module.exports = function registerMenu(win, state = {}) {
2255
{
2356
label: 'File',
2457
submenu: [
25-
isMac ? { role: 'close' } : { role: 'quit' }
58+
{ label: 'New',
59+
accelerator: shortcuts.menu.NEW,
60+
enabled: state.view === 'editor',
61+
click: () => win.webContents.send('shortcut-cmd', shortcuts.global.NEW)
62+
},
63+
{ label: 'Save',
64+
accelerator: shortcuts.menu.SAVE,
65+
enabled: state.view === 'editor',
66+
click: () => win.webContents.send('shortcut-cmd', shortcuts.global.SAVE)
67+
},
68+
{ label: 'Close tab',
69+
accelerator: 'CmdOrCtrl+W',
70+
enabled: state.view === 'editor',
71+
click: () => win.webContents.send('shortcut-cmd', shortcuts.global.CLOSE)
72+
},
73+
{ role: 'quit' }
2674
]
2775
},
2876
{
@@ -166,40 +214,14 @@ module.exports = function registerMenu(win, state = {}) {
166214
},
167215
{
168216
label:'About Arduino Lab for MicroPython',
169-
click: () => {
170-
openAboutWindow({
171-
icon_path: path.resolve(__dirname, '../ui/arduino/media/about_image.png'),
172-
css_path: path.resolve(__dirname, '../ui/arduino/views/about.css'),
173-
copyright: '© Arduino SA 2022',
174-
package_json_dir: path.resolve(__dirname, '..'),
175-
bug_report_url: "https://github.com/arduino/lab-micropython-editor/issues",
176-
bug_link_text: "report an issue",
177-
homepage: "https://labs.arduino.cc",
178-
use_version_info: false,
179-
win_options: {
180-
parent: win,
181-
modal: true,
182-
},
183-
show_close_button: 'Close',
184-
})
185-
}
217+
click: () => { openAppInfo(win) }
186218
},
187219
]
188220
}
189221
]
190222

191223
const menu = Menu.buildFromTemplate(template)
192224

193-
app.setAboutPanelOptions({
194-
applicationName: app.name,
195-
applicationVersion: app.getVersion(),
196-
copyright: app.copyright,
197-
credits: '(See "Info about this app" in the Help menu)',
198-
authors: ['Arduino'],
199-
website: 'https://arduino.cc',
200-
iconPath: path.join(__dirname, '../assets/image.png'),
201-
})
202-
203225
Menu.setApplicationMenu(menu)
204226

205227
}

backend/shortcuts.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
1-
module.exports = {
1+
const { globalShortcut } = require('electron')
2+
let shortcutsActive = false
3+
const shortcuts = {
24
global: {
5+
CLOSE: 'CommandOrControl+W',
36
CONNECT: 'CommandOrControl+Shift+C',
47
DISCONNECT: 'CommandOrControl+Shift+D',
5-
SAVE: 'CommandOrControl+S',
68
RUN: 'CommandOrControl+R',
79
RUN_SELECTION: 'CommandOrControl+Alt+R',
810
RUN_SELECTION_WL: 'CommandOrControl+Alt+S',
911
STOP: 'CommandOrControl+H',
1012
RESET: 'CommandOrControl+Shift+R',
13+
NEW: 'CommandOrControl+N',
14+
SAVE: 'CommandOrControl+S',
1115
CLEAR_TERMINAL: 'CommandOrControl+L',
1216
EDITOR_VIEW: 'CommandOrControl+Alt+1',
1317
FILES_VIEW: 'CommandOrControl+Alt+2',
14-
ESC: 'Escape'
1518
},
1619
menu: {
20+
CLOSE: 'CmdOrCtrl+W',
1721
CONNECT: 'CmdOrCtrl+Shift+C',
1822
DISCONNECT: 'CmdOrCtrl+Shift+D',
19-
SAVE: 'CmdOrCtrl+S',
2023
RUN: 'CmdOrCtrl+R',
2124
RUN_SELECTION: 'CmdOrCtrl+Alt+R',
2225
RUN_SELECTION_WL: 'CmdOrCtrl+Alt+S',
2326
STOP: 'CmdOrCtrl+H',
2427
RESET: 'CmdOrCtrl+Shift+R',
28+
NEW: 'CmdOrCtrl+N',
29+
SAVE: 'CmdOrCtrl+S',
2530
CLEAR_TERMINAL: 'CmdOrCtrl+L',
2631
EDITOR_VIEW: 'CmdOrCtrl+Alt+1',
2732
FILES_VIEW: 'CmdOrCtrl+Alt+2'
28-
}
33+
},
34+
// Shortcuts
35+
}
36+
37+
function disableShortcuts (win, value) {
38+
console.log(value ? 'disabling' : 'enabling', 'shortcuts')
39+
win.send('ignore-shortcuts', value)
40+
}
41+
42+
module.exports = {
43+
shortcuts,
44+
disableShortcuts
2945
}
46+

index.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const { app, BrowserWindow, ipcMain, dialog, globalShortcut } = require('electron')
22
const path = require('path')
33
const fs = require('fs')
4-
const shortcuts = require('./backend/shortcuts.js').global
5-
64
const registerIPCHandlers = require('./backend/ipc.js')
75
const registerMenu = require('./backend/menu.js')
86

@@ -63,28 +61,15 @@ function createWindow () {
6361
})
6462
}
6563

66-
function shortcutAction(key) {
67-
win.webContents.send('shortcut-cmd', key);
68-
}
69-
70-
// Shortcuts
71-
function registerShortcuts() {
72-
Object.entries(shortcuts).forEach(([command, shortcut]) => {
73-
globalShortcut.register(shortcut, () => {
74-
shortcutAction(shortcut)
75-
});
76-
})
77-
}
78-
7964
app.on('ready', () => {
8065
createWindow()
81-
registerShortcuts()
8266

8367
win.on('focus', () => {
84-
registerShortcuts()
68+
console.log("win focus")
8569
})
70+
8671
win.on('blur', () => {
87-
globalShortcut.unregisterAll()
72+
console.log("win blur")
8873
})
8974

90-
})
75+
})

preload.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
console.log('preload')
22
const { contextBridge, ipcRenderer } = require('electron')
33
const path = require('path')
4-
const shortcuts = require('./backend/shortcuts.js').global
4+
const shortcuts = require('./backend/shortcuts.js').shortcuts.global
55
const { emit, platform } = require('process')
66
const SerialBridge = require('./backend/serial/serial-bridge.js')
77

@@ -63,6 +63,11 @@ const Window = {
6363
callback(k);
6464
})
6565
},
66+
onDisableShortcuts: (callback, value) => {
67+
ipcRenderer.on('ignore-shortcuts', (e, value) => {
68+
callback(value);
69+
})
70+
},
6671

6772
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback),
6873
confirmClose: () => ipcRenderer.invoke('confirm-close'),

ui/arduino/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<!-- Components -->
2626
<script type="text/javascript" src="views/components/code-editor.js" charset="utf-8"></script>
2727
<script type="text/javascript" src="views/components/connection-dialog.js" charset="utf-8"></script>
28+
<script type="text/javascript" src="views/components/new-file-dialog.js" charset="utf-8"></script>
2829
<script type="text/javascript" src="views/components/file-actions.js" charset="utf-8"></script>
2930
<script type="text/javascript" src="views/components/file-list.js" charset="utf-8"></script>
3031
<script type="text/javascript" src="views/components/repl-panel.js" charset="utf-8"></script>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy