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