Skip to content

Commit

Permalink
Warn user when they're exporting without changes being made
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Mar 8, 2024
1 parent ff67309 commit 9c7d2ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.ui.config;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import software.coley.observables.ObservableBoolean;
Expand All @@ -23,6 +24,7 @@ public class ExportConfig extends BasicConfigContainer {
= new ObservableObject<>(WorkspaceExportOptions.CompressType.MATCH_ORIGINAL);
private final ObservableBoolean bundleSupportingResources = new ObservableBoolean(false);
private final ObservableBoolean createZipDirEntries = new ObservableBoolean(true);
private final ObservableBoolean warnNoChanges = new ObservableBoolean(true);

@Inject
public ExportConfig() {
Expand All @@ -31,18 +33,21 @@ public ExportConfig() {
addValue(new BasicConfigValue<>("compression", WorkspaceExportOptions.CompressType.class, compression));
addValue(new BasicConfigValue<>("bundle-supporting-resources", boolean.class, bundleSupportingResources));
addValue(new BasicConfigValue<>("create-zip-dir-entries", boolean.class, createZipDirEntries));
addValue(new BasicConfigValue<>("warn-no-changes", boolean.class, warnNoChanges));
}

/**
* @return Compression type to use when exporting workspaces.
*/
@Nonnull
public ObservableObject<WorkspaceExportOptions.CompressType> getCompression() {
return compression;
}

/**
* @return {@code true} to include {@link Workspace#getSupportingResources()} in the output.
*/
@Nonnull
public ObservableBoolean getBundleSupportingResources() {
return bundleSupportingResources;
}
Expand All @@ -55,7 +60,16 @@ public ObservableBoolean getBundleSupportingResources() {
*
* @return {@code true} to create ZIP entries for directory paths.
*/
@Nonnull
public ObservableBoolean getCreateZipDirEntries() {
return createZipDirEntries;
}

/**
* @return {@code true} to warn users when no changes were made prior to exporting.
*/
@Nonnull
public ObservableBoolean getWarnNoChanges() {
return warnNoChanges;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import org.kordamp.ikonli.carbonicons.CarbonIcons;
import org.slf4j.Logger;
import software.coley.observables.ObservableString;
import software.coley.recaf.analytics.logging.Logging;
import software.coley.recaf.info.JvmClassInfo;
import software.coley.recaf.services.workspace.WorkspaceManager;
import software.coley.recaf.ui.config.ExportConfig;
import software.coley.recaf.ui.config.RecentFilesConfig;
import software.coley.recaf.ui.control.FontIconView;
import software.coley.recaf.util.ErrorDialogs;
import software.coley.recaf.util.Icons;
import software.coley.recaf.util.Lang;
import software.coley.recaf.services.workspace.io.WorkspaceExportOptions;
import software.coley.recaf.services.workspace.io.WorkspaceExporter;
Expand Down Expand Up @@ -66,8 +72,21 @@ public void exportCurrent() {
* Workspace to export.
*/
public void export(@Nonnull Workspace workspace) {
// Prompt a path for the user to write to.
// Check if the user hasn't made any changes. Plenty of people have not understood that their changes weren't
// saved for one reason or another (the amount of people seeing a red flash thinking that is fine is crazy)
WorkspaceResource primaryResource = workspace.getPrimaryResource();
boolean noChangesFound = exportConfig.getWarnNoChanges().getValue() && primaryResource.bundleStream()
.allMatch(b -> b.getDirtyKeys().isEmpty());
if (noChangesFound) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, Lang.get("dialog.file.nochanges"), ButtonType.YES, ButtonType.NO);
alert.setTitle(Lang.get("dialog.title.nochanges"));
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(Icons.getImage(Icons.LOGO));
if (alert.showAndWait().orElse(ButtonType.NO) != ButtonType.YES)
return;
}

// Prompt a path for the user to write to.
ObservableString lastWorkspaceExportDir = recentFilesConfig.getLastWorkspaceExportDirectory();
File lastExportDir = lastWorkspaceExportDir.unboxingMap(File::new);
File selectedPath;
Expand Down
3 changes: 3 additions & 0 deletions recaf-ui/src/main/resources/translations/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ dialog.unknownextension=Unknown file extension. Do you want to configure a langu
## File chooser
dialog.title.primary=Primary resource
dialog.title.supporting=Supporting resources
dialog.title.nochanges=Export without changes?
dialog.file.open=Open
dialog.file.open.directory=Directories
dialog.file.open.file=Files
dialog.file.export=Export
dialog.file.save=Save
dialog.file.nothing=Nothing selected
dialog.file.nochanges=Do you want to export the application even though no changes were made?
dialog.filefilter.any=Any type
dialog.filefilter.mapping=Mappings
dialog.filefilter.input=Applications
Expand Down Expand Up @@ -666,6 +668,7 @@ service.io.export-config=Exporting
service.io.export-config.bundle-supporting-resources=Bundle supporting resources into output
service.io.export-config.compression=Compression strategy for contents of output
service.io.export-config.create-zip-dir-entries=Create ZIP 'directory' entries in output
service.io.export-config.warn-no-changes=Warn on exporting without any changes made
service.io.gson-provider-config=Json
service.io.gson-provider-config.pretty-print=Pretty printing
service.io.info-importer-config=Content importing
Expand Down

0 comments on commit 9c7d2ef

Please sign in to comment.