Skip to content

Commit aa28f01

Browse files
authored
IEP-1587 Integrate esp-idf-kconfig 3.x changes with IDE (#1426)
* feat: adding support for kconfig 3.0 * fix: make reset UI version-aware; use server version * feat: refactoring and moving UI rendering to separate class * fix: replaced loop iteration with putAll * feat: use constant and dynamic version for reset * fix: don't clear all edits on server reset * fix: do not show reset buttons if not supported
1 parent f3d4259 commit aa28f01

11 files changed

Lines changed: 580 additions & 330 deletions

File tree

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/IJsonServerConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IJsonServerConfig
1616
String VISIBLE = "visible"; //$NON-NLS-1$
1717
String RANGES = "ranges"; //$NON-NLS-1$
1818
String VERSION = "version"; //$NON-NLS-1$
19+
String DEFAULTS = "defaults"; //$NON-NLS-1$
1920

2021
// data types
2122
String HEX_TYPE = "hex"; //$NON-NLS-1$
@@ -29,6 +30,7 @@ public interface IJsonServerConfig
2930
String SET = "set"; //$NON-NLS-1$
3031
String SAVE = "save"; //$NON-NLS-1$
3132
String LOAD = "load"; //$NON-NLS-1$
33+
String RESET = "reset"; //$NON-NLS-1$
3234

3335
String COMPONENT_CONFIG_TITLE = "Component config"; //$NON-NLS-1$
3436

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/KConfigMenuItem.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class KConfigMenuItem
2323
private String type;
2424
private String id;
2525
private boolean isMenuConfig;
26+
private boolean isDefault;
2627

2728
public KConfigMenuItem(KConfigMenuItem parent)
2829
{
@@ -173,5 +174,21 @@ private boolean isVisible(JSONObject visibleJsonMap, String configKey)
173174
return visibleJsonMap.get(configKey) != null ? (boolean) visibleJsonMap.get(configKey) : false;
174175
}
175176

177+
public boolean isDefault()
178+
{
179+
return isDefault;
180+
}
181+
182+
public void setDefault(boolean isDefault)
183+
{
184+
this.isDefault = isDefault;
185+
}
176186

177-
}
187+
public void updateDefaultState(JSONObject defaultsJsonMap)
188+
{
189+
if (defaultsJsonMap != null && defaultsJsonMap.containsKey(getId()))
190+
{
191+
this.isDefault = (boolean) defaultsJsonMap.get(getId());
192+
}
193+
}
194+
}

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/CommandType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public enum CommandType
2929
*/
3030
SET,
3131

32+
RESET,
33+
3234
/**
3335
* To represent server connection is closed
3436
*/

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/IJsonConfigOutput.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public interface IJsonConfigOutput
2727
*/
2828
public JSONObject getRangesJsonMap();
2929

30+
public JSONObject getDefaultsJsonMap();
31+
32+
public long getVersion();
33+
3034
}

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigOutput.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public class JsonConfigOutput implements IJsonConfigOutput
2424
private JSONObject valuesJsonMap;
2525
private JSONObject visibleJsonMap;
2626
private JSONObject rangesJsonMap;
27+
private JSONObject defaultsJsonMap;
28+
private long version = 1;
29+
30+
@Override
31+
public long getVersion()
32+
{
33+
return version;
34+
}
2735

2836
@Override
2937
public JSONObject getValuesJsonMap()
@@ -56,12 +64,18 @@ public void parse(String response, boolean isUpdate) throws ParseException
5664
JSONObject jsonObj = (JSONObject) parser.parse(response);
5765
if (jsonObj != null)
5866
{
67+
if (jsonObj.containsKey(IJsonServerConfig.VERSION))
68+
{
69+
version = (long) jsonObj.get(IJsonServerConfig.VERSION);
70+
}
71+
5972
if (isUpdate)
6073
{
6174
// newly updated values and visible items
6275
JSONObject visibleJson = (JSONObject) jsonObj.get(IJsonServerConfig.VISIBLE);
6376
JSONObject valuesJson = (JSONObject) jsonObj.get(IJsonServerConfig.VALUES);
6477
JSONObject rangesJson = (JSONObject) jsonObj.get(IJsonServerConfig.RANGES);
78+
JSONObject defaultsJson = (JSONObject) jsonObj.get(IJsonServerConfig.DEFAULTS);
6579

6680
// Updated visible items
6781
Set<String> newVisibleKeyset = visibleJson.keySet();
@@ -89,9 +103,15 @@ public void parse(String response, boolean isUpdate) throws ParseException
89103
valuesJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.VALUES);
90104
visibleJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.VISIBLE);
91105
rangesJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.RANGES);
106+
defaultsJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.DEFAULTS);
92107
}
93108
}
94109

95110
}
96111

112+
public JSONObject getDefaultsJsonMap()
113+
{
114+
return defaultsJsonMap;
115+
}
116+
97117
}

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigServer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ public JsonConfigServer(IProject project, IFile file)
5353
this.file = file;
5454
}
5555

56+
public void resetElementById(String id)
57+
{
58+
String resetRequest = String.format("{\"version\": 3, \"reset\": [\"%s\"]}", id);
59+
execute(resetRequest, CommandType.RESET);
60+
}
61+
62+
public void resetElementChildren(List<String> children)
63+
{
64+
if (children == null || children.isEmpty())
65+
{
66+
return;
67+
}
68+
69+
String joinedIds = String.join("\", \"", children);
70+
String resetRequest = String.format("{\"version\": 3, \"reset\": [\"%s\"]}", joinedIds);
71+
execute(resetRequest, CommandType.RESET);
72+
}
73+
5674
@Override
5775
public void addListener(IMessageHandlerListener listener)
5876
{

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigServerRunnable.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,20 @@ protected boolean isValidJson(String output)
200200
{
201201
String jsonOutput = new JsonConfigProcessor().getInitialOutput(output);
202202
if (StringUtil.isEmpty(jsonOutput))
203-
{
204203
return false;
205-
}
204+
206205
try
207206
{
208207
JSONObject jsonObj = (JSONObject) new JSONParser().parse(jsonOutput);
209208
if (jsonObj != null)
210209
{
211-
if (jsonObj.get(IJsonServerConfig.VISIBLE) != null && jsonObj.get(IJsonServerConfig.VALUES) != null
212-
&& jsonObj.get(IJsonServerConfig.RANGES) != null)
213-
{
214-
return true;
215-
}
210+
return jsonObj.containsKey(IJsonServerConfig.VERSION) && jsonObj.containsKey(IJsonServerConfig.VALUES);
216211
}
217212
}
218213
catch (ParseException e)
219214
{
220215
return false;
221216
}
222-
223217
return false;
224218
}
225219

1.05 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.espressif.idf.sdk.config.ui;
2+
3+
import org.json.simple.JSONObject;
4+
5+
import com.espressif.idf.sdk.config.core.KConfigMenuItem;
6+
7+
public interface ConfigActionHandler
8+
{
9+
void onCommandExecuted(JSONObject jsonMap);
10+
11+
void onTextModified(String key, Object value);
12+
13+
void onResetRequested(String key);
14+
15+
void onMenuResetRequested(KConfigMenuItem menu);
16+
}

0 commit comments

Comments
 (0)