Skip to content

Commit

Permalink
Remember last used format version in NewSongWizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Nianna committed Oct 9, 2024
1 parent c9fd083 commit b96cf1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/github/nianna/karedi/Settings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.nianna.karedi;

import com.github.nianna.karedi.song.tag.FormatSpecification;
import com.github.nianna.karedi.util.ColorUtils;
import javafx.scene.paint.Color;

Expand Down Expand Up @@ -36,6 +37,8 @@ public final class Settings {

private static final String NEW_SONG_WIZARD_TAGS_CREATOR_DEFAULT = "ui_new_song_wizard_tags_creator_default";

private static final String NEW_SONG_WIZARD_FORMAT_VERSION_DEFAULT = "ui_new_song_wizard_format_version_default";

private static final String TAGS_MULTIPLAYER_USE_DUETSINGER = "format_tags_multiplayer_use_duetsinger";

private static final String FORMAT_PLACE_SPACE_AFTER_WORDS = "format_whitespaces_after_words";
Expand Down Expand Up @@ -165,4 +168,18 @@ public static void setPlaceSpacesAfterWords(boolean value) {
public static boolean isPlaceSpacesAfterWords() {
return PREFERENCES.getBoolean(FORMAT_PLACE_SPACE_AFTER_WORDS, false);
}

public static void setDefaultFormatSpecificationVersion(FormatSpecification value) {
if (value != null) {
PREFERENCES.put(NEW_SONG_WIZARD_FORMAT_VERSION_DEFAULT, value.toString());
} else {
PREFERENCES.remove(NEW_SONG_WIZARD_FORMAT_VERSION_DEFAULT);
}
}

public static Optional<FormatSpecification> getDefaultFormatSpecificationVersion() {
String value = PREFERENCES.get(NEW_SONG_WIZARD_FORMAT_VERSION_DEFAULT, null);
return Optional.ofNullable(value)
.flatMap(FormatSpecification::tryParse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private boolean createSong() {
dialog.setTitle(I18N.get("dialog.creator.title"));
dialog.hideInstrumental();
dialog.hideVocals();
Settings.getDefaultFormatSpecificationVersion().ifPresent(dialog::setFormatVersion);
Optional<FilenamesEditResult> optResult = dialog.showAndWait();
if (optResult.isPresent()) {
FilenamesEditResult result = optResult.get();
Expand All @@ -60,6 +61,8 @@ private boolean createSong() {
result.getVideoFilename().ifPresent(filename -> song.setTagValue(TagKey.VIDEO, filename));
result.getInstrumentalFilename().ifPresent(filename -> song.setTagValue(TagKey.INSTRUMENTAL, filename));
result.getVocalsFilename().ifPresent(filename -> song.setTagValue(TagKey.VOCALS, filename));

Settings.setDefaultFormatSpecificationVersion(result.getFormatSpecification().orElse(null));
return true;
}
return false;
Expand Down

0 comments on commit b96cf1f

Please sign in to comment.