Fork channel

Create a new channel as a copy of main.

Rename channel

Rename main to:

Delete channel

Delete main? This cannot be undone.

PijulChangesDialog.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.dialog

import com.github.jonathanxd.dracon.editor.EditorServer
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.intellij.lang.Language
import com.intellij.notification.NotificationGroup
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.ValidationInfo
import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.util.NlsContexts.DialogTitle
import com.intellij.openapi.util.NlsContexts.Button
import com.intellij.openapi.wm.IdeFocusManager
import com.intellij.ui.LanguageTextField
import com.intellij.ui.TextFieldWithAutoCompletion
import com.intellij.ui.TextFieldWithAutoCompletionListProvider
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.textCompletion.TextCompletionUtil
import java.awt.*
import java.awt.event.*
import java.beans.PropertyChangeEvent
import java.nio.file.Path
import javax.swing.*


open class PijulChangesDialog(val project: Project,
                              val vcsRoot: Path,
                              val editorServer: EditorServer,
                              val text: String,
                              @DialogTitle val title_: String,
                              @Button val button_: String) : DialogWrapper(project, true) {
    init {
        init()
        title = title_
    }

    private lateinit var editor: CustomEditorField

    override fun createCenterPanel(): JComponent {
        val dialogPanel = JPanel(BorderLayout())
        val tomlLanguage = Language.findLanguageByID("TOML")

        editor = CustomEditorField(tomlLanguage, project, this.text)

        editor.preferredSize = Dimension(800, 600)
        editor.setOneLineMode(false)
        editor.isViewer = false
        editor.isVisible = true
        editor.isEnabled = true
        dialogPanel.add(editor, BorderLayout.CENTER)

        return dialogPanel
    }

    override fun createActions(): Array<Action> {
        return arrayOf(RecordAction(), this.cancelAction)
    }

    override fun doOKAction() {
        this.editorServer.write(this.editor.text)
        this.editorServer.close()
        super.doOKAction()
    }

    protected inner class RecordAction() : DialogWrapper.DialogWrapperAction(button_) {
        override fun doAction(e: ActionEvent?) {

            val infoList: List<ValidationInfo> = doValidateAll()
            if (infoList.isNotEmpty()) {
                val info = infoList[0]
                if (info.component != null && info.component!!.isVisible) {
                    IdeFocusManager.getInstance(null).requestFocus(info.component!!, true)
                }

                updateErrorInfo(infoList)
                startTrackingValidation()
                if (ContainerUtil.exists(
                        infoList
                    ) { info1: ValidationInfo -> !info1.okEnabled }
                ) return
            }
            doOKAction()
        }

        init {
            addPropertyChangeListener { evt: PropertyChangeEvent ->
                if (NAME == evt.propertyName) {
                    repaint()
                }
            }
        }
    }

    class Provider : TextFieldWithAutoCompletionListProvider<String>(listOf("author", "[[authors]]", "authors", "name", "full_name", "email")) {
        override fun getLookupString(item: String): String {
            return item
        }

    }
    class RecordDocumentCreator : TextCompletionUtil.DocumentWithCompletionCreator(
        TextFieldWithAutoCompletion.StringsCompletionProvider(listOf("author", "[[authors]]", "authors", "name", "full_name", "email"),null),
        true
    )
}

class CustomEditorField(language: Language?, project: Project, s: String) : LanguageTextField(language, project, s, PijulChangesDialog.RecordDocumentCreator(), false) {

    override fun createEditor(): EditorEx {
        val editor = super.createEditor()
        editor.setVerticalScrollbarVisible(true)
        editor.setHorizontalScrollbarVisible(true)
        editor.setCaretEnabled(true)
        editor.isViewer = false
        editor.isOneLineMode = false


        val settings = editor.settings
        settings.isLineNumbersShown = true
        settings.isAutoCodeFoldingEnabled = true
        settings.isFoldingOutlineShown = true
        settings.isAllowSingleLogicalLineFolding = true
        settings.isRightMarginShown=true
        return editor
    }
}