use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.
the class UnsavedChangesDialog method addSelectionColumn.
private Column<UnsavedChangesTarget, Boolean> addSelectionColumn() {
Column<UnsavedChangesTarget, Boolean> checkColumn = new Column<UnsavedChangesTarget, Boolean>(new CheckboxCell(true, false)) {
@Override
public Boolean getValue(UnsavedChangesTarget object) {
return selectionModel_.isSelected(object);
}
};
checkColumn.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
targetsCellTable_.addColumn(checkColumn);
targetsCellTable_.setColumnWidth(checkColumn, 25, Unit.PX);
return checkColumn;
}
use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.
the class SourceBuildHelper method withSaveFilesBeforeCommand.
private void withSaveFilesBeforeCommand(final Command command, final Command cancelCommand, String commandSource) {
if (uiPrefs_.saveAllBeforeBuild().getValue()) {
sourceShim_.saveAllUnsaved(command);
} else {
String alwaysSaveOption = !uiPrefs_.saveAllBeforeBuild().getValue() ? "Always save files before build" : null;
ArrayList<UnsavedChangesTarget> unsavedSourceDocs = sourceShim_.getUnsavedChanges(Source.TYPE_FILE_BACKED);
if (unsavedSourceDocs.size() > 0) {
new UnsavedChangesDialog(commandSource, alwaysSaveOption, unsavedSourceDocs, new OperationWithInput<UnsavedChangesDialog.Result>() {
@Override
public void execute(Result result) {
if (result.getAlwaysSave()) {
uiPrefs_.saveAllBeforeBuild().setGlobalValue(true);
uiPrefs_.writeUIPrefs();
}
sourceShim_.handleUnsavedChangesBeforeExit(result.getSaveTargets(), command);
}
}, cancelCommand).showModal();
} else {
command.execute();
}
}
}
use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget 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.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.
the class Source method saveChanges.
private void saveChanges(ArrayList<UnsavedChangesTarget> targets, Command onCompleted) {
// convert back to editing targets
ArrayList<EditingTarget> saveTargets = new ArrayList<EditingTarget>();
for (UnsavedChangesTarget target : targets) {
EditingTarget saveTarget = getEditingTargetForId(target.getId());
if (saveTarget != null)
saveTargets.add(saveTarget);
}
// execute the save
cpsExecuteForEachEditor(// targets the user chose to save
saveTargets, // save each editor
new CPSEditingTargetCommand() {
@Override
public void execute(EditingTarget saveTarget, Command continuation) {
saveTarget.save(continuation);
}
}, // onCompleted at the end
onCompleted);
}
Aggregations