Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember and automatically fill-in last used creator in new song wizard #50

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
15 changes: 15 additions & 0 deletions src/main/java/com/github/nianna/karedi/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public final class Settings {

private static final String NEW_SONG_WIZARD_LIBRARY_DIR = "ui_new_song_wizard_library_dir";

private static final String NEW_SONG_WIZARD_TAGS_CREATOR_DEFAULT = "ui_new_song_wizard_tags_creator_default";

private static final Preferences PREFERENCES = Preferences.userNodeForPackage(Settings.class);

private Settings() {
Expand Down Expand Up @@ -123,4 +125,17 @@ public static Optional<File> getNewSongWizardLibraryDirectory() {
.map(File::new);
}

public static void setNewSongWizardDefaultCreator(String value) {
if (value != null && !value.isBlank()) {
PREFERENCES.put(NEW_SONG_WIZARD_TAGS_CREATOR_DEFAULT, value);
} else {
PREFERENCES.remove(NEW_SONG_WIZARD_TAGS_CREATOR_DEFAULT);
}
}

public static Optional<String> getNewSongWizardDefaultCreator() {
String value = PREFERENCES.get(NEW_SONG_WIZARD_TAGS_CREATOR_DEFAULT, null);
return Optional.ofNullable(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import com.github.nianna.karedi.Settings;
import org.controlsfx.control.textfield.TextFields;
import org.controlsfx.validation.ValidationMessage;
import org.controlsfx.validation.ValidationSupport;
Expand Down Expand Up @@ -51,6 +52,7 @@ public AddSongInfoDialog() {
getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
setResultConverter(dialogButtonType -> {
if (dialogButtonType == ButtonType.OK) {
Settings.setNewSongWizardDefaultCreator(creatorField.getText());
return generateListOfValidTags();
}
return null;
Expand All @@ -70,6 +72,8 @@ private void initialize() {
registerValidators();
validationSupport.initInitialDecoration();
});

Settings.getNewSongWizardDefaultCreator().ifPresent(creatorField::setText);
}

private void registerValidators() {
Expand Down
Loading