summaryrefslogtreecommitdiff
path: root/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt
blob: 49ca322e96bfe49d9f31d28ca70510166a65993f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package me.kyren223.trident.data

import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.JBColor
import com.intellij.ui.JBIntSpinner
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.JBFont
import javax.swing.JPanel

class SettingsData {
    
    private val minValue = 1
    private val maxValue = 5000
    private val step = 10

    val panel: JPanel

    private val width = JBIntSpinner(SettingsState.instance.width, minValue, maxValue, step)
    private val height = JBIntSpinner(SettingsState.instance.height, minValue, maxValue, step)
    private val fontSize = JBIntSpinner(SettingsState.instance.fontSize, minValue, maxValue, step)

    private val enterToSelect = JBCheckBox(null, SettingsState.instance.enterToSelect)
    private val rememberLine = JBCheckBox(null, SettingsState.instance.rememberLine)
    private val automaticMapping = ComboBox(AutomaticMapping.entries.toTypedArray())
    private val automaticReplacing = ComboBox(AutomaticReplacing.entries.toTypedArray())
    private val recursiveMapping = JBCheckBox(null, SettingsState.instance.recursiveMapping)
    private val indexCycling = JBCheckBox(null, SettingsState.instance.indexCycling)

    init {
        automaticMapping.selectedItem = SettingsState.instance.automaticMapping
        automaticReplacing.selectedItem = SettingsState.instance.automaticReplacing
        
        panel = FormBuilder.createFormBuilder()
            .addComponent(JBLabel("Popup settings").withFont(JBFont.h4()))
            .addLabeledComponent("Popup width", width)
            .addLabeledComponent("Popup height", height)
            .addLabeledComponent("Popup font size", fontSize)
            .addSeparator()

            .addComponent(JBLabel("Trident settings").withFont(JBFont.h4()))
            .addLabeledComponent("Enter to select item", enterToSelect)
            .addComponent(desc("If enabled while the TridentList is open, " +
                    "pressing enter will select the item in the current line and open the file (if it exists)."))
            .addVerticalGap(step)

            .addLabeledComponent("Automatic mapping (when possible)", automaticMapping)
            .addComponent(desc("Disabled - adds the full file path to the Trident Mappings."))
            .addComponent(desc("Filename - Adds the filename (with extension)."))
            .addComponent(desc("Filename (no extension) - Adds the filename (without extension)."))
            .addVerticalGap(step)
            
            .addLabeledComponent("Automatic replacing (when possible)", automaticReplacing)
            .addComponent(desc("Disabled - Keeps the full file path."))
            .addComponent(desc("Exact - Replaces the full path if an exact match is found."))
            .addComponent(desc("Smart - Like exact but if no exact match found, " +
                    "it will try to make the path shorter."))
            .addVerticalGap(step)

            .addLabeledComponent("Recursive mapping", recursiveMapping)
            .addComponent(desc("If enabled, when expanding a mapping for a path, " +
                    "each entry will be expanded recursively."))
            .addComponent(desc("This allows mapping entries to be nested (include other mappings)."))
            .addVerticalGap(step)

            .addLabeledComponent("Remember last line", rememberLine)
            .addComponent(desc("If enabled, the current line of the TridentList will be remembered " +
                    "and will be selected when the TridentList is opened."))
            .addComponent(desc("Note, this does not persist across restarts, it's run-time only."))

            .addLabeledComponent("Index cycling", indexCycling)
            .addComponent(desc("If enabled, indexes will be cyclic, " +
                    "For example if you have 3 files and hotkey to 4, it'll cycle to 1."))

            .addComponentFillVertically(JPanel(), 0)
            .panel
    }

    private fun desc(text: String): JBLabel {
        val label = JBLabel(text).withFont(JBFont.small())
        label.foreground = JBColor.GRAY
        return label
    }

    fun getWidth(): Int {
        return width.number
    }

    fun getHeight(): Int {
        return height.number
    }

    fun getFontSize(): Int {
        return fontSize.number
    }

    fun getEnterToSelect(): Boolean {
        return enterToSelect.isSelected
    }

    fun setWidth(width: Int) {
        this.width.number = width
    }

    fun setHeight(height: Int) {
        this.height.number = height
    }

    fun setFontSize(fontSize: Int) {
        this.fontSize.number = fontSize
    }

    fun setEnterToSelect(enter: Boolean) {
        this.enterToSelect.isSelected = enter
    }

    fun getAutomaticMapping(): AutomaticMapping {
        return automaticMapping.selectedItem as AutomaticMapping
    }

    fun setAutomaticMapping(automaticMapping: AutomaticMapping) {
        this.automaticMapping.selectedItem = automaticMapping
    }
    
    fun getAutomaticReplacing(): AutomaticReplacing {
        return automaticReplacing.selectedItem as AutomaticReplacing
    }
    
    fun setAutomaticReplacing(automaticReplacing: AutomaticReplacing) {
        this.automaticReplacing.selectedItem = automaticReplacing
    }

    fun getRememberLine(): Boolean {
        return rememberLine.isSelected
    }

    fun setRememberLine(rememberLine: Boolean) {
        this.rememberLine.isSelected = rememberLine
    }

    fun getRecursiveMapping(): Boolean {
        return recursiveMapping.isSelected
    }

    fun setRecursiveMapping(recursiveMapping: Boolean) {
        this.recursiveMapping.isSelected = recursiveMapping
    }

    fun getIndexCycling(): Boolean {
        return indexCycling.isSelected
    }

    fun setIndexCycling(indexCycling: Boolean) {
        this.indexCycling.isSelected = indexCycling
    }
}

enum class AutomaticMapping {
    Disabled,
    Filename,
    FilenameNoExtension,
    ;
    
    override fun toString(): String {
        if (this == FilenameNoExtension) return "Filename (without extension)"
        return super.toString()
    }
}

enum class AutomaticReplacing {
    Disabled,
    Exact,
    Smart,
}