PijulSettingsComponent.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.component
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.util.findBinaryOrNull
import com.github.jonathanxd.dracon.util.wrapInHml
import com.intellij.ide.BrowserUtil
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.HyperlinkLabel
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextArea
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.*
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"
}
)
it.toolTipText = DraconBundle.message("settings.pijul.path.tooltip.text")
}
val editorServerPath = TextFieldWithBrowseButton().also {
it.addBrowseFolderListener(
DraconBundle.message("settings.editor.path.select.text"),
"",
null,
FileChooserDescriptor(true, false, false, false, false, false)
.withFileFilter { file: VirtualFile? ->
file?.name == "editor-server"
}
)
it.toolTipText = DraconBundle.message("settings.editor.path.tooltip.text")
}
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()
}
val detectEditorServer = JButton(DraconBundle.message("settings.editor.path.detect.text")).also {
it.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
editorServerPath.text = findBinaryOrNull("editor-server") ?: ""
}
})
it.updateUI()
}
var mainPanel: JPanel =
FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel(DraconBundle.message("settings.pijul.text")), JSeparator())
.addLabeledComponent(
JBLabel(DraconBundle.message("settings.pijul.path.text")).also {
it.toolTipText = DraconBundle.message("settings.pijul.path.tooltip.text")
}, pijulPath, 1, false
)
.addComponent(JPanel(BorderLayout()).also {
it.add(indexAllRevisions, BorderLayout.WEST)
it.add(detectPijul, BorderLayout.EAST)
}, 0
)
.addLabeledComponent(JBLabel(DraconBundle.message("settings.editor.text")), JSeparator())
.addLabeledComponent(
JBLabel(DraconBundle.message("settings.editor.path.text")).also {
it.toolTipText = DraconBundle.message("settings.editor.path.tooltip.text")
}, editorServerPath, 1, false
)
.addComponent(JPanel(BorderLayout()).also {
it.add(detectEditorServer, BorderLayout.EAST)
}, 0)
.addComponent(HyperlinkLabel(DraconBundle.message("settings.install.text")).also {
it.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
BrowserUtil.browse("https://oblitersoftware.github.io/")
}
})
})
.addComponentFillVertically(JPanel(), 0)
.panel
val preferredFocusedComponent: JComponent
get() = this.pijulPath
}