Search in sources :

Example 1 with NativePreviewEvent

use of com.google.gwt.user.client.Event.NativePreviewEvent 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 NativePreviewEvent

use of com.google.gwt.user.client.Event.NativePreviewEvent 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 NativePreviewEvent

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

the class TextEditingTarget method onRenameInScope.

@Handler
void onRenameInScope() {
    docDisplay_.focus();
    // Save folds (we need to remove them temporarily for the rename helper)
    final JsArray<AceFold> folds = docDisplay_.getFolds();
    docDisplay_.unfoldAll();
    int matches = renameHelper_.renameInScope();
    if (matches <= 0) {
        if (!docDisplay_.getSelectionValue().isEmpty()) {
            String message = "No matches for '" + docDisplay_.getSelectionValue() + "'";
            view_.getStatusBar().showMessage(message, 1000);
        }
        for (AceFold fold : JsUtil.asIterable(folds)) docDisplay_.addFold(fold.getRange());
        return;
    }
    String message = "Found " + matches;
    if (matches == 1)
        message += " match";
    else
        message += " matches";
    String selectedItem = docDisplay_.getSelectionValue();
    message += " for " + selectedItem + ".";
    docDisplay_.disableSearchHighlight();
    view_.getStatusBar().showMessage(message, new HideMessageHandler() {

        private boolean onRenameFinished(boolean value) {
            for (AceFold fold : JsUtil.asIterable(folds)) docDisplay_.addFold(fold.getRange());
            return value;
        }

        @Override
        public boolean onNativePreviewEvent(NativePreviewEvent preview) {
            int type = preview.getTypeInt();
            if (docDisplay_.isPopupVisible())
                return false;
            // End if the user clicks somewhere
            if (type == Event.ONCLICK) {
                docDisplay_.exitMultiSelectMode();
                docDisplay_.clearSelection();
                docDisplay_.enableSearchHighlight();
                return onRenameFinished(true);
            } else // Otherwise, handle key events
            if (type == Event.ONKEYDOWN) {
                switch(preview.getNativeEvent().getKeyCode()) {
                    case KeyCodes.KEY_ENTER:
                        preview.cancel();
                    case KeyCodes.KEY_UP:
                    case KeyCodes.KEY_DOWN:
                    case KeyCodes.KEY_ESCAPE:
                        docDisplay_.exitMultiSelectMode();
                        docDisplay_.clearSelection();
                        docDisplay_.enableSearchHighlight();
                        return onRenameFinished(true);
                }
            }
            return false;
        }
    });
}
Also used : AceFold(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) JsArrayString(com.google.gwt.core.client.JsArrayString) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

Example 4 with NativePreviewEvent

use of com.google.gwt.user.client.Event.NativePreviewEvent 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 5 with NativePreviewEvent

use of com.google.gwt.user.client.Event.NativePreviewEvent 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)

Aggregations

NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)11 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)8 Element (com.google.gwt.dom.client.Element)3 Test (org.junit.Test)3 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 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