use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class Files method onRenameFile.
@Handler
void onRenameFile() {
// get currently selected files
ArrayList<FileSystemItem> selectedFiles = view_.getSelectedFiles();
// validation: some selection exists
if (selectedFiles.size() == 0)
return;
// validation: no more than one file selected
if (selectedFiles.size() > 1) {
globalDisplay_.showErrorMessage("Invalid Selection", "Please select only one file to rename");
return;
}
// validation -- not prohibited move of public folder
if (!validateNotRestrictedFolder(selectedFiles, "renamed"))
return;
// prompt for new file name then execute the rename
final FileSystemItem file = selectedFiles.get(0);
globalDisplay_.promptForText("Rename File", "Please enter the new file name:", file.getName(), 0, file.getStem().length(), null, new ProgressOperationWithInput<String>() {
public void execute(String input, final ProgressIndicator progress) {
progress.onProgress("Renaming file...");
String path = file.getParentPath().completePath(input);
final FileSystemItem target = file.isDirectory() ? FileSystemItem.createDir(path) : FileSystemItem.createFile(path);
// clear selection
view_.selectNone();
// premptively rename in the UI then fallback to refreshing
// the view if there is an error
view_.renameFile(file, target);
// execute on the server
server_.renameFile(file, target, new VoidServerRequestCallback(progress) {
@Override
protected void onSuccess() {
// if we were successful, let editor know
if (!file.isDirectory()) {
eventBus_.fireEvent(new SourcePathChangedEvent(file.getPath(), target.getPath()));
}
}
@Override
protected void onFailure() {
onRefreshFiles();
}
});
}
});
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class History method onHistorySendToConsole.
@Handler
void onHistorySendToConsole() {
String commandString = getSelectedCommands();
commandString = StringUtil.chomp(commandString);
if (commandString.length() > 0)
events_.fireEvent(new SendToConsoleEvent(commandString, false));
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class History method onClearHistory.
@Handler
void onClearHistory() {
view_.bringToFront();
globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_WARNING, "Confirm Clear History", "Are you sure you want to clear all history entries?", new ProgressOperation() {
public void execute(final ProgressIndicator indicator) {
indicator.onProgress("Clearing history...");
server_.clearHistory(new VoidServerRequestCallback(indicator));
}
}, true);
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class ProfilerPresenter method onStartProfiler.
@Handler
public void onStartProfiler() {
dependencyManager_.withProfvis(profilerDependecyUserAction_, new Command() {
@Override
public void execute() {
ProfileOperationRequest request = ProfileOperationRequest.create("");
server_.startProfiling(request, new ServerRequestCallback<ProfileOperationResponse>() {
@Override
public void onResponseReceived(ProfileOperationResponse response) {
if (response.getErrorMessage() != null) {
globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
return;
}
pSourceWindowManager_.get().ensureVisibleSourcePaneIfNecessary();
response_ = response;
sourceServer_.newDocument(FileTypeRegistry.PROFILER.getTypeId(), null, (JsObject) ProfilerContents.create(response.getFileName(), null, null, true).cast(), new SimpleRequestCallback<SourceDocument>("Show Profiler") {
@Override
public void onResponseReceived(SourceDocument response) {
currentDocId_ = response.getId();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
globalDisplay_.showErrorMessage("Failed to Stop Profiler", error.getMessage());
}
});
}
});
}
use of org.rstudio.core.client.command.Handler in project rstudio by rstudio.
the class ProfilerPresenter method onStopProfiler.
@Handler
public void onStopProfiler() {
ProfileOperationRequest request = ProfileOperationRequest.create(response_ != null ? response_.getFileName() : null);
response_ = null;
server_.stopProfiling(request, new ServerRequestCallback<ProfileOperationResponse>() {
@Override
public void onResponseReceived(ProfileOperationResponse response) {
if (response.getErrorMessage() != null) {
globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
return;
}
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
globalDisplay_.showErrorMessage("Failed to Stop Profiler", error.getMessage());
}
});
}
Aggregations