Skip to content

Commit e389954

Browse files
committed
fixes #16
fixes #15
1 parent 6f89f03 commit e389954

5 files changed

Lines changed: 115 additions & 106 deletions

File tree

app/src/main/java/frc238/App.kt

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ package frc238
33
import ch.bailu.gtk.adw.AboutWindow
44
import ch.bailu.gtk.adw.Application
55
import ch.bailu.gtk.adw.ApplicationWindow
6-
import ch.bailu.gtk.adw.ColorScheme
76
import ch.bailu.gtk.adw.HeaderBar
8-
import ch.bailu.gtk.adw.StyleManager
97
import ch.bailu.gtk.adw.ToastPriority
108
import ch.bailu.gtk.adw.WindowTitle
119
import ch.bailu.gtk.gio.ApplicationFlags
12-
import ch.bailu.gtk.gio.File
13-
import ch.bailu.gtk.gio.Gio
1410
import ch.bailu.gtk.gio.Menu
1511
import ch.bailu.gtk.gio.MenuItem
1612
import ch.bailu.gtk.gio.SimpleAction
@@ -22,7 +18,6 @@ import ch.bailu.gtk.gtk.Orientation
2218
import ch.bailu.gtk.gtk.StyleContext
2319
import ch.bailu.gtk.type.Str
2420
import ch.bailu.gtk.type.Strs
25-
import ch.bailu.gtk.type.exception.AllocationError
2621
import frc238.background.RobotProject
2722
import frc238.plugins.PluginManager
2823
import frc238.widgets.AutoPicker
@@ -31,114 +26,44 @@ import frc238.widgets.loadFolder
3126
import frc238.widgets.makeAndRunPopup
3227
import java.io.FileNotFoundException
3328
import java.nio.file.Paths
29+
import kotlin.system.exitProcess
3430

3531
object App {
3632
// FIXME avoid global variables
37-
lateinit var picker: AutoPicker
3833
lateinit var app: Application
34+
lateinit var picker: AutoPicker
3935
lateinit var window: ApplicationWindow
4036
lateinit var project: RobotProject
4137
lateinit var header: HeaderBar
4238
lateinit var title: WindowTitle
4339
lateinit var settings: Settings
4440
lateinit var plugins: PluginManager
45-
private fun init() {
46-
settings = Settings()
47-
plugins = PluginManager()
48-
}
4941

5042
@JvmStatic
5143
fun main(args: Array<String>) {
5244
// Adw.init() // This call should not be necessary if you use adw.Application instead of gtk.Application
53-
app = Application("org.frc238.autoBuilder", ApplicationFlags.FLAGS_NONE)
45+
val theApp = Application("org.frc238.autoBuilder", ApplicationFlags.FLAGS_NONE)
5446

5547
/*
5648
FIXME This works only with compiled resources
5749
Compile with `glib-compile-resources` application that is part of the gtk distribution
5850
See Adwaita example in java-gtk
5951
there is also a helper function to load compiled resource files: GResource.loadAndRegister("path/to/compiled.gresources")
6052
*/
61-
val gresource = File.newForPath(Str("icons/resources.gresource.xml"))
62-
try {
63-
Gio.resourceLoad(gresource.path)
64-
} catch (e: AllocationError) {
65-
throw RuntimeException(e)
66-
}
53+
// val gresource = File.newForPath(Str("icons/resources.gresource.xml"))
54+
// try {
55+
// Gio.resourceLoad(gresource.path)
56+
// } catch (e: AllocationError) {
57+
// throw RuntimeException(e)
58+
// }
6759

6860
// This could cause crashes
69-
StyleManager.getDefault().colorScheme = ColorScheme.FORCE_DARK
70-
71-
app.onActivate {
72-
73-
init() // Load widgets here (after app.run())
74-
75-
header = HeaderBar()
76-
header.addCssClass("flat")
77-
78-
project = RobotProject()
79-
picker = AutoPicker()
80-
title = WindowTitle("Autonomous Builder", "")
81-
header.titleWidget = title
82-
val cssProvider = CssProvider()
83-
val toggleCommandFlap = Button()
84-
toggleCommandFlap.setIconName("sidebar-show-right-symbolic")
85-
toggleCommandFlap.onClicked { picker.commandSidebar.onToggleClicked() }
86-
header.packEnd(toggleCommandFlap)
87-
88-
val menubutton = MenuButton()
89-
menubutton.setIconName("open-menu-symbolic")
90-
91-
val menu = Menu()
92-
val about = MenuItem("About", "app.about")
93-
menu.appendItem(about)
94-
val aboutAction = SimpleAction("about", null)
95-
app.asActionMap().addAction(aboutAction.asAction())
96-
aboutAction.onActivate { showAboutWindow() }
97-
val properties = MenuItem("Properties", "app.properties")
98-
val propertiesAction = SimpleAction("properties", null)
99-
menu.appendItem(properties)
100-
propertiesAction.onActivate { settings.openPrefsWindow() }
101-
app.asActionMap().addAction(propertiesAction.asAction())
102-
menubutton.menuModel = menu
103-
header.packEnd(menubutton)
104-
val load = Button()
105-
load.setLabel("Load")
106-
load.onClicked { loadFolder() }
107-
load.setIconName("folder-open-symbolic")
108-
header.packEnd(load)
109-
val save = Button()
110-
save.onClicked { saveAmodeFile() }
111-
save.setIconName("media-floppy-symbolic")
112-
header.packEnd(save)
113-
val toggleFlap = Button()
114-
toggleFlap.setIconName("sidebar-show-symbolic")
115-
toggleFlap.onClicked { picker.onToggleClicked() }
116-
header.packStart(toggleFlap)
117-
val addNewMode = Button()
118-
addNewMode.setIconName("list-add-symbolic")
119-
addNewMode.onClicked { picker.stack.addAmodeToList() }
120-
header.packStart(addNewMode)
121-
val removeMode = Button.newFromIconNameButton("user-trash-symbolic")
122-
removeMode.onClicked { picker.stack.removeAmode() }
123-
header.packStart(removeMode)
124-
val rename = Button.newFromIconNameButton("document-edit-symbolic")
125-
rename.onClicked { picker.stack.renameMode() }
126-
header.packStart(rename)
127-
window = ApplicationWindow(app)
128-
window.direction = Orientation.VERTICAL
129-
cssProvider.loadFromPath(Paths.get("").toAbsolutePath().toString() + "/gtk.css")
130-
StyleContext.addProviderForDisplay(window.display, cssProvider.asStyleProvider(), ToastPriority.HIGH)
131-
// window.addCssClass("accent");
132-
val vbox = Box(Orientation.VERTICAL, 0)
133-
val hbox = Box(Orientation.HORIZONTAL, 0)
134-
hbox.append(picker.flap)
135-
vbox.append(header)
136-
vbox.append(hbox)
137-
window.setDefaultSize(900, 800)
138-
window.content = vbox
139-
window.present()
140-
}
141-
app.run(args.size, Strs(args))
61+
// StyleManager.getDefault().colorScheme = ColorScheme.FORCE_DARK
62+
63+
theApp.onActivate { buildUI(theApp) }
64+
theApp.run(args.size, Strs(args))
65+
theApp.onShutdown { exitProcess(0) }
66+
app = theApp
14267
}
14368

14469
private fun showAboutWindow() {
@@ -150,6 +75,79 @@ object App {
15075
aboutMenu.show()
15176
}
15277

78+
private fun buildUI(app: Application) {
79+
80+
println("woah")
81+
82+
settings = Settings()
83+
plugins = PluginManager()
84+
header = HeaderBar()
85+
header.addCssClass("flat")
86+
87+
project = RobotProject()
88+
picker = AutoPicker()
89+
title = WindowTitle("Autonomous Builder", "")
90+
header.titleWidget = title
91+
val cssProvider = CssProvider()
92+
val toggleCommandFlap = Button()
93+
toggleCommandFlap.setIconName("sidebar-show-right-symbolic")
94+
toggleCommandFlap.onClicked { picker.commandSidebar.onToggleClicked() }
95+
header.packEnd(toggleCommandFlap)
96+
97+
val menubutton = MenuButton()
98+
menubutton.setIconName("open-menu-symbolic")
99+
100+
val menu = Menu()
101+
val about = MenuItem("About", "app.about")
102+
menu.appendItem(about)
103+
val aboutAction = SimpleAction("about", null)
104+
app.asActionMap().addAction(aboutAction.asAction())
105+
aboutAction.onActivate { showAboutWindow() }
106+
val properties = MenuItem("Properties", "app.properties")
107+
val propertiesAction = SimpleAction("properties", null)
108+
menu.appendItem(properties)
109+
propertiesAction.onActivate { settings.openPrefsWindow() }
110+
app.asActionMap().addAction(propertiesAction.asAction())
111+
menubutton.menuModel = menu
112+
header.packEnd(menubutton)
113+
val load = Button()
114+
load.setLabel("Load")
115+
load.onClicked { loadFolder() }
116+
load.setIconName("folder-open-symbolic")
117+
header.packEnd(load)
118+
val save = Button()
119+
save.onClicked { saveAmodeFile() }
120+
save.setIconName("media-floppy-symbolic")
121+
header.packEnd(save)
122+
val toggleFlap = Button()
123+
toggleFlap.setIconName("sidebar-show-symbolic")
124+
toggleFlap.onClicked { picker.onToggleClicked() }
125+
header.packStart(toggleFlap)
126+
val addNewMode = Button()
127+
addNewMode.setIconName("list-add-symbolic")
128+
addNewMode.onClicked { picker.stack.addAmodeToList() }
129+
header.packStart(addNewMode)
130+
val removeMode = Button.newFromIconNameButton("user-trash-symbolic")
131+
removeMode.onClicked { picker.stack.removeAmode() }
132+
header.packStart(removeMode)
133+
val rename = Button.newFromIconNameButton("document-edit-symbolic")
134+
rename.onClicked { picker.stack.renameMode() }
135+
header.packStart(rename)
136+
window = ApplicationWindow(app)
137+
window.direction = Orientation.VERTICAL
138+
cssProvider.loadFromPath(Paths.get("").toAbsolutePath().toString() + "/gtk.css")
139+
StyleContext.addProviderForDisplay(window.display, cssProvider.asStyleProvider(), ToastPriority.HIGH)
140+
// window.addCssClass("accent");
141+
val vbox = Box(Orientation.VERTICAL, 0)
142+
val hbox = Box(Orientation.HORIZONTAL, 0)
143+
hbox.append(picker.flap)
144+
vbox.append(header)
145+
vbox.append(hbox)
146+
window.setDefaultSize(900, 800)
147+
window.content = vbox
148+
window.present()
149+
}
150+
153151
@JvmStatic
154152
fun initAutoList() {
155153
val modes = project.autoModes!!.autonomousModes

app/src/main/java/frc238/background/RobotProject.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class RobotProject(var rootDirectory: String) {
143143
e.printStackTrace()
144144
makeAndRunPopup("there was a problem saving to the file", "JsonProcessingException")
145145
}
146+
146147
}
147148

148149
private fun reloadWPILibClassLoader() {

app/src/main/java/frc238/widgets/AmodeEditorWidget.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AmodeEditorWidget(commandList: Amode) : ScrolledWindow() {
2323
private var focusedCommandName: String? = null
2424
private var amodeCommands: TypedListBox<AutoCommandRow> = TypedListBox<AutoCommandRow>()
2525

26-
val modeName: String
26+
var modeName: String
2727
private lateinit var mode: Amode
2828
private var target: DropTarget
2929

@@ -45,17 +45,18 @@ class AmodeEditorWidget(commandList: Amode) : ScrolledWindow() {
4545
println("updated mode")
4646
println(amodeCommands.size())
4747
for (i in amodeCommands) {
48-
println("stuff")
4948
commands += i.updatedCommandList!!
50-
println(i.updatedCommandList)
49+
println(" - ${i.updatedCommandList?.name}")
5150

5251
}
52+
mode.name = modeName
5353
mode.commands = commands
5454
return mode
5555

5656
}
5757

5858
private fun setAuto(commandList: Amode) {
59+
println(commandList.name)
5960
focusOnClick = true
6061
mode = commandList
6162
amodeCommands.onMoveFocus {

app/src/main/java/frc238/widgets/AmodeStack.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class AmodeStack : Stack() {
2222
private var editorWidgetSupplier: MutableMap<String, AmodeEditorWidget> = TreeMap()
2323
private var up: Button
2424
private var down: Button
25+
//counter used to correctly number autos labelled as "New Auto (n)" with n being the number called that
26+
private var unnamedCount = 0
2527

2628
init {
2729
val action = SimpleAction("move-up", null)
@@ -76,16 +78,22 @@ class AmodeStack : Stack() {
7678
entry.onActivate {
7779
editorWidgetSupplier.run {
7880

79-
getPage(visibleChild).title = entry.asEditable().text.also { getPage(visibleChild).name = it }
80-
put(entry.asEditable().text.toString(), remove(visibleChild.name.toString())!!.also { it.name = visibleChildName })
81-
App.title.subtitle = entry.asEditable().text
81+
val oldName = getPage(visibleChild).name.toString()
82+
val newName = entry.asEditable().text
83+
getPage(visibleChild).title = newName
84+
getPage(visibleChild).name = newName
85+
val oldMode = remove(oldName)
86+
oldMode!!.modeName = newName.toString()
87+
put(newName.toString(), oldMode)
88+
App.title.subtitle = newName
89+
println("new name: $newName")
90+
println("old name: $oldName")
8291
namePop.hide()
8392
}
8493
}
8594
entry.asEditable().text = visibleChildName
8695
namePop.popdown()
8796
namePop.show()
88-
println("woah")
8997
}
9098
fun removeAmode() {
9199
editorWidgetSupplier.remove(visibleChildName.toString())
@@ -97,8 +105,8 @@ class AmodeStack : Stack() {
97105
}
98106

99107
fun addCommandToVisibleChild(info: CommandInfo?) {
100-
println(visibleChild.name.toString())
101-
editorWidgetSupplier[visibleChild.name.toString()]!!.addCommand(info!!)
108+
println(getPage(visibleChild).title.toString())
109+
editorWidgetSupplier[getPage(visibleChild).title.toString()]!!.addCommand(info!!)
102110
}
103111

104112
fun addTitled(widget: AmodeEditorWidget?, name: String) {
@@ -114,7 +122,7 @@ class AmodeStack : Stack() {
114122
}
115123

116124
fun moveFocusedCommandUp() {
117-
editorWidgetSupplier[visibleChild.name.toString()]!!.moveRowUp()
125+
editorWidgetSupplier[getPage(visibleChild).title.toString()]!!.moveRowUp()
118126
println("WOAH")
119127
}
120128
}

app/src/main/java/frc238/widgets/AutoCommandRow.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getTrailingCommaByClosingElement
2424
* @see ExpanderRow
2525
*
2626
*/
27-
class AutoCommandRow : ExpanderRow {
27+
class AutoCommandRow() : ExpanderRow() {
2828
private var command: AmodeCommand? = null
2929
private val parametersMap = HashMap<String, Supplier<Str?>>()
3030
private lateinit var info: CommandInfo
@@ -35,8 +35,6 @@ class AutoCommandRow : ExpanderRow {
3535
Parallel, Race, Deadline_Leader, Deadline_Follower, None
3636
}
3737

38-
constructor(): super()
39-
4038

4139
init {
4240
focusable = true
@@ -61,6 +59,7 @@ class AutoCommandRow : ExpanderRow {
6159
this.command = command
6260
setName(command.name)
6361
setTitle(command.name)
62+
println(command.name)
6463
val commands = App.project.commands
6564
for (commandInfo in commands) {
6665
if (commandInfo.name == command.name) {
@@ -183,7 +182,7 @@ class AutoCommandRow : ExpanderRow {
183182
*/
184183
val updatedCommandList: AmodeCommand?
185184
get() {
186-
println(parametersMap)
185+
// println(parametersMap)
187186
val parameters = ArrayList<String>()
188187
if (info.parameters.size >= 1) {
189188
for (i in info.parameters.indices) {
@@ -193,11 +192,13 @@ class AutoCommandRow : ExpanderRow {
193192
parameters.add("")
194193
}
195194
}
196-
command!!.parallelType = parametersMap["ParallelType"]!!.get().toString()
197195
}
196+
command!!.parallelType = parametersMap["ParallelType"]!!.get().toString()
198197
command!!.setParameters(parameters)
199198
println("Set " + command!!.name)
200-
println(command!!.parameters)
199+
println("params: " + command!!.parameters)
200+
println("ParallelType: " + command!!.parallelType)
201+
println("-------------------")
201202
return command
202203
}
203204

0 commit comments

Comments
 (0)