From 86b00e87888bfce42b1d05dbf7cdec8295144fd8 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Wed, 30 May 2012 18:17:59 -0700 Subject: Fix cut & paste in XML editors for Eclipse 4.x Change-Id: Ie30c362c71eff0d62e177e06687c362802d416b1 --- .../editors/layout/LayoutEditorDelegate.java | 10 ++++++++ .../internal/editors/layout/gle2/LayoutCanvas.java | 29 ++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java index 8d7b02e..f904f6e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java @@ -687,6 +687,16 @@ public class LayoutEditorDelegate extends CommonXmlDelegate public void delegatePostPageChange(int newPageIndex) { super.delegatePostPageChange(newPageIndex); + if (mGraphicalEditor != null) { + LayoutCanvas canvas = mGraphicalEditor.getCanvasControl(); + if (canvas != null) { + IActionBars bars = getEditor().getEditorSite().getActionBars(); + if (bars != null) { + canvas.updateGlobalActions(bars); + } + } + } + IFormPage page = getEditor().getActivePageInstance(); updateOutline(page); } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index 2154179..371852c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; +import com.android.annotations.NonNull; import com.android.ide.common.api.INode; import com.android.ide.common.api.Margins; import com.android.ide.common.api.Point; @@ -1213,16 +1214,30 @@ public class LayoutCanvas extends Canvas { * * @param bars the action bar for this canvas */ - public void updateGlobalActions(IActionBars bars) { + public void updateGlobalActions(@NonNull IActionBars bars) { updateMenuActionState(); - assert bars != null; - bars.setGlobalActionHandler(ActionFactory.CUT.getId(), mCutAction); - bars.setGlobalActionHandler(ActionFactory.COPY.getId(), mCopyAction); - bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), mPasteAction); - bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), mDeleteAction); - bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), mSelectAllAction); ITextEditor editor = mEditorDelegate.getEditor().getStructuredTextEditor(); + boolean graphical = getEditorDelegate().getEditor().getActivePage() == 0; + if (graphical) { + bars.setGlobalActionHandler(ActionFactory.CUT.getId(), mCutAction); + bars.setGlobalActionHandler(ActionFactory.COPY.getId(), mCopyAction); + bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), mPasteAction); + bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), mDeleteAction); + bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), mSelectAllAction); + } else { + bars.setGlobalActionHandler(ActionFactory.CUT.getId(), + editor.getAction(ActionFactory.CUT.getId())); + bars.setGlobalActionHandler(ActionFactory.COPY.getId(), + editor.getAction(ActionFactory.COPY.getId())); + bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), + editor.getAction(ActionFactory.PASTE.getId())); + bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), + editor.getAction(ActionFactory.DELETE.getId())); + bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), + editor.getAction(ActionFactory.SELECT_ALL.getId())); + } + IAction undoAction = editor.getAction(ActionFactory.UNDO.getId()); bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction); IAction redoAction = editor.getAction(ActionFactory.REDO.getId()); -- cgit v1.1