-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (71 loc) · 2.11 KB
/
index.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
var remote = require('remote');
var Menu = remote.require('menu');
var dialog = remote.require('dialog');
var fs = require('fs');
photon.init();
var appMenu = Menu.getApplicationMenu();
var menuTemplate = [
{
label: 'File',
submenu: [
{
label: 'Open',
click: function() {
var imagePaths = dialog.showOpenDialog({ properties: ['openFile']});
if (imagePaths)
photon.loadFromFile(imagePaths[0]);
}
},
{
label: 'Save'
},
{
label: 'Save As',
click: function() {
var imagePath = dialog.showSaveDialog({
filters:
[
{ name: 'jpg', extensions: ['jpg'] }
]
});
if (!imagePath)
return;
photon.saveToFile(imagePath);
}
}
]
},
{
label: 'Image',
submenu: [
{
label: 'Resize canvas',
click: function() {
var dialog = document.getElementById('resize-dialog');
var widthInput = document.getElementById('resize-width');
var heightInput = document.getElementById('resize-height');
var submit = document.getElementById('resize-submit');
widthInput.value = photon.getCanvasWidth();
heightInput.value = photon.getCanvasHeight();
submit.addEventListener('click', function() {
photon.resizeCanvas(widthInput.value, heightInput.value);
});
dialog.addEventListener('click', function(e) {
var rect = dialog.getBoundingClientRect();
var isInsideDialog = e.clientX >= rect.left
&& e.clientX <= rect.left + rect.width
&& e.clientY >= rect.top
&& e.clientY <= rect.top + rect.height;
if (!isInsideDialog)
dialog.close();
});
dialog.showModal();
}
}
]
}
];
var menu = Menu.buildFromTemplate(menuTemplate);
appMenu.insert(1, menu.items[0]);
appMenu.insert(3, menu.items[1]);
Menu.setApplicationMenu(appMenu);