use of com.android.tools.idea.uibuilder.api.InsertType in project android by JetBrains.
the class NlDropListener method captureDraggedComponents.
@Nullable
private InsertType captureDraggedComponents(@NotNull NlDropEvent event, boolean isPreview) {
clearDraggedComponents();
ScreenView screenView = myTree.getScreenView();
if (screenView == null) {
return null;
}
NlModel model = screenView.getModel();
if (event.isDataFlavorSupported(ItemTransferable.DESIGNER_FLAVOR)) {
try {
myTransferItem = (DnDTransferItem) event.getTransferable().getTransferData(ItemTransferable.DESIGNER_FLAVOR);
InsertType insertType = determineInsertType(event, isPreview);
if (insertType.isMove()) {
myDragged.addAll(keepOnlyAncestors(model.getSelectionModel().getSelection()));
} else {
Collection<NlComponent> captured = ApplicationManager.getApplication().runWriteAction((Computable<Collection<NlComponent>>) () -> model.createComponents(screenView, myTransferItem, insertType));
if (captured != null) {
myDragged.addAll(keepOnlyAncestors(captured));
}
}
return insertType;
} catch (IOException | UnsupportedFlavorException exception) {
Logger.getInstance(NlDropListener.class).warn(exception);
}
}
return null;
}
use of com.android.tools.idea.uibuilder.api.InsertType in project android by JetBrains.
the class NlDropListener method drop.
@Override
public void drop(@NotNull DropTargetDropEvent dropEvent) {
NlDropEvent event = new NlDropEvent(dropEvent);
InsertType insertType = captureDraggedComponents(event, false);
if (findInsertionPoint(event) != null) {
performDrop(dropEvent, insertType);
}
clearInsertionPoint();
clearDraggedComponents();
}
use of com.android.tools.idea.uibuilder.api.InsertType in project android by JetBrains.
the class DesignSurfaceActionHandler method pasteOperation.
private boolean pasteOperation(boolean checkOnly) {
ScreenView screenView = mySurface.getCurrentScreenView();
if (screenView == null) {
return false;
}
List<NlComponent> selection = screenView.getSelectionModel().getSelection();
NlComponent receiver = !selection.isEmpty() ? selection.get(0) : null;
if (receiver == null) {
// In the case where there is no selection but we only have a root component, use that one
List<NlComponent> components = screenView.getModel().getComponents();
if (components.size() == 1) {
receiver = components.get(0);
}
}
if (receiver == null) {
return false;
}
NlComponent before;
NlModel model = screenView.getModel();
ViewHandlerManager handlerManager = ViewHandlerManager.get(model.getProject());
ViewHandler handler = handlerManager.getHandler(receiver);
if (handler instanceof ViewGroupHandler) {
before = receiver.getChild(0);
} else {
before = receiver.getNextSibling();
receiver = receiver.getParent();
if (receiver == null) {
return false;
}
}
DnDTransferItem item = getClipboardData();
if (item == null) {
return false;
}
InsertType insertType = model.determineInsertType(DragType.PASTE, item, checkOnly);
List<NlComponent> pasted = model.createComponents(screenView, item, insertType);
if (!model.canAddComponents(pasted, receiver, before)) {
return false;
}
if (checkOnly) {
return true;
}
model.addComponents(pasted, receiver, before, insertType);
return true;
}
Aggregations