Skip to content

Commit

Permalink
Load from and store global settings in current ApiProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Sep 12, 2023
1 parent 72e9d9d commit c88de30
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package de.griefed.serverpackcreator.gui.window.settings

import Gui
import de.comahe.i18n4k.Locale
import de.griefed.serverpackcreator.api.ApiProperties
import de.griefed.serverpackcreator.api.ExclusionFilter
import de.griefed.serverpackcreator.gui.GuiProps
Expand All @@ -28,12 +29,13 @@ import de.griefed.serverpackcreator.gui.window.MainFrame
import de.griefed.serverpackcreator.gui.window.configs.components.ComponentResizer
import de.griefed.serverpackcreator.gui.window.settings.components.*
import java.io.File
import java.net.URL
import javax.swing.DefaultComboBoxModel
import javax.swing.JCheckBox
import javax.swing.JComboBox
import javax.swing.JFileChooser

class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, componentResizer: ComponentResizer, mainFrame: MainFrame) : Editor("Global", guiProps) {
class GlobalSettings(guiProps: GuiProps, private val apiProperties: ApiProperties, componentResizer: ComponentResizer, mainFrame: MainFrame) : Editor("Global", guiProps) {

val homeIcon = StatusIcon(guiProps, "Home directory setting")

Check notice on line 40 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'homeIcon' could be private
val homeLabel = ElementLabel("Home Directory")

Check notice on line 41 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'homeLabel' could be private
Expand Down Expand Up @@ -162,6 +164,8 @@ class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, component
val autodetectionReset = BalloonTipButton(null,guiProps.resetIcon,"Reset to default value",guiProps) { autodetectionSetting.isSelected = apiProperties.fallbackAutoExcludingModsEnabled }

Check notice on line 164 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'autodetectionReset' could be private

init {
languageSetting.selectedItem = apiProperties.i18n4kConfig.locale
exclusionSetting.selectedItem = apiProperties.exclusionFilter
overwriteSetting.isSelected = apiProperties.isServerPacksOverwriteEnabled
javaVariableSetting.isSelected = apiProperties.isJavaScriptAutoupdateEnabled
prereleaseSetting.isSelected = apiProperties.isCheckingForPreReleasesEnabled
Expand Down Expand Up @@ -308,10 +312,42 @@ class GlobalSettings(guiProps: GuiProps, apiProperties: ApiProperties, component
}

override fun loadSettings() {
TODO("Not yet implemented")
homeSetting.file = apiProperties.homeDirectory.absoluteFile
javaSetting.file = File(apiProperties.javaPath).absoluteFile
serverPacksSetting.file = apiProperties.serverPacksDirectory.absoluteFile
zipSetting.text = apiProperties.zipArchiveExclusions.joinToString(", ")
inclusionsSetting.text = apiProperties.directoriesToInclude.joinToString(", ")
aikarsSetting.text = apiProperties.aikarsFlags
scriptSetting.text = apiProperties.scriptTemplates.joinToString(", ")
fallbackURLSetting.text = apiProperties.updateUrl.toString()
exclusionSetting.selectedItem = apiProperties.exclusionFilter
languageSetting.selectedItem = apiProperties.i18n4kConfig.locale
overwriteSetting.isSelected = apiProperties.isServerPacksOverwriteEnabled
javaVariableSetting.isSelected = apiProperties.isJavaScriptAutoupdateEnabled
prereleaseSetting.isSelected = apiProperties.isCheckingForPreReleasesEnabled
zipExclusionsSetting.isSelected = apiProperties.isZipFileExclusionEnabled
cleanupSetting.isSelected = apiProperties.isServerPackCleanupEnabled
snapshotsSetting.isSelected = apiProperties.isMinecraftPreReleasesAvailabilityEnabled
autodetectionSetting.isSelected = apiProperties.isAutoExcludingModsEnabled
}

override fun saveSettings() {
TODO("Not yet implemented")
apiProperties.homeDirectory = homeSetting.file.absoluteFile
apiProperties.javaPath = javaSetting.file.absolutePath
apiProperties.serverPacksDirectory = serverPacksSetting.file.absoluteFile
apiProperties.zipArchiveExclusions.addAll(zipSetting.text.replace(", ",",").split(","))
apiProperties.directoriesToInclude.addAll(inclusionsSetting.text.replace(", ",",").split(","))
apiProperties.aikarsFlags = aikarsSetting.text
apiProperties.scriptTemplates.addAll(scriptSetting.text.replace(", ",",").split(",").map { File(it) })
apiProperties.updateUrl = URL(fallbackURLSetting.text)
apiProperties.exclusionFilter = exclusionSetting.selectedItem as ExclusionFilter
apiProperties.language = languageSetting.selectedItem as Locale

Check warning on line 344 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

Cast will always fail

Check warning on line 344 in serverpackcreator-gui/src/main/kotlin/de/griefed/serverpackcreator/gui/window/settings/GlobalSettings.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of redundant or deprecated syntax or deprecated symbols

No cast needed
apiProperties.isServerPacksOverwriteEnabled = overwriteSetting.isSelected
apiProperties.isJavaScriptAutoupdateEnabled = javaVariableSetting.isSelected
apiProperties.isCheckingForPreReleasesEnabled = prereleaseSetting.isSelected
apiProperties.isZipFileExclusionEnabled = zipExclusionsSetting.isSelected
apiProperties.isServerPackCleanupEnabled = cleanupSetting.isSelected
apiProperties.isMinecraftPreReleasesAvailabilityEnabled = snapshotsSetting.isSelected
apiProperties.isAutoExcludingModsEnabled = autodetectionSetting.isSelected
}
}

0 comments on commit c88de30

Please sign in to comment.