Introduce Parameter: Add "Introduce default value" checkbox to the dialog
This commit is contained in:
+22
-7
@@ -86,6 +86,7 @@ public class KotlinIntroduceParameterDialog private (
|
|||||||
private val nameField = NameSuggestionsField(nameSuggestions, project, JetFileType.INSTANCE)
|
private val nameField = NameSuggestionsField(nameSuggestions, project, JetFileType.INSTANCE)
|
||||||
private val typeField = NameSuggestionsField(typeNameSuggestions, project, JetFileType.INSTANCE)
|
private val typeField = NameSuggestionsField(typeNameSuggestions, project, JetFileType.INSTANCE)
|
||||||
private var replaceAllCheckBox: JCheckBox? = null
|
private var replaceAllCheckBox: JCheckBox? = null
|
||||||
|
private var defaultValueCheckBox: JCheckBox? = null
|
||||||
private val removeParamsCheckBoxes = LinkedHashMap<JCheckBox, JetParameter>(descriptor.parametersToRemove.size())
|
private val removeParamsCheckBoxes = LinkedHashMap<JCheckBox, JetParameter>(descriptor.parametersToRemove.size())
|
||||||
private var parameterTablePanel: KotlinParameterTablePanel? = null
|
private var parameterTablePanel: KotlinParameterTablePanel? = null
|
||||||
|
|
||||||
@@ -99,6 +100,14 @@ public class KotlinIntroduceParameterDialog private (
|
|||||||
|
|
||||||
override fun getPreferredFocusedComponent() = nameField.getFocusableComponent()
|
override fun getPreferredFocusedComponent() = nameField.getFocusableComponent()
|
||||||
|
|
||||||
|
private fun updateRemoveParamCheckBoxes() {
|
||||||
|
val enableParamRemove = (replaceAllCheckBox?.isSelected() ?: true) && (!defaultValueCheckBox!!.isSelected())
|
||||||
|
removeParamsCheckBoxes.keySet().forEach {
|
||||||
|
it.setEnabled(enableParamRemove)
|
||||||
|
it.setSelected(enableParamRemove)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun createNorthPanel(): JComponent? {
|
override fun createNorthPanel(): JComponent? {
|
||||||
val gbConstraints = GridBagConstraints()
|
val gbConstraints = GridBagConstraints()
|
||||||
|
|
||||||
@@ -177,19 +186,24 @@ public class KotlinIntroduceParameterDialog private (
|
|||||||
gbConstraints.gridx = 0
|
gbConstraints.gridx = 0
|
||||||
gbConstraints.insets = Insets(4, 0, 4, 8)
|
gbConstraints.insets = Insets(4, 0, 4, 8)
|
||||||
gbConstraints.gridwidth = 2
|
gbConstraints.gridwidth = 2
|
||||||
|
gbConstraints.gridy++
|
||||||
|
|
||||||
|
val defaultValueCheckBox = NonFocusableCheckBox("Introduce default value")
|
||||||
|
defaultValueCheckBox.setSelected(descriptor.withDefaultValue)
|
||||||
|
defaultValueCheckBox.setMnemonic('d')
|
||||||
|
defaultValueCheckBox.addActionListener { updateRemoveParamCheckBoxes() }
|
||||||
|
panel.add(defaultValueCheckBox, gbConstraints)
|
||||||
|
|
||||||
|
this.defaultValueCheckBox = defaultValueCheckBox
|
||||||
|
|
||||||
val occurrenceCount = descriptor.occurrencesToReplace.size()
|
val occurrenceCount = descriptor.occurrencesToReplace.size()
|
||||||
|
|
||||||
if (occurrenceCount > 1) {
|
if (occurrenceCount > 1) {
|
||||||
gbConstraints.gridy++
|
gbConstraints.gridy++
|
||||||
val replaceAllCheckBox = NonFocusableCheckBox("Replace all occurrences ($occurrenceCount)")
|
val replaceAllCheckBox = NonFocusableCheckBox("Replace all occurrences ($occurrenceCount)")
|
||||||
replaceAllCheckBox.setSelected(true)
|
replaceAllCheckBox.setSelected(true)
|
||||||
replaceAllCheckBox.setMnemonic('R')
|
replaceAllCheckBox.setMnemonic('R')
|
||||||
replaceAllCheckBox.addActionListener {
|
replaceAllCheckBox.addActionListener { updateRemoveParamCheckBoxes() }
|
||||||
val enableParamRemove = replaceAllCheckBox.isSelected()
|
|
||||||
removeParamsCheckBoxes.keySet().forEach {
|
|
||||||
it.setEnabled(enableParamRemove)
|
|
||||||
it.setSelected(enableParamRemove)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panel.add(replaceAllCheckBox, gbConstraints)
|
panel.add(replaceAllCheckBox, gbConstraints)
|
||||||
this.replaceAllCheckBox = replaceAllCheckBox
|
this.replaceAllCheckBox = replaceAllCheckBox
|
||||||
}
|
}
|
||||||
@@ -286,6 +300,7 @@ public class KotlinIntroduceParameterDialog private (
|
|||||||
newParameterName = chosenName,
|
newParameterName = chosenName,
|
||||||
newParameterTypeText = chosenType,
|
newParameterTypeText = chosenType,
|
||||||
newArgumentValue = newArgumentValue,
|
newArgumentValue = newArgumentValue,
|
||||||
|
withDefaultValue = defaultValueCheckBox!!.isSelected(),
|
||||||
occurrencesToReplace = with(descriptor) {
|
occurrencesToReplace = with(descriptor) {
|
||||||
if (replaceAllCheckBox?.isSelected() ?: true) {
|
if (replaceAllCheckBox?.isSelected() ?: true) {
|
||||||
occurrencesToReplace
|
occurrencesToReplace
|
||||||
|
|||||||
Reference in New Issue
Block a user