Skip to content

Commit 50d2af8

Browse files
committed
Powerline with file name
1 parent ebbc84b commit 50d2af8

File tree

7 files changed

+91
-29
lines changed

7 files changed

+91
-29
lines changed

.idea/workspace.xml

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/kotlin/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
opens org.idaesbasic.buffer to tornadofx;
1515
opens org.idaesbasic.buffer.run to tornadofx;
1616
opens org.idaesbasic.sidepanel to tornadofx;
17+
opens org.idaesbasic.powerline to tornadofx;
1718

1819
exports org.idaesbasic;
1920
}

src/main/kotlin/org/idaesbasic/MainView.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.idaesbasic
22

3+
import javafx.beans.property.SimpleIntegerProperty
4+
import javafx.beans.property.SimpleListProperty
35
import javafx.collections.ListChangeListener
46
import javafx.geometry.Insets
57
import javafx.scene.input.MouseEvent
@@ -15,14 +17,14 @@ import org.idaesbasic.buffer.run.RunConfigController
1517
import org.idaesbasic.buffer.run.RunConfigModel
1618
import org.idaesbasic.buffer.run.RunConfigProperty
1719
import org.idaesbasic.intelline.IntellineView
20+
import org.idaesbasic.powerline.PowerLineView
1821
import org.idaesbasic.sidepanel.SidepanelView
1922
import org.kordamp.ikonli.javafx.FontIcon
2023
import tornadofx.*
2124
import java.nio.file.Files
2225
import java.nio.file.Path
2326
import java.nio.file.Paths
2427

25-
2628
class MainView : View() {
2729
val controller: MainController by inject()
2830

@@ -38,8 +40,8 @@ class MainView : View() {
3840
iconColor = Color.web("#f8f8f2")
3941
}
4042
action {
41-
if (controller.currentBufferIndex > 0) {
42-
controller.currentBufferIndex -= 1
43+
if (controller.currentBufferIndexProperty.get() > 0) {
44+
controller.currentBufferIndexProperty.value -= 1
4345
controller.openCurrentBufferIndexBuffer()
4446
}
4547
}
@@ -52,8 +54,8 @@ class MainView : View() {
5254
iconColor = Color.web("#f8f8f2")
5355
}
5456
action {
55-
if (controller.currentBufferIndex +1 < controller.buffers.size) {
56-
controller.currentBufferIndex += 1
57+
if (controller.currentBufferIndexProperty.value +1 < controller.buffers.size) {
58+
controller.currentBufferIndexProperty.value += 1
5759
controller.openCurrentBufferIndexBuffer()
5860
}
5961
}
@@ -73,7 +75,7 @@ class MainView : View() {
7375
prefWidth = 30.0
7476
prefHeight = prefWidth
7577
action {
76-
controller.removeBuffer(controller.currentBufferIndex)
78+
controller.removeBuffer(controller.currentBufferIndexProperty.get())
7779
}
7880
graphic = FontIcon().apply {
7981
iconLiteral = "fa-minus"
@@ -169,6 +171,7 @@ class MainView : View() {
169171
}
170172
}
171173
}
174+
bottom<PowerLineView>()
172175
}
173176

174177
private fun showSaveDialogAndSaveText(extensions: Array<FileChooser.ExtensionFilter>, text: String, file: FileModel) {
@@ -197,14 +200,14 @@ class MainView : View() {
197200
controller.buffers[bufferIndex] = textEditor
198201
} else {
199202
// Add as new buffer
200-
controller.buffers = controller.buffers.plus(textEditor)
203+
controller.buffers.add(textEditor)
201204
}
202205
}
203206

204207
fun newBuffer() {
205-
val textEditor = NewBufferView()
206-
controller.buffers = controller.buffers.plus(textEditor)
207-
controller.currentBufferIndex = controller.buffers.size -1
208+
val newBuffer = NewBufferView()
209+
controller.buffers.add(newBuffer)
210+
controller.currentBufferIndexProperty.set(controller.buffers.size -1)
208211
controller.openCurrentBufferIndexBuffer()
209212
}
210213

@@ -217,7 +220,6 @@ class MainViewModel : ItemViewModel<MainView>() {
217220
val root = bind(MainView::root)
218221
}
219222

220-
221223
class Editor(file: FileModel): Fragment() {
222224
override val root = CodeArea()
223225
lateinit var fileObject: FileModel
@@ -231,22 +233,20 @@ class Editor(file: FileModel): Fragment() {
231233

232234
class MainController : Controller() {
233235

234-
var buffers = emptyArray<Fragment>()
235-
var currentBufferIndex = -1
236+
var buffers = SortedFilteredList<Fragment>()
237+
var currentBufferIndexProperty = SimpleIntegerProperty(-1)
236238

237239
fun getCurrentBuffer(): Fragment {
238-
return buffers[currentBufferIndex]
240+
return buffers[currentBufferIndexProperty.get()]
239241
}
240242
fun openCurrentBufferIndexBuffer() {
241243
find(MainView::class).switchCenterToBufferView(getCurrentBuffer())
242244
}
243245

244246
fun removeBuffer(index: Int) {
245-
val mutableBuffers = buffers.toMutableList()
246-
mutableBuffers.removeAt(index)
247-
buffers = mutableBuffers.toTypedArray()
248-
if (currentBufferIndex >= index && currentBufferIndex != 0) {
249-
currentBufferIndex -= 1
247+
buffers.removeAt(index)
248+
if (currentBufferIndexProperty.get() >= index && currentBufferIndexProperty.get() != 0) {
249+
currentBufferIndexProperty.value -= 1
250250
}
251251
openCurrentBufferIndexBuffer()
252252
}

src/main/kotlin/org/idaesbasic/buffer/NewBufferView.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class NewBufferView : Fragment () {
1515

1616
override val root = squeezebox {
1717
fold("New file", expanded = true) {
18+
val newFileName = SimpleStringProperty()
1819
form {
1920
fieldset ("Basic file configuration"){
2021
field("Filename") {
21-
textfield()
22+
textfield(newFileName)
2223
}
2324
field("Language") {
2425
label("Plain text")
@@ -30,8 +31,8 @@ class NewBufferView : Fragment () {
3031
button("Create") {
3132
action {
3233
val mainView = find(MainView::class)
33-
val file = FileModel(null, null, null)
34-
mainView.newEditor(mainView.controller.currentBufferIndex, file)
34+
val file = FileModel(newFileName.get(), null, null)
35+
mainView.newEditor(mainView.controller.currentBufferIndexProperty.get(), file)
3536
mainView.controller.openCurrentBufferIndexBuffer()
3637
}
3738
}
@@ -88,7 +89,7 @@ class NewBufferController : Controller () {
8889
val mainView = find(MainView::class)
8990
val openedFile = Paths.get(location)
9091
val file = FileModel(openedFile.fileName.toString(), openedFile, Files.readString(openedFile))
91-
mainView.newEditor(mainView.controller.currentBufferIndex, file)
92+
mainView.newEditor(mainView.controller.currentBufferIndexProperty.get(), file)
9293
mainView.controller.openCurrentBufferIndexBuffer()
9394
}
9495
}

src/main/kotlin/org/idaesbasic/intelline/IntellineView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class IntellineView : View() {
2525
val mainView = find(MainView::class)
2626
val currentBuffersSize = mainView.controller.buffers.size
2727
mainView.newEditor(currentBuffersSize + 1, FileModel(null, null, null))
28-
mainView.controller.currentBufferIndex = currentBuffersSize
28+
mainView.controller.currentBufferIndexProperty.value = currentBuffersSize
2929
mainView.controller.openCurrentBufferIndexBuffer()
3030
}
3131
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.idaesbasic.powerline
2+
3+
import org.idaesbasic.MainView
4+
import tornadofx.Controller
5+
6+
class PowerLineController : Controller() {
7+
val mainView: MainView by inject()
8+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.idaesbasic.powerline
2+
3+
import javafx.beans.property.SimpleStringProperty
4+
import org.idaesbasic.Editor
5+
import org.idaesbasic.MainController
6+
import tornadofx.View
7+
import tornadofx.label
8+
import tornadofx.onChange
9+
import tornadofx.toolbar
10+
11+
class PowerLineView : View() {
12+
val fileNameProperty = SimpleStringProperty()
13+
val mainController = find(MainController::class)
14+
15+
override val root = toolbar() {
16+
// Listen changes
17+
// On current buffer got replaced
18+
mainController.buffers.onChange {
19+
it.next()
20+
if(it.wasReplaced()) {
21+
setFileName()
22+
}
23+
}
24+
// On buffer switched
25+
mainController.currentBufferIndexProperty.onChange {
26+
setFileName()
27+
}
28+
label(fileNameProperty)
29+
}
30+
31+
fun setFileName() {
32+
if (mainController.getCurrentBuffer() is Editor) {
33+
fileNameProperty.value = (mainController.getCurrentBuffer() as Editor).fileObject.name
34+
}
35+
else {
36+
fileNameProperty.value = "No file opened"
37+
}
38+
}
39+
40+
}

0 commit comments

Comments
 (0)