diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextEditorDropAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextEditorDropAdapter.java index 8890e3ee947..d5bb672aa63 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextEditorDropAdapter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextEditorDropAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextViewerDragAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextViewerDragAdapter.java index f51d99f9c65..f6b6c74c758 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextViewerDragAdapter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/TextViewerDragAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -50,6 +50,8 @@ public class TextViewerDragAdapter extends DragSourceAdapter { private ITextEditorExtension fEditor; /** Location of last mouse down event (as a workaround for bug 151197) */ private Point fDragStartLocation; + /** Flag whether this drag source listener allows to drag */ + private boolean fIsEnabled= true; /** * Create a new TextViewerDragAdapter. @@ -122,6 +124,10 @@ public class TextViewerDragAdapter extends DragSourceAdapter { * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent) */ public void dragStart(DragSourceEvent event) { + if (!fIsEnabled) { + event.doit= false; + return; + } // workaround for bug 151197 if (fDragStartLocation == null) { event.doit= false; @@ -233,4 +239,12 @@ public class TextViewerDragAdapter extends DragSourceAdapter { return fViewer.isEditable(); } + /** + * Enable or disable this drag listener. + * @param enabled + */ + public void setEnabled(boolean enabled) { + fIsEnabled= enabled; + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index 2ef264c6417..1cc2baf7554 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -105,8 +105,6 @@ import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DragSource; -import org.eclipse.swt.dnd.DragSourceListener; -import org.eclipse.swt.dnd.DropTarget; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.VerifyEvent; @@ -125,6 +123,7 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.dnd.IDragAndDropService; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.part.EditorActionBarContributor; import org.eclipse.ui.part.IShowInSource; @@ -1526,6 +1525,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR */ private SemanticHighlightingManager fSemanticManager; + /** + * Custom text drag source listener overriding platform implementation. + * @since 4.0 + */ + private TextViewerDragAdapter fTextViewerDragAdapter; + private static final Set angularIntroducers = new HashSet(); static { angularIntroducers.add("template"); //$NON-NLS-1$ @@ -2422,22 +2427,39 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR } /* - * @see org.eclipse.ui.texteditor.AbstractTextEditor#initializeDragAndDrop(org.eclipse.jface.text.source.ISourceViewer) + * @see org.eclipse.ui.texteditor.AbstractTextEditor#installTextDragAndDrop(org.eclipse.jface.text.source.ISourceViewer) */ - protected void initializeDragAndDrop(ISourceViewer viewer) { + protected void installTextDragAndDrop(ISourceViewer viewer) { + if (fTextViewerDragAdapter != null) { + // already installed, enable it + fTextViewerDragAdapter.setEnabled(true); + return; + } + final IDragAndDropService dndService= (IDragAndDropService)getSite().getService(IDragAndDropService.class); + if (dndService == null || viewer == null) { + return; + } Control control = viewer.getTextWidget(); int operations = DND.DROP_MOVE | DND.DROP_COPY; - DropTarget dropTarget = new DropTarget(control, operations); - ITextEditorDropTargetListener dropTargetListener = new TextEditorDropAdapter(viewer, this); - dropTarget.setTransfer(dropTargetListener.getTransfers()); - dropTarget.addDropListener(dropTargetListener); - DragSource dragSource = new DragSource(control, operations); Transfer[] dragTypes = new Transfer[] { TextTransfer.getInstance() }; dragSource.setTransfer(dragTypes); - DragSourceListener dragSourceListener = new TextViewerDragAdapter(viewer, this); - dragSource.addDragListener(dragSourceListener); + fTextViewerDragAdapter = new TextViewerDragAdapter(viewer, this); + dragSource.addDragListener(fTextViewerDragAdapter); + + ITextEditorDropTargetListener dropTargetListener = new TextEditorDropAdapter(viewer, this); + dndService.addMergedDropTarget(control, operations, dropTargetListener.getTransfers(), dropTargetListener); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#uninstallTextDragAndDrop(org.eclipse.jface.text.source.ISourceViewer) + */ + protected void uninstallTextDragAndDrop(ISourceViewer viewer) { + if (fTextViewerDragAdapter != null) { + // uninstall not possible, disable instead + fTextViewerDragAdapter.setEnabled(false); + } } /*