Search in sources :

Example 6 with UnsavedChangesTarget

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;
}
Also used : IdentityColumn(com.google.gwt.user.cellview.client.IdentityColumn) Column(com.google.gwt.user.cellview.client.Column) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) CheckboxCell(com.google.gwt.cell.client.CheckboxCell)

Example 7 with UnsavedChangesTarget

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();
        }
    }
}
Also used : UnsavedChangesDialog(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) Result(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)

Example 8 with UnsavedChangesTarget

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);
}
Also used : ApplicationQuit(org.rstudio.studio.client.application.ApplicationQuit) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) Command(com.google.gwt.user.client.Command) Scheduler(com.google.gwt.core.client.Scheduler) Operation(org.rstudio.core.client.widget.Operation)

Example 9 with UnsavedChangesTarget

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);
}
Also used : UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ArrayList(java.util.ArrayList) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)

Aggregations

UnsavedChangesTarget (org.rstudio.studio.client.workbench.model.UnsavedChangesTarget)9 Command (com.google.gwt.user.client.Command)4 UnsavedChangesItem (org.rstudio.studio.client.workbench.model.UnsavedChangesItem)3 Column (com.google.gwt.user.cellview.client.Column)2 IdentityColumn (com.google.gwt.user.cellview.client.IdentityColumn)2 ArrayList (java.util.ArrayList)2 Operation (org.rstudio.core.client.widget.Operation)2 UnsavedChangesDialog (org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog)2 Result (org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)2 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)1 ImageResourceCell (com.google.gwt.cell.client.ImageResourceCell)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Scheduler (com.google.gwt.core.client.Scheduler)1 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 Label (com.google.gwt.user.client.ui.Label)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1