@@ -2,6 +2,7 @@ const path = require('path')
2
2
const file = require ( 'fs' ) ;
3
3
const amdLoader = require ( 'monaco-editor/min/vs/loader.js' ) ;
4
4
const Split = require ( 'split.js' )
5
+ const { ipcRenderer } = require ( 'electron' ) ;
5
6
6
7
const amdRequire = amdLoader . require ;
7
8
const amdDefine = amdLoader . require . define ;
@@ -17,18 +18,22 @@ amdRequire.config({
17
18
// workaround monaco-css not understanding the environment
18
19
self . module = undefined ;
19
20
20
- function saveSolution ( problemName , language , content ) {
21
- if ( ! problemName ) {
21
+ function saveSolution ( language , content ) {
22
+ if ( ! previousProblem ) {
22
23
return ;
23
24
}
24
25
25
26
const userSolutionFilename =
26
- directoryManager . getUserSolutionFilename ( problemName ) ;
27
- console . log ( "Saving problem " + problemName + " to " +
27
+ directoryManager . getUserSolutionFilename ( previousProblem ) ;
28
+ console . log ( "Saving problem " + previousProblem + " to " +
28
29
userSolutionFilename ) ;
29
30
file . writeFileSync ( userSolutionFilename , content ) ;
30
31
}
31
32
33
+ function run ( ) {
34
+ console . log ( "Running solution" ) ;
35
+ }
36
+
32
37
function setDescription ( problemName ) {
33
38
var element = document . querySelector ( '.markdown-content#description-content' ) ;
34
39
element . innerHTML = directoryManager . getDescription ( problemName ) ;
@@ -48,14 +53,13 @@ function setUserSolution(problemName) {
48
53
49
54
var previousProblem ;
50
55
function onProblemSelected ( problemName ) {
51
- saveSolution ( previousProblem , 'cpp' , editor . getValue ( ) ) ;
56
+ saveSolution ( 'cpp' , editor . getValue ( ) ) ;
52
57
previousProblem = problemName ;
53
58
54
59
console . log ( `Problem selected: ${ problemName } ` ) ;
55
60
setDescription ( problemName ) ;
56
61
setSolution ( problemName ) ;
57
62
setUserSolution ( problemName ) ;
58
- console . log ( `previousProblem: ${ previousProblem } ` ) ;
59
63
}
60
64
61
65
function initializeProblemsCombo ( problemNames ) {
@@ -72,12 +76,40 @@ function initializeProblemsCombo(problemNames) {
72
76
} ) ;
73
77
}
74
78
79
+ function initializeSaveCommand ( ) {
80
+ ipcRenderer . on ( 'save-command' , ( ) => {
81
+ console . log ( 'Received save command' ) ;
82
+ saveSolution ( 'cpp' , editor . getValue ( ) ) ;
83
+ } ) ;
84
+
85
+ document . getElementById ( 'save-button' )
86
+ . addEventListener ( 'click' , function ( ) {
87
+ console . log ( 'Save button clicked' ) ;
88
+ saveSolution ( 'cpp' , editor . getValue ( ) ) ;
89
+ } ) ;
90
+ }
91
+
92
+ function initializeRunCommand ( ) {
93
+ ipcRenderer . on ( 'run-command' , ( ) => {
94
+ console . log ( 'Received run command' ) ;
95
+ run ( ) ;
96
+ } ) ;
97
+
98
+ document . getElementById ( 'run-button' )
99
+ . addEventListener ( 'click' , function ( ) {
100
+ console . log ( 'Run button clicked' ) ;
101
+ run ( ) ;
102
+ } ) ;
103
+ }
104
+
75
105
document . addEventListener ( 'DOMContentLoaded' , ( event ) => {
76
106
var tabs = document . querySelectorAll ( '.tab' ) ;
77
107
78
108
// For now...
79
109
const problemNames = directoryManager . getProblemNames ( ) ;
80
110
initializeProblemsCombo ( problemNames ) ;
111
+ initializeSaveCommand ( ) ;
112
+ initializeRunCommand ( ) ;
81
113
82
114
amdRequire ( [ 'vs/editor/editor.main' ] , function ( ) {
83
115
monaco . editor . setTheme ( 'vs-dark' ) ;
0 commit comments