@@ -5,19 +5,19 @@ import javafx.beans.property.SimpleIntegerProperty
5
5
import javafx.event.Event
6
6
import javafx.geometry.Insets
7
7
import javafx.scene.input.KeyCode
8
- import javafx.scene.input.KeyCombination.*
9
8
import javafx.scene.input.KeyEvent
10
9
import javafx.scene.layout.Priority
11
10
import javafx.scene.paint.Color
12
11
import javafx.stage.FileChooser
13
12
import org.fxmisc.richtext.CodeArea
14
13
import org.fxmisc.richtext.LineNumberFactory
15
- import org.fxmisc.wellbehaved.event.EventPattern.*
14
+ import org.fxmisc.wellbehaved.event.EventPattern.anyOf
15
+ import org.fxmisc.wellbehaved.event.EventPattern.keyPressed
16
16
import org.fxmisc.wellbehaved.event.InputMap
17
17
import org.fxmisc.wellbehaved.event.Nodes
18
18
import org.idaesbasic.buffer.NewBufferView
19
19
import org.idaesbasic.buffer.file.FileModel
20
- import org.idaesbasic.buffer.run.ExecutationSetupView
20
+ import org.idaesbasic.buffer.run.ExecutionSetupView
21
21
import org.idaesbasic.buffer.run.RunConfigController
22
22
import org.idaesbasic.intelline.IntellineView
23
23
import org.idaesbasic.powerline.PowerLineView
@@ -30,7 +30,6 @@ import java.nio.file.Paths
30
30
import java.util.regex.Matcher
31
31
import java.util.regex.Pattern
32
32
33
-
34
33
class MainView : View () {
35
34
val controller: MainController by inject()
36
35
@@ -60,7 +59,7 @@ class MainView : View() {
60
59
iconColor = Color .web(" #f8f8f2" )
61
60
}
62
61
action {
63
- if (controller.currentBufferIndexProperty.value + 1 < controller.buffers.size) {
62
+ if (controller.currentBufferIndexProperty.value + 1 < controller.buffers.size) {
64
63
controller.currentBufferIndexProperty.value + = 1
65
64
controller.openCurrentBufferIndexBuffer()
66
65
}
@@ -94,15 +93,15 @@ class MainView : View() {
94
93
action {
95
94
val currentEditor: Editor = controller.getCurrentBuffer() as Editor
96
95
showSaveDialogAndSaveText(
97
- arrayOf(
96
+ extensions = arrayOf(
98
97
FileChooser .ExtensionFilter (" All" , " *" ),
99
98
FileChooser .ExtensionFilter (" Plain text" , " *.txt" ),
100
99
FileChooser .ExtensionFilter (" Java class" , " *.java" ),
101
100
FileChooser .ExtensionFilter (" Python" , " *.py" ),
102
- FileChooser .ExtensionFilter (" Kotlin class" , " *.kt" ),
103
- ),
104
- currentEditor.root.text,
105
- currentEditor.fileObject
101
+ FileChooser .ExtensionFilter (" Kotlin class" , " *.kt" )
102
+ ),
103
+ text = currentEditor.root.text,
104
+ file = currentEditor.fileObject
106
105
)
107
106
}
108
107
graphic = FontIcon ().apply {
@@ -130,13 +129,13 @@ class MainView : View() {
130
129
prefHeight = prefWidth
131
130
val configsController = find(RunConfigController ::class )
132
131
val contextMenu = contextmenu {
133
- item (" Change config" ){
132
+ item(" Change config" ) {
134
133
action {
135
- ExecutationSetupView ().openWindow()
134
+ ExecutionSetupView ().openWindow()
136
135
}
137
136
}
138
137
}
139
- val runContextToggleGroup = togglegroup { }
138
+ val runContextToggleGroup = togglegroup { }
140
139
configsController.configs.onChange() {
141
140
// Update context menu to the changed config
142
141
it.next()
@@ -183,11 +182,9 @@ class MainView : View() {
183
182
private fun showSaveDialogAndSaveText (extensions : Array <FileChooser .ExtensionFilter >, text : String , file : FileModel ) {
184
183
if (file.directory == null ) {
185
184
val fileArray = chooseFile(
186
- " Save file" ,
187
- extensions,
188
- null ,
189
- null ,
190
- FileChooserMode .Save
185
+ title = " Save file" ,
186
+ filters = extensions,
187
+ mode = FileChooserMode .Save
191
188
)
192
189
if (fileArray.isNotEmpty()) {
193
190
val newDirectory = fileArray[0 ]
@@ -213,7 +210,7 @@ class MainView : View() {
213
210
fun newBuffer () {
214
211
val newBuffer = NewBufferView ()
215
212
controller.buffers.add(newBuffer)
216
- controller.currentBufferIndexProperty.set(controller.buffers.size - 1 )
213
+ controller.currentBufferIndexProperty.set(controller.buffers.size - 1 )
217
214
controller.openCurrentBufferIndexBuffer()
218
215
}
219
216
@@ -226,7 +223,7 @@ class MainViewModel : ItemViewModel<MainView>() {
226
223
val root = bind(MainView ::root)
227
224
}
228
225
229
- class Editor (file : FileModel ): Fragment() {
226
+ class Editor (file : FileModel ) : Fragment() {
230
227
override val root = CodeArea ()
231
228
lateinit var fileObject: FileModel
232
229
@@ -237,42 +234,41 @@ class Editor(file: FileModel): Fragment() {
237
234
root.appendText(file.text)
238
235
val preventTab: InputMap <Event > = InputMap .consume(
239
236
anyOf(
240
- // Prevent tab to replace with 4 spaces indention
237
+ // Prevent tab to replace with 4 spaces indentation
241
238
keyPressed(KeyCode .TAB )
242
239
)
243
240
)
244
241
Nodes .addInputMap(root, preventTab)
245
242
val whiteSpace: Pattern = Pattern .compile(" ^\\ s+" )
246
243
root.addEventHandler(KeyEvent .KEY_PRESSED ) { KE ->
247
244
// Vim movement
248
- if (KE .getCode() == = KeyCode .H ) {
245
+ if (KE .code == = KeyCode .H ) {
249
246
Platform .runLater {
250
- val caretPosition: Int = root.getCaretPosition()
251
- root.deleteText(caretPosition- 1 , caretPosition)
247
+ val caretPosition: Int = root.caretPosition
248
+ root.deleteText(caretPosition - 1 , caretPosition)
252
249
root.moveTo(caretPosition - 2 )
253
250
}
254
251
}
255
- if (KE .getCode() == = KeyCode .L ) {
252
+ if (KE .code == = KeyCode .L ) {
256
253
Platform .runLater {
257
- val caretPosition: Int = root.getCaretPosition()
258
- root.deleteText(caretPosition- 1 , caretPosition)
254
+ val caretPosition: Int = root.caretPosition
255
+ root.deleteText(caretPosition - 1 , caretPosition)
259
256
root.moveTo(caretPosition)
260
257
}
261
258
}
262
259
// Four spaces for tab
263
- if (KE .getCode() == = KeyCode .TAB ) {
264
- val caretPosition: Int = root.getCaretPosition()
265
- val currentParagraph: Int = root.getCurrentParagraph()
260
+ if (KE .code == = KeyCode .TAB ) {
261
+ val caretPosition: Int = root.caretPosition
266
262
root.insertText(caretPosition, " " )
267
263
}
268
- // Auto-indent after pressing enter from last line
269
- if (KE .getCode() == = KeyCode .ENTER ) {
270
- val caretPosition: Int = root.getCaretPosition()
271
- val currentParagraph: Int = root.getCurrentParagraph()
272
- val m0: Matcher = whiteSpace.matcher(root.getParagraph(currentParagraph - 1 ).getSegments().get( 0 ) )
264
+ // Auto-indent after pressing enter from the last line
265
+ if (KE .code == = KeyCode .ENTER ) {
266
+ val caretPosition: Int = root.caretPosition
267
+ val currentParagraph: Int = root.currentParagraph
268
+ val m0: Matcher = whiteSpace.matcher(root.getParagraph(currentParagraph - 1 ).getSegments()[ 0 ] )
273
269
if (m0.find()) Platform .runLater { root.insertText(caretPosition, m0.group()) }
274
270
}
275
- // TODO: Implement backpaces that removes 4 space intendations
271
+ // TODO: Implement backspaces that remove 4 space indentations
276
272
}
277
273
}
278
274
}
@@ -285,6 +281,7 @@ class MainController : Controller() {
285
281
fun getCurrentBuffer (): Fragment {
286
282
return buffers[currentBufferIndexProperty.get()]
287
283
}
284
+
288
285
fun openCurrentBufferIndexBuffer () {
289
286
find(MainView ::class ).switchCenterToBufferView(getCurrentBuffer())
290
287
}
@@ -300,5 +297,4 @@ class MainController : Controller() {
300
297
fun saveTextToFile (text : String , file : Path ) {
301
298
Files .writeString(file, text)
302
299
}
303
-
304
- }
300
+ }
0 commit comments