diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index 7a60c448f..b21a62b4d 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -3,6 +3,8 @@ import { observable, autorun } from 'mobx'; | |||
3 | import { defineMessages } from 'react-intl'; | 3 | import { defineMessages } from 'react-intl'; |
4 | 4 | ||
5 | import { isMac, ctrlKey, cmdKey } from '../environment'; | 5 | import { isMac, ctrlKey, cmdKey } from '../environment'; |
6 | import { workspacesState } from '../features/workspaces/state'; | ||
7 | import workspaceActions from '../features/workspaces/actions'; | ||
6 | 8 | ||
7 | const { app, Menu, dialog } = remote; | 9 | const { app, Menu, dialog } = remote; |
8 | 10 | ||
@@ -179,6 +181,10 @@ const menuItems = defineMessages({ | |||
179 | id: 'menu.services.addNewService', | 181 | id: 'menu.services.addNewService', |
180 | defaultMessage: '!!!Add New Service...', | 182 | defaultMessage: '!!!Add New Service...', |
181 | }, | 183 | }, |
184 | addNewWorkspace: { | ||
185 | id: 'menu.workspaces.addNewWorkspace', | ||
186 | defaultMessage: '!!!Add New Workspace...', | ||
187 | }, | ||
182 | activateNextService: { | 188 | activateNextService: { |
183 | id: 'menu.services.setNextServiceActive', | 189 | id: 'menu.services.setNextServiceActive', |
184 | defaultMessage: '!!!Activate next service...', | 190 | defaultMessage: '!!!Activate next service...', |
@@ -195,6 +201,14 @@ const menuItems = defineMessages({ | |||
195 | id: 'sidebar.unmuteApp', | 201 | id: 'sidebar.unmuteApp', |
196 | defaultMessage: '!!!Enable notifications & audio', | 202 | defaultMessage: '!!!Enable notifications & audio', |
197 | }, | 203 | }, |
204 | workspaces: { | ||
205 | id: 'menu.workspaces', | ||
206 | defaultMessage: '!!!Workspaces', | ||
207 | }, | ||
208 | defaultWorkspace: { | ||
209 | id: 'menu.workspaces.defaultWorkspace', | ||
210 | defaultMessage: '!!!Default', | ||
211 | }, | ||
198 | }); | 212 | }); |
199 | 213 | ||
200 | function getActiveWebview() { | 214 | function getActiveWebview() { |
@@ -298,6 +312,10 @@ const _templateFactory = intl => [ | |||
298 | submenu: [], | 312 | submenu: [], |
299 | }, | 313 | }, |
300 | { | 314 | { |
315 | label: intl.formatMessage(menuItems.workspaces), | ||
316 | submenu: [], | ||
317 | }, | ||
318 | { | ||
301 | label: intl.formatMessage(menuItems.window), | 319 | label: intl.formatMessage(menuItems.window), |
302 | role: 'window', | 320 | role: 'window', |
303 | submenu: [ | 321 | submenu: [ |
@@ -537,6 +555,7 @@ export default class FranzMenu { | |||
537 | _build() { | 555 | _build() { |
538 | // need to clone object so we don't modify computed (cached) object | 556 | // need to clone object so we don't modify computed (cached) object |
539 | const serviceTpl = Object.assign([], this.serviceTpl()); | 557 | const serviceTpl = Object.assign([], this.serviceTpl()); |
558 | const workspacesMenu = Object.assign([], this.workspacesMenu()); | ||
540 | 559 | ||
541 | if (window.franz === undefined) { | 560 | if (window.franz === undefined) { |
542 | return; | 561 | return; |
@@ -669,7 +688,7 @@ export default class FranzMenu { | |||
669 | }, | 688 | }, |
670 | ); | 689 | ); |
671 | 690 | ||
672 | tpl[4].submenu.unshift(about, { | 691 | tpl[5].submenu.unshift(about, { |
673 | type: 'separator', | 692 | type: 'separator', |
674 | }); | 693 | }); |
675 | } else { | 694 | } else { |
@@ -704,6 +723,8 @@ export default class FranzMenu { | |||
704 | tpl[3].submenu = serviceTpl; | 723 | tpl[3].submenu = serviceTpl; |
705 | } | 724 | } |
706 | 725 | ||
726 | tpl[4].submenu = workspacesMenu; | ||
727 | |||
707 | this.currentTemplate = tpl; | 728 | this.currentTemplate = tpl; |
708 | const menu = Menu.buildFromTemplate(tpl); | 729 | const menu = Menu.buildFromTemplate(tpl); |
709 | Menu.setApplicationMenu(menu); | 730 | Menu.setApplicationMenu(menu); |
@@ -754,6 +775,50 @@ export default class FranzMenu { | |||
754 | return menu; | 775 | return menu; |
755 | } | 776 | } |
756 | 777 | ||
778 | workspacesMenu() { | ||
779 | const { workspaces, activeWorkspace } = workspacesState; | ||
780 | const { intl } = window.franz; | ||
781 | const menu = []; | ||
782 | |||
783 | // Add new workspace item: | ||
784 | menu.push({ | ||
785 | label: intl.formatMessage(menuItems.addNewWorkspace), | ||
786 | accelerator: `${cmdKey}+Shift+N`, | ||
787 | click: () => { | ||
788 | this.actions.ui.openSettings({ path: 'workspaces' }); | ||
789 | }, | ||
790 | enabled: this.stores.user.isLoggedIn, | ||
791 | }, { | ||
792 | type: 'separator', | ||
793 | }); | ||
794 | |||
795 | // Default workspace | ||
796 | menu.push({ | ||
797 | label: intl.formatMessage(menuItems.defaultWorkspace), | ||
798 | accelerator: `${cmdKey}+Alt+1`, | ||
799 | type: 'radio', | ||
800 | checked: !activeWorkspace, | ||
801 | click: () => { | ||
802 | workspaceActions.deactivate(); | ||
803 | }, | ||
804 | }); | ||
805 | |||
806 | // Workspace items | ||
807 | if (this.stores.user.isLoggedIn) { | ||
808 | workspaces.forEach((workspace, i) => menu.push({ | ||
809 | label: workspace.name, | ||
810 | accelerator: i < 9 ? `${cmdKey}+Alt+${i + 2}` : null, | ||
811 | type: 'radio', | ||
812 | checked: activeWorkspace ? workspace.id === activeWorkspace.id : false, | ||
813 | click: () => { | ||
814 | workspaceActions.activate({ workspace }); | ||
815 | }, | ||
816 | })); | ||
817 | } | ||
818 | |||
819 | return menu; | ||
820 | } | ||
821 | |||
757 | _getServiceName(service) { | 822 | _getServiceName(service) { |
758 | if (service.name) { | 823 | if (service.name) { |
759 | return service.name; | 824 | return service.name; |