Search in sources :

Example 1 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class DiagnosticsBackgroundPopup method start.

public void start() {
    isRunning_ = true;
    stopRequested_ = false;
    if (handler_ != null) {
        handler_.removeHandler();
        handler_ = null;
    }
    handler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONMOUSEMOVE) {
                movedMouseMostRecently_ = true;
                Element target = Element.as(event.getNativeEvent().getEventTarget());
                if (target.hasClassName("ace_gutter-cell")) {
                    lastMouseCoords_ = null;
                    hidePopup();
                    return;
                }
                lastMouseCoords_ = ScreenCoordinates.create(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                if (activeMarker_ != null && !activeMarker_.getRange().containsRightExclusive(editor_.toDocumentPosition(lastMouseCoords_))) {
                    hidePopup();
                }
            } else {
                movedMouseMostRecently_ = false;
            }
        }
    });
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (stopRequested_)
                return stopExecution();
            // restarted later)
            if (!docDisplay_.isFocused())
                return stopExecution();
            long currentTime = System.currentTimeMillis();
            long lastModifiedTime = docDisplay_.getLastModifiedTime();
            long lastCursorChangedTime = docDisplay_.getLastCursorChangedTime();
            // cursor was moved recently, then bail
            if ((currentTime - lastModifiedTime) < 500)
                return completeExecution();
            if ((currentTime - lastCursorChangedTime) < 500)
                return completeExecution();
            Markers markers = editor_.getSession().getMarkers(true);
            Position currentPos;
            if (movedMouseMostRecently_) {
                if (lastMouseCoords_ == null)
                    return completeExecution();
                currentPos = editor_.toDocumentPosition(lastMouseCoords_);
            } else {
                currentPos = docDisplay_.getCursorPosition();
            }
            int[] keys = markers.getIds();
            for (int i = 0; i < keys.length; i++) {
                Marker marker = markers.get(keys[i]);
                if (marker.getRange().containsRightExclusive(currentPos)) {
                    displayMarkerDiagnostics(marker);
                    return completeExecution();
                }
            }
            return completeExecution();
        }
    }, 500);
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Element(com.google.gwt.dom.client.Element) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Markers(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Markers) Marker(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker)

Example 2 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class MiniPopupPanel method addDragHandler.

private void addDragHandler() {
    if (dragHandler_ != null)
        dragHandler_.removeHandler();
    dragHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent npe) {
            if (npe.getNativeEvent().getButton() != NativeEvent.BUTTON_LEFT)
                return;
            int type = npe.getTypeInt();
            if (type == Event.ONMOUSEDOWN || type == Event.ONMOUSEMOVE || type == Event.ONMOUSEUP) {
                if (dragging_) {
                    handleDrag(npe);
                    return;
                }
                Element target = npe.getNativeEvent().getEventTarget().cast();
                String tagName = target.getTagName().toLowerCase();
                for (String tag : TAGS_EXCLUDE_DRAG) if (tagName.equals(tag))
                    return;
                if (DomUtils.isDescendantOfElementWithTag(target, TAGS_EXCLUDE_DRAG))
                    return;
                Element self = MiniPopupPanel.this.getElement();
                if (!DomUtils.isDescendant(target, self))
                    return;
                handleDrag(npe);
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Element(com.google.gwt.dom.client.Element) Point(org.rstudio.core.client.Point)

Example 3 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class AceEditorBackgroundLinkHighlighter method onAttachOrDetach.

// Event Handlers ---
@Override
public void onAttachOrDetach(AttachEvent event) {
    if (event.isAttached()) {
        previewHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

            @Override
            public void onPreviewNativeEvent(NativePreviewEvent preview) {
                int type = preview.getTypeInt();
                if (type == Event.ONKEYDOWN) {
                    int modifier = KeyboardShortcut.getModifierValue(preview.getNativeEvent());
                    beginDetectClickTarget(mouseTracker_.getLastMouseX(), mouseTracker_.getLastMouseY(), modifier);
                } else if (type == Event.ONKEYUP) {
                    endDetectClickTarget();
                }
            }
        });
    } else {
        for (HandlerRegistration handler : handlers_) handler.removeHandler();
        handlers_.clear();
        if (previewHandler_ != null) {
            previewHandler_.removeHandler();
            previewHandler_ = null;
        }
    }
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent)

Example 4 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class CppCompletionSignatureTip method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    allTips_.add(this);
    nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        public void onPreviewNativeEvent(NativePreviewEvent e) {
            if (e.getTypeInt() == Event.ONKEYDOWN) {
                // handle keys
                switch(e.getNativeEvent().getKeyCode()) {
                    case KeyCodes.KEY_ESCAPE:
                        e.cancel();
                        hide();
                        break;
                    case KeyCodes.KEY_DOWN:
                        e.cancel();
                        setTextIndex(currentTextIndex_ + 1);
                        break;
                    case KeyCodes.KEY_UP:
                        e.cancel();
                        setTextIndex(currentTextIndex_ - 1);
                        break;
                }
                // dismiss if we've left our anchor zone
                // (defer this so the current key has a chance to 
                // enter the editor and affect the cursor)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        Position cursorPos = docDisplay_.getCursorPosition();
                        Range anchorRange = anchor_.getRange();
                        if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
                            hide();
                        }
                    }
                });
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 5 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class SignatureToolTipManager method attachPreviewHandler.

private void attachPreviewHandler() {
    detachPreviewHandler();
    preview_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent preview) {
            if (preview.getTypeInt() == Event.ONMOUSEMOVE) {
                NativeEvent event = preview.getNativeEvent();
                coordinates_ = new MouseCoordinates(event.getClientX(), event.getClientY());
                ready_ = true;
            } else if (preview.getTypeInt() == Event.ONKEYDOWN) {
                coordinates_ = null;
                ready_ = true;
                if (preview.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE)
                    suppressed_ = true;
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) MouseCoordinates(org.rstudio.core.client.events.MouseDragHandler.MouseCoordinates) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)8 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)8 Element (com.google.gwt.dom.client.Element)3 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 TableRowElement (com.google.gwt.dom.client.TableRowElement)1 AttachEvent (com.google.gwt.event.logical.shared.AttachEvent)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Event (com.google.gwt.user.client.Event)1 DockPanel (com.google.gwt.user.client.ui.DockPanel)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 SubmitCompleteEvent (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent)1 SubmitEvent (com.google.gwt.user.client.ui.FormPanel.SubmitEvent)1 Label (com.google.gwt.user.client.ui.Label)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 Test (org.junit.Test)1