DLDMHQY6F53N2YXNDBQY77GAU2I4N2OWC3DL6L36T2SSAVW6YSXAC
RE4EKNSLYGCITZZEOPIRJAWTKIONGP7IY6S77BQO7JQL2CK27RZAC
37OJKSWJFDRHNWQW6P7HSZX6OWZWVNCJ2IFT42O5TANQF7VOVX6AC
OMZXJL6QA6INENIEAARSWYFHOPMLTP4WRCVI646GQVJVWCH3LENQC
GGYFPXND4VBCROZZXTKAP7Y4JOP2OOYQAFVLMUE7SLFM225EUSIAC
ZCRW57C5MSBXYGUMGQTZNHGHO4HGHFBICW53X5I2IMGP3H2CKWRQC
FNNW5IEAXQ43WKB6QSQB7DFLG3Y3T5FYPXIUX7KQ2URR2GU3QLTAC
Q7FXTHVUPVAFMNY277C3NFJO3VXLZU5G6C6UYSD5QPURHSG3A7OQC
FRFFQV7VNYKGCA7ZAOSRPC2HHYTAIZ6AGGR7A5QEV6QPAQGFDYGAC
B43WNBLFFR2UQIH3C6KIZAQTAEQOQM3J3IYLGQMVGJHYOME73OKQC
OPFG6CZ26PPTGTH7ULLRQGZGR3YEIEJOV5W2E3WN7PFRZS62CVLQC
ISO7J5ZH5UB7NFZKTKKJQHQHCP4DWQ3F7SM2NDMVYJAGGIKDLX4QC
2N67RQZCVGL6GYJJLM2US4YVCEIUK25AHCLD66C7HR4PPTNUOCWAC
MZYZIVHY5DUHVJH7YGENRAIKTKMZWJ5ANRVGFLLU7YTHXC2OXZJQC
remote.invalid.remote.text=Invalid remote server {0}...
settings.title=Dracon (Pijul)
settings.pijul.path.text=Pijul path:
settings.pijul.path.detect.text=Detect
settings.pijul.path.select.text=Select Pijul Binary
settings.dracon.index.all.text=Index all revisions
settings.dracon.index.all.tooltip.text=Enable caching of all revisions, it does speed up revision loading however \
caching uses a bunch of storage space and takes a bit of more time at first loading.
package com.github.jonathanxd.dracon.exec
import com.github.jonathanxd.dracon.i18n.BUNDLE
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.ProcessOutput
import com.intellij.execution.util.ExecUtil
import org.jetbrains.annotations.PropertyKey
import java.nio.file.Path
fun execInTerminal(
@PropertyKey(resourceBundle = BUNDLE) name: String,
command: String
) {
ExecUtil.execAndGetOutput(GeneralCommandLine(ExecUtil.getTerminalCommand(DraconBundle.message(name), command)))
}
fun execInTerminal(
@PropertyKey(resourceBundle = BUNDLE) name: String,
vars: Map<String, String>,
workDir: Path,
command: String
): ProcessOutput {
val cmd = GeneralCommandLine(ExecUtil.getTerminalCommand(DraconBundle.message(name), command))
cmd.environment.putAll(vars)
cmd.workDirectory = workDir.toFile()
return ExecUtil.execAndGetOutput(cmd)
}
fun terminalCommand(
@PropertyKey(resourceBundle = BUNDLE) name: String,
command: String
): List<String> {
return ExecUtil.getTerminalCommand(DraconBundle.message(name), command)
}
package com.github.jonathanxd.dracon.component
import com.github.jonathanxd.dracon.config.PijulSettings
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.intellij.openapi.options.Configurable
import javax.swing.JComponent
class PijulSettingsConfigurable: Configurable {
private var pijulSettingsComponent: PijulSettingsComponent? = null
override fun createComponent(): JComponent =
PijulSettingsComponent().let {
this.pijulSettingsComponent = it
it
}.mainPanel
override fun getPreferredFocusedComponent(): JComponent? =
this.pijulSettingsComponent?.preferredFocusedComponent
override fun isModified(): Boolean {
val settings = PijulSettings.instance
val pathToPijul = settings.getPathToPijul()
val cacheAllRevisions = settings.isToCacheAllRevisions()
var modified = this.pijulSettingsComponent?.pijulPath?.text != pathToPijul
modified = modified || (this.pijulSettingsComponent?.indexAllRevisions?.isSelected == cacheAllRevisions)
return modified
}
override fun apply() {
val settings = PijulSettings.instance
settings.savePathToPijul(this.pijulSettingsComponent?.pijulPath?.text)
settings.saveToCacheAllRevisions(this.pijulSettingsComponent?.indexAllRevisions?.isSelected ?: false)
}
override fun getDisplayName(): String =
DraconBundle.message("settings.title")
override fun reset() {
val settings = PijulSettings.instance
this.pijulSettingsComponent?.pijulPath?.text = settings.getPathToPijul() ?: ""
this.pijulSettingsComponent?.indexAllRevisions?.isSelected = settings.isToCacheAllRevisions()
}
override fun disposeUIResources() {
this.pijulSettingsComponent = null
}
}
package com.github.jonathanxd.dracon.component
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.util.findBinaryOrNull
import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.ui.FixedSizeButton
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.uiDesigner.core.Spacer
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.UIUtil
import java.awt.BorderLayout
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.JButton
import javax.swing.JComponent
import javax.swing.JPanel
class PijulSettingsComponent {
val indexAllRevisions = JBCheckBox(DraconBundle.message("settings.dracon.index.all.text")).also {
it.toolTipText = DraconBundle.message("settings.dracon.index.all.tooltip.text")
}
val pijulPath = TextFieldWithBrowseButton().also {
it.addBrowseFolderListener(
DraconBundle.message("settings.pijul.path.select.text"),
"",
null,
FileChooserDescriptor(true, false, false, false, false, false)
.withFileFilter { file: VirtualFile? ->
file?.name == "pijul"
}
)
}
val detectPijul = JButton(DraconBundle.message("settings.pijul.path.detect.text")).also {
it.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
pijulPath.text = findBinaryOrNull("pijul") ?: ""
}
})
it.updateUI()
}
var mainPanel: JPanel =
FormBuilder.createFormBuilder()
.addLabeledComponent(
JBLabel(DraconBundle.message("settings.pijul.path.text")), pijulPath, 1, false
)
.addComponent(JPanel(BorderLayout()).also {
it.add(indexAllRevisions, BorderLayout.WEST)
it.add(detectPijul, BorderLayout.EAST)
}, 0)
.addComponentFillVertically(JPanel(), 0)
.panel
val preferredFocusedComponent: JComponent
get() = this.pijulPath
}
this.project,
root,
arguments,
editorServerConsumer
)
return this.doExecutionWithMapper("push", operation) {
it
}
}
override fun pushInTerminal(
project: Project,
root: Path,
fromChannel: String?,
toChannel: String?,
repository: String?,
editorServerConsumer: (EditorServer) -> Unit
): PijulOperationResult<String> {
val arguments = mutableListOf("push")
if (fromChannel != null) {
arguments.add("--from-channel")
arguments.add(fromChannel)
}
if (toChannel != null) {
arguments.add("--to-channel")
arguments.add(toChannel)
}
if (repository != null) {
arguments.add(repository)
}
val operation = this.createPainlessExecPijulWithEditorServerInTerminal(
.directory(dir.toFile())
.start()
editorServerConsumer(EditorServer(freePort) {
!process.isAlive
})
val input = String(process.inputStream.readAllBytes(), Charsets.UTF_8)
val error = String(process.errorStream.readAllBytes(), Charsets.UTF_8)
input.split("\n").forEach {
draconConsoleWriter(project).logCommand("pijul", args, it)
}
error.split("\n").forEach {
draconConsoleWriter(project).logCommandError("pijul", args, it)
}
val exit = process.waitFor()
if (exit == 0) {
draconConsoleWriter(project).logCommand("pijul", args, "<Exit status> $exit")
} else {
draconConsoleWriter(project).logCommandError("pijul", args, "<Exit status> $exit")
}
return PijulExecution(
input,
error,
exit
)
}
/**
* Creates a [PijulExecution] operation that could be executed at any time. This operation uses Kotlin Coroutines
* and can be executed immediately through [doExecution] or through [doExecutionWithMapper].
*
* This implementation does not requires a delay value to be provided, like [createExecPijulOperation] does, instead
* it uses the kotlin conversion from `CompletionStage` to `Coroutines` and awaits the process through [Process.onExit].
*
* [doExecution] and [doExecutionWithMapper] does execution by scheduling task to [Dispatchers.IO], instead of Main Thread,
* offloading the Process execution handling to a different scheduler. However, mapping operation of [doExecutionWithMapper]
* is not offloaded from the caller context.
*
*/
@RequiresBackgroundThread
private fun createPainlessExecPijulWithEditorServerInTerminal(
project: Project,
dir: Path,
args: List<String>,
editorServerConsumer: (EditorServer) -> Unit
): PijulExecution {
val freePort = freePort()
val cmd = listOf(this.findPijul()) + args
val terminalCmd = terminalCommand("command.execute.text", cmd.joinToString(" "))
val process = ProcessBuilder()
.apply {
environment()["EDITOR_SERVER_PORT"] = freePort.toString()
environment()["VISUAL"] = editorServerPath()
environment()["EDITOR"] = editorServerPath()
}
.command(terminalCmd)