Search in sources :

Example 16 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent 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());
        }
    });
}
Also used : KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler)

Example 17 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent 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());
}
Also used : ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ToolbarLabel(org.rstudio.core.client.widget.ToolbarLabel) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) CanFocus(org.rstudio.core.client.widget.CanFocus) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) SlideNavigationToolbarMenu(org.rstudio.studio.client.common.presentation.SlideNavigationToolbarMenu) WindowEx(org.rstudio.core.client.dom.WindowEx) FindTextBox(org.rstudio.core.client.widget.FindTextBox)

Example 18 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent 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;
}
Also used : ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ToolbarLabel(org.rstudio.core.client.widget.ToolbarLabel) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) CanFocus(org.rstudio.core.client.widget.CanFocus) WindowEx(org.rstudio.core.client.dom.WindowEx) FindTextBox(org.rstudio.core.client.widget.FindTextBox) Toolbar(org.rstudio.core.client.widget.Toolbar)

Example 19 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent 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;
}
Also used : KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) NativeKeyDownEvent(org.rstudio.core.client.events.NativeKeyDownEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SmallButton(org.rstudio.core.client.widget.SmallButton) SecondaryToolbar(org.rstudio.core.client.widget.SecondaryToolbar) WindowEx(org.rstudio.core.client.dom.WindowEx) FindTextBox(org.rstudio.core.client.widget.FindTextBox)

Example 20 with KeyDownEvent

use of com.google.gwt.event.dom.client.KeyDownEvent in project gerrit by GerritCodeReview.

the class PreferencesBox method onLoad.

@Override
public void onLoad() {
    super.onLoad();
    save.setVisible(Gerrit.isSignedIn());
    if (view != null) {
        addDomHandler(new KeyDownHandler() {

            @Override
            public void onKeyDown(KeyDownEvent event) {
                if (event.getNativeKeyCode() == KEY_ESCAPE || event.getNativeKeyCode() == ',') {
                    close();
                }
            }
        }, KeyDownEvent.getType());
        updateContextTimer = new Timer() {

            @Override
            public void run() {
                if (prefs.context() == WHOLE_FILE_CONTEXT) {
                    contextEntireFile.setValue(true);
                }
                if (view.canRenderEntireFile(prefs)) {
                    renderEntireFile.setEnabled(true);
                    renderEntireFile.setValue(prefs.renderEntireFile());
                } else {
                    renderEntireFile.setValue(false);
                    renderEntireFile.setEnabled(false);
                }
                view.setContext(prefs.context());
            }
        };
    }
}
Also used : KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) Timer(com.google.gwt.user.client.Timer) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler)

Aggregations

KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)29 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)15 Test (org.junit.Test)12 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)3 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)3 WindowEx (org.rstudio.core.client.dom.WindowEx)3 CanFocus (org.rstudio.core.client.widget.CanFocus)3 FindTextBox (org.rstudio.core.client.widget.FindTextBox)3 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)2 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)2 KeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler)2 KeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler)2 PostConstruct (javax.annotation.PostConstruct)2 ToolbarButton (org.rstudio.core.client.widget.ToolbarButton)2 ToolbarLabel (org.rstudio.core.client.widget.ToolbarLabel)2 RSConnectPublishButton (org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton)2 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)2 AccountInfo (com.google.gerrit.client.info.AccountInfo)1