Skip to content

Commit 4058aea

Browse files
committed
Notify user about backing up existing env
1 parent 409316b commit 4058aea

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/org/scijava/plugins/scripting/python/RebuildEnvironment.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import org.scijava.log.Logger;
4545
import org.scijava.plugin.Parameter;
4646
import org.scijava.plugin.Plugin;
47+
import org.scijava.ui.DialogPrompt;
48+
import org.scijava.ui.UIService;
4749

4850
/**
4951
* SciJava command wrapper to build a Python environment.
@@ -65,13 +67,31 @@ public class RebuildEnvironment implements Command {
6567
@Parameter(label = "Target directory")
6668
private File targetDir;
6769

70+
@Parameter(required = false)
71+
private UIService uiService;
72+
6873
// -- OptionsPython methods --
6974

7075
@Override
7176
public void run() {
7277
final File backupDir = new File(targetDir.getPath() + ".old");
78+
if (targetDir.exists()) {
79+
boolean confirmed = true;
80+
if (uiService != null) {
81+
String msg =
82+
"The environment directory already exists. If you continue, it will be renamed to '" +
83+
backupDir.getName() +
84+
"' (and any previous backup will be deleted). Continue?";
85+
DialogPrompt.Result result = uiService.showDialog(msg,
86+
"Confirm Environment Rebuild",
87+
DialogPrompt.MessageType.QUESTION_MESSAGE,
88+
DialogPrompt.OptionType.YES_NO_OPTION);
89+
confirmed = result == DialogPrompt.Result.YES_OPTION;
90+
}
91+
if (!confirmed) return;
92+
}
93+
// Delete the previous backup environment recursively.
7394
if (backupDir.exists()) {
74-
// Delete the previous backup environment recursively.
7595
try (Stream<Path> x = Files.walk(backupDir.toPath())) {
7696
x.sorted(Comparator.reverseOrder()).forEach(p -> {
7797
try {

0 commit comments

Comments
 (0)