mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Auto-increment component names when copy-pasting
This commit is contained in:
+18
-15
@@ -130,21 +130,7 @@ public class InstantiationManager {
|
|||||||
// Instantiate the component.
|
// Instantiate the component.
|
||||||
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
||||||
|
|
||||||
// Find the next available componentName for the component.
|
component.setName(createUniqueName(componentType, currentProject));
|
||||||
int i = 0;
|
|
||||||
boolean exists = true;
|
|
||||||
while (exists) {
|
|
||||||
i++;
|
|
||||||
String name = componentType.getNamePrefix() + i;
|
|
||||||
exists = false;
|
|
||||||
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
|
||||||
if (c.getName().equals(name)) {
|
|
||||||
exists = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
component.setName(componentType.getNamePrefix() + i);
|
|
||||||
|
|
||||||
// Translate them to the desired location.
|
// Translate them to the desired location.
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
@@ -160,6 +146,23 @@ public class InstantiationManager {
|
|||||||
|
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String createUniqueName(ComponentType componentType, Project currentProject) {
|
||||||
|
int i = 0;
|
||||||
|
boolean exists = true;
|
||||||
|
while (exists) {
|
||||||
|
i++;
|
||||||
|
String name = componentType.getNamePrefix() + i;
|
||||||
|
exists = false;
|
||||||
|
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
||||||
|
if (c.getName().equals(name)) {
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return componentType.getNamePrefix() + i;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds any properties that have default values and injects default values.
|
* Finds any properties that have default values and injects default values.
|
||||||
|
|||||||
+4
@@ -892,6 +892,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
(int) currentProject.getGridSpacing().convertToPixels());
|
(int) currentProject.getGridSpacing().convertToPixels());
|
||||||
component.setControlPoint(point, i);
|
component.setControlPoint(point, i);
|
||||||
}
|
}
|
||||||
|
component.setName(instantiationManager.createUniqueName(ComponentProcessor
|
||||||
|
.getInstance().extractComponentTypeFrom(
|
||||||
|
(Class<? extends IDIYComponent<?>>) component.getClass()),
|
||||||
|
currentProject));
|
||||||
addComponent(component, ComponentProcessor.getInstance().extractComponentTypeFrom(
|
addComponent(component, ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||||
(Class<? extends IDIYComponent<?>>) component.getClass()), false);
|
(Class<? extends IDIYComponent<?>>) component.getClass()), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,6 +330,10 @@
|
|||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Increased PNG export resolution</description>
|
<description>Increased PNG export resolution</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Auto-increment component names when copy-pasting</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Allow zero ohm resistors</description>
|
<description>Allow zero ohm resistors</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user