use of org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay in project che by eclipse.
the class OrionEditorWidget method addChangeHandler.
@Override
public HandlerRegistration addChangeHandler(final ChangeHandler handler) {
if (!changeHandlerAdded) {
changeHandlerAdded = true;
final OrionTextViewOverlay textView = this.editorOverlay.getTextView();
textView.addEventListener(OrionEventConstants.MODEL_CHANGED_EVENT, new OrionTextViewOverlay.EventHandlerNoParameter() {
@Override
public void onEvent() {
fireChangeEvent();
}
});
}
return addHandler(handler, ChangeEvent.getType());
}
use of org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay in project che by eclipse.
the class OrionEditorWidget method addCursorActivityHandler.
@Override
public HandlerRegistration addCursorActivityHandler(CursorActivityHandler handler) {
if (!cursorHandlerAdded) {
cursorHandlerAdded = true;
final OrionTextViewOverlay textView = this.editorOverlay.getTextView();
textView.addEventListener(OrionEventConstants.SELECTION_EVENT, new OrionTextViewOverlay.EventHandlerNoParameter() {
@Override
public void onEvent() {
fireCursorActivityEvent();
}
});
}
return addHandler(handler, CursorActivityEvent.TYPE);
}
use of org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay in project che by eclipse.
the class OrionEditorWidget method addScrollHandler.
@Override
public HandlerRegistration addScrollHandler(final ScrollHandler handler) {
if (!scrollHandlerAdded) {
scrollHandlerAdded = true;
final OrionTextViewOverlay textView = this.editorOverlay.getTextView();
textView.addEventListener(OrionEventConstants.SCROLL_EVENT, new OrionTextViewOverlay.EventHandlerNoParameter() {
@Override
public void onEvent() {
fireScrollEvent();
}
});
}
return addHandler(handler, ScrollEvent.TYPE);
}
use of org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay in project che by eclipse.
the class OrionEditorWidget method addBlurHandler.
@Override
public HandlerRegistration addBlurHandler(BlurHandler handler) {
if (!blurHandlerAdded) {
blurHandlerAdded = true;
final OrionTextViewOverlay textView = this.editorOverlay.getTextView();
textView.addEventListener(OrionEventConstants.BLUR_EVENT, new OrionTextViewOverlay.EventHandlerNoParameter() {
@Override
public void onEvent() {
fireBlurEvent();
}
});
}
return addHandler(handler, BlurEvent.getType());
}
use of org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay in project che by eclipse.
the class ContentAssistWidget method show.
/**
* Displays assist popup relative to the current cursor position.
*
* @param proposals
* proposals to display
*/
public void show(final List<CompletionProposal> proposals) {
this.proposals = proposals;
OrionTextViewOverlay textView = textEditor.getTextView();
OrionPixelPositionOverlay caretLocation = textView.getLocationAtOffset(textView.getCaretOffset());
caretLocation.setY(caretLocation.getY() + textView.getLineHeight());
caretLocation = textView.convert(caretLocation, "document", "page");
/** The fastest way to remove element children. Clear and add items. */
listElement.setInnerHTML("");
/* Display an empty popup when it is nothing to show. */
if (getTotalItems() == 0) {
final Element emptyElement = Elements.createLiElement(popupResources.popupStyle().item());
emptyElement.setTextContent("No proposals");
listElement.appendChild(emptyElement);
return;
}
/* Automatically apply the completion proposal if it only one. */
if (getTotalItems() == 1) {
applyProposal(proposals.get(0));
return;
}
/* Reset popup dimensions and show. */
popupElement.getStyle().setLeft(caretLocation.getX(), PX);
popupElement.getStyle().setTop(caretLocation.getY(), PX);
popupElement.getStyle().setWidth("400px");
popupElement.getStyle().setHeight("200px");
popupElement.getStyle().setOpacity(1);
Elements.getDocument().getBody().appendChild(this.popupElement);
/* Add the top extra row. */
setExtraRowHeight(appendExtraRow(), 0);
/* Add the popup items. */
for (int i = 0; i < Math.min(DOM_ITEMS_SIZE, getTotalItems()); i++) {
listElement.appendChild(createProposalPopupItem(i));
}
/* Add the bottom extra row. */
setExtraRowHeight(appendExtraRow(), Math.max(0, getTotalItems() - DOM_ITEMS_SIZE));
/* Correct popup position (wants to be refactored) */
final Window window = Elements.getWindow();
final int viewportWidth = window.getInnerWidth();
final int viewportHeight = window.getInnerHeight();
int spaceBelow = viewportHeight - caretLocation.getY();
if (this.popupElement.getOffsetHeight() > spaceBelow) {
// Check if div is too large to fit above
int spaceAbove = caretLocation.getY() - textView.getLineHeight();
if (this.popupElement.getOffsetHeight() > spaceAbove) {
// Squeeze the div into the larger area
if (spaceBelow > spaceAbove) {
this.popupElement.getStyle().setProperty("maxHeight", spaceBelow + "px");
} else {
this.popupElement.getStyle().setProperty("maxHeight", spaceAbove + "px");
this.popupElement.getStyle().setTop("0");
}
} else {
// Put the div above the line
this.popupElement.getStyle().setTop((caretLocation.getY() - this.popupElement.getOffsetHeight() - textView.getLineHeight()) + "px");
this.popupElement.getStyle().setProperty("maxHeight", spaceAbove + "px");
}
} else {
this.popupElement.getStyle().setProperty("maxHeight", spaceBelow + "px");
}
if (caretLocation.getX() + this.popupElement.getOffsetWidth() > viewportWidth) {
int leftSide = viewportWidth - this.popupElement.getOffsetWidth();
if (leftSide < 0) {
leftSide = 0;
}
this.popupElement.getStyle().setLeft(leftSide + "px");
this.popupElement.getStyle().setProperty("maxWidth", (viewportWidth - leftSide) + "px");
} else {
this.popupElement.getStyle().setProperty("maxWidth", viewportWidth + caretLocation.getX() + "px");
}
/* Don't attach handlers twice. Visible popup must already have their attached. */
if (!visible) {
addPopupEventListeners();
}
/* Indicates the codeassist is visible. */
visible = true;
focused = false;
/* Update documentation popup position */
docPopup.getElement().getStyle().setLeft(popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3, Style.Unit.PX);
docPopup.getElement().getStyle().setTop(popupElement.getOffsetTop(), Style.Unit.PX);
/* Select first row. */
selectFirst();
}
Aggregations