use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class TerminalSession method sendUserInput.
/**
* Send user input to the server, breaking down into chunks. We do this
* for when a large amount of text is pasted into the terminal; we don't
* want to overwhelm the RPC.
* @param userInput string to send
*/
private void sendUserInput() {
final int MAXCHUNK = 128;
String userInput;
if (inputQueue_.length() == 0) {
return;
}
if (inputQueue_.length() > MAXCHUNK) {
userInput = inputQueue_.substring(0, MAXCHUNK);
inputQueue_.delete(0, MAXCHUNK);
} else {
userInput = inputQueue_.toString();
inputQueue_.setLength(0);
}
// message so server can put messages back in order
if (BrowseCap.isWindowsDesktop()) {
if (inputSequence_ == ShellInput.IGNORE_SEQUENCE) {
// First message sent for this client-side terminal instance, start
// by flushing the server-side queue to reset server's "last-sequence"
// back to default.
inputSequence_ = ShellInput.FLUSH_SEQUENCE;
} else if (inputSequence_ == ShellInput.FLUSH_SEQUENCE) {
// Last message has flushed server, start tracking sequences again.
inputSequence_ = 0;
} else if (inputSequence_ >= Integer.MAX_VALUE - 100) {
// Very diligent typist! Tell server to flush its input
// queue, temporarily ignoring sequences.
inputSequence_ = ShellInput.FLUSH_SEQUENCE;
} else {
inputSequence_++;
}
}
socket_.dispatchInput(inputSequence_, userInput, new VoidServerRequestCallback() {
@Override
public void onResponseReceived(Void response) {
sendUserInput();
}
@Override
public void onError(ServerError error) {
writeError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class EnvironmentPresenter method onClearWorkspace.
void onClearWorkspace() {
view_.bringToFront();
final List<String> objectNames = view_.getSelectedObjects();
new ClearAllDialog(objectNames.size(), new ProgressOperationWithInput<Boolean>() {
@Override
public void execute(Boolean includeHidden, ProgressIndicator indicator) {
indicator.onProgress("Removing objects...");
if (objectNames.size() == 0) {
server_.removeAllObjects(includeHidden, new VoidServerRequestCallback(indicator) {
@Override
public void onSuccess() {
view_.clearSelection();
view_.clearObjects();
}
});
} else {
server_.removeObjects(objectNames, new VoidServerRequestCallback(indicator) {
@Override
public void onSuccess() {
view_.clearSelection();
for (String obj : objectNames) {
view_.removeObject(obj);
}
}
});
}
}
}).showModal();
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class EditSnippetsDialog method attemptSaveAndClose.
private void attemptSaveAndClose() {
// record pending edits
recordEditorState();
// check for edits we need to save
JsArray<SnippetData> changedSnippets = JsArray.createArray().cast();
for (int i = 0; i < snippetTypes_.getItemCount(); i++) {
EditableSnippets snippets = snippetTypes_.getItemAtIdx(i);
String edits = snippets.getPendingEdits();
if (edits != null) {
String mode = snippets.getEditorMode();
JavaScriptException ex = SnippetHelper.loadSnippetsForMode(mode, edits);
if (ex != null) {
snippetTypes_.setSelectedIndex(i);
globalDisplay_.showErrorMessage("Error Applying Snippets (" + snippets.getFileTypeLabel() + ")", ex.getDescription());
// early return (don't close dialog)
return;
}
changedSnippets.push(SnippetData.create(mode, edits));
}
}
// perform the save then close the dialog
if (changedSnippets.length() > 0) {
server_.saveSnippets(changedSnippets, new VoidServerRequestCallback() {
@Override
protected void onSuccess() {
closeDialog();
}
});
} else {
closeDialog();
}
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class ApplicationInterrupt method interruptR.
public void interruptR(final InterruptHandler handler) {
if (interruptRequestCounter_ == 0) {
interruptRequestCounter_ = 1;
interruptUnresponsiveTimer_ = new Timer() {
@Override
public void run() {
showInterruptUnresponsiveDialog();
}
};
interruptUnresponsiveTimer_.schedule(10000);
eventBus_.fireEvent(new InterruptStatusEvent(InterruptStatusEvent.INTERRUPT_INITIATED));
server_.interrupt(new VoidServerRequestCallback() {
@Override
public void onSuccess() {
eventBus_.fireEvent(new InterruptStatusEvent(InterruptStatusEvent.INTERRUPT_COMPLETED));
finishInterrupt(handler);
}
@Override
public void onFailure() {
finishInterrupt(handler);
}
});
} else {
interruptRequestCounter_++;
if (interruptRequestCounter_ >= 3) {
interruptUnresponsiveTimer_.cancel();
showInterruptUnresponsiveDialog();
}
}
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class ApplicationQuit method onSuspendAndRestart.
@Override
public void onSuspendAndRestart(final SuspendAndRestartEvent event) {
// Ignore nested restarts once restart starts
if (suspendingAndRestarting_)
return;
// set restart pending for desktop
setPendinqQuit(DesktopFrame.PENDING_QUIT_AND_RESTART);
final TimedProgressIndicator progress = new TimedProgressIndicator(globalDisplay_.getProgressIndicator("Error"));
progress.onTimedProgress("Restarting R", 1000);
final Operation onRestartComplete = new Operation() {
@Override
public void execute() {
suspendingAndRestarting_ = false;
progress.onCompleted();
}
};
// perform the suspend and restart
suspendingAndRestarting_ = true;
eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_INITIATED));
server_.suspendForRestart(event.getSuspendOptions(), new VoidServerRequestCallback() {
@Override
protected void onSuccess() {
// send pings until the server restarts
sendPing(event.getAfterRestartCommand(), 200, 25, new Command() {
@Override
public void execute() {
onRestartComplete.execute();
eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
}
});
}
@Override
protected void onFailure() {
onRestartComplete.execute();
eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
setPendinqQuit(DesktopFrame.PENDING_QUIT_NONE);
}
});
}
Aggregations