Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-only */
package de.uka.ilkd.key.settings;

import java.io.File;
import java.util.*;

import org.slf4j.Logger;
Expand Down Expand Up @@ -43,20 +44,30 @@ public class GeneralSettings extends AbstractSettings {
public static final String RIGHT_CLICK_MACROS_KEY = "RightClickMacros";
public static final String AUTO_SAVE = "AutoSavePeriod";

public static final String LAST_USED_PATH = "LastUsedPath";

/**
* The key for storing the ensureSourceConsistency flag in settings
*/
private static final String ENSURE_SOURCE_CONSISTENCY = "EnsureSourceConsistency";

/** Whether automatic proof search uses the multi-core (parallel) prover. */
/**
* Whether automatic proof search uses the multi-core (parallel) prover.
*/
public static final String PARALLEL_PROVER_ENABLED = "ParallelProverEnabled";
/** The number of worker threads the multi-core prover uses. */
/**
* The number of worker threads the multi-core prover uses.
*/
public static final String PARALLEL_PROVER_THREADS = "ParallelProverThreadCount";

/** Default worker count when the multi-core prover is first enabled. */
/**
* Default worker count when the multi-core prover is first enabled.
*/
public static final int PARALLEL_PROVER_THREADS_DEFAULT = 4;

/** Default value for {@link #getJmlEnabledKeys()} */
/**
* Default value for {@link #getJmlEnabledKeys()}
*/
public static final Set<String> JML_ENABLED_KEYS_DEFAULT = Set.of("key");

private Set<String> jmlEnabledKeys = new TreeSet<>(JML_ENABLED_KEYS_DEFAULT);
Expand Down Expand Up @@ -86,6 +97,11 @@ public class GeneralSettings extends AbstractSettings {
*/
private int autoSave = 0;

/**
*
*/
private String lastUsedPath;

/**
* If enabled, source files are cached at first use to ensure consistency between proof and
* source code. Toggles between SimpleFilerepo (false) and DiskFileRepo (true).
Expand Down Expand Up @@ -218,6 +234,30 @@ public void setParallelProverThreadCount(int count) {
firePropertyChange(PARALLEL_PROVER_THREADS, old, parallelProverThreadCount);
}

public void setLastUsedPath(File f) {
setLastUsedPath(f.getAbsolutePath());
}

public void setLastUsedPath(String absolutePath) {
var old = lastUsedPath;
lastUsedPath = absolutePath;
firePropertyChange(LAST_USED_PATH, old, lastUsedPath);
}

public File getLastUsedPath() {
if (lastUsedPath == null) {
setLastUsedPath(new File("."));
}
return new File(lastUsedPath);
}

public File getLastUsedPathEnsureFolder() {
if (getLastUsedPath().isFile())
return getLastUsedPath().getParentFile();
else
return getLastUsedPath();
}

/**
* gets a Properties object and has to perform the necessary steps in order to change this
* object in a way that it represents the stored settings
Expand Down Expand Up @@ -340,6 +380,8 @@ public void readSettings(Configuration props) {
} else {
setJmlEnabledKeys(new TreeSet<>(props.getStringList(KEY_JML_ENABLED_KEYS)));
}

setLastUsedPath(props.getString(LAST_USED_PATH, new File(".").getAbsolutePath()));
}

@Override
Expand All @@ -354,4 +396,6 @@ public void writeSettings(Configuration props) {
props.set(PARALLEL_PROVER_THREADS, parallelProverThreadCount);
props.set(KEY_JML_ENABLED_KEYS, jmlEnabledKeys.stream().toList());
}


}
18 changes: 0 additions & 18 deletions key.ui/src/main/java/de/uka/ilkd/key/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,24 +533,6 @@ private static File createTempDirectory() throws IOException {
return tempDir;
}

/**
* Used by {@link de.uka.ilkd.key.gui.KeYFileChooser} (and potentially others)
* to determine
* working directory. In case there is at least one location (i.e. a file or
* directory)
* specified as command line argument, working directory is determined based on
* first location
* that occurred in the list of arguments. Otherwise, value of
* System.getProperty("user.home")
* is used to determine working directory.
*
* @return {@link File} object representing working directory.
*/
public static Path getWorkingDir() {
return workingDir;
}


/**
* Perform necessary actions before loading any problem files. Currently only
* performs RIFL to JML transformation.
Expand Down
24 changes: 20 additions & 4 deletions key.ui/src/main/java/de/uka/ilkd/key/gui/KeYFileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import de.uka.ilkd.key.core.Main;
import de.uka.ilkd.key.settings.ProofIndependentSettings;

import org.key_project.util.java.IOUtil;

import org.jspecify.annotations.Nullable;

/**
* Extends the usual Swing file chooser by a bookmark panel and predefined filters. This class is a
* singleton, the only instance is created lazily and can be obtained via
Expand Down Expand Up @@ -307,10 +309,12 @@ private int showOverwriteDialog(File file) {
*
* @return the key file chooser
*/
public static KeYFileChooser getFileChooser(String title) {
public static KeYFileChooser getFileChooser(String title, @Nullable File startFolder) {
if (INSTANCE == null) {
File initDir = Main.getWorkingDir().toFile();
INSTANCE = new KeYFileChooser(initDir);
INSTANCE = new KeYFileChooser(startFolder == null
? ProofIndependentSettings.DEFAULT_INSTANCE.getGeneralSettings()
.getLastUsedPath()
: startFolder);

// not the best design probably: this constructor has the side effect of connecting
// the new bookmark panel to the file chooser.
Expand All @@ -321,4 +325,16 @@ public static KeYFileChooser getFileChooser(String title) {
INSTANCE.prepare();
return INSTANCE;
}

/**
* Convenience overload of {@link #getFileChooser(String, File)} that starts from the last used
* path remembered in the settings instead of an explicit start folder.
*
* @param title the title of the key file chooser
* @return the key file chooser, as described in {@link #getFileChooser(String, File)}
* @see #getFileChooser(String, File)
*/
public static KeYFileChooser getFileChooser(String title) {
return getFileChooser(title, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.nio.file.Path;
import javax.swing.*;

import de.uka.ilkd.key.core.Main;
import de.uka.ilkd.key.gui.KeYFileChooser;
import de.uka.ilkd.key.gui.KeYFileChooserLoadingOptions;
import de.uka.ilkd.key.gui.MainWindow;
Expand All @@ -24,14 +23,14 @@ public OpenFileAction(MainWindow mainWindow) {
setName("Load...");
setIcon(IconFactory.openKeYFile(MainWindow.TOOLBAR_ICON_SIZE));
setTooltip("Browse and load problem or proof files.");
lastSelectedPath = Main.getWorkingDir().toFile();
lastSelectedPath =
ProofIndependentSettings.DEFAULT_INSTANCE.getGeneralSettings().getLastUsedPath();
}

public void actionPerformed(ActionEvent e) {
KeYFileChooser fc = new KeYFileChooser(lastSelectedPath);
KeYFileChooser fc =
KeYFileChooser.getFileChooser("Select file to load proof or problem", lastSelectedPath);
fc.setDialogTitle("Select file to load proof or problem");
fc.setSelectedFile(KeYFileChooser.getFileChooser("Select file to load proof or problem")
.getSelectedFile());
KeYFileChooserLoadingOptions options = fc.addLoadingOptions();
fc.addBookmarkPanel();
fc.prepare();
Expand All @@ -42,6 +41,8 @@ public void actionPerformed(ActionEvent e) {
if (result == JFileChooser.APPROVE_OPTION) {
Path file = fc.getSelectedFile().toPath();
lastSelectedPath = fc.getSelectedFile();
ProofIndependentSettings.DEFAULT_INSTANCE.getGeneralSettings()
.setLastUsedPath(lastSelectedPath);

// special case proof bundles -> allow to select the proof to load
if (ProofSelectionDialog.isProofBundle(file)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import de.uka.ilkd.key.control.RuleCompletionHandler;
import de.uka.ilkd.key.control.UserInterfaceControl;
import de.uka.ilkd.key.core.KeYMediator;
import de.uka.ilkd.key.core.Main;
import de.uka.ilkd.key.gui.notification.events.NotificationEvent;
import de.uka.ilkd.key.informationflow.macros.StartSideProofMacro;
import de.uka.ilkd.key.macros.ProofMacro;
Expand All @@ -30,6 +29,7 @@
import de.uka.ilkd.key.proof.mgt.ProofEnvironmentEvent;
import de.uka.ilkd.key.proof.mgt.ProofEnvironmentListener;
import de.uka.ilkd.key.prover.impl.DefaultTaskStartedInfo;
import de.uka.ilkd.key.settings.ProofIndependentSettings;
import de.uka.ilkd.key.util.KeYResourceManager;
import de.uka.ilkd.key.util.MiscTools;
import de.uka.ilkd.key.util.ThreadUtilities;
Expand Down Expand Up @@ -211,7 +211,8 @@ private void saveSideProof(Proof proof) {
if (proof.getProofFile() != null) {
proofFolder = proof.getProofFile().getParent();
} else { // happens when a Java file is loaded
proofFolder = Main.getWorkingDir();
proofFolder = ProofIndependentSettings.DEFAULT_INSTANCE.getGeneralSettings()
.getLastUsedPathEnsureFolder().toPath();
}
final Path toSave = proofFolder.resolve(filename);
final KeYResourceManager krm = KeYResourceManager.getManager();
Expand Down
Loading