-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Observable Preferences O (Language and FileHistory) (#9173)
* Included localization prefs in GeneralPreferences * Convertet getLanguage to new prefs pattern * Extracted localization from MetaDataDiff in logic * Refactored FileHistory and converted getFileHistory to new prefs model * Partial localization without restart * Convert list to EnumSet * Used pattern matching and applied IDE suggestions * Fixed comparison of optionals
- Loading branch information
1 parent
09db449
commit 1c933b5
Showing
15 changed files
with
173 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,61 @@ | ||
package org.jabref.logic.util.io; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.collections.ModifiableObservableListBase; | ||
|
||
public class FileHistory { | ||
public class FileHistory extends ModifiableObservableListBase<Path> { | ||
|
||
private static final int HISTORY_SIZE = 8; | ||
|
||
private final ObservableList<Path> history; | ||
private final List<Path> history; | ||
|
||
public FileHistory(List<Path> files) { | ||
history = FXCollections.observableList(Objects.requireNonNull(files)); | ||
private FileHistory(List<Path> list) { | ||
history = new ArrayList<>(list); | ||
} | ||
|
||
@Override | ||
public Path get(int index) { | ||
return history.get(index); | ||
} | ||
|
||
public int size() { | ||
return history.size(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return history.isEmpty(); | ||
@Override | ||
protected void doAdd(int index, Path element) { | ||
history.add(index, element); | ||
} | ||
|
||
@Override | ||
protected Path doSet(int index, Path element) { | ||
return history.set(index, element); | ||
} | ||
|
||
@Override | ||
protected Path doRemove(int index) { | ||
return history.remove(index); | ||
} | ||
|
||
/** | ||
* Adds the file to the top of the list. If it already is in the list, it is merely moved to the top. | ||
*/ | ||
public void newFile(Path file) { | ||
removeItem(file); | ||
history.add(0, file); | ||
this.add(0, file); | ||
while (size() > HISTORY_SIZE) { | ||
history.remove(HISTORY_SIZE); | ||
} | ||
} | ||
|
||
public Path getFileAt(int index) { | ||
return history.get(index); | ||
} | ||
|
||
public void removeItem(Path file) { | ||
history.remove(file); | ||
this.remove(file); | ||
} | ||
|
||
public ObservableList<Path> getHistory() { | ||
return history; | ||
public static FileHistory of(List<Path> list) { | ||
return new FileHistory(new ArrayList<>(list)); | ||
} | ||
} |
Oops, something went wrong.