fredsa / gwt-dnd

Library providing easy to use mouse or touch based drag-and-drop capabilities to GWT
43 stars 40 forks source link

Improvement: Extract method to determine if Event should initiate dragging in MouseDragHandler #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the relevant code that decides on whether to drag or not is this:

    Event event = DOM.eventGetCurrentEvent();
    int button = DOM.eventGetButton(event);
    if (button != Event.BUTTON_LEFT) {
      return;
    }

I would like to drag only when the CTRL key is pressed:

    Event event = DOM.eventGetCurrentEvent();
    int button = DOM.eventGetButton(event);
    if (!(button == Event.BUTTON_LEFT && event.getCtrlKey())) {
      return;
    }

To make this possible the test should be extracted to a method which takes 
the Event can be overridden:

    Event event = DOM.eventGetCurrentEvent();
    if (!isDragEvent(event)) {
      return;
    }

    protected boolean isDragEvent(Event event) {
        int button = DOM.eventGetButton(event);
        return button == Event.BUTTON_LEFT && event.getCtrlKey();
    }

Original issue reported on code.google.com by steven.d...@gmail.com on 12 Aug 2008 at 12:24

GoogleCodeExporter commented 9 years ago
I might suggest registered a DragHandler with your DragController and throwing a
VetoDragException when the CTRL/META key is not pressed in onPreviewDragStart()

Would that address your use case?

Original comment by fredsa on 26 Aug 2008 at 3:01

GoogleCodeExporter commented 9 years ago

Original comment by fredsa on 31 Jan 2012 at 6:11

GoogleCodeExporter commented 9 years ago

Original comment by fredsa on 31 Jan 2012 at 6:11