PijulSettings.kt
/**
* Dracon - An IntelliJ-Pijul integration.
* Copyright 2021 JonathanxD <jhrldev@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.github.jonathanxd.dracon.config
import com.github.jonathanxd.dracon.util.findBinary
import com.github.jonathanxd.dracon.util.findBinaryOrNull
import com.intellij.dvcs.branch.DvcsBranchSettings
import com.intellij.dvcs.branch.DvcsCompareSettings
import com.intellij.dvcs.branch.DvcsSyncSettings
import com.intellij.openapi.components.*
import com.intellij.util.xmlb.annotations.OptionTag
import com.intellij.util.xmlb.annotations.Property
import com.intellij.vcs.log.VcsUser
@State(name = "Pijul.Settings", storages = [Storage("DraconSettings.xml")])
class PijulSettings : SimplePersistentStateComponent<PijulOptions>(PijulOptions()), DvcsSyncSettings, DvcsCompareSettings {
companion object {
val instance get() = service<PijulSettings>()
}
override fun getSyncSetting(): DvcsSyncSettings.Value =
this.state.rootSync
fun getAuthor(): String? {
return this.state.author
}
fun saveAuthor(author: VcsUser) { // Pijul still does not support specifying emails?
this.state.author = author.name
}
fun isToCacheAllRevisions(): Boolean =
this.state.cacheAllRevisions
fun saveToCacheAllRevisions(cacheAllRevisions: Boolean) {
this.state.cacheAllRevisions = cacheAllRevisions
}
fun savePathToPijul(pathToPijul: String?) {
this.state.pathToPijul = pathToPijul
}
fun getPathToPijul() =
this.state.pathToPijul
fun savePathToEditorServer(pathToEditorServer: String?) {
this.state.pathToEditorServer = pathToEditorServer
}
fun getPathToEditorServer() =
this.state.pathToEditorServer
fun getChannelSettings(): DvcsBranchSettings =
this.state.channelSettings
fun setChannelSettings(settings: DvcsBranchSettings) {
this.state.channelSettings = settings
}
override fun setSyncSetting(syncSetting: DvcsSyncSettings.Value) {
this.state.rootSync = syncSetting
}
override fun shouldSwapSidesInCompareBranches(): Boolean =
this.state.isSwapSidesInCompareBranches
override fun setSwapSidesInCompareBranches(value: Boolean) {
this.state.isSwapSidesInCompareBranches = value
}
}
class PijulOptions : BaseState() {
@get:OptionTag("PATH_TO_PIJUL")
var pathToPijul by string(defaultValue = findBinaryOrNull("pijul"))
@get:OptionTag("PATH_TO_EDITOR_SERVER")
var pathToEditorServer by string(defaultValue = findBinaryOrNull("editor-server"))
@get:OptionTag("CACHE_ALL_REVISIONS")
var cacheAllRevisions by property(defaultValue = false)
@get:OptionTag("AUTHOR")
var author by string()
@get:OptionTag("ROOT_SYNC")
var rootSync by enum(DvcsSyncSettings.Value.NOT_DECIDED)
@get:OptionTag("SWAP_SIDES_IN_COMPARE_BRANCHES")
var isSwapSidesInCompareBranches by property(false)
@get:OptionTag("CHANNEL_SETTINGS")
@get:Property(surroundWithTag = false, flat = true)
var channelSettings by property(DvcsBranchSettings())
}