Auto-increment component names when copy-pasting

This commit is contained in:
bancika
2011-08-26 18:18:53 +00:00
parent ba694add0c
commit bea19f326c
3 changed files with 26 additions and 15 deletions
@@ -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.
@@ -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>