Search in sources :

Example 1 with FindTextBox

use of org.rstudio.core.client.widget.FindTextBox 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 2 with FindTextBox

use of org.rstudio.core.client.widget.FindTextBox 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 3 with FindTextBox

use of org.rstudio.core.client.widget.FindTextBox 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)

Aggregations

KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)3 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)3 WindowEx (org.rstudio.core.client.dom.WindowEx)3 FindTextBox (org.rstudio.core.client.widget.FindTextBox)3 CanFocus (org.rstudio.core.client.widget.CanFocus)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 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)1 KeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler)1 NativeKeyDownEvent (org.rstudio.core.client.events.NativeKeyDownEvent)1 SecondaryToolbar (org.rstudio.core.client.widget.SecondaryToolbar)1 SmallButton (org.rstudio.core.client.widget.SmallButton)1 Toolbar (org.rstudio.core.client.widget.Toolbar)1 ToolbarPopupMenu (org.rstudio.core.client.widget.ToolbarPopupMenu)1 SlideNavigationToolbarMenu (org.rstudio.studio.client.common.presentation.SlideNavigationToolbarMenu)1