Skip to content

Commit

Permalink
Copy attributes when copying styles between maps (freeplane#1539)
Browse files Browse the repository at this point in the history
* 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 <dpolivaev@gmx.de>
EdoFro and dpolivaev authored Nov 26, 2023
1 parent 671e84e commit a424d97
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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,23 +273,23 @@ 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();
}

@Override
public void remove(final int index) {
getAndCheckNodeAttributeTableModelForIndex(index, "remove:");
getAttributeController().removeAttribute(getDelegate(), index);
getAttributeController().performRemoveAttribute(getDelegate(), index);
}

@Override
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);
}
}

0 comments on commit a424d97

Please sign in to comment.