forked from hirokidaichi/guiflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
173 lines (164 loc) · 4.42 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
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
var fs = require("fs");
var electron = require('electron');
var app = electron.app;
var BrowserWindow = electron.BrowserWindow;
var Menu = electron.Menu;
var dialog = electron.dialog;
app.on('window-all-closed', function() {
app.quit();
});
var exec = require('child_process').exec;
var warn = function(message) {
dialog.showMessageBox({
type: "warning",
title: "warning",
message: message,
buttons: ["close"]
});
};
var sendToFocusedBrowser = function(channel) {
return function() {
var win = BrowserWindow.getFocusedWindow();
if (!win) {
return warn("no selected window");
}
win.webContents.send(channel);
};
};
var mainMenu = {
label: app.getName(),
submenu: [{
label: 'About guiflow',
click: function() {
dialog.showMessageBox({
type: "info",
title: "about guiflow",
message: "version : 0.01",
buttons: ["close"]
});
}
}, {
type: 'separator'
}, {
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click: function() {
app.quit();
}
}, {
label: 'Toggle Full Screen',
accelerator: 'F11',
click: function() {
var win = BrowserWindow.getFocusedWindow();
if (win) {
win.setFullScreen(!win.isFullScreen());
}
}
}, {
label: 'Toggle Dev Tool',
accelerator: 'F5',
click: function() {
var win = BrowserWindow.getFocusedWindow();
if (win) {
win.toggleDevTools();
}
}
}]
};
var fileMenu = {
label: 'File',
submenu: [{
label: 'New File',
accelerator: 'CmdOrCtrl+N',
click: function() {
createWindow();
},
}, {
label: 'Open...',
accelerator: 'CmdOrCtrl+O',
click: function() {
dialog.showOpenDialog({
defaultPath: app.getPath('userDesktop'),
properties: ['openFile'],
filters: [{
name: 'Documents',
extensions: ['txt', 'md', 'text']
}, ],
}, function(fileNames) {
if (fileNames) {
createWindow(fileNames[0]);
}
});
},
}, {
label: "Save",
accelerator: 'CmdOrCtrl+S',
onlyFocusedWindow: true,
click: sendToFocusedBrowser("save"),
}, {
label: "Save As...",
accelerator: 'Shift+CmdOrCtrl+S',
click: sendToFocusedBrowser("saveAs"),
}]
};
var editMenu = {
label: 'Edit',
submenu: [{
label: "Undo",
accelerator: 'CmdOrCtrl+Z',
click: sendToFocusedBrowser("undo"),
}, {
label: "Redo",
accelerator: 'CmdOrCtrl+Y',
click: sendToFocusedBrowser("redo"),
}, {
type: 'separator'
}, {
label: "Cut",
accelerator: 'CmdOrCtrl+X',
click: sendToFocusedBrowser("cut"),
}, {
label: "Copy",
accelerator: 'CmdOrCtrl+C',
click: sendToFocusedBrowser("copy"),
}, {
label: "Paste",
accelerator: 'CmdOrCtrl+V',
click: sendToFocusedBrowser("paste"),
}, {
label: "Select All",
accelerator: 'CmdOrCtrl+A',
click: sendToFocusedBrowser("selectAll"),
},
]
};
var createWindow = function(fileName) {
var mainWindow = null;
mainWindow = new BrowserWindow({
width: 1100,
height: 800,
title: "guiflow -- " + (fileName ? fileName : "Untitled")
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
if (fileName) {
setTimeout(function() {
mainWindow.webContents.send("open", fileName);
}, 1000);
}
if (process.env.DEBUG) {
mainWindow.toggleDevTools();
}
};
app.on('ready', function() {
var fileName = process.argv[2];
var builtMenu = Menu.buildFromTemplate([
mainMenu, fileMenu, editMenu
]);
app.on("browser-window-blur", function() {});
app.on("browser-window-focus", function() {});
Menu.setApplicationMenu(builtMenu);
var firstWindow = createWindow(fileName);
});