Skip to content

Commit

Permalink
default to not saving all files before build but allow easy opt-in fr…
Browse files Browse the repository at this point in the history
…om unsaved changes dialog
  • Loading branch information
jjallaire committed Jul 16, 2012
1 parent 46cfb17 commit 87976a8
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.model.UnsavedChangesTarget;
import org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog;
import org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result;
import org.rstudio.studio.client.workbench.views.source.SourceShim;

import com.google.gwt.resources.client.ImageResource;
Expand Down Expand Up @@ -161,11 +162,14 @@ public void execute()
new UnsavedChangesDialog(
caption,
unsaved,
new OperationWithInput<ArrayList<UnsavedChangesTarget>>() {
new OperationWithInput<UnsavedChangesDialog.Result>() {

@Override
public void execute(ArrayList<UnsavedChangesTarget> saveTargets)
public void execute(Result result)
{
ArrayList<UnsavedChangesTarget> saveTargets =
result.getSaveTargets();

// remote global env target from list (if specified) and
// compute the saveChanges value
boolean saveGlobalEnv = saveAction == SaveAction.SAVE;
Expand Down Expand Up @@ -253,13 +257,13 @@ else if (unsavedSourceDocs.size() > 1)
new UnsavedChangesDialog(
"Quit R Session",
unsavedSourceDocs,
new OperationWithInput<ArrayList<UnsavedChangesTarget>>() {
new OperationWithInput<UnsavedChangesDialog.Result>() {
@Override
public void execute(ArrayList<UnsavedChangesTarget> targets)
public void execute(Result result)
{
// save specified documents and then quit
sourceShim_.handleUnsavedChangesBeforeExit(
targets,
result.getSaveTargets(),
new HandleUnsavedCommand(true));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public PrefValue<Boolean> syntaxColorConsole()

public PrefValue<Boolean> saveAllBeforeBuild()
{
return bool("save_all_before_build", true);
return bool("save_files_before_build", false);
}

public PrefValue<Double> fontSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;

import org.rstudio.core.client.SafeHtmlUtil;
import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.widget.ModalDialog;
import org.rstudio.core.client.widget.Operation;
import org.rstudio.core.client.widget.OperationWithInput;
Expand All @@ -36,6 +37,7 @@
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.IdentityColumn;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
Expand All @@ -46,12 +48,45 @@
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.ProvidesKey;

public class UnsavedChangesDialog extends ModalDialog<ArrayList<UnsavedChangesTarget>>
public class UnsavedChangesDialog extends ModalDialog<UnsavedChangesDialog.Result>
{
public class Result
{
public Result(ArrayList<UnsavedChangesTarget> saveTargets,
boolean alwaysSave)
{
saveTargets_ = saveTargets;
alwaysSave_ = alwaysSave;
}

public ArrayList<UnsavedChangesTarget> getSaveTargets()
{
return saveTargets_;
}

public boolean getAlwaysSave()
{
return alwaysSave_;
}

private ArrayList<UnsavedChangesTarget> saveTargets_;
private boolean alwaysSave_;
}

public UnsavedChangesDialog(
String title,
ArrayList<UnsavedChangesTarget> dirtyTargets,
final OperationWithInput<ArrayList<UnsavedChangesTarget>> saveOperation,
final OperationWithInput<Result> saveOperation,
final Command onCancelled)
{
this(title, null, dirtyTargets, saveOperation, onCancelled);
}

public UnsavedChangesDialog(
String title,
String alwaysSaveOption,
ArrayList<UnsavedChangesTarget> dirtyTargets,
final OperationWithInput<Result> saveOperation,
final Command onCancelled)
{
super(title,
Expand All @@ -63,6 +98,7 @@ public void execute()
onCancelled.execute();
}} :
null);
alwaysSaveOption_ = StringUtil.notNull(alwaysSaveOption);
targets_ = dirtyTargets;

setOkButtonCaption("Save Selected");
Expand All @@ -72,7 +108,9 @@ public void execute()
public void onClick(ClickEvent event)
{
closeDialog();
saveOperation.execute(new ArrayList<UnsavedChangesTarget>());
saveOperation.execute(new Result(
new ArrayList<UnsavedChangesTarget>(),
false));
}
}));
}
Expand Down Expand Up @@ -111,13 +149,25 @@ protected Widget createMainWidget()
scrollPanel.setStylePrimaryName(RESOURCES.styles().targetScrollPanel());
scrollPanel.setWidget(targetsCellTable_);

// always save check box (may not be shown)
chkAlwaysSave_ = new CheckBox(alwaysSaveOption_);

// main widget
VerticalPanel panel = new VerticalPanel();
Label captionLabel = new Label(
"The following files have unsaved changes:");
captionLabel.setStylePrimaryName(RESOURCES.styles().captionLabel());
panel.add(captionLabel);
panel.add(scrollPanel);
if (!StringUtil.isNullOrEmpty(alwaysSaveOption_))
{
panel.add(chkAlwaysSave_);
panel.setCellHeight(chkAlwaysSave_, "30px");
panel.setCellVerticalAlignment(chkAlwaysSave_,
HasVerticalAlignment.ALIGN_MIDDLE);

}

return panel;
}

Expand Down Expand Up @@ -198,13 +248,15 @@ private IdentityColumn<UnsavedChangesTarget> addNameAndPathColumn()
}

@Override
protected ArrayList<UnsavedChangesTarget> collectInput()
protected Result collectInput()
{
return new ArrayList<UnsavedChangesTarget>(selectionModel_.getSelectedSet());
return new Result(new ArrayList<UnsavedChangesTarget>(
selectionModel_.getSelectedSet()),
chkAlwaysSave_.getValue());
}

@Override
protected boolean validate(ArrayList<UnsavedChangesTarget> input)
protected boolean validate(Result input)
{
return true;
}
Expand Down Expand Up @@ -245,6 +297,9 @@ public Object getKey(UnsavedChangesTarget item)
private CellTable<UnsavedChangesTarget> targetsCellTable_;
private ListDataProvider<UnsavedChangesTarget> dataProvider_;
private MultiSelectionModel<UnsavedChangesTarget> selectionModel_;

private final String alwaysSaveOption_;
private CheckBox chkAlwaysSave_;


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.rstudio.studio.client.workbench.views.buildtools;

import java.util.ArrayList;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
Expand All @@ -20,15 +22,19 @@
import com.google.inject.Inject;

import org.rstudio.core.client.CommandWithArg;
import org.rstudio.core.client.widget.OperationWithInput;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.common.DelayedProgressRequestCallback;
import org.rstudio.studio.client.common.GlobalDisplay;
import org.rstudio.studio.client.common.SimpleRequestCallback;
import org.rstudio.studio.client.workbench.WorkbenchView;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.model.UnsavedChangesTarget;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedEvent;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedHandler;
import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;
import org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog;
import org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result;
import org.rstudio.studio.client.workbench.views.BasePresenter;
import org.rstudio.studio.client.workbench.views.buildtools.events.BuildCompletedEvent;
import org.rstudio.studio.client.workbench.views.buildtools.events.BuildOutputEvent;
Expand Down Expand Up @@ -225,7 +231,7 @@ private void startBuild(final String type)
{
// attempt to start a build (this will be a silent no-op if there
// is already a build running)
Command buildCommand = new Command() {
final Command buildCommand = new Command() {
@Override
public void execute()
{
Expand All @@ -245,7 +251,35 @@ public void onResponseReceived(Boolean response)
}
else
{
buildCommand.execute();
String alwaysSaveOption = !uiPrefs_.saveAllBeforeBuild().getValue() ?
"Always save files before build" : null;

ArrayList<UnsavedChangesTarget> unsavedSourceDocs =
sourceShim_.getUnsavedChanges();

new UnsavedChangesDialog(
"Build",
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(),
buildCommand);


}
},
null
).showModal();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.rstudio.studio.client.workbench.model.UnsavedChangesTarget;
import org.rstudio.studio.client.workbench.model.helper.IntStateValue;
import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;
import org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog;
import org.rstudio.studio.client.workbench.views.data.events.ViewDataEvent;
import org.rstudio.studio.client.workbench.views.data.events.ViewDataHandler;
import org.rstudio.studio.client.workbench.views.source.editors.EditingTarget;
Expand Down Expand Up @@ -126,7 +127,7 @@ void addTab(Widget widget,
void showUnsavedChangesDialog(
String title,
ArrayList<UnsavedChangesTarget> dirtyTargets,
OperationWithInput<ArrayList<UnsavedChangesTarget>> saveOperation,
OperationWithInput<UnsavedChangesDialog.Result> saveOperation,
Command onCancelled);

void ensureVisible();
Expand Down Expand Up @@ -777,12 +778,12 @@ else if (editingTargets.size() == 1)
view_.showUnsavedChangesDialog(
title,
unsavedTargets,
new OperationWithInput<ArrayList<UnsavedChangesTarget>>()
new OperationWithInput<UnsavedChangesDialog.Result>()
{
@Override
public void execute(ArrayList<UnsavedChangesTarget> targets)
public void execute(UnsavedChangesDialog.Result result)
{
saveChanges(targets, onCompleted);
saveChanges(result.getSaveTargets(), onCompleted);
}
},
onCancelled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void showOverflowPopup()
public void showUnsavedChangesDialog(
String title,
ArrayList<UnsavedChangesTarget> dirtyTargets,
OperationWithInput<ArrayList<UnsavedChangesTarget>> saveOperation,
OperationWithInput<UnsavedChangesDialog.Result> saveOperation,
Command onCancelled)
{
new UnsavedChangesDialog(title,
Expand Down

0 comments on commit 87976a8

Please sign in to comment.