Skip to content

Commit

Permalink
fix fatal bugs in saving state.
Browse files Browse the repository at this point in the history
  • Loading branch information
liying2008 committed Apr 29, 2018
1 parent 2c727b1 commit cac857d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 45 deletions.
5 changes: 3 additions & 2 deletions src/main/java/cc/duduhuo/git/conflict/BuiltInColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public interface BuiltInColor {
String INTELLIJ_SCHEME_NAME = "IntelliJ";
String DARCULA_SCHEME_NAME = "Darcula";

String DEFAULT_SCHEME = AUTO_SCHEME_NAME;

MarkColor AUTO = new MarkColor(AUTO_SCHEME_NAME, true, 0x9fe3d6, 0xd9f4ef, 0x9fd2ff, 0xd9edff,
0x2f7366, 0x25403b, 0x2f628f, 0x25394b);
MarkColor INTELLIJ = new MarkColor(INTELLIJ_SCHEME_NAME, true, 0x9fe3d6, 0xd9f4ef, 0x9fd2ff, 0xd9edff);
MarkColor DARCULA = new MarkColor(DARCULA_SCHEME_NAME, true, 0x2f7366, 0x25403b, 0x2f628f, 0x25394b);

String DEFAULT_SCHEME_NAME = AUTO_SCHEME_NAME;
MarkColor DEFAULT_MARK_COLOR = AUTO;
}
3 changes: 1 addition & 2 deletions src/main/java/cc/duduhuo/git/conflict/model/MarkColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cc.duduhuo.git.conflict.BuiltInColor;

import java.io.Serializable;
import java.util.Objects;

/**
Expand All @@ -13,7 +12,7 @@
* Remarks:
* =======================================================
*/
public final class MarkColor implements Serializable {
public final class MarkColor {
private String mSchemeName;
private boolean mIsBuiltIn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class PersistentState {
private LinkedHashMap<String, MarkColor> mMarkColors;

public PersistentState() {
mSchemeName = BuiltInColor.DEFAULT_SCHEME;
mSchemeName = BuiltInColor.DEFAULT_SCHEME_NAME;
mMarkColors = new LinkedHashMap<>();
mMarkColors.put(BuiltInColor.AUTO_SCHEME_NAME, BuiltInColor.AUTO);
mMarkColors.put(BuiltInColor.INTELLIJ_SCHEME_NAME, BuiltInColor.INTELLIJ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="5" 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="511" height="400"/>
<xy x="20" y="20" width="549" height="400"/>
</constraints>
<properties/>
<border type="none" title=""/>
Expand Down Expand Up @@ -39,7 +39,7 @@
<children>
<component id="3f3d5" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="12" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="13" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Current Change:"/>
Expand All @@ -55,16 +55,16 @@
</component>
<component id="c7cbc" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="13" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Incoming Change: "/>
</properties>
</component>
<component id="db16d" class="com.intellij.ui.components.JBLabel" binding="cCurrentColor">
<constraints>
<grid row="1" column="9" row-span="1" col-span="3" vsize-policy="0" hsize-policy="1" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="120" height="-1"/>
<grid row="1" column="8" row-span="1" col-span="4" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="60" height="-1"/>
</grid>
</constraints>
<properties>
Expand All @@ -83,8 +83,8 @@
</component>
<component id="a0d4" class="com.intellij.ui.components.JBLabel" binding="cIncomingTitleColor">
<constraints>
<grid row="4" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="1" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="120" height="-1"/>
<grid row="4" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="60" height="-1"/>
</grid>
</constraints>
<properties>
Expand All @@ -95,8 +95,8 @@
</component>
<component id="6420d" class="com.intellij.ui.components.JBLabel" binding="cIncomingColor">
<constraints>
<grid row="4" column="9" row-span="1" col-span="3" vsize-policy="0" hsize-policy="1" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="120" height="-1"/>
<grid row="4" column="8" row-span="1" col-span="4" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="60" height="-1"/>
</grid>
</constraints>
<properties>
Expand All @@ -107,7 +107,7 @@
</component>
<component id="5bdbf" class="com.intellij.ui.components.JBLabel" binding="lbCurrentTitle">
<constraints>
<grid row="1" column="5" row-span="1" col-span="2" vsize-policy="0" hsize-policy="5" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="5" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="0"/>
Expand Down Expand Up @@ -137,28 +137,18 @@
<text value="0"/>
</properties>
</component>
<hspacer id="3186d">
<constraints>
<grid row="1" column="7" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="6c131">
<constraints>
<grid row="4" column="7" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="85f11" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="2" 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>
<text value=""/>
<text value=" "/>
</properties>
</component>
<component id="59c96" class="com.intellij.ui.components.JBLabel" binding="cCurrentTitleColor">
<constraints>
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="1" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="120" height="-1"/>
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="60" height="-1"/>
</grid>
</constraints>
<properties>
Expand All @@ -169,15 +159,15 @@
</component>
<component id="2a854" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="1" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Content: "/>
</properties>
</component>
<component id="40bd9" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="4" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="4" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Content: "/>
Expand All @@ -192,7 +182,7 @@
</vspacer>
<component id="7d2f2" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=" "/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ private void setListeners() {
String selectedItem = (String) cbColorScheme.getSelectedItem();
int confirm = JOptionPane.showConfirmDialog(mainPanel, "Delete scheme: " + selectedItem + " ?", "Delete", JOptionPane.OK_CANCEL_OPTION);
if (confirm == JOptionPane.OK_OPTION) {
MarkColor markColor = mMarkColors.get((String) cbColorScheme.getSelectedItem());
MarkColor markColor = mMarkColors.get(selectedItem);
// Double check. Prevent the built-in color scheme from being deleted.
if (!markColor.isBuiltIn()) {
mMarkColors.remove(selectedItem);
cbColorScheme.removeItem(selectedItem);
mAllSchemeNames.remove(selectedItem);
updateUI(markColor);
} else {
JOptionPane.showMessageDialog(mainPanel, "The built-in color scheme cannot be deleted.",
"Failed", JOptionPane.ERROR_MESSAGE);
Expand All @@ -102,27 +101,35 @@ private void setListeners() {
});
}

@SuppressWarnings("unchecked")
private void initUI() {
PersistentState persistentState = GlobalSettings.getPersistentState();
mMarkColors = persistentState.getMarkColors();
LinkedHashMap<String, MarkColor> map = persistentState.getMarkColors();
mSchemeName = persistentState.getSchemeName();
String name;
// clone markColors map
mMarkColors = (LinkedHashMap<String, MarkColor>) map.clone();

// make sure the built-in color is displayed at the top.
cbColorScheme.addItem(BuiltInColor.AUTO_SCHEME_NAME);
cbColorScheme.addItem(BuiltInColor.INTELLIJ_SCHEME_NAME);
cbColorScheme.addItem(BuiltInColor.DARCULA_SCHEME_NAME);
Set<String> keySet = mMarkColors.keySet();
Set<String> keySet = map.keySet();
for (String key : keySet) {
name = mMarkColors.get(key).getSchemeName();
if (!name.equals(BuiltInColor.AUTO_SCHEME_NAME) &&
!name.equals(BuiltInColor.INTELLIJ_SCHEME_NAME) &&
!name.equals(BuiltInColor.DARCULA_SCHEME_NAME)) {
cbColorScheme.addItem(name);
if (!key.equals(BuiltInColor.AUTO_SCHEME_NAME) &&
!key.equals(BuiltInColor.INTELLIJ_SCHEME_NAME) &&
!key.equals(BuiltInColor.DARCULA_SCHEME_NAME)) {
cbColorScheme.addItem(key);
}
mAllSchemeNames.add(name);
mAllSchemeNames.add(key);
}
// Double check.
if (keySet.contains(mSchemeName)) {
cbColorScheme.setSelectedItem(mSchemeName);
mOldMarkColor.copy(map.get(mSchemeName));
} else {
cbColorScheme.setSelectedItem(BuiltInColor.DEFAULT_SCHEME_NAME);
mOldMarkColor.copy(BuiltInColor.DEFAULT_MARK_COLOR);
}
cbColorScheme.setSelectedItem(mSchemeName);
mOldMarkColor.copy(mMarkColors.get(mSchemeName));
updateUI(mOldMarkColor);
}

Expand Down Expand Up @@ -258,9 +265,10 @@ public void reset() {
}

@Override
@SuppressWarnings("unchecked")
public void apply() {
boolean isModified = isModified();
GlobalSettings.getPersistentState().setMarkColors(mMarkColors);
GlobalSettings.getPersistentState().setMarkColors((LinkedHashMap<String, MarkColor>) mMarkColors.clone());
GlobalSettings.getPersistentState().setSchemeName((String) cbColorScheme.getSelectedItem());
if (isModified) {
mSchemeName = (String) cbColorScheme.getSelectedItem();
Expand Down

0 comments on commit cac857d

Please sign in to comment.