Skip to content

Commit 3a7685f

Browse files
committed
settings editor: fix recently used, update old state on save
1 parent c3d3f02 commit 3a7685f

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
lines changed

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/SettingsEditorApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ public void saveUiMpq() {
345345
}
346346
hasUnsavedFileChanges = false;
347347
updateAppTitle();
348+
updateValueDefsUnchangedState();
348349
log.trace("opened mpq within {}ms.", (System.nanoTime() - time) / 1_000_000);
349350
} catch (final InterruptedException e) {
350351
Thread.currentThread().interrupt();
@@ -354,6 +355,10 @@ public void saveUiMpq() {
354355
}
355356
}
356357

358+
private void updateValueDefsUnchangedState() {
359+
this.layoutExtReader.updateValueDefsUnchangedState();
360+
}
361+
357362
/**
358363
* Returns true, if the path of the current opened document is valid. Invalid usually means that no document has
359364
* been opened.

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/controllers/TabsController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class TabsController {
2929

3030
private static final Callback<TableColumn<ValueDef, Boolean>, TableCell<ValueDef, Boolean>>
31-
ActionColumnCellFactoryReset =
31+
ACTION_COLUMN_CELL_FACTORY_RESET =
3232
_ -> new ResetDefaultButtonTableCell(Messages.getString("TabsController.ResetDefault"),
3333
Messages.getString("TabsController.ResetOldValue"));
3434

@@ -102,7 +102,7 @@ public void initialize() {
102102
hotkeysKeyCol.setSortable(false);
103103
hotkeysActionsCol.setSortable(false);
104104
hotkeysActionsCol.setCellValueFactory(hasChangedFac);
105-
hotkeysActionsCol.setCellFactory(ActionColumnCellFactoryReset);
105+
hotkeysActionsCol.setCellFactory(ACTION_COLUMN_CELL_FACTORY_RESET);
106106

107107
settingsNameCol.setCellValueFactory(idFac);
108108
settingsDescriptionCol.setCellValueFactory(descFac);
@@ -113,7 +113,7 @@ public void initialize() {
113113
settingsValueCol.setSortable(false);
114114
settingsActionsCol.setSortable(false);
115115
settingsActionsCol.setCellValueFactory(hasChangedFac);
116-
settingsActionsCol.setCellFactory(ActionColumnCellFactoryReset);
116+
settingsActionsCol.setCellFactory(ACTION_COLUMN_CELL_FACTORY_RESET);
117117

118118
hotkeysTable.setItems(hotkeysData);
119119
settingsTable.setItems(settingsData);

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/galaxy/ext/LayoutExtensionReader.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,13 @@ public boolean hasChanges() {
369369
}
370370
return false;
371371
}
372+
373+
public void updateValueDefsUnchangedState() {
374+
for (final ValueDef setting : settings) {
375+
setting.setOldValueToCurrent();
376+
}
377+
for (final TextValueDef hotkey : hotkeys) {
378+
hotkey.setOldValueToCurrent();
379+
}
380+
}
372381
}

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/integration/RecentlyUsed.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@
1818
@Slf4j
1919
public class RecentlyUsed {
2020
private static final int MAX_RECENT_ELEMENTS = 5;
21+
private static final String GALAXY_OBS_UI_SETTINGS_EDITOR_RECENT_BIN = ".GalaxyObsUiSettingsEditor/recent.bin";
22+
private static final String USER_HOME = "user.home";
2123

2224
private final ArrayDeque<Path> recent = new ArrayDeque<>(MAX_RECENT_ELEMENTS);
2325
private final Kryo kryo;
2426

2527
public RecentlyUsed() {
2628
kryo = new Kryo(new ListReferenceResolver());
2729
kryo.setRegistrationRequired(true);
28-
loadItems(Path.of(System.getProperty("user.home"), ".GalaxyObsUiSettingsEditor/recent.bin"));
30+
loadItems(Path.of(System.getProperty(USER_HOME), GALAXY_OBS_UI_SETTINGS_EDITOR_RECENT_BIN));
2931
}
3032

3133
private void loadItems(final Path recentSaveFile) {
3234
if (Files.exists(recentSaveFile)) {
3335
try (final InflaterInputStream in = new InflaterInputStream(Files.newInputStream(recentSaveFile))) {
3436
try (final Input input = new Input(in)) {
35-
while (input.position() < input.limit()) {
37+
while (input.available() > 0) {
3638
Path path = Path.of(kryo.readObject(input, String.class));
3739
if (Files.exists(path)) {
3840
recent.add(path);
@@ -59,7 +61,7 @@ public void addRecent(final Path path) {
5961
recent.pollFirst();
6062
}
6163
recent.add(path);
62-
save(Path.of(System.getProperty("user.home"), ".GalaxyObsUiSettingsEditor/recent.bin"));
64+
save(Path.of(System.getProperty("user.home"), GALAXY_OBS_UI_SETTINGS_EDITOR_RECENT_BIN));
6365
}
6466

6567
private void save(final Path path) {

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/model/OptionValueDef.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
import com.ahli.hotkey_ui.application.model.abstracts.ValueDef;
44
import javafx.beans.property.SimpleIntegerProperty;
55
import javafx.beans.value.ChangeListener;
6+
import lombok.Getter;
67

78
import java.util.Arrays;
89
import java.util.Locale;
910

1011
public class OptionValueDef extends ValueDef {
1112

13+
@Getter
1214
protected final OptionValueDefType type;
1315
private final String[] allowedValues;
16+
@Getter
1417
private final String[] allowedDisplayValues;
18+
@Getter
1519
private final String gamestringsAdd;
1620
private final SimpleIntegerProperty selectedIndex;
1721
private final SimpleIntegerProperty defaultSelectedIndex;
@@ -115,14 +119,6 @@ public void setSelectedIndex(final int selectedIndex) {
115119
this.selectedIndex.set(selectedIndex);
116120
}
117121

118-
public String getGamestringsAdd() {
119-
return gamestringsAdd;
120-
}
121-
122-
public String[] getAllowedDisplayValues() {
123-
return allowedDisplayValues;
124-
}
125-
126122
/**
127123
* Returns whether the value is the default value.
128124
*
@@ -133,10 +129,6 @@ public boolean isDefaultValue() {
133129
return selectedIndex.get() == defaultSelectedIndex.get();
134130
}
135131

136-
public OptionValueDefType getType() {
137-
return type;
138-
}
139-
140132
@Override
141133
public void addListener(final ChangeListener<Object> changeListener) {
142134
selectedIndex.addListener(changeListener);
@@ -207,6 +199,11 @@ public String getDisplayValue() {
207199
return allowedDisplayValues[selectedIndex.get()];
208200
}
209201

202+
@Override
203+
public void setOldValueToCurrent() {
204+
oldSelectedIndex.set(selectedIndex.get());
205+
}
206+
210207
public SimpleIntegerProperty getSelectedIndexProperty() {
211208
return selectedIndex;
212209
}

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/model/TextValueDef.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import com.ahli.hotkey_ui.application.model.abstracts.ValueDef;
44
import javafx.beans.property.SimpleStringProperty;
55
import javafx.beans.value.ChangeListener;
6+
import lombok.Getter;
67

78
import java.util.Locale;
89

910
public class TextValueDef extends ValueDef {
1011

1112
private final SimpleStringProperty oldValue;
13+
@Getter
1214
private final TextValueDefType type;
1315

1416
public TextValueDef(final String id, final String description, final String defaultValue, final String typeStr) {
@@ -49,10 +51,6 @@ public void addListener(final ChangeListener<Object> changeListener) {
4951
displayValue.addListener(changeListener);
5052
}
5153

52-
public TextValueDefType getType() {
53-
return type;
54-
}
55-
5654
@Override
5755
public void resetToDefault() {
5856
displayValue.set(defaultDisplayValue.get());
@@ -77,6 +75,11 @@ public String getDisplayValue() {
7775
return displayValue.get();
7876
}
7977

78+
@Override
79+
public void setOldValueToCurrent() {
80+
setOldValue(getValue());
81+
}
82+
8083
public void setOldValue(final String oldValue) {
8184
this.oldValue.set(oldValue);
8285
}

tools/observerUiSettingsEditor/project/src/main/java/com/ahli/hotkey_ui/application/model/abstracts/ValueDef.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,6 @@ public SimpleBooleanProperty hasChangedProperty() {
8383
return hasChanged;
8484
}
8585

86+
// update old value, e.g. after saving
87+
public abstract void setOldValueToCurrent();
8688
}

0 commit comments

Comments
 (0)