forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.js
More file actions
37 lines (33 loc) · 1.14 KB
/
format.js
File metadata and controls
37 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const MENU_ID_FORMAT_MAP = {
strongMenuItem: 'strong',
emphasisMenuItem: 'em',
inlineCodeMenuItem: 'inline_code',
strikeMenuItem: 'del',
hyperlinkMenuItem: 'link',
imageMenuItem: 'image',
inlineMathMenuItem: 'inline_math'
}
export const format = (win, type) => {
if (win && win.webContents) {
win.webContents.send('mt::editor-format-action', { type })
}
}
// --- IPC events -------------------------------------------------------------
// NOTE: Don't use static `getMenuItemById` here, instead request the menu by
// window id from `AppMenu` manager.
/**
* Update format menu entires from given state.
*
* @param {Electron.MenuItem} applicationMenu The application menu instance.
* @param {Object.<string, boolean>} formats A object map with selected formats.
*/
export const updateFormatMenu = (applicationMenu, formats) => {
const formatMenuItem = applicationMenu.getMenuItemById('formatMenuItem')
formatMenuItem.submenu.items.forEach(item => (item.checked = false))
formatMenuItem.submenu.items
.forEach(item => {
if (item.id && formats[MENU_ID_FORMAT_MAP[item.id]]) {
item.checked = true
}
})
}