diff options
author | 2019-03-01 14:25:44 +0100 | |
---|---|---|
committer | 2019-03-01 14:25:44 +0100 | |
commit | 739ef2e8a2dec94c3e10c3d26d797fe759fac7aa (patch) | |
tree | 4a2e066bf8627249f803eee16ba8e73268127fbd /src/lib | |
parent | fixes merge conflicts with latest develop (diff) | |
download | ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.gz ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.zst ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.zip |
finish workspaces mvp
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index c378619ad..1560dd285 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -3,6 +3,8 @@ import { observable, autorun, computed } 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,18 @@ 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 | workspaces: { | ||
185 | id: 'menu.workspaces', | ||
186 | defaultMessage: '!!!Workspaces', | ||
187 | }, | ||
188 | defaultWorkspace: { | ||
189 | id: 'menu.workspaces.defaultWorkspace', | ||
190 | defaultMessage: '!!!Default', | ||
191 | }, | ||
192 | addNewWorkspace: { | ||
193 | id: 'menu.workspaces.addNewWorkspace', | ||
194 | defaultMessage: '!!!Add New Workspace...', | ||
195 | }, | ||
182 | }); | 196 | }); |
183 | 197 | ||
184 | function getActiveWebview() { | 198 | function getActiveWebview() { |
@@ -266,6 +280,10 @@ const _templateFactory = intl => [ | |||
266 | submenu: [], | 280 | submenu: [], |
267 | }, | 281 | }, |
268 | { | 282 | { |
283 | label: intl.formatMessage(menuItems.workspaces), | ||
284 | submenu: [], | ||
285 | }, | ||
286 | { | ||
269 | label: intl.formatMessage(menuItems.window), | 287 | label: intl.formatMessage(menuItems.window), |
270 | role: 'window', | 288 | role: 'window', |
271 | submenu: [ | 289 | submenu: [ |
@@ -499,7 +517,9 @@ export default class FranzMenu { | |||
499 | } | 517 | } |
500 | 518 | ||
501 | _build() { | 519 | _build() { |
502 | const serviceTpl = Object.assign([], this.serviceTpl); // need to clone object so we don't modify computed (cached) object | 520 | // need to clone object so we don't modify computed (cached) object |
521 | const serviceTpl = Object.assign([], this.serviceTpl); | ||
522 | const workspacesMenu = Object.assign([], this.workspacesMenu); | ||
503 | 523 | ||
504 | if (window.franz === undefined) { | 524 | if (window.franz === undefined) { |
505 | return; | 525 | return; |
@@ -632,7 +652,7 @@ export default class FranzMenu { | |||
632 | }, | 652 | }, |
633 | ); | 653 | ); |
634 | 654 | ||
635 | tpl[4].submenu.unshift(about, { | 655 | tpl[5].submenu.unshift(about, { |
636 | type: 'separator', | 656 | type: 'separator', |
637 | }); | 657 | }); |
638 | } else { | 658 | } else { |
@@ -678,6 +698,8 @@ export default class FranzMenu { | |||
678 | tpl[3].submenu = serviceTpl; | 698 | tpl[3].submenu = serviceTpl; |
679 | } | 699 | } |
680 | 700 | ||
701 | tpl[4].submenu = workspacesMenu; | ||
702 | |||
681 | this.currentTemplate = tpl; | 703 | this.currentTemplate = tpl; |
682 | const menu = Menu.buildFromTemplate(tpl); | 704 | const menu = Menu.buildFromTemplate(tpl); |
683 | Menu.setApplicationMenu(menu); | 705 | Menu.setApplicationMenu(menu); |
@@ -701,6 +723,51 @@ export default class FranzMenu { | |||
701 | return []; | 723 | return []; |
702 | } | 724 | } |
703 | 725 | ||
726 | @computed get workspacesMenu() { | ||
727 | const { workspaces, activeWorkspace } = workspacesState; | ||
728 | const { intl } = window.franz; | ||
729 | const menu = []; | ||
730 | |||
731 | // Add new workspace item: | ||
732 | menu.push({ | ||
733 | label: intl.formatMessage(menuItems.addNewWorkspace), | ||
734 | accelerator: `${cmdKey}+Shift+N`, | ||
735 | click: () => { | ||
736 | this.actions.ui.openSettings({ path: 'workspaces' }); | ||
737 | }, | ||
738 | enabled: this.stores.user.isLoggedIn, | ||
739 | }, { | ||
740 | type: 'separator', | ||
741 | }); | ||
742 | |||
743 | // Default workspace | ||
744 | menu.push({ | ||
745 | label: intl.formatMessage(menuItems.defaultWorkspace), | ||
746 | accelerator: `${cmdKey}+Alt+1`, | ||
747 | type: 'radio', | ||
748 | checked: !activeWorkspace, | ||
749 | click: () => { | ||
750 | workspaceActions.deactivate(); | ||
751 | }, | ||
752 | }); | ||
753 | |||
754 | // Workspace items | ||
755 | if (this.stores.user.isLoggedIn) { | ||
756 | workspaces.forEach((workspace, i) => menu.push({ | ||
757 | label: workspace.name, | ||
758 | accelerator: i < 9 ? `${cmdKey}+Alt+${i + 2}` : null, | ||
759 | type: 'radio', | ||
760 | checked: activeWorkspace ? workspace.id === activeWorkspace.id : false, | ||
761 | click: () => { | ||
762 | workspaceActions.activate({ workspace }); | ||
763 | }, | ||
764 | })); | ||
765 | } | ||
766 | |||
767 | console.log(menu); | ||
768 | return menu; | ||
769 | } | ||
770 | |||
704 | _getServiceName(service) { | 771 | _getServiceName(service) { |
705 | if (service.name) { | 772 | if (service.name) { |
706 | return service.name; | 773 | return service.name; |