Search in sources :

Example 31 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class CppCompletionRequest method applyValue.

private void applyValue(CppCompletion completion) {
    if (invalidationToken_.isInvalid())
        return;
    terminate();
    if (completion.getType() == CppCompletion.SNIPPET) {
        snippets_.applySnippet(getUserTypedText(), completion.getTypedText());
        return;
    }
    String insertText = completion.getTypedText();
    if (completion.getType() == CppCompletion.FUNCTION && uiPrefs_.insertParensAfterFunctionCompletion().getValue()) {
        if (uiPrefs_.insertMatching().getValue())
            insertText = insertText + "()";
        else
            insertText = insertText + "(";
    } else if (completion.getType() == CppCompletion.DIRECTORY) {
        insertText += "/";
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                manager_.codeCompletion();
            }
        });
    }
    docDisplay_.setFocus(true);
    docDisplay_.setSelection(getReplacementSelection());
    docDisplay_.replaceSelection(insertText, true);
    if (completion.hasParameters() && uiPrefs_.insertParensAfterFunctionCompletion().getValue() && uiPrefs_.insertMatching().getValue()) {
        Position pos = docDisplay_.getCursorPosition();
        pos = Position.create(pos.getRow(), pos.getColumn() - 1);
        docDisplay_.setSelectionRange(Range.fromPoints(pos, pos));
    } else if (completion.getType() == CppCompletion.FILE) {
        char ch = docDisplay_.getCharacterAtCursor();
        // if there is a '>' or '"' following the cursor, move over it
        if (ch == '>' || ch == '"') {
            docDisplay_.moveCursorForward();
        } else // otherwise, insert the corresponding closing character
        {
            String line = docDisplay_.getCurrentLine();
            if (line.contains("<"))
                docDisplay_.insertCode(">");
            else if (line.contains("\""))
                docDisplay_.insertCode("\"");
        }
    }
    if (completion.hasParameters() && uiPrefs_.showSignatureTooltips().getValue()) {
        new CppCompletionSignatureTip(completion, docDisplay_);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)

Example 32 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class CppCompletionSignatureTip method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    allTips_.add(this);
    nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        public void onPreviewNativeEvent(NativePreviewEvent e) {
            if (e.getTypeInt() == Event.ONKEYDOWN) {
                // handle keys
                switch(e.getNativeEvent().getKeyCode()) {
                    case KeyCodes.KEY_ESCAPE:
                        e.cancel();
                        hide();
                        break;
                    case KeyCodes.KEY_DOWN:
                        e.cancel();
                        setTextIndex(currentTextIndex_ + 1);
                        break;
                    case KeyCodes.KEY_UP:
                        e.cancel();
                        setTextIndex(currentTextIndex_ - 1);
                        break;
                }
                // dismiss if we've left our anchor zone
                // (defer this so the current key has a chance to 
                // enter the editor and affect the cursor)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        Position cursorPos = docDisplay_.getCursorPosition();
                        Range anchorRange = anchor_.getRange();
                        if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
                            hide();
                        }
                    }
                });
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 33 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class TextEditingTargetIdleMonitor method beginMonitoring.

public void beginMonitoring() {
    endMonitoring();
    monitors_.add(display_.addEditorModeChangedHandler(new EditorModeChangedEvent.Handler() {

        @Override
        public void onEditorModeChanged(EditorModeChangedEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    refreshCommands();
                }
            });
        }
    }));
    monitors_.add(display_.addCursorChangedHandler(new CursorChangedHandler() {

        @Override
        public void onCursorChanged(CursorChangedEvent event) {
            mouseMovedLast_ = false;
            timer_.schedule(DELAY_MS);
        }
    }));
    monitors_.add(display_.addAttachHandler(new AttachEvent.Handler() {

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            if (!event.isAttached())
                onDetach();
        }
    }));
}
Also used : EditorModeChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.EditorModeChangedEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) AttachEvent(com.google.gwt.event.logical.shared.AttachEvent) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent)

Example 34 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class TextEditingTargetPresentationHelper method navigateToSlide.

public static void navigateToSlide(final EditingTarget editor, int slideIndex) {
    // scan for the specified slide
    int currentSlide = 0;
    Position navPos = null;
    Position pos = Position.create(0, 0);
    while ((pos = editor.search(pos, "^\\={3,}\\s*$")) != null) {
        if (currentSlide++ == slideIndex) {
            navPos = Position.create(pos.getRow() - 1, 0);
            break;
        }
        pos = Position.create(pos.getRow() + 1, 0);
    }
    // navigate to the slide
    if (navPos != null) {
        final Position navPosAlias = navPos;
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                editor.navigateToPosition(SourcePosition.create(navPosAlias.getRow(), 0), false);
            }
        });
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition)

Example 35 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class ChangelistTable method setItems.

public void setItems(ArrayList<StatusAndPath> items) {
    setProgress(false);
    table_.setPageSize(items.size());
    dataProvider_.getList().clear();
    dataProvider_.getList().addAll(items);
    ColumnSortEvent.fire(table_, table_.getColumnSortList());
    if (selectFirstItemByDefault_) {
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                if (table_.getVisibleItemCount() > 0 && selectionModel_.getSelectedSet().isEmpty()) {
                    selectionModel_.setSelected(table_.getVisibleItem(0), true);
                }
            }
        });
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)105 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)7 Element (com.google.gwt.dom.client.Element)6 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)6 JsArray (com.google.gwt.core.client.JsArray)5 Command (com.google.gwt.user.client.Command)5 ServerError (org.rstudio.studio.client.server.ServerError)5 JsArrayString (com.google.gwt.core.client.JsArrayString)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 Event (com.google.gwt.user.client.Event)3 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)3 Timer (com.google.gwt.user.client.Timer)3 WindowEx (org.rstudio.core.client.dom.WindowEx)3 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)3 ErrorDialog (com.google.gerrit.client.ErrorDialog)2 OnEditEnabler (com.google.gerrit.client.ui.OnEditEnabler)2