Clean up code

This commit is contained in:
SiboVG 2022-08-18 00:57:33 +02:00
parent e1a4816e10
commit 3364b29189

View File

@ -418,35 +418,22 @@ public class RocketActions {
* should be pasted. Returns null if the clipboard is empty or if the * should be pasted. Returns null if the clipboard is empty or if the
* clipboard cannot be pasted to the current selection. * clipboard cannot be pasted to the current selection.
* *
* @param copyComponent the component to be copy-pasted. * @param srcComponent the component to be copy-pasted.
* @param pasteComponent the component where copyComponent should be pasted to. * @param destComponent the component where srcComponent should be pasted to.
* @return a Pair with both components defined, or null. * @return a Pair with both components defined, or null.
*/ */
private Pair<RocketComponent, Integer> getPastePosition(RocketComponent copyComponent, RocketComponent pasteComponent) { private Pair<RocketComponent, Integer> getPastePosition(RocketComponent srcComponent, RocketComponent destComponent) {
if (pasteComponent == null) if (destComponent == null)
return null; return null;
if (copyComponent == null) if (srcComponent == null)
return null; return null;
if (pasteComponent.isCompatible(copyComponent)) if (destComponent.isCompatible(srcComponent))
return new Pair<RocketComponent, Integer>(pasteComponent, pasteComponent.getChildCount()); return new Pair<RocketComponent, Integer>(destComponent, destComponent.getChildCount());
RocketComponent parent = pasteComponent.getParent(); RocketComponent parent = destComponent.getParent();
return getPastePositionFromParent(copyComponent, parent); return getPastePositionFromParent(srcComponent, parent);
}
/**
* Return the component and position to which the current clipboard
* should be pasted. Returns null if the clipboard is empty or if the
* clipboard cannot be pasted to the current selection.
*
* @param copyComponent the component to be copy-pasted.
* @return a Pair with both components defined, or null.
*/
private Pair<RocketComponent, Integer> getPastePosition(RocketComponent copyComponent) {
RocketComponent selected = selectionModel.getSelectedComponent();
return getPastePosition(copyComponent, selected);
} }
private Pair<RocketComponent, Integer> getPastePositionFromParent(RocketComponent component, RocketComponent parent) { private Pair<RocketComponent, Integer> getPastePositionFromParent(RocketComponent component, RocketComponent parent) {
@ -468,8 +455,9 @@ public class RocketActions {
*/ */
private List<Pair<RocketComponent, Integer>> getPastePositions(List<RocketComponent> clipboard) { private List<Pair<RocketComponent, Integer>> getPastePositions(List<RocketComponent> clipboard) {
List<Pair<RocketComponent, Integer>> result = new LinkedList<>(); List<Pair<RocketComponent, Integer>> result = new LinkedList<>();
RocketComponent selected = selectionModel.getSelectedComponent();
for (RocketComponent component : clipboard) { for (RocketComponent component : clipboard) {
Pair<RocketComponent, Integer> position = getPastePosition(component); Pair<RocketComponent, Integer> position = getPastePosition(component, selected);
if (position != null) { if (position != null) {
result.add(position); result.add(position);
} }
@ -775,10 +763,7 @@ public class RocketActions {
pasted.add(component.copy()); pasted.add(component.copy());
} }
List<Pair<RocketComponent, Integer>> positions = new LinkedList<>(); List<Pair<RocketComponent, Integer>> positions = getPastePositions(pasted);
for (RocketComponent component : pasted) {
positions.add(getPastePosition(component));
}
if (pasted.size() == 1) { if (pasted.size() == 1) {
document.addUndoPosition("Paste " + pasted.get(0).getComponentName()); document.addUndoPosition("Paste " + pasted.get(0).getComponentName());