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);
}
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);
}
}
});
}
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;
}
});
}
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;
}
}
}
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();
}
}
});
}
}
});
}
Aggregations