mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Workaround for SWT bug 151197
This commit is contained in:
parent
847e5b67b0
commit
be7b98b84e
2 changed files with 40 additions and 9 deletions
|
@ -59,6 +59,8 @@ import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||||
* A drop adapter which supports dragging a non-workspace file from some
|
* A drop adapter which supports dragging a non-workspace file from some
|
||||||
* external tool (e.g. explorer) into the editor area. The adaptor also supports
|
* external tool (e.g. explorer) into the editor area. The adaptor also supports
|
||||||
* text and marker transfer.
|
* text and marker transfer.
|
||||||
|
*
|
||||||
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class TextEditorDropAdapter extends DropTargetAdapter implements
|
public class TextEditorDropAdapter extends DropTargetAdapter implements
|
||||||
ITextEditorDropTargetListener {
|
ITextEditorDropTargetListener {
|
||||||
|
@ -395,13 +397,15 @@ public class TextEditorDropAdapter extends DropTargetAdapter implements
|
||||||
* Convert mouse screen coordinates to a <code>StyledText</code> offset.
|
* Convert mouse screen coordinates to a <code>StyledText</code> offset.
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
|
* screen X-coordinate
|
||||||
* @param y
|
* @param y
|
||||||
|
* screen Y-coordinate
|
||||||
* @param absolute
|
* @param absolute
|
||||||
* if <code>true</code>, coordinates are expected to be
|
* if <code>true</code>, coordinates are expected to be
|
||||||
* absolute screen coordinates
|
* absolute screen coordinates
|
||||||
* @return text offset
|
* @return text offset
|
||||||
*
|
*
|
||||||
* @see StyledText#getOffsetAtLocation() \
|
* @see StyledText#getOffsetAtLocation()
|
||||||
*/
|
*/
|
||||||
private int getOffsetAtLocation(int x, int y, boolean absolute) {
|
private int getOffsetAtLocation(int x, int y, boolean absolute) {
|
||||||
StyledText textWidget= fViewer.getTextWidget();
|
StyledText textWidget= fViewer.getTextWidget();
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.dnd;
|
package org.eclipse.cdt.internal.ui.dnd;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.BadPositionCategoryException;
|
import org.eclipse.jface.text.BadPositionCategoryException;
|
||||||
import org.eclipse.jface.text.DefaultPositionUpdater;
|
import org.eclipse.jface.text.DefaultPositionUpdater;
|
||||||
|
@ -21,16 +20,21 @@ import org.eclipse.jface.text.ITextViewer;
|
||||||
import org.eclipse.jface.text.ITextViewerExtension;
|
import org.eclipse.jface.text.ITextViewerExtension;
|
||||||
import org.eclipse.jface.text.ITextViewerExtension5;
|
import org.eclipse.jface.text.ITextViewerExtension5;
|
||||||
import org.eclipse.jface.text.Position;
|
import org.eclipse.jface.text.Position;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.custom.StyledText;
|
import org.eclipse.swt.custom.StyledText;
|
||||||
import org.eclipse.swt.custom.StyledTextContent;
|
import org.eclipse.swt.custom.StyledTextContent;
|
||||||
import org.eclipse.swt.dnd.DND;
|
import org.eclipse.swt.dnd.DND;
|
||||||
import org.eclipse.swt.dnd.DragSourceAdapter;
|
import org.eclipse.swt.dnd.DragSourceAdapter;
|
||||||
import org.eclipse.swt.dnd.DragSourceEvent;
|
import org.eclipse.swt.dnd.DragSourceEvent;
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
|
import org.eclipse.swt.widgets.Event;
|
||||||
|
import org.eclipse.swt.widgets.Listener;
|
||||||
import org.eclipse.ui.texteditor.ITextEditorExtension;
|
import org.eclipse.ui.texteditor.ITextEditorExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drag source adapter for text selections in ITextViewers.
|
* Drag source adapter for text selections in ITextViewers.
|
||||||
|
*
|
||||||
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class TextViewerDragAdapter extends DragSourceAdapter {
|
public class TextViewerDragAdapter extends DragSourceAdapter {
|
||||||
|
|
||||||
|
@ -44,6 +48,8 @@ public class TextViewerDragAdapter extends DragSourceAdapter {
|
||||||
private ITextViewer fViewer;
|
private ITextViewer fViewer;
|
||||||
/** The editor of the viewer (may be null) */
|
/** The editor of the viewer (may be null) */
|
||||||
private ITextEditorExtension fEditor;
|
private ITextEditorExtension fEditor;
|
||||||
|
/** Location of last mouse down event (as a workaround for bug 151197) */
|
||||||
|
private Point fDragStartLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new TextViewerDragAdapter.
|
* Create a new TextViewerDragAdapter.
|
||||||
|
@ -60,7 +66,22 @@ public class TextViewerDragAdapter extends DragSourceAdapter {
|
||||||
public TextViewerDragAdapter(ITextViewer viewer, ITextEditorExtension editor) {
|
public TextViewerDragAdapter(ITextViewer viewer, ITextEditorExtension editor) {
|
||||||
fViewer= viewer;
|
fViewer= viewer;
|
||||||
fEditor= editor;
|
fEditor= editor;
|
||||||
|
fViewer.getTextWidget().addListener(SWT.MouseDown, new Listener() {
|
||||||
|
public void handleEvent(Event event) {
|
||||||
|
// workaround for bug 151197
|
||||||
|
Point selection= fViewer.getTextWidget().getSelection();
|
||||||
|
if (selection.x != selection.y) {
|
||||||
|
// remember last mouse down location
|
||||||
|
// to check if drag started inside selection
|
||||||
|
fDragStartLocation= new Point(event.x,event.y);
|
||||||
|
} else {
|
||||||
|
// no active selection - this is no valid drag start
|
||||||
|
fDragStartLocation= null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
|
* @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
|
||||||
*/
|
*/
|
||||||
|
@ -101,13 +122,13 @@ public class TextViewerDragAdapter extends DragSourceAdapter {
|
||||||
* @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
|
* @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
|
||||||
*/
|
*/
|
||||||
public void dragStart(DragSourceEvent event) {
|
public void dragStart(DragSourceEvent event) {
|
||||||
// disable text drag on GTK until bug 151197 is fixed
|
// workaround for bug 151197
|
||||||
if (Platform.WS_GTK.equals(Platform.getWS())) {
|
if (fDragStartLocation == null) {
|
||||||
event.doit= false;
|
event.doit= false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/// convert screen coordinates to widget offest
|
// convert screen coordinates to widget offest
|
||||||
int offset= getOffsetAtLocation(event.x, event.y, false);
|
int offset= getOffsetAtLocation(fDragStartLocation.x, fDragStartLocation.y, false);
|
||||||
// convert further to a document offset
|
// convert further to a document offset
|
||||||
offset= getDocumentOffset(offset);
|
offset= getDocumentOffset(offset);
|
||||||
Point selection= fViewer.getSelectedRange();
|
Point selection= fViewer.getSelectedRange();
|
||||||
|
@ -145,11 +166,17 @@ public class TextViewerDragAdapter extends DragSourceAdapter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert mouse screen coordinates to a <code>StyledText</code> offset.
|
* Convert mouse screen coordinates to a <code>StyledText</code> offset.
|
||||||
|
*
|
||||||
* @param x
|
* @param x
|
||||||
|
* screen X-coordinate
|
||||||
* @param y
|
* @param y
|
||||||
* @param absolute if true, coordinates are expected to be absolute
|
* screen Y-coordinate
|
||||||
* screen coordinates
|
* @param absolute
|
||||||
|
* if <code>true</code>, coordinates are expected to be
|
||||||
|
* absolute screen coordinates
|
||||||
* @return text offset
|
* @return text offset
|
||||||
|
*
|
||||||
|
* @see StyledText#getOffsetAtLocation()
|
||||||
*/
|
*/
|
||||||
private int getOffsetAtLocation(int x, int y, boolean absolute) {
|
private int getOffsetAtLocation(int x, int y, boolean absolute) {
|
||||||
StyledText textWidget= fViewer.getTextWidget();
|
StyledText textWidget= fViewer.getTextWidget();
|
||||||
|
|
Loading…
Add table
Reference in a new issue