-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
498 lines (482 loc) · 8.92 KB
/
main.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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
const electron = require('electron')
const path = require('path')
const url = require('url')
// Module to control application life.
const app = electron.app
const ipcMain = electron.ipcMain
const Menu = electron.Menu
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
console.log(process.versions)
const template = [
{
label: 'File',
submenu: [
{
label: 'New',
accelerator: 'CmdOrCtrl+N',
click () {
openWindow("")
}
},
{
label: 'Open',
accelerator: 'CmdOrCtrl+O',
click () {
electron.dialog.showOpenDialog({
properties: ['openFile'],
filters: [
{name: 'Edge', extensions: ['edge']},
],
},function(ps){
if (!ps) return
openWindow(ps[0])
})
}
},
{type: 'separator'},
{
label: 'Save',
accelerator: 'CmdOrCtrl+S',
click () {
sendCmd("save")
}
},
{
label: 'Save As...',
accelerator: 'Shift+CmdOrCtrl+S',
click () {
sendCmd("saveAs")
}
},
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
click (menuItem,win) {
win.webContents.undo()
sendCmd("undo")
}
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
click (menuItem,win) {
win.webContents.redo()
sendCmd("redo")
}
},
{type: 'separator'},
{
label: 'Cut',
role:"cut",
accelerator: 'CmdOrCtrl+X',
click (menuItem,win) {
win.webContents.cut()
sendCmd("cut")
}
},
{
label: 'Copy',
role:"copy",
accelerator: 'CmdOrCtrl+C',
click (menuItem,win) {
win.webContents.copy()
sendCmd("copy")
}
},
{
label: 'Paste',
role:"paste",
accelerator: 'CmdOrCtrl+V',
click (menuItem,win) {
win.webContents.paste()
sendCmd("paste")
}
},
{
label: 'Paste And Match Style',
accelerator: 'Shift+CmdOrCtrl+V',
click (menuItem,win) {
win.webContents.pasteAndMatchStyle()
sendCmd("pasteAndMatchStyle")
}
},
{
label: 'Delete',
accelerator: 'Backspace',
click (menuItem,win) {
win.webContents.delete()
sendCmd("del")
}
},
{type: 'separator'},
{
label: 'New Vertex',
accelerator: 'CmdOrCtrl+T',
click () {
sendCmd("newVert")
}
},
{
label: 'New Vertex (Reverse)',
accelerator: 'Shift+CmdOrCtrl+T',
click () {
sendCmd("newVertR")
}
},
{
label: 'New Edge',
accelerator: 'CmdOrCtrl+E',
click () {
sendCmd("newEdge")
}
},
{
label: 'New Edge (Reverse)',
accelerator: 'Shift+CmdOrCtrl+E',
click () {
sendCmd("newEdgeR")
}
},
{
label: 'Graph Directed/Undirected',
accelerator: 'CmdOrCtrl+Alt+E',
click () {
sendCmd("graphDirMode")
}
},
{
label: 'Edge Direction',
accelerator: 'Alt+E',
click () {
sendCmd("edgeDir")
}
},
{
label: 'Rename',
accelerator: 'CmdOrCtrl+Enter',
click () {
sendCmd("rename")
}
},
{
label: 'Color',
submenu: [
{
label: 'Customize Colors',
accelerator: 'Shift+Alt+C',
click () {
sendCmd("customizeColors")
}
},
{
label: 'Switch Color',
accelerator: 'Alt+C',
click () {
sendCmd("switchColor")
}
},
{type: 'separator'},
{
label: 'Color 0',
accelerator: 'Alt+0',
click () {
sendCmd("color0")
}
},
{
label: 'Color 1',
accelerator: 'Alt+1',
click () {
sendCmd("color1")
}
},
{
label: 'Color 2',
accelerator: 'Alt+2',
click () {
sendCmd("color2")
}
},
{
label: 'Color 3',
accelerator: 'Alt+3',
click () {
sendCmd("color3")
}
},
{
label: 'Color 4',
accelerator: 'Alt+4',
click () {
sendCmd("color4")
}
},
{
label: 'Color 5',
accelerator: 'Alt+5',
click () {
sendCmd("color5")
}
},
{
label: 'Color 6',
accelerator: 'Alt+6',
click () {
sendCmd("color6")
}
},
{
label: 'Color 7',
accelerator: 'Alt+7',
click () {
sendCmd("color7")
}
},
{
label: 'Color 8',
accelerator: 'Alt+8',
click () {
sendCmd("color8")
}
},
{
label: 'Color 9',
accelerator: 'Alt+9',
click () {
sendCmd("color9")
}
}
]
}
]
},
{
label: 'View',
submenu: [
{role: 'reload'},
{role: 'forcereload'},
{role: 'toggledevtools'},
{type: 'separator'},
{
label: 'Auto Layout Pause/Resume',
accelerator: 'CmdOrCtrl+P',
click () {
sendCmd("autoLayout")
}
},
{
label: 'Show/Hide Vertex',
accelerator: 'CmdOrCtrl+D',
click () {
sendCmd("showOrHideVert")
}
},
{
label: 'Show Vertex Alone',
accelerator: 'Shift+CmdOrCtrl+D',
click () {
sendCmd("showVertAlone")
}
},
{
label: 'Switch Adjacent Display',
accelerator: 'Shift+Alt+D',
click () {
sendCmd("displayAdjacent")
}
},
{
label: 'Find Vertex',
accelerator: 'CmdOrCtrl+F',
click () {
sendCmd("findVert")
}
},
{
label: 'History Panel',
accelerator: 'Shift+CmdOrCtrl+H',
click () {
sendCmd("switchHistoryPanel")
}
},
{type: 'separator'},
{
label: 'Reset Viewport',
click () {
sendCmd("resetZoom")
}
},
{
label: 'Zoom In',
accelerator: 'CmdOrCtrl+Plus',
click () {
sendCmd("zoomin")
}
},
{
label: 'Zoom Out',
accelerator: 'CmdOrCtrl+-',
click () {
sendCmd("zoomout")
}
},
{type: 'separator'},
{role: 'togglefullscreen'}
]
},
{
label: 'Selection',
submenu: [
{
label: 'Select All',
accelerator: 'Alt+A',
click (menuItem,win) {
sendCmd("selectAll")
}
},
{
label: 'Unselect',
accelerator: 'Shift+Alt+A',
click (menuItem,win) {
sendCmd("unselect")
}
},{
label: 'Switch Selection (Outset)',
accelerator: 'Alt+S',
click (menuItem,win) {
sendCmd("switchSelectionOutset")
}
},
{
label: 'Switch Selection (Inset)',
accelerator: 'Shift+Alt+S',
click (menuItem,win) {
sendCmd("switchSelectionInset")
}
},
]
},
{
role: 'window',
submenu: [
{role: 'minimize'},
{role: 'close'}
]
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click () { require('electron').shell.openExternal('https://electron.atom.io') }
}
]
}
]
if (process.platform === 'darwin') {
template.unshift({
label: app.getName(),
submenu: [
{role: 'about'},
{type: 'separator'},
{role: 'services', submenu: []},
{type: 'separator'},
{role: 'hide'},
{role: 'hideothers'},
{role: 'unhide'},
{type: 'separator'},
{role: 'quit'}
]
})
// Edit menu
template[2].submenu.push(
{type: 'separator'},
{
label: 'Speech',
submenu: [
{role: 'startspeaking'},
{role: 'stopspeaking'}
]
}
)
// Window menu
template[5].submenu = [
{role: 'close'},
{role: 'minimize'},
{role: 'zoom'},
{type: 'separator'},
{role: 'front'}
]
}
let wins = []
app.on('ready', function() {
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
openWindow("")
ipcMain.on('showSaveDialog', (event, p) => {
electron.dialog.showSaveDialog({
defaultPath:p||"",
filters: [
{name: 'Edge', extensions: ['edge']},
],
},function(ps){
if (!ps){
event.returnValue = ""
}else{
event.returnValue = ps
}
})
})
})
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (wins.length==0) {
openWindow()
}
})
function openWindow(p){
// Create the browser window.
let win = new BrowserWindow({
width: 1300,
height: 820,
title:p||"",
})
wins.push(win)
// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
search:'path='+(p||''),
slashes: true
}))
// Open the DevTools.
//win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
wins.splice(wins.indexOf(win),1)
})
return win
}
function sendCmd(cmd){
let win = BrowserWindow.getFocusedWindow()
if (!win) return
win.webContents.send("cmd",cmd)
}