diff --git a/src/sporemodder/EditorManager.java b/src/sporemodder/EditorManager.java index 2929461..037f6e7 100644 --- a/src/sporemodder/EditorManager.java +++ b/src/sporemodder/EditorManager.java @@ -21,10 +21,7 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import java.util.Properties; +import java.util.*; import javafx.collections.ListChangeListener; import javafx.scene.Node; @@ -519,7 +516,7 @@ private void updateFileLabel(String relativePath) { } - public void loadFixedTabs(List tabPaths) { + public void loadFixedTabs(Collection tabPaths) { disableTabEvents = true; for (String path : tabPaths) { @@ -587,7 +584,7 @@ public void setUI(EditorPaneUI ui) { } if (!disableTabEvents) { - List paths = ProjectManager.get().getActive().getFixedTabPaths(); + Set paths = ProjectManager.get().getActive().getFixedTabPaths(); paths.clear(); for (Tab tab : l.getList()) { diff --git a/src/sporemodder/ProjectManager.java b/src/sporemodder/ProjectManager.java index 32c5bf5..a86fd63 100644 --- a/src/sporemodder/ProjectManager.java +++ b/src/sporemodder/ProjectManager.java @@ -971,7 +971,7 @@ public void loadItemFolder(ProjectTreeItem parentItem) { loadItemFolder(parentItem.getValue().getProject(), parentItem.getValue().getProject().getReferences(), parentItem); } - public void loadItemFolder(Project project, List sources, ProjectTreeItem parentItem) { + public void loadItemFolder(Project project, Collection sources, ProjectTreeItem parentItem) { /** The nodes that have already been loaded in this level. */ Map loadedItems = createChildrenMap(null); @@ -980,7 +980,7 @@ public void loadItemFolder(Project project, List sources, ProjectTreeIt String relativePath = parentItem.getValue().getRelativePath(); // Iterate the sources in reverse orders, as the last ones (the least important) have to be loaded first - ListIterator iterable = sources.listIterator(sources.size()); + ListIterator iterable = new LinkedList<>(sources).listIterator(sources.size()); while (iterable.hasPrevious()) { Project source = iterable.previous(); diff --git a/src/sporemodder/util/Project.java b/src/sporemodder/util/Project.java index 1a67104..db460bb 100644 --- a/src/sporemodder/util/Project.java +++ b/src/sporemodder/util/Project.java @@ -21,11 +21,7 @@ import java.io.*; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import java.util.*; import java.util.stream.Collectors; import sporemodder.MessageManager; @@ -101,13 +97,13 @@ public enum PackageSignature { /** External projects have a file in the Projects folder that links to the real path. */ private File externalLink; - private final List references = new ArrayList<>(); + private final Set references = new LinkedHashSet<>(); /** The object that holds the path to the folder where the project DBPF is packed. */ private final GamePathConfiguration packPath; /** A list of relative paths of all those files that are fixed tabs. */ - private final List fixedTabPaths = new ArrayList<>(); + private final Set fixedTabPaths = new LinkedHashSet<>(); /** The embedded 'editorPackages~' file that represents the package signature. */ private PackageSignature packageSignature = PackageSignature.NONE; @@ -142,7 +138,7 @@ public Project(String name, File folder, File externalLink) { onNameChanged(null); } - public List getReferences() { + public Set getReferences() { return references; } @@ -177,15 +173,15 @@ public void loadSettings() { ProjectManager projectManager = ProjectManager.get(); String[] sourceNames = stringListSplit(PROPERTY_sources); + references.clear(); for (String str : sourceNames) { Project p = projectManager.getProject(str); if (p != null) references.add(p); } String[] tabPaths = stringListSplit(PROPERTY_fixedTabPaths); - for (String str : tabPaths) { - fixedTabPaths.add(str); - } + fixedTabPaths.clear(); + fixedTabPaths.addAll(Arrays.asList(tabPaths)); packageName = settings.getProperty(PROPERTY_packageName); if (packageName == null) packageName = getDefaultPackageName(name); @@ -229,24 +225,12 @@ public void saveSettings() { //if (!sources.isEmpty()) { // Do this even if it's empty, as we need to update it if sources were removed { - StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < references.size(); i++) { - sb.append("\"" + references.get(i).name + "\""); - if (i != references.size()-1) sb.append("|"); - } - - settings.setProperty(PROPERTY_sources, sb.toString()); + String referencesStr = references.stream().map(r -> '"' + r.name + '"').collect(Collectors.joining("|")); + settings.setProperty(PROPERTY_sources, referencesStr); } if (!fixedTabPaths.isEmpty()) { - StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < fixedTabPaths.size(); i++) { - sb.append("\"" + fixedTabPaths.get(i) + "\""); - if (i != fixedTabPaths.size()-1) sb.append("|"); - } - - settings.setProperty(PROPERTY_fixedTabPaths, sb.toString()); + String str = fixedTabPaths.stream().map(r -> '"' + r + '"').collect(Collectors.joining("|")); + settings.setProperty(PROPERTY_fixedTabPaths, str); } settings.put(PROPERTY_packageName, packageName); @@ -304,7 +288,7 @@ public void setReadOnly(boolean isReadOnly) { * Returns a list of relative paths of all those files that are fixed tabs. * @return */ - public List getFixedTabPaths() { + public Set getFixedTabPaths() { return fixedTabPaths; } diff --git a/src/sporemodder/view/dialogs/ProjectSettingsUI.java b/src/sporemodder/view/dialogs/ProjectSettingsUI.java index 92b6897..9558a1d 100644 --- a/src/sporemodder/view/dialogs/ProjectSettingsUI.java +++ b/src/sporemodder/view/dialogs/ProjectSettingsUI.java @@ -19,8 +19,10 @@ package sporemodder.view.dialogs; import java.io.File; +import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import javafx.fxml.FXML; import javafx.scene.Node; @@ -189,22 +191,12 @@ private void saveSettings(boolean saveSettingsOnExit) { if (saveSettingsOnExit && nameChanged) { ProjectManager.get().rename(project, tfName.getText()); } - - List oldSources = project.getReferences(); - List newSources = sourcesList.getItems(); - boolean sourcesChanged = oldSources.size() != newSources.size(); - - if (!sourcesChanged) { - for (int i = 0; i < oldSources.size(); i++) { - if (oldSources.get(i) != newSources.get(i)) { - sourcesChanged = true; - break; - } - } - } - + project.setPackageName(packageNameField.getText()); - + + Set oldSources = project.getReferences(); + Set newSources = new LinkedHashSet<>(sourcesList.getItems()); + boolean sourcesChanged = !oldSources.equals(newSources); if (sourcesChanged) { project.getReferences().clear(); project.getReferences().addAll(sourcesList.getItems());