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.
|
||||
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
||||
|
||||
// Find the next available componentName for the component.
|
||||
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);
|
||||
component.setName(createUniqueName(componentType, currentProject));
|
||||
|
||||
// Translate them to the desired location.
|
||||
if (point != null) {
|
||||
@@ -160,6 +146,23 @@ public class InstantiationManager {
|
||||
|
||||
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.
|
||||
|
||||
+4
@@ -892,6 +892,10 @@ public class Presenter implements IPlugInPort {
|
||||
(int) currentProject.getGridSpacing().convertToPixels());
|
||||
component.setControlPoint(point, i);
|
||||
}
|
||||
component.setName(instantiationManager.createUniqueName(ComponentProcessor
|
||||
.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass()),
|
||||
currentProject));
|
||||
addComponent(component, ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass()), false);
|
||||
}
|
||||
|
||||
@@ -330,6 +330,10 @@
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Increased PNG export resolution</description>
|
||||
</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>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Allow zero ohm resistors</description>
|
||||
|
||||
Reference in New Issue
Block a user