Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-3964: move popup from Quick documentation in the right place #4088

Merged
merged 1 commit into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void getAdditionalProposalInfo(AsyncCallback<Widget> callback) {
frame.setSize("100%", "100%");
frame.getElement().getStyle().setBorderStyle(Style.BorderStyle.NONE);
frame.getElement().setAttribute("sandbox", ""); // empty value, not null
frame.getElement().getStyle().setProperty("resize", "both");
frame.setUrl(client.getProposalDocUrl(id, sessionId));
callback.onSuccess(frame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,36 +118,30 @@ public ContentAssistWidget(final PopupResources popupResources,
docPopup.setStyleName(popupResources.popupStyle().popup());
docPopup.setSize("370px", "180px");

popupListener = new EventListener() {
@Override
public void handleEvent(final Event evt) {
if (evt instanceof MouseEvent) {
final MouseEvent mouseEvent = (MouseEvent)evt;
final EventTarget target = mouseEvent.getTarget();
if (target instanceof Element) {
final Element elementTarget = (Element)target;
if (docPopup.isVisible() &&
(elementTarget.equals(docPopup.getElement()) ||
elementTarget.getParentElement().equals(docPopup.getElement()))) {
return;
}
popupListener = evt -> {
if (!(evt instanceof MouseEvent)) {
return;
}
final MouseEvent mouseEvent = (MouseEvent)evt;
final EventTarget target = mouseEvent.getTarget();
if (target instanceof Element) {
final Element elementTarget = (Element)target;
if (docPopup.isVisible() &&
(elementTarget.equals(docPopup.getElement()) ||
elementTarget.getParentElement().equals(docPopup.getElement()))) {
return;
}

if (!ContentAssistWidget.this.popupElement.contains(elementTarget)) {
hide();
evt.preventDefault();
}
}
if (!ContentAssistWidget.this.popupElement.contains(elementTarget)) {
hide();
evt.preventDefault();
}
// else won't happen
}
};

handler = new OrionTextViewOverlay.EventHandler<OrionModelChangedEventOverlay>() {
@Override
public void onEvent(OrionModelChangedEventOverlay event) {
callCodeAssistTimer.cancel();
callCodeAssistTimer.schedule(250);
}
handler = event -> {
callCodeAssistTimer.cancel();
callCodeAssistTimer.schedule(250);
};
}

Expand All @@ -174,7 +168,8 @@ private native CustomEvent createValidateEvent(String eventType) /*-{
/**
* Creates a new proposal item.
*
* @param proposal
* @param index
* of proposal
*/
private Element createProposalPopupItem(int index) {
final CompletionProposal proposal = proposals.get(index);
Expand All @@ -195,21 +190,11 @@ private Element createProposalPopupItem(int index) {

element.setTabIndex(1);

final EventListener validateListener = new EventListener() {
@Override
public void handleEvent(final Event evt) {
applyProposal(proposal);
}
};
final EventListener validateListener = evt -> applyProposal(proposal);

element.addEventListener(Event.DBLCLICK, validateListener, false);
element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
element.addEventListener(Event.CLICK, new EventListener() {
@Override
public void handleEvent(Event event) {
select(element);
}
}, false);
element.addEventListener(Event.CLICK, event -> select(element), false);
element.addEventListener(Event.FOCUS, this, false);

element.addEventListener(DOCUMENTATION, new EventListener() {
Expand All @@ -224,13 +209,16 @@ public void onSuccess(Widget info) {
docPopup.getElement().getStyle().setOpacity(1);

if (!docPopup.isAttached()) {
final int x = popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3;
final int y = popupElement.getOffsetTop();
RootPanel.get().add(docPopup);
updateMenuPosition(docPopup, x, y);
}
} else {
docPopup.getElement().getStyle().setOpacity(0);
}
}

@Override
public void onFailure(Throwable e) {
Log.error(getClass(), e);
Expand All @@ -243,82 +231,69 @@ public void onFailure(Throwable e) {
return element;
}

private void updateMenuPosition(FlowPanel popupMenu, int x, int y) {
if (x + popupMenu.getOffsetWidth() > com.google.gwt.user.client.Window.getClientWidth()) {
popupMenu.getElement().getStyle().setLeft(x - popupMenu.getOffsetWidth() - popupElement.getOffsetWidth() - 5, Style.Unit.PX);
} else {
popupMenu.getElement().getStyle().setLeft(x, Style.Unit.PX);
}

if (y + popupMenu.getOffsetHeight() > com.google.gwt.user.client.Window.getClientHeight()) {
popupMenu.getElement().getStyle().setTop(y - popupMenu.getOffsetHeight() - popupElement.getOffsetHeight() - 3, Style.Unit.PX);
} else {
popupMenu.getElement().getStyle().setTop(y, Style.Unit.PX);
}
}

private void addPopupEventListeners() {
Elements.getDocument().addEventListener(Event.MOUSEDOWN, this.popupListener, false);

textEditor.getTextView().addKeyMode(assistMode);

// add key event listener on popup
textEditor.getTextView().setAction("cheContentAssistCancel", new Action() {
@Override
public boolean onAction() {
hide();
return true;
}
textEditor.getTextView().setAction("cheContentAssistCancel", () -> {
hide();
return true;
});

textEditor.getTextView().setAction("cheContentAssistApply", new Action() {
@Override
public boolean onAction() {
validateItem(true);
return true;
}
textEditor.getTextView().setAction("cheContentAssistApply", () -> {
validateItem(true);
return true;
});

textEditor.getTextView().setAction("cheContentAssistPreviousProposal", new Action() {
@Override
public boolean onAction() {
selectPrevious();
return true;
}
textEditor.getTextView().setAction("cheContentAssistPreviousProposal", () -> {
selectPrevious();
return true;
});

textEditor.getTextView().setAction("cheContentAssistNextProposal", new Action() {
@Override
public boolean onAction() {
selectNext();
return true;
}
textEditor.getTextView().setAction("cheContentAssistNextProposal", () -> {
selectNext();
return true;
});

textEditor.getTextView().setAction("cheContentAssistNextPage", new Action() {
@Override
public boolean onAction() {
selectNextPage();
return true;
}
textEditor.getTextView().setAction("cheContentAssistNextPage", () -> {
selectNextPage();
return true;
});

textEditor.getTextView().setAction("cheContentAssistPreviousPage", new Action() {
@Override
public boolean onAction() {
selectPreviousPage();
return true;
}
textEditor.getTextView().setAction("cheContentAssistPreviousPage", () -> {
selectPreviousPage();
return true;
});

textEditor.getTextView().setAction("cheContentAssistEnd", new Action() {
@Override
public boolean onAction() {
selectLast();
return true;
}
textEditor.getTextView().setAction("cheContentAssistEnd", () -> {
selectLast();
return true;
});

textEditor.getTextView().setAction("cheContentAssistHome", new Action() {
@Override
public boolean onAction() {
selectFirst();
return true;
}
textEditor.getTextView().setAction("cheContentAssistHome", () -> {
selectFirst();
return true;
});

textEditor.getTextView().setAction("cheContentAssistTab", new Action() {
@Override
public boolean onAction() {
validateItem(false);
return true;
}
textEditor.getTextView().setAction("cheContentAssistTab", () -> {
validateItem(false);
return true;
});

textEditor.getTextView().addEventListener("ModelChanging", handler);
Expand Down Expand Up @@ -576,12 +551,7 @@ public void handleEvent(Event evt) {
final KeyboardEvent keyEvent = (KeyboardEvent)evt;
switch (keyEvent.getKeyCode()) {
case KeyCodes.KEY_ESCAPE:
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
hide();
}
});
Scheduler.get().scheduleDeferred(() -> hide());
break;

case KeyCodes.KEY_DOWN:
Expand Down Expand Up @@ -693,15 +663,10 @@ public void showCompletionInfo() {
}

private void applyProposal(CompletionProposal proposal) {
CompletionProposal.CompletionCallback callback = new CompletionProposal.CompletionCallback() {
@Override
public void onCompletion(Completion completion) {
applyCompletion(completion);
}
};
CompletionProposal.CompletionCallback callback = this::applyCompletion;

if (proposal instanceof CompletionProposalExtension) {
((CompletionProposalExtension) proposal).getCompletion(insert, callback);
((CompletionProposalExtension)proposal).getCompletion(insert, callback);
} else {
proposal.getCompletion(callback);
}
Expand Down Expand Up @@ -755,7 +720,7 @@ private int getItemId(Element item) {
}

private Element getItem(int index) {
return (Element) listElement.getChildren().namedItem(Integer.toString(index));
return (Element)listElement.getChildren().namedItem(Integer.toString(index));
}

private int getItemHeight() {
Expand All @@ -776,7 +741,7 @@ private void setExtraRowHeight(Element extraRow, int items) {
}

private int getItemsPerPage() {
return (int) Math.ceil((double) popupBodyElement.getClientHeight() / getItemHeight());
return (int)Math.ceil((double)popupBodyElement.getClientHeight() / getItemHeight());
}

private int getTotalItems() {
Expand Down