mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Duplicate selection option in Edit menu and popup menu (Ctrl+D)
This commit is contained in:
@@ -183,6 +183,11 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
*/
|
||||
void pasteComponents(Collection<IDIYComponent<?>> components);
|
||||
|
||||
/**
|
||||
* Duplicates selected components and places them nearby.
|
||||
*/
|
||||
void duplicateSelection();
|
||||
|
||||
/**
|
||||
* Deletes all the selected components from the project.
|
||||
*/
|
||||
|
||||
@@ -164,7 +164,7 @@ public class InstantiationManager {
|
||||
// Update the location according to mouse location
|
||||
updateSingleClick(scaledPoint, snapToGrid, gridSpacing);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates location of component slot based on the new mouse location.
|
||||
*
|
||||
|
||||
@@ -1410,6 +1410,38 @@ public class Presenter implements IPlugInPort {
|
||||
instantiationManager.getFirstControlPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void duplicateSelection() {
|
||||
LOG.info("duplicateSelection()");
|
||||
if (selectedComponents.isEmpty()) {
|
||||
LOG.debug("Nothing to duplicate");
|
||||
return;
|
||||
}
|
||||
Project oldProject = currentProject.clone();
|
||||
Set<IDIYComponent<?>> newSelection = new HashSet<IDIYComponent<?>>();
|
||||
|
||||
int grid = (int) currentProject.getGridSpacing().convertToPixels();
|
||||
for (IDIYComponent<?> component : this.selectedComponents) {
|
||||
try {
|
||||
IDIYComponent<?> cloned = component.clone();
|
||||
newSelection.add(cloned);
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
Point newPoint = new Point(p.x + grid, p.y + grid);
|
||||
cloned.setControlPoint(newPoint, i);
|
||||
}
|
||||
currentProject.getComponents().add(cloned);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
updateSelection(newSelection);
|
||||
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), "Duplicate");
|
||||
projectFileManager.notifyFileChange();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSelectedComponents() {
|
||||
LOG.info("deleteSelectedComponents()");
|
||||
|
||||
Reference in New Issue
Block a user