forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout.js
More file actions
73 lines (63 loc) · 2.13 KB
/
layout.js
File metadata and controls
73 lines (63 loc) · 2.13 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { ipcRenderer } from 'electron'
import bus from '../bus'
const width = localStorage.getItem('side-bar-width')
const sideBarWidth = typeof +width === 'number' ? Math.max(+width, 220) : 280
// messages from main process, and do not change the state
const state = {
rightColumn: 'files',
showSideBar: false,
showTabBar: false,
sideBarWidth
}
const getters = {}
const mutations = {
SET_LAYOUT (state, layout) {
if (layout.showSideBar !== undefined) {
const { windowId } = global.marktext.env
ipcRenderer.send('mt::update-sidebar-menu', windowId, !!layout.showSideBar)
}
Object.assign(state, layout)
},
TOGGLE_LAYOUT_ENTRY (state, entryName) {
state[entryName] = !state[entryName]
},
SET_SIDE_BAR_WIDTH (state, width) {
// TODO: Add side bar to session (GH#732).
localStorage.setItem('side-bar-width', Math.max(+width, 220))
state.sideBarWidth = width
}
}
const actions = {
LISTEN_FOR_LAYOUT ({ state, commit, dispatch }) {
ipcRenderer.on('mt::set-view-layout', (e, layout) => {
if (layout.rightColumn) {
commit('SET_LAYOUT', {
...layout,
rightColumn: layout.rightColumn === state.rightColumn ? '' : layout.rightColumn,
showSideBar: true
})
} else {
commit('SET_LAYOUT', layout)
}
dispatch('DISPATCH_LAYOUT_MENU_ITEMS')
})
ipcRenderer.on('mt::toggle-view-layout-entry', (event, entryName) => {
commit('TOGGLE_LAYOUT_ENTRY', entryName)
dispatch('DISPATCH_LAYOUT_MENU_ITEMS')
})
bus.$on('view:toggle-layout-entry', entryName => {
commit('TOGGLE_LAYOUT_ENTRY', entryName)
const { windowId } = global.marktext.env
ipcRenderer.send('mt::view-layout-changed', windowId, { [entryName]: state[entryName] })
})
},
DISPATCH_LAYOUT_MENU_ITEMS ({ state }) {
const { windowId } = global.marktext.env
const { showTabBar, showSideBar } = state
ipcRenderer.send('mt::view-layout-changed', windowId, { showTabBar, showSideBar })
},
CHANGE_SIDE_BAR_WIDTH ({ commit }, width) {
commit('SET_SIDE_BAR_WIDTH', width)
}
}
export default { state, getters, mutations, actions }