mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: cleanup: convert GitUpdateOptionsPanel to Kotlin DSL
GitOrigin-RevId: bc7384352459d27caa1ef5e7ab4075dd5501df65
This commit is contained in:
committed by
intellij-monorepo-bot
parent
80f17a9fde
commit
2847e957fc
@@ -216,9 +216,7 @@ internal class GitVcsPanel(private val project: Project,
|
||||
EnumComboBoxModel(UpdateMethod::class.java),
|
||||
{ projectSettings.updateMethod },
|
||||
{ projectSettings.updateMethod = it!! },
|
||||
renderer = SimpleListCellRenderer.create<UpdateMethod>("") { value ->
|
||||
value.name.replace('_', ' ').toLowerCase().capitalize()
|
||||
}
|
||||
renderer = SimpleListCellRenderer.create<UpdateMethod>("", UpdateMethod::asString)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package git4idea.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The type of update to perform
|
||||
*/
|
||||
@@ -22,13 +24,24 @@ public enum UpdateMethod {
|
||||
/**
|
||||
* Use default specified in the config file for the branch
|
||||
*/
|
||||
BRANCH_DEFAULT,
|
||||
BRANCH_DEFAULT("Branch Default"),
|
||||
/**
|
||||
* Merge fetched commits with local branch
|
||||
*/
|
||||
MERGE,
|
||||
MERGE("Merge"),
|
||||
/**
|
||||
* Rebase local commits upon the fetched branch
|
||||
*/
|
||||
REBASE
|
||||
REBASE("Rebase");
|
||||
|
||||
@NotNull private final String myPresentation;
|
||||
|
||||
UpdateMethod(@NotNull String presentation) {
|
||||
myPresentation = presentation;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String asString() {
|
||||
return myPresentation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GitUpdateConfigurable implements Configurable {
|
||||
*/
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
myPanel = new GitUpdateOptionsPanel();
|
||||
myPanel = new GitUpdateOptionsPanel(mySettings);
|
||||
return myPanel.getPanel();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class GitUpdateConfigurable implements Configurable {
|
||||
*/
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return myPanel.isModified(mySettings);
|
||||
return myPanel.isModified();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ public class GitUpdateConfigurable implements Configurable {
|
||||
*/
|
||||
@Override
|
||||
public void apply() {
|
||||
myPanel.applyTo(mySettings);
|
||||
myPanel.applyTo();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public class GitUpdateConfigurable implements Configurable {
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
myPanel.updateFrom(mySettings);
|
||||
myPanel.updateFrom();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="git4idea.update.GitUpdateOptionsPanel">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="10" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="392" height="121"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="150f4" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
|
||||
</clientProperties>
|
||||
<border type="none" title-resource-bundle="git4idea/i18n/GitBundle" title-key="update.options.type"/>
|
||||
<children>
|
||||
<component id="dcccd" class="javax.swing.JRadioButton" binding="myForceMergeRadioButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="git4idea/i18n/GitBundle" key="update.options.type.merge"/>
|
||||
<toolTipText resource-bundle="git4idea/i18n/GitBundle" key="update.options.type.merge.tooltip"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="864a1" class="javax.swing.JRadioButton" binding="myForceRebaseRadioButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="git4idea/i18n/GitBundle" key="update.options.type.rebase"/>
|
||||
<toolTipText resource-bundle="git4idea/i18n/GitBundle" key="update.options.type.rebase.tooltip"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="48ad6" class="javax.swing.JRadioButton" binding="myBranchDefaultRadioButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="true"/>
|
||||
<text resource-bundle="git4idea/i18n/GitBundle" key="update.options.type.default"/>
|
||||
<toolTipText resource-bundle="git4idea/i18n/GitBundle" key="update.options.type.default.tooltip"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<buttonGroups>
|
||||
<group name="myUpateTypeGroup">
|
||||
<member id="48ad6"/>
|
||||
<member id="864a1"/>
|
||||
<member id="dcccd"/>
|
||||
</group>
|
||||
<group name="mySavePolicyGroup">
|
||||
<member id="98593"/>
|
||||
<member id="d7fb3"/>
|
||||
<member id="4c529"/>
|
||||
</group>
|
||||
</buttonGroups>
|
||||
</form>
|
||||
@@ -13,72 +13,46 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.update;
|
||||
package git4idea.update
|
||||
|
||||
import git4idea.config.GitVcsSettings;
|
||||
import git4idea.config.UpdateMethod;
|
||||
import com.intellij.openapi.ui.DialogPanel
|
||||
import com.intellij.ui.layout.*
|
||||
import git4idea.config.GitVcsSettings
|
||||
import git4idea.config.UpdateMethod
|
||||
import git4idea.config.UpdateMethod.BRANCH_DEFAULT
|
||||
|
||||
import javax.swing.*;
|
||||
class GitUpdateOptionsPanel(private val settings: GitVcsSettings) {
|
||||
val panel = createPanel()
|
||||
|
||||
/**
|
||||
* Update options panel
|
||||
*/
|
||||
public class GitUpdateOptionsPanel {
|
||||
private JPanel myPanel;
|
||||
private JRadioButton myBranchDefaultRadioButton;
|
||||
private JRadioButton myForceRebaseRadioButton;
|
||||
private JRadioButton myForceMergeRadioButton;
|
||||
|
||||
public JComponent getPanel() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
public boolean isModified(GitVcsSettings settings) {
|
||||
UpdateMethod type = getUpdateType();
|
||||
return type != settings.getUpdateMethod();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get the currently selected update type
|
||||
*/
|
||||
private UpdateMethod getUpdateType() {
|
||||
UpdateMethod type = null;
|
||||
if (myForceRebaseRadioButton.isSelected()) {
|
||||
type = UpdateMethod.REBASE;
|
||||
fun createPanel(): DialogPanel =
|
||||
panel {
|
||||
titledRow("Update Type") {
|
||||
buttonGroup {
|
||||
getUpdateMethods().forEach { method ->
|
||||
row {
|
||||
radioButton(method.asString()).withSelectedBinding(PropertyBinding(
|
||||
get = { settings.updateMethod == method },
|
||||
set = { selected -> if (selected) settings.updateMethod = method }
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (myForceMergeRadioButton.isSelected()) {
|
||||
type = UpdateMethod.MERGE;
|
||||
}
|
||||
else if (myBranchDefaultRadioButton.isSelected()) {
|
||||
type = UpdateMethod.BRANCH_DEFAULT;
|
||||
}
|
||||
assert type != null;
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save configuration to settings object
|
||||
*/
|
||||
public void applyTo(GitVcsSettings settings) {
|
||||
settings.setUpdateMethod(getUpdateType());
|
||||
}
|
||||
fun isModified(): Boolean = panel.isModified()
|
||||
|
||||
/**
|
||||
* Update panel according to settings
|
||||
*/
|
||||
public void updateFrom(GitVcsSettings settings) {
|
||||
switch (settings.getUpdateMethod()) {
|
||||
case REBASE:
|
||||
myForceRebaseRadioButton.setSelected(true);
|
||||
break;
|
||||
case MERGE:
|
||||
myForceMergeRadioButton.setSelected(true);
|
||||
break;
|
||||
case BRANCH_DEFAULT:
|
||||
myBranchDefaultRadioButton.setSelected(true);
|
||||
break;
|
||||
default:
|
||||
assert false : "Unknown value of update type: " + settings.getUpdateMethod();
|
||||
}
|
||||
}
|
||||
}
|
||||
fun applyTo() = panel.apply()
|
||||
|
||||
fun updateFrom() = panel.reset()
|
||||
|
||||
private fun getUpdateMethods(): List<UpdateMethod> =
|
||||
UpdateMethod.values().sortedWith(Comparator { o1, o2 ->
|
||||
when {
|
||||
o1 == o2 -> 0
|
||||
o1 == BRANCH_DEFAULT -> 1
|
||||
o2 == BRANCH_DEFAULT -> -1
|
||||
else -> o1.ordinal - o2.ordinal
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user