-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
462 lines (455 loc) · 13.4 KB
/
menu.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
const EventEmitter = require('events');
const { ipcMain } = require('electron');
const emitter = new EventEmitter();
// 菜单栏模板
const menuTemplate = [
{
label: '文件',
submenu: [
{
label: '新建',
accelerator: 'CmdOrCtrl+N',
click: function () {
emitter.emit('action','new');
}
},
{
label: '新建窗口',
accelerator: 'CmdOrCtrl+Shift+N',
click: function () {
emitter.emit('action','new-win');
}
},
{type: 'separator'},
{
label: '打开',
accelerator: 'CmdOrCtrl+O',
click: function () {
emitter.emit('action','open');
}
},
{type: 'separator'},
{
label: '保存',
accelerator: 'CmdOrCtrl+S',
click: function () {
emitter.emit('action','save');
}
},
{
label: '另存为',
accelerator: 'CmdOrCtrl+Shift+S',
click: function () {
emitter.emit('action','save-as');
}
},
{type: 'separator'},
{
label: '关闭',
accelerator: 'CmdOrCtrl+W',
click: function () {
emitter.emit('action','quit');
}
},
]
},
{label: '编辑',
submenu: [
{ label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' },
{ label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' },
{ label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' },
{ label: '删除', accelerator: 'CmdOrCtrl+D', role: 'delete' },
{ type: 'separator' }, //分隔线
{ label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectall' },
]
},
{
label: '段落',
submenu: [
{
label: '一级标题',
accelerator: 'CmdOrCtrl+1',
click: function () {
emitter.emit('set-title', 1);
}
},
{
label: '二级标题',
accelerator: 'CmdOrCtrl+2',
click: function () {
emitter.emit('set-title', 2);
}
},
{
label: '三级标题',
accelerator: 'CmdOrCtrl+3',
click: function () {
emitter.emit('set-title', 3);
}
},
{
label: '四级标题',
accelerator: 'CmdOrCtrl+4',
click: function () {
emitter.emit('set-title', 4);
}
},
{
label: '五级标题',
accelerator: 'CmdOrCtrl+5',
click: function () {
emitter.emit('set-title', 5);
}
},
{
label: '六级标题',
accelerator: 'CmdOrCtrl+6',
click: function () {
emitter.emit('set-title', 6);
}
},
{ type: 'separator' },
{
label: '公式块',
click: function () {
emitter.emit('edit','set-formula');
}
},
{
label: '代码块',
click: function () {
emitter.emit('edit','set-code');
}
},
{ type: 'separator' },
{
label: '引用',
click: function () {
emitter.emit('edit','set-quote');
}
},
{ type: 'separator' },
{
label: '有序列表',
click: function () {
emitter.emit('editor','ordered-list');
}
},
{
label: '无序列表',
click: function () {
emitter.emit('editor','unordered-list');
}
},
{
label: '任务列表',
click: function () {
emitter.emit('editor','task-list');
}
},
{ type: 'separator' },
{
label: '脚注',
click: function () {
emitter.emit('edit','set-footnote');
}
},
{ type: 'separator' },
{
label: '水平分割线',
click: function () {
emitter.emit('edit','set-divider');
}
},
]
},
{
label: '格式',
submenu: [
{
label: '加粗',
accelerator: 'CmdOrCtrl+B',
click: function () {
emitter.emit('editor','bold');
}
},
{
label: '斜体',
accelerator: 'CmdOrCtrl+I',
click: function () {
emitter.emit('editor','italic');
}
},
{
label: '下划线',
accelerator: 'CmdOrCtrl+U',
click: function () {
emitter.emit('editor','underline');
}
},
{
label: '代码',
click: function () {
emitter.emit('editor','code');
}
},
{ type: 'separator' },
{
label: '删除线',
click: function () {
emitter.emit('editor','deleteline');
}
},
{
label: '注释',
click: function () {
emitter.emit('editor','comment');
}
},
]
},
{
label: '视图',
submenu: [
{
label: '大纲',
click: function () {
emitter.emit('view','toggleOutline');
}
},
{ type: 'separator' },
{
label: '源代码模式',
click: function () {
emitter.emit('view','toggleSourceMode');
}
},
{ type: 'separator' },
{
label: '只读模式',
click: function () {
emitter.emit('view','toggleEditorLock');
}
},
{
label: '打字机模式',
click: function () {
emitter.emit('view','toggleTypewriterMode');
}
},
{ type: 'separator' },
{
label: '状态栏',
click: function () {
emitter.emit('view','toggleBottomBar');
}
},
{ type: 'separator' },
{
label: '开发者工具',
click: function () {
emitter.emit('view','chromiumDevTools');
}
},
]
},
{
label: '主题',
submenu: [
{
label: 'Classic',
click: function () {
emitter.emit('theme','classic');
}
},
{
label: 'Dark',
click: function () {
emitter.emit('theme','dark');
}
},
]
},
{
label: '帮助',
submenu: [
{
label: '关于',
click: function () {
emitter.emit('help','about');
}
},
//{
// label: '开源许可证',
// click: function () {
// emitter.emit('help','opensource');
// }
//},
]
},
];
const contextMenuTemplate = [
{ label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' },
{ label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' },
{ label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' },
{ label: '删除', accelerator: 'CmdOrCtrl+D', role: 'delete' },
{ label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectall' },
{ type: 'separator' },
{ label: '复制/粘贴为...',
submenu: [
{
label: '复制为纯文本',
click: function () {
emitter.emit('editor','copy2text');
}
},
{ type: 'separator' },
{
label: '粘贴为Markdown',
click: function () {
emitter.emit('editor','paste2md');
}
},
]
},
{ type: 'separator' },
{
label: '格式',
submenu: [
{
label: '加粗',
click: function () {
emitter.emit('editor','bold');
}
},
{
label: '斜体',
click: function () {
emitter.emit('editor','italic');
}
},
{
label: '下划线',
click: function () {
emitter.emit('editor','underline');
}
},
{
label: '引用',
click: function () {
emitter.emit('edit','set-quote');
}
},
{
label: '有序列表',
click: function () {
emitter.emit('editor','ordered-list');
}
},
{
label: '无序列表',
click: function () {
emitter.emit('editor','unordered-list');
}
},
{
label: '任务列表',
click: function () {
emitter.emit('editor','task-list');
}
},
]
},
{
label: '段落',
submenu: [
{
label: '一级标题',
accelerator: 'CmdOrCtrl+1',
click: function () {
emitter.emit('set-title', 1);
}
},
{
label: '二级标题',
accelerator: 'CmdOrCtrl+2',
click: function () {
emitter.emit('set-title', 2);
}
},
{
label: '三级标题',
accelerator: 'CmdOrCtrl+3',
click: function () {
emitter.emit('set-title', 3);
}
},
{
label: '四级标题',
accelerator: 'CmdOrCtrl+4',
click: function () {
emitter.emit('set-title', 4);
}
},
{
label: '五级标题',
accelerator: 'CmdOrCtrl+5',
click: function () {
emitter.emit('set-title', 5);
}
},
{
label: '六级标题',
accelerator: 'CmdOrCtrl+6',
click: function () {
emitter.emit('set-title', 6);
}
}
]
},
{
label: '插入',
submenu: [
{
label: '脚注',
click: function () {
emitter.emit('edit','set-footnote');
}
},
{
label: '水平分割线',
click: function () {
emitter.emit('edit','set-divider');
}
},
{
label: '代码块',
click: function () {
emitter.emit('edit','set-code');
}
},
{
label: '公式块',
click: function () {
emitter.emit('edit','set-formula');
}
},
]
},
];
const aboutDialog = {
type: 'info',
title: '关于 Hypora',
message: ' Hypora 是一款类似于 Typora 的 Markdown 文本编辑器 \n\n 开源地址:https://github.com/DanKE123abc/Hypora \n\n' +
'Hypora是自由软件,你不需要支付任何费用就可以使用、复制、修改它,不过,你的行为受 MIT 协议约束。详见:https://github.com/DanKE123abc/Hypora/blob/main/LICENSE \n\n' +
'Hypora在开发时,使用了部分优秀的开源项目,Hypora在遵守开源协议的同时在此附上使用的开源项目及其开发者、归属协议名单:https://github.com/DanKE123abc/Hypora/blob/main/OpenSourceLicense.md \n\n' +
' 作者:DanKe \n' +
' 版本:1.0.0',
buttons: ['确定']
}
module.exports = {
menuTemplate : menuTemplate,
contextMenuTemplate : contextMenuTemplate,
emitter : emitter,
aboutDialog : aboutDialog
};