mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEADEV-41036: Artifact editor: Remove button is enabled with focus on the output tree root
This commit is contained in:
+8
-12
@@ -36,22 +36,18 @@ import java.util.Collection;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ExtractArtifactAction extends DumbAwareAction {
|
||||
private ArtifactEditorEx myEditor;
|
||||
|
||||
public class ExtractArtifactAction extends LayoutTreeActionBase {
|
||||
public ExtractArtifactAction(ArtifactEditorEx editor) {
|
||||
super(ProjectBundle.message("action.name.extract.artifact"));
|
||||
myEditor = editor;
|
||||
super(ProjectBundle.message("action.name.extract.artifact"), editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
final LayoutTreeSelection selection = myEditor.getLayoutTreeComponent().getSelection();
|
||||
e.getPresentation().setEnabled(selection.getCommonParentElement() != null);
|
||||
protected boolean isEnabled() {
|
||||
return myArtifactEditor.getLayoutTreeComponent().getSelection().getCommonParentElement() != null;
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final LayoutTreeComponent treeComponent = myEditor.getLayoutTreeComponent();
|
||||
final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
|
||||
final LayoutTreeSelection selection = treeComponent.getSelection();
|
||||
final CompositePackagingElement<?> parent = selection.getCommonParentElement();
|
||||
if (parent == null) return;
|
||||
@@ -61,12 +57,12 @@ public class ExtractArtifactAction extends DumbAwareAction {
|
||||
}
|
||||
|
||||
final Collection<? extends PackagingElement> selectedElements = selection.getElements();
|
||||
final String name = Messages.showInputDialog(myEditor.getMainComponent(), ProjectBundle.message("label.text.specify.artifact.name"),
|
||||
final String name = Messages.showInputDialog(myArtifactEditor.getMainComponent(), ProjectBundle.message("label.text.specify.artifact.name"),
|
||||
ProjectBundle.message("dialog.title.extract.artifact"), null);
|
||||
if (name != null) {
|
||||
final Project project = myEditor.getContext().getProject();
|
||||
final Project project = myArtifactEditor.getContext().getProject();
|
||||
//todo[nik] select type?
|
||||
final ModifiableArtifact artifact = myEditor.getContext().getModifiableArtifactModel().addArtifact(name, PlainArtifactType.getInstance());
|
||||
final ModifiableArtifact artifact = myArtifactEditor.getContext().getModifiableArtifactModel().addArtifact(name, PlainArtifactType.getInstance());
|
||||
treeComponent.editLayout(new Runnable() {
|
||||
public void run() {
|
||||
for (PackagingElement<?> element : selectedElements) {
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class LayoutTreeActionBase extends DumbAwareAction {
|
||||
protected final ArtifactEditorEx myArtifactEditor;
|
||||
|
||||
protected LayoutTreeActionBase(String text, String description, Icon icon, ArtifactEditorEx artifactEditor) {
|
||||
super(text, description, icon);
|
||||
myArtifactEditor = artifactEditor;
|
||||
}
|
||||
|
||||
protected LayoutTreeActionBase(String text, ArtifactEditorEx artifactEditor) {
|
||||
super(text);
|
||||
myArtifactEditor = artifactEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
protected abstract boolean isEnabled();
|
||||
}
|
||||
+19
-7
@@ -19,23 +19,35 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.util.Icons;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class RemovePackagingElementAction extends DumbAwareAction {
|
||||
private final ArtifactEditorEx myArtifactEditor;
|
||||
public class RemovePackagingElementAction extends LayoutTreeActionBase {
|
||||
|
||||
public RemovePackagingElementAction(ArtifactEditorEx artifactEditor) {
|
||||
super(ProjectBundle.message("action.name.remove.packaging.element"), ProjectBundle.message("action.description.remove.packaging.elements"), Icons.DELETE_ICON);
|
||||
myArtifactEditor = artifactEditor;
|
||||
super(ProjectBundle.message("action.name.remove.packaging.element"), ProjectBundle.message("action.description.remove.packaging.elements"), Icons.DELETE_ICON,
|
||||
artifactEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(!myArtifactEditor.getLayoutTreeComponent().getSelection().getElements().isEmpty()
|
||||
&& !myArtifactEditor.getLayoutTreeComponent().isEditing());
|
||||
protected boolean isEnabled() {
|
||||
final LayoutTreeSelection selection = myArtifactEditor.getLayoutTreeComponent().getSelection();
|
||||
if (selection.getElements().isEmpty() || myArtifactEditor.getLayoutTreeComponent().isEditing()) {
|
||||
return false;
|
||||
}
|
||||
for (PackagingElementNode<?> node : selection.getNodes()) {
|
||||
if (node.getParentNode() == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
|
||||
Reference in New Issue
Block a user