use of com.google.gwt.event.dom.client.KeyDownHandler in project che by eclipse.
the class View method handleEvents.
private void handleEvents() {
KeyDownHandler handler = new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (KeyboardEvent.KeyCode.ESC == event.getNativeEvent().getKeyCode()) {
event.stopPropagation();
event.preventDefault();
if (delegate != null) {
delegate.onEscapeKey();
}
} else if (KeyboardEvent.KeyCode.ENTER == event.getNativeEvent().getKeyCode()) {
event.stopPropagation();
event.preventDefault();
if (delegate != null) {
delegate.onEnterKey();
}
}
}
};
focusPanel.addDomHandler(handler, KeyDownEvent.getType());
closeButton.addDomHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (delegate != null) {
delegate.onClose();
}
event.stopPropagation();
}
}, ClickEvent.getType());
/* Don't start moving the window when clicking close button */
closeButton.addDomHandler(new MouseDownHandler() {
@Override
public void onMouseDown(MouseDownEvent event) {
event.preventDefault();
event.stopPropagation();
}
}, MouseDownEvent.getType());
MouseHandler mouseHandler = new MouseHandler();
header.addDomHandler(mouseHandler, MouseDownEvent.getType());
header.addDomHandler(mouseHandler, MouseUpEvent.getType());
header.addDomHandler(mouseHandler, MouseMoveEvent.getType());
}
use of com.google.gwt.event.dom.client.KeyDownHandler in project rstudio by rstudio.
the class DomUtils method addKeyHandlers.
public static void addKeyHandlers(HasAllKeyHandlers widget, final NativeEventHandler handler) {
widget.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(final KeyDownEvent event) {
handler.onNativeEvent(event.getNativeEvent());
}
});
widget.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(final KeyPressEvent event) {
handler.onNativeEvent(event.getNativeEvent());
}
});
widget.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(final KeyUpEvent event) {
handler.onNativeEvent(event.getNativeEvent());
}
});
}
use of com.google.gwt.event.dom.client.KeyDownHandler in project rstudio by rstudio.
the class RmdOutputPanel method initToolbar.
@Override
protected void initToolbar(Toolbar toolbar, Commands commands) {
slideNavigationMenu_ = new SlideNavigationToolbarMenu(toolbar, 400, 100, true);
fileLabel_ = new ToolbarLabel();
fileLabel_.addStyleName(ThemeStyles.INSTANCE.subtitle());
fileLabel_.getElement().getStyle().setMarginRight(7, Unit.PX);
toolbar.addLeftWidget(fileLabel_);
fileLabelSeparator_ = toolbar.addLeftSeparator();
ToolbarButton popoutButton = commands.viewerPopout().createToolbarButton();
popoutButton.setText("Open in Browser");
toolbar.addLeftWidget(popoutButton);
findTextBox_ = new FindTextBox("Find");
findTextBox_.setIconVisible(true);
findTextBox_.setOverrideWidth(120);
findTextBox_.getElement().getStyle().setMarginRight(6, Unit.PX);
findSeparator_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(findTextBox_);
findTextBox_.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
// enter key triggers a find
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
event.preventDefault();
event.stopPropagation();
findInTopic(findTextBox_.getValue().trim(), findTextBox_);
findTextBox_.focus();
} else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
findTextBox_.setValue("");
}
}
private void findInTopic(String term, CanFocus findInputSource) {
// get content window
WindowEx contentWindow = getFrame().getWindow();
if (contentWindow == null)
return;
if (!contentWindow.find(term, false, false, true, false)) {
RStudioGinjector.INSTANCE.getGlobalDisplay().showMessage(MessageDialog.INFO, "Find in Page", "No occurences found", findInputSource);
}
}
});
toolbar.addLeftSeparator();
publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null);
toolbar.addRightWidget(publishButton_);
toolbar.addRightSeparator();
toolbar.addRightWidget(commands.viewerRefresh().createToolbarButton());
}
use of com.google.gwt.event.dom.client.KeyDownHandler in project rstudio by rstudio.
the class HTMLPreviewPanel method createToolbar.
private Toolbar createToolbar(Commands commands) {
Toolbar toolbar = new Toolbar();
toolbar.addLeftWidget(new ToolbarLabel("Preview: "));
fileLabel_ = new ToolbarLabel();
fileLabel_.addStyleName(ThemeStyles.INSTANCE.subtitle());
fileLabel_.getElement().getStyle().setMarginRight(7, Unit.PX);
toolbar.addLeftWidget(fileLabel_);
toolbar.addLeftSeparator();
toolbar.addLeftWidget(commands.openHtmlExternal().createToolbarButton());
showLogButtonSeparator_ = toolbar.addLeftSeparator();
showLogButton_ = commands.showHtmlPreviewLog().createToolbarButton();
toolbar.addLeftWidget(showLogButton_);
saveHtmlPreviewAsSeparator_ = toolbar.addLeftSeparator();
if (Desktop.isDesktop()) {
saveHtmlPreviewAs_ = commands.saveHtmlPreviewAs().createToolbarButton();
toolbar.addLeftWidget(saveHtmlPreviewAs_);
} else {
ToolbarPopupMenu menu = new ToolbarPopupMenu();
menu.addItem(commands.saveHtmlPreviewAs().createMenuItem(false));
menu.addItem(commands.saveHtmlPreviewAsLocalFile().createMenuItem(false));
saveHtmlPreviewAs_ = toolbar.addLeftWidget(new ToolbarButton("Save As", commands.saveSourceDoc().getImageResource(), menu));
}
publishButtonSeparator_ = toolbar.addLeftSeparator();
toolbar.addLeftWidget(publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null));
findTextBox_ = new FindTextBox("Find");
findTextBox_.setIconVisible(true);
findTextBox_.setOverrideWidth(120);
findTextBox_.getElement().getStyle().setMarginRight(6, Unit.PX);
toolbar.addRightWidget(findTextBox_);
findTextBox_.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
// enter key triggers a find
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
event.preventDefault();
event.stopPropagation();
findInTopic(findTextBox_.getValue().trim(), findTextBox_);
findTextBox_.focus();
} else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
findTextBox_.setValue("");
}
}
private void findInTopic(String term, CanFocus findInputSource) {
// get content window
WindowEx contentWindow = previewFrame_.getWindow();
if (contentWindow == null)
return;
if (!contentWindow.find(term, false, false, true, false)) {
RStudioGinjector.INSTANCE.getGlobalDisplay().showMessage(MessageDialog.INFO, "Find in Page", "No occurences found", findInputSource);
}
}
});
refreshButtonSeparator_ = toolbar.addRightSeparator();
refreshButton_ = toolbar.addRightWidget(commands.refreshHtmlPreview().createToolbarButton());
return toolbar;
}
use of com.google.gwt.event.dom.client.KeyDownHandler in project rstudio by rstudio.
the class HelpPane method createSecondaryToolbar.
@Override
protected SecondaryToolbar createSecondaryToolbar() {
SecondaryToolbar toolbar = new SecondaryToolbar();
toolbar.addLeftPopupMenu(title_ = new Label(), history_.getMenu());
if (isFindSupported()) {
final SmallButton btnNext = new SmallButton(">", true);
btnNext.setTitle("Find next (Enter)");
btnNext.setVisible(false);
btnNext.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
findNext();
}
});
final SmallButton btnPrev = new SmallButton("<", true);
btnPrev.setTitle("Find previous");
btnPrev.setVisible(false);
btnPrev.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
findPrev();
}
});
findTextBox_ = new FindTextBox("Find in Topic");
findTextBox_.setOverrideWidth(90);
toolbar.addLeftWidget(findTextBox_);
findTextBox_.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
// ignore modifier key release
if (event.getNativeKeyCode() == KeyCodes.KEY_CTRL || event.getNativeKeyCode() == KeyCodes.KEY_ALT || event.getNativeKeyCode() == KeyCodes.KEY_SHIFT) {
return;
}
WindowEx contentWindow = getContentWindow();
if (contentWindow != null) {
// into the main content window
if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE || event.getNativeKeyCode() == KeyCodes.KEY_TAB) {
event.preventDefault();
event.stopPropagation();
if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE)
clearTerm();
contentWindow.focus();
} else {
// minimizing or maximizing the help pane
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
event.preventDefault();
event.stopPropagation();
}
// check for term
String term = findTextBox_.getValue().trim();
int modifier = KeyboardShortcut.getModifierValue(event.getNativeEvent());
boolean isShift = modifier == KeyboardShortcut.SHIFT;
// if there is a term then search for it
if (term.length() > 0) {
// make buttons visible
setButtonVisibility(true);
// perform the find (check for incremental)
if (isIncrementalFindSupported()) {
boolean incremental = !event.isAnyModifierKeyDown() && (event.getNativeKeyCode() != KeyCodes.KEY_ENTER);
performFind(term, !isShift, incremental);
} else {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
performFind(term, !isShift, false);
}
} else // no term means clear term and remove selection
{
if (isIncrementalFindSupported()) {
clearTerm();
contentWindow.removeSelection();
}
}
}
}
}
private void clearTerm() {
findTextBox_.setValue("");
setButtonVisibility(false);
}
private void setButtonVisibility(final boolean visible) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
btnNext.setVisible(visible);
btnPrev.setVisible(visible);
}
});
}
});
findTextBox_.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
// from handling them
if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE || event.getNativeKeyCode() == KeyCodes.KEY_TAB || event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
event.preventDefault();
event.stopPropagation();
}
}
});
if (isIncrementalFindSupported()) {
btnPrev.getElement().getStyle().setMarginRight(3, Unit.PX);
toolbar.addLeftWidget(btnPrev);
toolbar.addLeftWidget(btnNext);
}
}
return toolbar;
}
Aggregations