From a424d971a9661747fe68d339bdd331a60e1745b2 Mon Sep 17 00:00:00 2001 From: EdoFro <35700575+EdoFro@users.noreply.github.com> Date: Sun, 26 Nov 2023 17:26:54 -0300 Subject: [PATCH] Copy attributes when copying styles between maps (#1539) * Update MapStyleModel.java Added: - copy icons - copy attributes * Update MapStyleModel.java * old attributes should be removed Update MapStyleModel.java * use non undoable method here * rename method for consistency --------- Co-authored-by: Dimitry Polivaev --- .../attribute/mindmapmode/MAttributeController.java | 4 ++-- .../java/org/freeplane/features/styles/MapStyleModel.java | 8 ++++++-- .../freeplane/plugin/script/proxy/AttributesProxy.java | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/freeplane/src/main/java/org/freeplane/features/attribute/mindmapmode/MAttributeController.java b/freeplane/src/main/java/org/freeplane/features/attribute/mindmapmode/MAttributeController.java index 5693da0967..cc08bd2807 100644 --- a/freeplane/src/main/java/org/freeplane/features/attribute/mindmapmode/MAttributeController.java +++ b/freeplane/src/main/java/org/freeplane/features/attribute/mindmapmode/MAttributeController.java @@ -615,7 +615,7 @@ public int editAttribute(final NodeModel pNode, final String pName, final String setAttribute(pNode, i, newAttribute); } else { - removeAttribute(pNode, i); + performRemoveAttribute(pNode, i); } return i; } @@ -867,7 +867,7 @@ public void performSetVisibility(MapModel map, final int index, final boolean is Controller.getCurrentModeController().execute(actor, map); } - public void removeAttribute(final NodeModel node, final int pPosition) { + public void performRemoveAttribute(final NodeModel node, final int pPosition) { createAttributeTableModel(node); performRemoveRow(node, NodeAttributeTableModel.getModel(node), pPosition); } diff --git a/freeplane/src/main/java/org/freeplane/features/styles/MapStyleModel.java b/freeplane/src/main/java/org/freeplane/features/styles/MapStyleModel.java index 8eaeadd5ad..bf31530725 100644 --- a/freeplane/src/main/java/org/freeplane/features/styles/MapStyleModel.java +++ b/freeplane/src/main/java/org/freeplane/features/styles/MapStyleModel.java @@ -44,6 +44,7 @@ import org.freeplane.core.util.LogUtils; import org.freeplane.features.attribute.AttributeRegistry; import org.freeplane.features.attribute.FontSizeExtension; +import org.freeplane.features.attribute.NodeAttributeTableModel; import org.freeplane.features.attribute.mindmapmode.MAttributeController; import org.freeplane.features.cloud.CloudModel; import org.freeplane.features.cloud.CloudShape; @@ -507,6 +508,7 @@ ComboBoxModel getStylesAsComboBoxModel() { void copyStyle(NodeModel copiedStyleNode, IStyle styleKey) { NodeModel targetStyleNode = getStyleNode(styleKey); ModeController modeController = Controller.getCurrentModeController(); + MAttributeController mAttributeController = MAttributeController.getController(); if(targetStyleNode == null) { NodeModel sourceGroupNode = copiedStyleNode.getParentNode(); String group = (String) ((StyleTranslatedObject)sourceGroupNode.getUserObject()).getObject(); @@ -529,9 +531,11 @@ void copyStyle(NodeModel copiedStyleNode, IStyle styleKey) { } else { modeController.removeExtensions(LogicalStyleKeys.NODE_STYLE, targetStyleNode, targetStyleNode); modeController.removeExtensions(MIconController.Keys.ICONS, targetStyleNode, targetStyleNode); + targetStyleNode.removeExtension(NodeAttributeTableModel.class); } - modeController.copyExtensions(LogicalStyleKeys.NODE_STYLE, copiedStyleNode, targetStyleNode); - modeController.copyExtensions(MIconController.Keys.ICONS, copiedStyleNode, targetStyleNode); + modeController.copyExtensions(LogicalStyleKeys.NODE_STYLE, copiedStyleNode, targetStyleNode); + modeController.copyExtensions(MIconController.Keys.ICONS, copiedStyleNode, targetStyleNode); + mAttributeController.copyAttributesToNode(copiedStyleNode, targetStyleNode); } } diff --git a/freeplane_plugin_script/src/main/java/org/freeplane/plugin/script/proxy/AttributesProxy.java b/freeplane_plugin_script/src/main/java/org/freeplane/plugin/script/proxy/AttributesProxy.java index 82025b2112..883500a476 100644 --- a/freeplane_plugin_script/src/main/java/org/freeplane/plugin/script/proxy/AttributesProxy.java +++ b/freeplane_plugin_script/src/main/java/org/freeplane/plugin/script/proxy/AttributesProxy.java @@ -254,7 +254,7 @@ public boolean remove(final String name) { if (index == -1) { return false; } - getAttributeController().removeAttribute(getDelegate(), index); + getAttributeController().performRemoveAttribute(getDelegate(), index); return true; } @@ -273,7 +273,7 @@ public boolean removeAll(final String name) { } // do it backwards in order not to invalidate the first indexes for (int i = toRemove.size() - 1; i >= 0; --i) { - getAttributeController().removeAttribute(getDelegate(), toRemove.get(i)); + getAttributeController().performRemoveAttribute(getDelegate(), toRemove.get(i)); } return !toRemove.isEmpty(); } @@ -281,7 +281,7 @@ public boolean removeAll(final String name) { @Override public void remove(final int index) { getAndCheckNodeAttributeTableModelForIndex(index, "remove:"); - getAttributeController().removeAttribute(getDelegate(), index); + getAttributeController().performRemoveAttribute(getDelegate(), index); } @Override @@ -289,7 +289,7 @@ public void clear() { final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel(); final int size = attributeTableModel.getRowCount(); for (int i = size - 1; i >= 0; i--) { - getAttributeController().removeAttribute(getDelegate(), i); + getAttributeController().performRemoveAttribute(getDelegate(), i); } }