-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from anboralabs/settings
Settings
- Loading branch information
Showing
15 changed files
with
290 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/co/anbora/labs/jsoncrack/ide/fileType/FileTypePanel.form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="co.anbora.labs.jsoncrack.ide.fileType.FileTypePanel"> | ||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<xy x="20" y="20" width="500" height="47"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="61a3d" class="javax.swing.JTextField" binding="myPatternField"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> | ||
<preferred-size width="150" height="-1"/> | ||
</grid> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="7a639" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="61a3d"/> | ||
<text resource-bundle="messages/jsoncrack" key="filetype.edit.add.pattern.prompt"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</form> |
20 changes: 20 additions & 0 deletions
20
src/main/java/co/anbora/labs/jsoncrack/ide/fileType/FileTypePanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package co.anbora.labs.jsoncrack.ide.fileType; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
|
||
public class FileTypePanel { | ||
private JTextField myPatternField; | ||
private JPanel myMainPanel; | ||
|
||
@NotNull | ||
public JTextField getPatternField() { | ||
return myPatternField; | ||
} | ||
|
||
@NotNull | ||
public JPanel getMainPanel() { | ||
return myMainPanel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/co/anbora/labs/jsoncrack/ide/fileType/FileTypeDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package co.anbora.labs.jsoncrack.ide.fileType | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.DialogWrapper | ||
import com.intellij.openapi.ui.ValidationInfo | ||
import javax.swing.JComponent | ||
|
||
|
||
class FileTypeDialog(title: String, project: Project): DialogWrapper(project, false) { | ||
|
||
private val fileTypePanel = FileTypePanel() | ||
|
||
init { | ||
this.title = title | ||
init() | ||
} | ||
|
||
override fun createCenterPanel(): JComponent = fileTypePanel.mainPanel | ||
|
||
fun getExtension(): String = fileTypePanel.patternField.text | ||
|
||
override fun doValidate(): ValidationInfo? { | ||
if (fileTypePanel.patternField.text.isEmpty()) { | ||
return ValidationInfo("Not valid extension", fileTypePanel.patternField) | ||
} | ||
|
||
if (!fileTypePanel.patternField.text.startsWith(".")) { | ||
return ValidationInfo("Extension must start with `.`", fileTypePanel.patternField) | ||
} | ||
|
||
return null | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/kotlin/co/anbora/labs/jsoncrack/ide/fileType/FileTypeService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package co.anbora.labs.jsoncrack.ide.fileType | ||
|
||
import co.anbora.labs.jsoncrack.ide.SUPPORTED_EXTENSIONS | ||
import com.intellij.openapi.components.PersistentStateComponent | ||
import com.intellij.openapi.components.State | ||
import com.intellij.openapi.components.Storage | ||
import com.intellij.openapi.components.service | ||
import com.intellij.util.xmlb.XmlSerializerUtil | ||
import com.intellij.util.xmlb.annotations.XCollection | ||
|
||
@State( | ||
name = "JSONCrackN", | ||
storages = [Storage("JSONCrackN.xml")] | ||
) | ||
class FileTypeService: PersistentStateComponent<FileTypeService.ToolchainState?> { | ||
|
||
private var state = ToolchainState() | ||
|
||
fun extensions(): Set<String> { | ||
if (state.extensions.isEmpty()) { | ||
this.addExtensions(SUPPORTED_EXTENSIONS) | ||
} | ||
return state.extensions | ||
} | ||
|
||
class ToolchainState { | ||
@XCollection | ||
var extensions = mutableSetOf<String>() | ||
} | ||
|
||
override fun getState(): ToolchainState = this.state | ||
|
||
override fun loadState(state: ToolchainState) { | ||
XmlSerializerUtil.copyBean(state, this.state) | ||
} | ||
|
||
fun addExtensions(supportedExtensions: Set<String>) { | ||
this.state.extensions.clear() | ||
this.state.extensions.addAll(supportedExtensions) | ||
} | ||
|
||
companion object { | ||
val fileTypeSettings | ||
get() = service<FileTypeService>() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/co/anbora/labs/jsoncrack/ide/i18n/JSonCrackBundle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package co.anbora.labs.jsoncrack.ide.i18n | ||
|
||
import com.intellij.DynamicBundle | ||
import org.jetbrains.annotations.NonNls | ||
|
||
object JSonCrackBundle { | ||
|
||
@NonNls | ||
private val INSTANCE: DynamicBundle = DynamicBundle(JSonCrackBundle::class.java, "messages.jsoncrack") | ||
|
||
fun message(key: String): String { | ||
return INSTANCE.getMessage(key) | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/co/anbora/labs/jsoncrack/ide/settings/FileTypeSettingsConfigurable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package co.anbora.labs.jsoncrack.ide.settings | ||
|
||
import co.anbora.labs.jsoncrack.ide.fileType.FileTypeService.Companion.fileTypeSettings | ||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.options.Configurable | ||
import com.intellij.openapi.project.Project | ||
import javax.swing.JComponent | ||
|
||
class FileTypeSettingsConfigurable( | ||
project: Project | ||
): Configurable, Disposable { | ||
|
||
private val dialog = PatternsPanel(project, HashSet(fileTypeSettings.extensions())) | ||
|
||
override fun createComponent(): JComponent = dialog | ||
|
||
override fun isModified(): Boolean = fileTypeSettings.extensions() != dialog.getExtensions() | ||
|
||
override fun apply() { | ||
fileTypeSettings.addExtensions(dialog.getExtensions()) | ||
} | ||
|
||
override fun getDisplayName(): String = "JSonCrack" | ||
|
||
override fun dispose() = Unit | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/kotlin/co/anbora/labs/jsoncrack/ide/settings/PatternsPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package co.anbora.labs.jsoncrack.ide.settings | ||
|
||
import co.anbora.labs.jsoncrack.ide.fileType.FileTypeDialog | ||
import co.anbora.labs.jsoncrack.ide.i18n.JSonCrackBundle | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.ui.IdeBorderFactory | ||
import com.intellij.ui.JBColor | ||
import com.intellij.ui.ListUtil | ||
import com.intellij.ui.ToolbarDecorator | ||
import com.intellij.ui.components.JBList | ||
import com.intellij.ui.components.JBScrollPane | ||
import com.intellij.util.ui.JBUI | ||
import java.awt.BorderLayout | ||
import javax.swing.DefaultListModel | ||
import javax.swing.JPanel | ||
import javax.swing.JScrollPane | ||
import javax.swing.ListSelectionModel | ||
|
||
|
||
class PatternsPanel( | ||
private val project: Project, | ||
private val extensions: Collection<String> | ||
): JPanel() { | ||
|
||
private val myList = JBList<String>(DefaultListModel()) | ||
private val TITLE_INSETS = JBUI.insetsTop(8) | ||
|
||
init { | ||
layout = BorderLayout() | ||
myList.selectionMode = ListSelectionModel.SINGLE_SELECTION | ||
//myList.setCellRenderer(ExtensionRenderer()) | ||
myList.emptyText.setText(JSonCrackBundle.message("filetype.settings.no.patterns")) | ||
myList.border = JBUI.Borders.empty() | ||
|
||
val decorator: ToolbarDecorator = ToolbarDecorator.createDecorator(myList) | ||
.setScrollPaneBorder(JBUI.Borders.empty()) | ||
.setPanelBorder(JBUI.Borders.customLine(JBColor.border(), 1, 1, 0, 1)) | ||
.setAddAction { showAddExtensionDialog() } | ||
.setRemoveAction { removeExtension() } | ||
.disableUpDownActions() | ||
add(decorator.createPanel(), BorderLayout.NORTH) | ||
val scrollPane: JScrollPane = JBScrollPane(myList) | ||
scrollPane.border = JBUI.Borders.customLine(JBColor.border(), 0, 1, 1, 1) | ||
add(scrollPane, BorderLayout.CENTER) | ||
|
||
|
||
border = IdeBorderFactory.createTitledBorder( | ||
JSonCrackBundle.message("filetype.registered.patterns.group"), | ||
false, | ||
TITLE_INSETS | ||
).setShowLine(false) | ||
|
||
|
||
this.refill() | ||
} | ||
|
||
private fun refill() { | ||
val model: DefaultListModel<String> = | ||
myList.model as DefaultListModel<String> | ||
|
||
model.addAll(extensions) | ||
} | ||
|
||
private fun addExtensions(extension: String) { | ||
val model: DefaultListModel<String> = | ||
myList.model as DefaultListModel<String> | ||
|
||
model.addElement(extension) | ||
} | ||
|
||
private fun removeExtension() { | ||
val selectedItem = myList.selectedValue | ||
if (selectedItem != null) { | ||
ListUtil.removeSelectedItems(myList) | ||
} | ||
} | ||
|
||
fun getExtensions(): Set<String> { | ||
val model: DefaultListModel<String> = | ||
myList.model as DefaultListModel<String> | ||
|
||
return model.elements().toList().toSet() | ||
} | ||
|
||
private fun showAddExtensionDialog() { | ||
val dialog = FileTypeDialog("Add Extension", project) | ||
|
||
if (dialog.showAndGet()) { | ||
this.addExtensions(dialog.getExtension()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
filetype.settings.no.patterns=No registered file patterns | ||
filetype.registered.patterns.group=File name extensions: | ||
filetype.edit.add.pattern.prompt=Enter new extension: |