forked from MikeC-Cn/MiEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
89 lines (81 loc) · 2.38 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MiEdit</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
border-radius: 4px;
}
#editor {
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
<link rel="stylesheet" href="node_modules/electron-tabs/electron-tabs.css">
</head>
<body>
<div class="etabs-tabgroup">
<div class="etabs-tabs"></div>
<div class="etabs-buttons"></div>
</div>
<div class="etabs-views">
<pre id="editor"></pre>
</div>
<script src="ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
const electron = require('electron');
const {
ipcRenderer,
remote
} = electron;
var editor = ace.edit("editor"),
path;
//启用提示菜单
ace.require("ace/ext/language_tools");
//以下部分是设置输入代码提示的
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
editor.setHighlightActiveLine(true); //代码高亮
editor.getSession().setUseWrapMode(true); //支持代码折叠
ipcRenderer.send('data');
ipcRenderer.on('data-back', function(event, theme, mode) {
editor.setTheme("ace/theme/" + theme);
editor.getSession().setMode("ace/mode/" + mode);
editor.setFontSize(18);
})
ipcRenderer.on('change-theme', function(event, data) {
editor.setTheme("ace/theme/" + data);
})
ipcRenderer.on('change-mode', function(event, data) {
editor.getSession().setMode("ace/mode/" + data);
})
ipcRenderer.on('open-file', function(event, message, p) {
editor.setValue(message);
path = p;
})
ipcRenderer.on('save-data', function(event) {
ipcRenderer.send('save-data-back', editor.getValue(), path);
})
//拖放
var content = document.querySelector("#editor");
content.ondragenter = content.ondragover = content.ondragleave = function() {
return false; /*阻止默认行为*/
}
content.ondrop = function(event) {
//阻止默认行为
event.preventDefault();
path = event.dataTransfer.files[0].path;
ipcRenderer.send("drag-file", path);
}
</script>
</body>
</html>