git ssb

16+

Dominic / patchbay



Commit 2cb8123fabc8c9afd098f2f7d134679e1eea8a71

Add keyboard tab controls

Tab keyboard shortcuts like Chrome or Firefox

I couldn't prove that windows has a different `Window` menu, if I'm wrong I'm happy to put back the conditional.

Chrome and Firefox has their tab controls under `File` but that seems weird here. Also I'd love to bring in a new tab window but that's a completely new view and I have no idea what it might look like. Additionally I'd love to do an undo close tab but I'm not sure how we'd want to keep history.
Francis Gulotta committed on 2/2/2018, 2:16:12 PM
Parent: a3577fc70f3b65a93d2d0e8cd6c529f6695a70a4

Files changed

README.mdchanged
app/html/app.jschanged
app/html/tabs.jschanged
index.jschanged
README.mdView
@@ -7,9 +7,8 @@
77 Patchbay is built using [patchcore](https://github.com/ssbc/patchcore) + [depject](https://github.com/dominictarr/depject). The goal is to make it easier to develop new features, and enable or disable features. This has so far been quite successful!
88
99 This makes in very easy to create say, a renderer for a new message type, or switch to a different method for choosing user names.
1010
11-
1211 ## Setup
1312
1413 Libsodium has some build dependencies. On ubuntu systems the following might help:
1514
@@ -99,8 +98,16 @@
9998 # from the patchbay repo folder
10099 npm run dev
101100 ```
102101
102 +## Keyboard shortcuts
103 +`CmdOrCtrl` is the `command` key on Apple keyboards or the `ctrl` key on PC keyboards.
104 +
105 +### Tabs and Window
106 +- `CmdOrCtrl+Shift+]` and `CmdOrCtrl+Shift+[` will cycle the tabs left and right
107 +- `CmdOrCtrl+w` will close the current tab
108 +- `CmdOrCtrl+Shift+w` will close the current window
109 +
103110 ## How to add a feature
104111
105112 To add a new message type, add add a js to `./modules/` that exports a function named `message_content` (it should return an HTML element). To add a new tab, export a function named `screen_view` (returns an html element).
106113
app/html/app.jsView
@@ -29,9 +29,8 @@
2929
3030 api.app.sync.initialise()
3131
3232 window = api.app.sync.window(window)
33-
3433 const css = values(api.styles.css()).join('\n')
3534 insertCss(css)
3635
3736 const initialTabs = ['/public', '/inbox', '/notifications']
@@ -39,8 +38,20 @@
3938 const tabs = api.app.html.tabs(initialTabs)
4039
4140 const App = h('App', tabs)
4241
42 + electron.ipcRenderer.on('nextTab', () => {
43 + tabs.nextTab()
44 + })
45 +
46 + electron.ipcRenderer.on('previousTab', () => {
47 + tabs.previousTab()
48 + })
49 +
50 + electron.ipcRenderer.on('closeTab', () => {
51 + tabs.closeCurrentTab()
52 + })
53 +
4354 // Catch user actions
4455 api.app.sync.catchKeyboardShortcut(window, { tabs })
4556 api.app.async.catchLinkClick(App)
4657
app/html/tabs.jsView
@@ -42,18 +42,24 @@
4242 return JSON.stringify(loc) != page.id
4343 })
4444 history.set(prunedHistory)
4545 }
46-
46 +
4747 const search = api.app.html.searchBar()
4848 const menu = api.app.html.menu()
4949
5050 _tabs = Tabs({
5151 onSelect,
5252 onClose,
5353 append: h('div.navExtra', [ search, menu ])
5454 })
55- _tabs.currentPage = () => _tabs.get(_tabs.selected[0]).firstChild
55 + _tabs.currentPage = () => {
56 + const currentPage = _tabs.get(_tabs.selected[0])
57 + return currentPage && currentPage.firstChild
58 + }
59 + _tabs.nextTab = () => _tabs.currentPage() && _tabs.selectRelative(1)
60 + _tabs.previousTab = () => _tabs.currentPage() && _tabs.selectRelative(-1)
61 + _tabs.closeCurrentTab = () => _tabs.currentPage() && _tabs.remove(_tabs.selected[0])
5662
5763 // # TODO: review - this works but is strange
5864 initialTabs.forEach(p => api.app.sync.goTo(p))
5965 api.app.sync.goTo(initialTabs[0])
index.jsView
@@ -21,18 +21,38 @@
2121 { role: 'zoomout' },
2222 { type: 'separator' },
2323 { role: 'togglefullscreen' }
2424 ]
25- if (process.platform === 'darwin') {
26- var win = menu.find(x => x.label === 'Window')
27- win.submenu = [
28- { role: 'minimize' },
29- { role: 'zoom' },
30- { role: 'close', label: 'Close' },
31- { type: 'separator' },
32- { role: 'front' }
33- ]
34- }
25 + var win = menu.find(x => x.label === 'Window')
26 + win.submenu = [
27 + { role: 'minimize' },
28 + { role: 'zoom' },
29 + { role: 'close', label: 'Close Window', accelerator: 'CmdOrCtrl+Shift+W' },
30 + { type: 'separator' },
31 + {
32 + label: 'Close Tab',
33 + accelerator: 'CmdOrCtrl+W',
34 + click() {
35 + windows.main.webContents.send('closeTab')
36 + }
37 + },
38 + {
39 + label: 'Select Next Tab',
40 + accelerator: 'CmdOrCtrl+Shift+]',
41 + click() {
42 + windows.main.webContents.send('nextTab')
43 + }
44 + },
45 + {
46 + label: 'Select Previous Tab',
47 + accelerator: 'CmdOrCtrl+Shift+[',
48 + click() {
49 + windows.main.webContents.send('previousTab')
50 + }
51 + },
52 + { type: 'separator' },
53 + { role: 'front' }
54 + ]
3555
3656 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
3757
3858 startBackgroundProcess()

Built with git-ssb-web