Load translations via data store to ensure that data will be loaded without an opened ui
This commit is contained in:
parent
05a2dabdc1
commit
a3f6545fea
@ -8,6 +8,7 @@
|
||||
|
||||
### Changed
|
||||
- Updated dependencies
|
||||
- Load translations even if ui tool window is not opened
|
||||
|
||||
### Fixed
|
||||
- NullPointerException's on translation annotation / completion inside editor
|
||||
|
@ -54,11 +54,9 @@ public class TranslatorToolWindowFactory implements ToolWindowFactory {
|
||||
// Initialize Window Manager
|
||||
WindowManager.getInstance().initialize(toolWindow, treeView, tableView);
|
||||
|
||||
// Initialize data store and load from disk
|
||||
// Synchronize ui with underlying data
|
||||
DataStore store = DataStore.getInstance(project);
|
||||
store.addSynchronizer(treeView);
|
||||
store.addSynchronizer(tableView);
|
||||
|
||||
store.reloadFromDisk();
|
||||
}
|
||||
}
|
@ -14,6 +14,10 @@ import java.util.List;
|
||||
*/
|
||||
public class Translations {
|
||||
|
||||
public static Translations empty() {
|
||||
return new Translations(new ArrayList<>(), new LocalizedNode(LocalizedNode.ROOT_KEY, new ArrayList<>()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final List<String> locales;
|
||||
|
||||
@ -34,7 +38,7 @@ public class Translations {
|
||||
return locales;
|
||||
}
|
||||
|
||||
public LocalizedNode getNodes() {
|
||||
public @NotNull LocalizedNode getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.marhali.easyi18n.service;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
import de.marhali.easyi18n.model.LocalizedNode;
|
||||
@ -40,8 +42,10 @@ public class DataStore {
|
||||
private DataStore(@NotNull Project project) {
|
||||
this.project = project;
|
||||
this.synchronizer = new ArrayList<>();
|
||||
this.translations = Translations.empty();
|
||||
|
||||
reloadFromDisk();
|
||||
// Load data after first initialization
|
||||
ApplicationManager.getApplication().invokeLater(this::reloadFromDisk, ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,10 +63,8 @@ public class DataStore {
|
||||
String localesPath = SettingsService.getInstance(project).getState().getLocalesPath();
|
||||
|
||||
if(localesPath == null || localesPath.isEmpty()) {
|
||||
translations = new Translations(new ArrayList<>(),
|
||||
new LocalizedNode(LocalizedNode.ROOT_KEY, new ArrayList<>()));
|
||||
|
||||
// Propagate changes
|
||||
// Propagate empty state
|
||||
translations = Translations.empty();
|
||||
synchronizer.forEach(synchronizer -> synchronizer.synchronize(translations, searchQuery, null));
|
||||
|
||||
} else {
|
||||
@ -78,8 +80,7 @@ public class DataStore {
|
||||
|
||||
} else {
|
||||
// If state cannot be loaded from disk, show empty instance
|
||||
this.translations = new Translations(new ArrayList<>(),
|
||||
new LocalizedNode(LocalizedNode.ROOT_KEY, new ArrayList<>()));
|
||||
this.translations = Translations.empty();
|
||||
|
||||
// Propagate changes
|
||||
synchronizer.forEach(synchronizer ->
|
||||
@ -87,6 +88,8 @@ public class DataStore {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
System.out.println("reloadFromDisk()");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user