From bb486a081bcb2a169ecd8e6dfcf4b0bf342e7cdd Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Fri, 25 May 2012 12:56:51 +0400 Subject: [PATCH] IDEA-86605 --- .../actions/CommonEditActionsProvider.java | 21 ++++++++++--------- .../designer/componentTree/ComponentTree.java | 15 ++++++++++++- .../componentTree/ComponentTreeBuilder.java | 2 ++ .../designer/designSurface/CaptionPanel.java | 2 +- .../designer/designSurface/EditableArea.java | 3 +++ .../designer/designSurface/GlassLayer.java | 10 ++------- .../designSurface/tools/SelectionTool.java | 4 ++-- .../intellij/designer/model/RadComponent.java | 2 ++ 8 files changed, 37 insertions(+), 22 deletions(-) diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java index 7a6bf5ae69da..c81c9d5ffb4a 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java @@ -53,8 +53,9 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, myDesigner = designer; } - protected EditableArea getArea() { - return myDesigner.getActionsArea(); + protected EditableArea getArea(DataContext dataContext) { + EditableArea area = EditableArea.DATA_KEY.getData(dataContext); + return area == null ? myDesigner.getSurfaceArea() : area; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -68,7 +69,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, if (myDesigner.getInplaceEditingLayer().isEditing()) { return false; } - List selection = getArea().getSelection(); + List selection = getArea(dataContext).getSelection(); if (selection.isEmpty()) { return false; } @@ -81,11 +82,11 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, } @Override - public void deleteElement(@NotNull DataContext dataContext) { + public void deleteElement(final @NotNull DataContext dataContext) { myDesigner.getToolProvider().execute(new ThrowableRunnable() { @Override public void run() throws Exception { - EditableArea area = getArea(); + EditableArea area = getArea(dataContext); List selection = area.getSelection(); if (selection.isEmpty()) { @@ -145,20 +146,20 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, @Override public boolean isCopyEnabled(@NotNull DataContext dataContext) { - return !myDesigner.getInplaceEditingLayer().isEditing() && !getArea().getSelection().isEmpty(); + return !myDesigner.getInplaceEditingLayer().isEditing() && !getArea(dataContext).getSelection().isEmpty(); } @Override public void performCopy(@NotNull DataContext dataContext) { - doCopy(); + doCopy(dataContext); } - private boolean doCopy() { + private boolean doCopy(DataContext dataContext) { try { Element root = new Element("designer"); root.setAttribute("target", myDesigner.getPlatformTarget()); - List components = RadComponent.getPureSelection(getArea().getSelection()); + List components = RadComponent.getPureSelection(getArea(dataContext).getSelection()); for (RadComponent component : components) { component.copyTo(root); } @@ -243,7 +244,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, @Override public void performCut(@NotNull DataContext dataContext) { - if (doCopy()) { + if (doCopy(dataContext)) { deleteElement(dataContext); } } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java index e39eb730ca18..633ed1da333f 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java @@ -18,6 +18,7 @@ package com.intellij.designer.componentTree; import com.intellij.designer.actions.DesignerActionPanel; import com.intellij.designer.actions.StartInplaceEditing; import com.intellij.designer.designSurface.DesignerEditorPanel; +import com.intellij.designer.designSurface.EditableArea; import com.intellij.designer.designSurface.FeedbackTreeLayer; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.actionSystem.DataProvider; @@ -40,6 +41,7 @@ public final class ComponentTree extends Tree implements DataProvider { private final StartInplaceEditing myInplaceEditingAction; private TreeComponentDecorator myDecorator; private DesignerActionPanel myActionPanel; + private EditableArea myArea; private RadComponent myMarkComponent; private int myMarkFeedback; @@ -75,9 +77,14 @@ public final class ComponentTree extends Tree implements DataProvider { myActionPanel = designer.getActionPanel(); } myMarkComponent = null; + myArea = null; myInplaceEditingAction.setDesignerPanel(designer); } + public void setArea(@Nullable EditableArea area) { + myArea = area; + } + public void mark(RadComponent component, int feedback) { myMarkComponent = component; myMarkFeedback = feedback; @@ -86,7 +93,13 @@ public final class ComponentTree extends Tree implements DataProvider { @Override public Object getData(@NonNls String dataId) { - return myActionPanel == null ? null : myActionPanel.getData(dataId); + if (EditableArea.DATA_KEY.is(dataId)) { + return myArea; + } + if (myActionPanel != null) { + return myActionPanel.getData(dataId); + } + return null; } @Nullable diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java index e5fecc7c0cd3..e1e29059a39d 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java @@ -49,6 +49,8 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder implements C myGlassLayer = new TreeGlassLayer(tree, designer.getToolProvider(), myTreeArea); myExpandStateHandler = new ExpandStateHandler(tree, designer, this); + tree.setArea(myTreeArea); + new TreeDropListener(tree, myTreeArea, designer.getToolProvider()); selectFromSurface(); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java index 19af11b3eb39..7eb831645f13 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java @@ -150,7 +150,7 @@ public class CaptionPanel extends JLayeredPane implements DataProvider, DeletePr myActionsProvider = new CommonEditActionsProvider(designer) { @Override - protected EditableArea getArea() { + protected EditableArea getArea(DataContext dataContext) { return myArea; } }; diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EditableArea.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EditableArea.java index 285dfec7b781..ebc32a71ad76 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EditableArea.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EditableArea.java @@ -18,6 +18,7 @@ package com.intellij.designer.designSurface; import com.intellij.designer.designSurface.tools.InputTool; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.DataKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,6 +30,8 @@ import java.util.List; * @author Alexander Lobas */ public interface EditableArea { + DataKey DATA_KEY = DataKey.create("EditableArea"); + ////////////////////////////////////////////////////////////////////////////////////////// // // Selection diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/GlassLayer.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/GlassLayer.java index 2d4719534750..f28b4c94f2c2 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/GlassLayer.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/GlassLayer.java @@ -17,7 +17,6 @@ package com.intellij.designer.designSurface; import com.intellij.designer.designSurface.tools.ToolProvider; import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.ui.popup.PopupOwner; import org.jetbrains.annotations.NonNls; import javax.swing.*; @@ -28,7 +27,7 @@ import java.awt.event.MouseEvent; /** * @author Alexander Lobas */ -public final class GlassLayer extends JComponent implements PopupOwner, DataProvider { +public final class GlassLayer extends JComponent implements DataProvider { private static final long EVENT_FLAGS = AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK; private final ToolProvider myToolProvider; @@ -74,13 +73,8 @@ public final class GlassLayer extends JComponent implements PopupOwner, DataProv myToolProvider.processMouseEvent(event, myArea); } - @Override - public Point getBestPopupPosition() { - return null; // TODO: Auto-generated method stub - } - @Override public Object getData(@NonNls String dataId) { - return null; // TODO: Auto-generated method stub + return EditableArea.DATA_KEY.is(dataId) ? myArea : null; } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java index 7efcfb6c1f7c..077c881ebca9 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/SelectionTool.java @@ -89,7 +89,7 @@ public class SelectionTool extends InputTool { @Override protected void handleDoubleClick(int button) { - if (button == MouseEvent.BUTTON1 && myToolProvider != null) { + if (button == MouseEvent.BUTTON1 && myToolProvider != null && !myArea.isTree()) { myToolProvider.startInplaceEditing(null); } } @@ -199,7 +199,7 @@ public class SelectionTool extends InputTool { if (myTracker != null) { myTracker.keyTyped(event, area); } - else if (myToolProvider != null && + else if (myToolProvider != null && !area.isTree() && Character.isLetterOrDigit(event.getKeyChar()) && (event.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK)) == 0) { myToolProvider.startInplaceEditing(new InplaceContext(event.getKeyChar())); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java index c43400d71452..ffd7f5ad3064 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java @@ -111,6 +111,8 @@ public abstract class RadComponent { if (myLayout != null) { myLayout.removeComponentFromContainer(component); } + + component.setParent(null); } public void removeFromParent() {