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_);
}
}
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();
}
}
});
}
}
});
}
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();
}
}));
}
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);
}
});
}
}
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);
}
}
});
}
}
Aggregations