This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
153 lines (133 loc) · 3.86 KB
/
renderer.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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
var fs = require('fs'),
struct_languages = require('./language.struct.js'),
File = require('./File.class.js'),
{
ipcRenderer,
remote
} = require('electron'),
{
dialog
} = require('electron').remote,
Preferences = require('./Preferences.class.js'),
Console = require('./Console.class.js');
remote.require('./menu.js');
var value = "";
var editor = CodeMirror(document.body.getElementsByTagName("article")[0], {
value: value,
lineNumbers: true,
lineWrapping: true,
mode: "text/x-csrc",
keyMap: "sublime",
autoCloseBrackets: true,
matchBrackets: true,
showCursorWhenSelecting: true,
theme: "tomorrow-night-eighties"
});
$('.workspace').paneless();
var currentConsole = new Console($('.console'));
var currentFile = new File(currentConsole);
var currentPreferences = new Preferences(editor, currentConsole);
ipcRenderer.on('save!', function(event, args) {
if (currentFile.temp) {
var currentLanguage = currentFile.language;
dialog.showSaveDialog({
filters: [{
'name': currentLanguage + ' Files',
extensions: [struct_languages[currentLanguage].extension.substr(1)]
}]
}, function(response, checkboxChecked) {
console.log(response);
currentFile.changePath(response);
currentFile.save(editor.getValue(), function() {
});
});
} else {
currentFile.save(editor.getValue(), function() {
});
}
});
ipcRenderer.on('open!', function(event, args) {
dialog.showOpenDialog(function(response, checkboxChecked) {
response = response[0];
currentFile.changePath(response);
fs.readFile(response, function(err, data) {
if (err) {
throw err;
}
tmp = data.toString();
editor.setValue(tmp);
});
});
});
ipcRenderer.on('openPreferences', function(event, args) {
currentPreferences.show();
});
jQuery.loadScript = function(url, callback) {
jQuery.ajax({
url: url,
dataType: 'script',
success: callback,
async: true
});
};
var loadedLanguages = [];
var loadLanguage = function(language) {
if (loadedLanguages.indexOf(language) < 0) {
var path = 'bower_components/codemirror/mode/' + struct_languages[language].style + '/' + struct_languages[language].style + '.js';
$.loadScript(path, function() {
editor.setOption("mode", struct_languages[language].mime);
loadedLanguages.push(language);
});
} else {
editor.setOption("mode", struct_languages[language].mime);
}
currentFile.changeLanguage(language);
};
for (var key in struct_languages) {
if (struct_languages.hasOwnProperty(key)) {
var ele = $("<option></option>").text(key);
$("#language").append(ele);
}
}
var template = "";
var loadTemplate = function(language, callback) {
var filename = struct_languages[language].mime.replace("text/", "");
fs.readFile(__dirname + '/templates/' + filename + '.template', function(err, data) {
if (err) {
throw err;
}
template = data.toString();
callback.call(this);
});
};
$("#language").change(function() {
var name = $("#language").find("option:selected").text();
loadLanguage(name);
// console.log(JSON.stringify(editor.getValue()), JSON.stringify(template.replace(/\r/g,'')));
if (editor.getValue() == template.replace(/\r/g, '')) {
loadTemplate(name, function() {
editor.setValue(template);
});
}
});
$("#btnstart").click(function() {
currentFile.save(editor.getValue(), function() {
currentFile.compile(function() {
currentFile.run();
});
});
});
$("#btnstop").click(function() {
currentFile.stop();
});
loadLanguage("C");
loadTemplate("C", function() {
editor.setValue(template);
});
// Setup console background color
$(function() {
currentConsole.reload();
});