mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-08 05:57:02 +09:00
JS-6593: Update accelerators with shortcut settings, fix export/import
This commit is contained in:
parent
62b3b97fbc
commit
9535c4b688
4 changed files with 59 additions and 23 deletions
|
@ -19,7 +19,6 @@ if (is.windows) {
|
|||
};
|
||||
|
||||
storage.setDataPath(app.getPath('userData'));
|
||||
//Store.initRenderer();
|
||||
|
||||
const Api = require('./electron/js/api.js');
|
||||
const ConfigManager = require('./electron/js/config.js');
|
||||
|
@ -31,6 +30,8 @@ const Util = require('./electron/js/util.js');
|
|||
const Cors = require('./electron/json/cors.json');
|
||||
const csp = [];
|
||||
|
||||
MenuManager.store = store;
|
||||
|
||||
for (let i in Cors) {
|
||||
csp.push([ i ].concat(Cors[i]).join(' '));
|
||||
};
|
||||
|
|
|
@ -89,8 +89,7 @@ class Api {
|
|||
ConfigManager.set({ hideTray: !show }, () => {
|
||||
Util.send(win, 'config', ConfigManager.config);
|
||||
|
||||
MenuManager.initMenu();
|
||||
MenuManager.initTray();
|
||||
this.initMenu(win);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -192,11 +191,15 @@ class Api {
|
|||
setInterfaceLang (win, lang) {
|
||||
ConfigManager.set({ interfaceLang: lang }, () => {
|
||||
WindowManager.reloadAll();
|
||||
MenuManager.initMenu();
|
||||
MenuManager.initTray();
|
||||
this.initMenu(win);
|
||||
});
|
||||
};
|
||||
|
||||
initMenu (win) {
|
||||
MenuManager.initMenu();
|
||||
MenuManager.initTray();
|
||||
};
|
||||
|
||||
setSpellingLang (win, languages) {
|
||||
languages = languages || [];
|
||||
|
||||
|
|
|
@ -11,12 +11,43 @@ class MenuManager {
|
|||
win = null;
|
||||
menu = null;
|
||||
tray = null;
|
||||
store = null;
|
||||
|
||||
setWindow (win) {
|
||||
this.win = win;
|
||||
};
|
||||
|
||||
initShortcuts () {
|
||||
this.shortcuts = this.store.get('shortcuts') || {};
|
||||
};
|
||||
|
||||
getAccelerator (id) {
|
||||
const keys = this.shortcuts[id] || [];
|
||||
if (!keys.length) {
|
||||
return '';
|
||||
};
|
||||
|
||||
const ret = [];
|
||||
|
||||
for (const key of keys) {
|
||||
if (key == 'ctrl') {
|
||||
ret.push('CmdOrCtrl');
|
||||
} else
|
||||
if (key == 'shift') {
|
||||
ret.push('Shift');
|
||||
} else
|
||||
if (key == 'alt') {
|
||||
ret.push('Alt');
|
||||
} else {
|
||||
ret.push(key.toUpperCase());
|
||||
};
|
||||
};
|
||||
return ret.join('+');
|
||||
};
|
||||
|
||||
initMenu () {
|
||||
this.initShortcuts();
|
||||
|
||||
const { config } = ConfigManager;
|
||||
const Api = require('./api.js');
|
||||
const WindowManager = require('./window.js');
|
||||
|
@ -53,7 +84,7 @@ class MenuManager {
|
|||
{
|
||||
role: 'fileMenu', label: Util.translate('electronMenuFile'),
|
||||
submenu: [
|
||||
{ label: Util.translate('commonNewObject'), accelerator: 'CmdOrCtrl+N', click: () => Util.send(this.win, 'commandGlobal', 'createObject') },
|
||||
{ label: Util.translate('commonNewObject'), accelerator: this.getAccelerator('createObject') || 'CmdOrCtrl+N', click: () => Util.send(this.win, 'commandGlobal', 'createObject') },
|
||||
{ label: Util.translate('commonNewSpace'), click: () => Util.send(this.win, 'commandGlobal', 'createSpace') },
|
||||
|
||||
Separator,
|
||||
|
@ -106,7 +137,7 @@ class MenuManager {
|
|||
label: Util.translate('electronMenuEdit'),
|
||||
submenu: [
|
||||
{
|
||||
label: Util.translate('electronMenuUndo'), accelerator: 'CmdOrCtrl+Z',
|
||||
label: Util.translate('electronMenuUndo'), accelerator: this.getAccelerator('undo') || 'CmdOrCtrl+Z',
|
||||
click: () => {
|
||||
if (this.win) {
|
||||
this.win.webContents.undo();
|
||||
|
@ -115,7 +146,7 @@ class MenuManager {
|
|||
}
|
||||
},
|
||||
{
|
||||
label: Util.translate('electronMenuRedo'), accelerator: 'CmdOrCtrl+Shift+Z',
|
||||
label: Util.translate('electronMenuRedo'), accelerator: this.getAccelerator('redo') || 'CmdOrCtrl+Shift+Z',
|
||||
click: () => {
|
||||
if (this.win) {
|
||||
this.win.webContents.redo();
|
||||
|
@ -141,7 +172,7 @@ class MenuManager {
|
|||
Separator,
|
||||
|
||||
{
|
||||
label: Util.translate('electronMenuSelectAll'), accelerator: 'CmdOrCtrl+A',
|
||||
label: Util.translate('electronMenuSelectAll'), accelerator: this.getAccelerator('selectAll') || 'CmdOrCtrl+A',
|
||||
click: () => {
|
||||
if (this.win) {
|
||||
this.win.webContents.selectAll();
|
||||
|
@ -149,26 +180,26 @@ class MenuManager {
|
|||
};
|
||||
}
|
||||
},
|
||||
{ label: Util.translate('electronMenuSearch'), accelerator: 'CmdOrCtrl+F', click: () => Util.send(this.win, 'commandGlobal', 'search') },
|
||||
{ label: Util.translate('electronMenuSearch'), accelerator: this.getAccelerator('searchText') || 'CmdOrCtrl+F', click: () => Util.send(this.win, 'commandGlobal', 'search') },
|
||||
|
||||
Separator,
|
||||
|
||||
{ label: Util.translate('electronMenuPrint'), accelerator: 'CmdOrCtrl+P', click: () => Util.send(this.win, 'commandGlobal', 'print') },
|
||||
{ label: Util.translate('electronMenuPrint'), accelerator: this.getAccelerator('print') || 'CmdOrCtrl+P', click: () => Util.send(this.win, 'commandGlobal', 'print') },
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'windowMenu', label: Util.translate('electronMenuWindow'),
|
||||
submenu: [
|
||||
{ label: Util.translate('electronMenuNewWindow'), accelerator: 'CmdOrCtrl+Shift+N', click: () => WindowManager.createMain({ isChild: true }) },
|
||||
{ label: Util.translate('electronMenuNewWindow'), accelerator: this.getAccelerator('newWindow') || 'CmdOrCtrl+Shift+N', click: () => WindowManager.createMain({ isChild: true }) },
|
||||
|
||||
Separator,
|
||||
|
||||
{ role: 'minimize', label: Util.translate('electronMenuMinimise') },
|
||||
{ label: Util.translate('electronMenuZoomIn'), accelerator: 'CmdOrCtrl+=', click: () => Api.setZoom(this.win, this.win.webContents.getZoomLevel() + 1) },
|
||||
{ label: Util.translate('electronMenuZoomOut'), accelerator: 'CmdOrCtrl+-', click: () => Api.setZoom(this.win, this.win.webContents.getZoomLevel() - 1) },
|
||||
{ label: Util.translate('electronMenuZoomDefault'), accelerator: 'CmdOrCtrl+0', click: () => Api.setZoom(this.win, 0) },
|
||||
{ label: Util.translate('electronMenuZoomIn'), accelerator: this.getAccelerator('zoomIn') || 'CmdOrCtrl+=', click: () => Api.setZoom(this.win, this.win.webContents.getZoomLevel() + 1) },
|
||||
{ label: Util.translate('electronMenuZoomOut'), accelerator: this.getAccelerator('zoomOut') || 'CmdOrCtrl+-', click: () => Api.setZoom(this.win, this.win.webContents.getZoomLevel() - 1) },
|
||||
{ label: Util.translate('electronMenuZoomDefault'), accelerator: this.getAccelerator('zoomReset') || 'CmdOrCtrl+0', click: () => Api.setZoom(this.win, 0) },
|
||||
{
|
||||
label: Util.translate('electronMenuFullscreen'), accelerator: 'CmdOrCtrl+Shift+F', type: 'checkbox', checked: this.win.isFullScreen(),
|
||||
label: Util.translate('electronMenuFullscreen'), accelerator: this.getAccelerator('toggleFullscreen') || 'CmdOrCtrl+Shift+F', type: 'checkbox', checked: this.win.isFullScreen(),
|
||||
click: () => this.win.setFullScreen(!this.win.isFullScreen())
|
||||
},
|
||||
{ label: Util.translate('electronMenuReload'), accelerator: 'CmdOrCtrl+R', click: () => this.win.reload() }
|
||||
|
@ -182,7 +213,7 @@ class MenuManager {
|
|||
click: () => Util.send(this.win, 'popup', 'help', { data: { document: 'whatsNew' } })
|
||||
},
|
||||
{
|
||||
label: Util.translate('electronMenuShortcuts'), accelerator: 'Ctrl+Space',
|
||||
label: Util.translate('electronMenuShortcuts'), accelerator: this.getAccelerator('shortcut') || 'Ctrl+Space',
|
||||
click: () => Util.send(this.win, 'commandGlobal', 'shortcut')
|
||||
},
|
||||
|
||||
|
@ -355,7 +386,7 @@ class MenuManager {
|
|||
|
||||
Separator,
|
||||
|
||||
{ label: Util.translate('electronMenuNewWindow'), accelerator: 'CmdOrCtrl+Shift+N', click: () => WindowManager.createMain({ isChild: true }) },
|
||||
{ label: Util.translate('electronMenuNewWindow'), accelerator: this.getAccelerator('newWindow') || 'CmdOrCtrl+Shift+N', click: () => WindowManager.createMain({ isChild: true }) },
|
||||
|
||||
Separator,
|
||||
|
||||
|
@ -455,7 +486,7 @@ class MenuManager {
|
|||
Separator,
|
||||
|
||||
{
|
||||
label: Util.translate('commonNewObject'), accelerator: 'CmdOrCtrl+N', click: () => {
|
||||
label: Util.translate('commonNewObject'), accelerator:this.getAccelerator('createObject') || 'CmdOrCtrl+N', click: () => {
|
||||
this.winShow();
|
||||
Util.send(this.win, 'commandGlobal', 'createObject');
|
||||
}
|
||||
|
|
|
@ -74,14 +74,14 @@ const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
|
|||
onSelect: (e: any, item: any) => {
|
||||
switch (item.id) {
|
||||
case 'export': {
|
||||
const ret = [];
|
||||
const ret = {};
|
||||
const items = J.Shortcut.getItems();
|
||||
|
||||
for (const k in items) {
|
||||
const item = items[k];
|
||||
|
||||
if (item.id) {
|
||||
ret.push({ id: item.id, keys: item.keys });
|
||||
ret[item.id] = item.keys;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -256,12 +256,13 @@ const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
|
|||
setEditingId('');
|
||||
setEditingKeys([]);
|
||||
window.clearTimeout(timeout.current);
|
||||
keyboard.setShortcutEditing(false);
|
||||
Renderer.send('initMenu');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
window.clearTimeout(timeout.current);
|
||||
keyboard.setShortcutEditing(false);
|
||||
clear();
|
||||
$(window).off('keyup.shortcut keydown.shortcut');
|
||||
};
|
||||
}, []);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue