Search in sources :

Example 1 with HideMessageHandler

use of org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler in project rstudio by rstudio.

the class TextEditingTarget method onRenameInScope.

@Handler
void onRenameInScope() {
    docDisplay_.focus();
    // Save folds (we need to remove them temporarily for the rename helper)
    final JsArray<AceFold> folds = docDisplay_.getFolds();
    docDisplay_.unfoldAll();
    int matches = renameHelper_.renameInScope();
    if (matches <= 0) {
        if (!docDisplay_.getSelectionValue().isEmpty()) {
            String message = "No matches for '" + docDisplay_.getSelectionValue() + "'";
            view_.getStatusBar().showMessage(message, 1000);
        }
        for (AceFold fold : JsUtil.asIterable(folds)) docDisplay_.addFold(fold.getRange());
        return;
    }
    String message = "Found " + matches;
    if (matches == 1)
        message += " match";
    else
        message += " matches";
    String selectedItem = docDisplay_.getSelectionValue();
    message += " for " + selectedItem + ".";
    docDisplay_.disableSearchHighlight();
    view_.getStatusBar().showMessage(message, new HideMessageHandler() {

        private boolean onRenameFinished(boolean value) {
            for (AceFold fold : JsUtil.asIterable(folds)) docDisplay_.addFold(fold.getRange());
            return value;
        }

        @Override
        public boolean onNativePreviewEvent(NativePreviewEvent preview) {
            int type = preview.getTypeInt();
            if (docDisplay_.isPopupVisible())
                return false;
            // End if the user clicks somewhere
            if (type == Event.ONCLICK) {
                docDisplay_.exitMultiSelectMode();
                docDisplay_.clearSelection();
                docDisplay_.enableSearchHighlight();
                return onRenameFinished(true);
            } else // Otherwise, handle key events
            if (type == Event.ONKEYDOWN) {
                switch(preview.getNativeEvent().getKeyCode()) {
                    case KeyCodes.KEY_ENTER:
                        preview.cancel();
                    case KeyCodes.KEY_UP:
                    case KeyCodes.KEY_DOWN:
                    case KeyCodes.KEY_ESCAPE:
                        docDisplay_.exitMultiSelectMode();
                        docDisplay_.clearSelection();
                        docDisplay_.enableSearchHighlight();
                        return onRenameFinished(true);
                }
            }
            return false;
        }
    });
}
Also used : AceFold(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) JsArrayString(com.google.gwt.core.client.JsArrayString) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)1 Handler (org.rstudio.core.client.command.Handler)1 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)1 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)1 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)1 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)1 FileChangeHandler (org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)1 AceFold (org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold)1 HideMessageHandler (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler)1 RecordNavigationPositionHandler (org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler)1