Preserve z-order of components when copy-pasting

This commit is contained in:
Branislav Stojkovic
2018-12-15 18:35:51 +01:00
parent 2ee81093a0
commit 3939d2c5a7
5 changed files with 21 additions and 2 deletions
@@ -26,6 +26,7 @@ import java.util.Comparator;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
public class ComparatorFactory { public class ComparatorFactory {
@@ -128,4 +129,16 @@ public class ComparatorFactory {
} }
return componentZOrderComparator; return componentZOrderComparator;
} }
public Comparator<IDIYComponent<?>> getComponentProjectZOrderComparator(final Project project) {
return new Comparator<IDIYComponent<?>>() {
@Override
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
int index1 = project.getComponents().indexOf(o1);
int index2 = project.getComponents().indexOf(o2);
return new Integer(index1).compareTo(index2);
}
};
}
} }
@@ -831,7 +831,9 @@ public class Presenter implements IPlugInPort {
@Override @Override
public Collection<IDIYComponent<?>> getSelectedComponents() { public Collection<IDIYComponent<?>> getSelectedComponents() {
return selectedComponents; List<IDIYComponent<?>> selection = new ArrayList<IDIYComponent<?>>(selectedComponents);
Collections.sort(selection, ComparatorFactory.getInstance().getComponentProjectZOrderComparator(currentProject));
return selection;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Binary file not shown.
Binary file not shown.
+4
View File
@@ -1878,6 +1878,10 @@
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Holding "shift" key switches mouse wheel scrolling from vertical to horizontal</description> <description>Holding "shift" key switches mouse wheel scrolling from vertical to horizontal</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Preserve z-order of components when copy-pasting</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>"Cut Line" component sometimes disappears</description> <description>"Cut Line" component sometimes disappears</description>