use of com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection in project intellij-community by JetBrains.
the class ExtractArtifactAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
final LayoutTreeSelection selection = treeComponent.getSelection();
final CompositePackagingElement<?> parent = selection.getCommonParentElement();
if (parent == null)
return;
final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
if (parentNode == null)
return;
if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
return;
}
final Collection<? extends PackagingElement> selectedElements = selection.getElements();
String initialName = "artifact";
if (selectedElements.size() == 1) {
initialName = PathUtil.suggestFileName(ContainerUtil.getFirstItem(selectedElements, null).createPresentation(myArtifactEditor.getContext()).getPresentableName());
}
IExtractArtifactDialog dialog = showDialog(treeComponent, initialName);
if (dialog == null)
return;
final Project project = myArtifactEditor.getContext().getProject();
final ModifiableArtifactModel model = myArtifactEditor.getContext().getOrCreateModifiableArtifactModel();
final ModifiableArtifact artifact = model.addArtifact(dialog.getArtifactName(), dialog.getArtifactType());
treeComponent.editLayout(() -> {
for (PackagingElement<?> element : selectedElements) {
artifact.getRootElement().addOrFindChild(ArtifactUtil.copyWithChildren(element, project));
}
for (PackagingElement element : selectedElements) {
parent.removeChild(element);
}
parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact, myArtifactEditor.getContext().getArtifactModel())));
});
treeComponent.rebuildTree();
}
use of com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection in project intellij-community by JetBrains.
the class HideContentAction method update.
@Override
public void update(AnActionEvent e) {
final LayoutTreeSelection selection = myArtifactEditor.getLayoutTreeComponent().getSelection();
final PackagingElementNode<?> node = selection.getNodeIfSingle();
if (node != null) {
final Collection<PackagingNodeSource> sources = node.getNodeSources();
if (!sources.isEmpty()) {
String description;
if (sources.size() == 1) {
description = "Hide Content of '" + sources.iterator().next().getPresentableName() + "'";
} else {
description = "Hide Content";
}
e.getPresentation().setVisible(true);
e.getPresentation().setText(description);
return;
}
}
e.getPresentation().setVisible(false);
}
use of com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection in project intellij-community by JetBrains.
the class InlineArtifactAction method update.
@Override
public void update(AnActionEvent e) {
final LayoutTreeSelection selection = myEditor.getLayoutTreeComponent().getSelection();
final PackagingElementNode<?> node = selection.getNodeIfSingle();
PackagingElement<?> element = selection.getElementIfSingle();
e.getPresentation().setEnabled(element instanceof ArtifactPackagingElement && node != null && node.getParentElement(element) != null);
}
Aggregations