Skip to content

Commit 12752f0

Browse files
Remove stale theme entries in CSSTheme.updateResources
When updating theme resources from CSS, if a property is removed from the CSS, it should be removed from the generated resource file. Previously, removed properties would persist as stale entries. This change introduces a cleanup step in `updateResources` that iterates over modified UIIDs and removes all existing theme properties associated with them before applying the new properties from the CSS. A helper method `isOwnedBy` ensures that only properties strictly belonging to the UIID (and its states) are removed, preventing accidental deletion of unrelated properties even if UIIDs contain dots.
1 parent 258c0e9 commit 12752f0

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

CodenameOneDesigner/src/com/codename1/designer/css/CSSTheme.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,9 +1667,42 @@ public Map<String, CacheStatus> calculateSelectorCacheStatus(File cachedFile) th
16671667

16681668
}
16691669

1670+
private boolean isOwnedBy(String key, String id) {
1671+
if (key.length() <= id.length() + 1) {
1672+
return false;
1673+
}
1674+
if (!key.startsWith(id)) {
1675+
return false;
1676+
}
1677+
char sep = key.charAt(id.length());
1678+
if (sep != '.' && sep != '#') {
1679+
return false;
1680+
}
1681+
// Check for dots in the suffix
1682+
return key.indexOf('.', id.length() + 1) == -1;
1683+
}
1684+
16701685
public void updateResources() {
1671-
// TODO: We need to remove stale theme entries
1672-
// https://github.com/codenameone/CodenameOne/issues/2698
1686+
if (res != null) {
1687+
Map<String, Object> themeData = res.getTheme(themeName);
1688+
if (themeData != null) {
1689+
Set<String> keys = new HashSet<String>(themeData.keySet());
1690+
Set<String> modifiedIds = new HashSet<String>();
1691+
for (String id : elements.keySet()) {
1692+
if (isModified(id)) {
1693+
modifiedIds.add(id);
1694+
}
1695+
}
1696+
1697+
for (String id : modifiedIds) {
1698+
for (String key : keys) {
1699+
if (isOwnedBy(key, id)) {
1700+
res.setThemeProperty(themeName, key, null);
1701+
}
1702+
}
1703+
}
1704+
}
1705+
}
16731706

16741707
for (String id : elements.keySet()) {
16751708
if (!isModified(id)) {

0 commit comments

Comments
 (0)