use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class SourceWindow method closeSourceWindow.
private void closeSourceWindow() {
final ApplicationQuit.QuitContext quitContext = new ApplicationQuit.QuitContext() {
@Override
public void onReadyToQuit(boolean saveChanges) {
markReadyToClose();
// we may be in the middle of closing the window already, so
// defer the closure request
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
WindowEx.get().close();
}
});
}
};
// collect titled and untitled changes -- we don't prompt for untitled
// changes in the main window, but we do in the source window
ArrayList<UnsavedChangesTarget> untitled = sourceShim_.getUnsavedChanges(Source.TYPE_UNTITLED);
ArrayList<UnsavedChangesTarget> fileBacked = sourceShim_.getUnsavedChanges(Source.TYPE_FILE_BACKED);
if (Desktop.isDesktop() && untitled.size() > 0) {
// so handle that gracefully
if (fileBacked.size() == 0 && untitled.size() == 1) {
sourceShim_.saveWithPrompt(untitled.get(0), new Command() {
@Override
public void execute() {
quitContext.onReadyToQuit(false);
}
}, null);
return;
} else {
// if we have multiple unsaved untitled targets or a mix of untitled
// and file backed targets, we just fall back to a generic prompt
RStudioGinjector.INSTANCE.getGlobalDisplay().showYesNoMessage(GlobalDisplay.MSG_WARNING, "Unsaved Changes", "There are unsaved documents in this window. Are you sure " + "you want to close it?", // include cancel
false, new Operation() {
@Override
public void execute() {
quitContext.onReadyToQuit(false);
}
}, null, null, "Close and Discard Changes", "Cancel", false);
return;
}
}
// prompt to save any unsaved documents
if (fileBacked.size() == 0)
quitContext.onReadyToQuit(false);
else
ApplicationQuit.handleUnsavedChanges(SaveAction.SAVEASK, "Close Source Window", false, sourceShim_, null, null, quitContext);
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class Source method openFile.
// top-level wrapper for opening files. takes care of:
// - making sure the view is visible
// - checking whether it is already open and re-selecting its tab
// - prohibit opening very large files (>500KB)
// - confirmation of opening large files (>100KB)
// - finally, actually opening the file from the server
// via the call to the lower level openFile method
private void openFile(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
ensureVisible(true);
if (fileType.isRNotebook()) {
openNotebook(file, fileType, resultCallback);
return;
}
if (file == null) {
newDoc(fileType, resultCallback);
return;
}
if (openFileAlreadyOpen(file, resultCallback))
return;
EditingTarget target = editingTargetSource_.getEditingTarget(fileType);
if (file.getLength() > target.getFileSizeLimit()) {
if (resultCallback != null)
resultCallback.onCancelled();
showFileTooLargeWarning(file, target.getFileSizeLimit());
} else if (file.getLength() > target.getLargeFileSize()) {
confirmOpenLargeFile(file, new Operation() {
public void execute() {
openFileFromServer(file, fileType, resultCallback);
}
}, new Operation() {
public void execute() {
// user (wisely) cancelled
if (resultCallback != null)
resultCallback.onCancelled();
}
});
} else {
openFileFromServer(file, fileType, resultCallback);
}
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class TerminalTabPresenter method confirmClose.
public void confirmClose(final Command onConfirmed) {
if (view_.activeTerminals()) {
globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Close Terminal(s) ", "Are you sure you want to close all terminals? Any running jobs " + "will be stopped.", false, new Operation() {
@Override
public void execute() {
shutDownTerminals();
onConfirmed.execute();
}
}, null, null, "Close Terminals", "Cancel", true);
} else {
shutDownTerminals();
onConfirmed.execute();
}
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class CreateBranchToolbarButton method promptUserRegardingLocalBranchOfSameName.
private boolean promptUserRegardingLocalBranchOfSameName(final CreateBranchDialog.Input input, final BranchesInfo branchesInfo) {
boolean hasBranch = false;
for (String branch : JsUtil.asIterable(branchesInfo.getBranches())) {
if (branch.equals(input.getBranch())) {
hasBranch = true;
break;
}
}
if (hasBranch) {
String message = "A local branch named '" + input.getBranch() + "' already exists. " + "Would you like to check out that branch, or overwrite it?";
List<String> labels = new ArrayList<String>();
labels.add("Checkout");
labels.add("Overwrite");
labels.add("Cancel");
List<Operation> operations = new ArrayList<Operation>();
operations.add(new Operation() {
@Override
public void execute() {
onCheckout(input);
}
});
operations.add(new Operation() {
@Override
public void execute() {
onCreate(input);
}
});
operations.add(new Operation() {
@Override
public void execute() {
// no-op
}
});
globalDisplay_.showGenericDialog(MessageDialog.INFO, "Local Branch Already Exists", message, labels, operations, 2);
}
return hasBranch;
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class GitPresenter method doRevert.
private void doRevert(final ArrayList<String> revertList, final Command onRevertConfirmed) {
String noun = revertList.size() == 1 ? "file" : "files";
globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_WARNING, "Revert Changes", "Changes to the selected " + noun + " will be lost, including " + "staged changes.\n\nAre you sure you want to continue?", new Operation() {
@Override
public void execute() {
if (onRevertConfirmed != null)
onRevertConfirmed.execute();
server_.gitRevert(revertList, new SimpleRequestCallback<Void>("Revert Changes"));
}
}, false);
}
Aggregations