upgrade to new data structure
This commit is contained in:
parent
dd783a0b2e
commit
a20d4be2cf
@ -4,6 +4,8 @@ import com.intellij.lang.annotation.AnnotationHolder;
|
|||||||
import com.intellij.lang.annotation.HighlightSeverity;
|
import com.intellij.lang.annotation.HighlightSeverity;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
|
import de.marhali.easyi18n.model.TranslationNode;
|
||||||
import de.marhali.easyi18n.service.SettingsService;
|
import de.marhali.easyi18n.service.SettingsService;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -37,7 +39,7 @@ public class KeyAnnotator {
|
|||||||
searchKey = searchKey.substring(1);
|
searchKey = searchKey.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalizedNode node = LegacyDataStore.getInstance(project).getTranslations().getNode(searchKey);
|
TranslationNode node = InstanceManager.get(project).store().getData().getNode(searchKey);
|
||||||
|
|
||||||
if(node == null) { // Unknown translation. Just ignore it
|
if(node == null) { // Unknown translation. Just ignore it
|
||||||
return;
|
return;
|
||||||
|
@ -5,7 +5,11 @@ import com.intellij.codeInsight.lookup.*;
|
|||||||
import com.intellij.icons.AllIcons;
|
import com.intellij.icons.AllIcons;
|
||||||
import com.intellij.openapi.project.*;
|
import com.intellij.openapi.project.*;
|
||||||
import com.intellij.util.*;
|
import com.intellij.util.*;
|
||||||
|
import de.marhali.easyi18n.DataStore;
|
||||||
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
|
import de.marhali.easyi18n.model.Translation;
|
||||||
import de.marhali.easyi18n.service.*;
|
import de.marhali.easyi18n.service.*;
|
||||||
|
import de.marhali.easyi18n.util.PathUtil;
|
||||||
import org.jetbrains.annotations.*;
|
import org.jetbrains.annotations.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -27,7 +31,8 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyDataStore store = LegacyDataStore.getInstance(project);
|
DataStore store = InstanceManager.get(project).store();
|
||||||
|
PathUtil pathUtil = new PathUtil(project);
|
||||||
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
|
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
|
||||||
String pathPrefix = SettingsService.getInstance(project).getState().getPathPrefix();
|
String pathPrefix = SettingsService.getInstance(project).getState().getPathPrefix();
|
||||||
|
|
||||||
@ -52,7 +57,7 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
|
|||||||
pathPrefix += ".";
|
pathPrefix += ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> fullKeys = store.getTranslations().getFullKeys();
|
Set<String> fullKeys = store.getData().getFullKeys();
|
||||||
|
|
||||||
int sections = path.split("\\.").length;
|
int sections = path.split("\\.").length;
|
||||||
int maxSectionForwardLookup = 5;
|
int maxSectionForwardLookup = 5;
|
||||||
@ -63,19 +68,20 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
|
|||||||
String[] keySections = key.split("\\.");
|
String[] keySections = key.split("\\.");
|
||||||
|
|
||||||
if(keySections.length > sections + maxSectionForwardLookup) { // Key is too deep nested
|
if(keySections.length > sections + maxSectionForwardLookup) { // Key is too deep nested
|
||||||
String shrinkKey = TranslationsUtil.sectionsToFullPath(Arrays.asList(
|
String shrinkKey = pathUtil.concat(Arrays.asList(
|
||||||
Arrays.copyOf(keySections, sections + maxSectionForwardLookup)));
|
Arrays.copyOf(keySections, sections + maxSectionForwardLookup)
|
||||||
|
));
|
||||||
|
|
||||||
result.addElement(LookupElementBuilder.create(pathPrefix + shrinkKey)
|
result.addElement(LookupElementBuilder.create(pathPrefix + shrinkKey)
|
||||||
.appendTailText(" I18n([])", true));
|
.appendTailText(" I18n([])", true));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LocalizedNode node = store.getTranslations().getNode(key);
|
Translation translation = store.getData().getTranslation(key);
|
||||||
String translation = node != null ? node.getValue().get(previewLocale) : null;
|
String content = translation.get(previewLocale);
|
||||||
|
|
||||||
result.addElement(LookupElementBuilder.create(pathPrefix + key)
|
result.addElement(LookupElementBuilder.create(pathPrefix + key)
|
||||||
.withIcon(AllIcons.Actions.PreserveCaseHover)
|
.withIcon(AllIcons.Actions.PreserveCaseHover)
|
||||||
.appendTailText(" I18n(" + previewLocale + ": " + translation + ")", true)
|
.appendTailText(" I18n(" + previewLocale + ": " + content + ")", true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,12 @@ import com.intellij.openapi.util.TextRange;
|
|||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.impl.FakePsiElement;
|
import com.intellij.psi.impl.FakePsiElement;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
import de.marhali.easyi18n.dialog.AddDialog;
|
import de.marhali.easyi18n.dialog.AddDialog;
|
||||||
import de.marhali.easyi18n.dialog.EditDialog;
|
import de.marhali.easyi18n.dialog.EditDialog;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.KeyedTranslation;
|
||||||
|
import de.marhali.easyi18n.model.Translation;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -49,10 +52,10 @@ public class KeyReference extends PsiReferenceBase<PsiElement> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void navigate(boolean requestFocus) {
|
public void navigate(boolean requestFocus) {
|
||||||
LocalizedNode node = LegacyDataStore.getInstance(getProject()).getTranslations().getNode(getKey());
|
Translation translation = InstanceManager.get(getProject()).store().getData().getTranslation(getKey());
|
||||||
|
|
||||||
if(node != null) {
|
if(translation != null) {
|
||||||
new EditDialog(getProject(), new LegacyKeyedTranslation(getKey(), node.getValue())).showAndHandle();
|
new EditDialog(getProject(), new KeyedTranslation(getKey(), translation)).showAndHandle();
|
||||||
} else {
|
} else {
|
||||||
new AddDialog(getProject(), getKey()).showAndHandle();
|
new AddDialog(getProject(), getKey()).showAndHandle();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.intellij.patterns.PlatformPatterns;
|
|||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.util.ProcessingContext;
|
import com.intellij.util.ProcessingContext;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
import de.marhali.easyi18n.editor.KeyReference;
|
import de.marhali.easyi18n.editor.KeyReference;
|
||||||
import de.marhali.easyi18n.service.SettingsService;
|
import de.marhali.easyi18n.service.SettingsService;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ public class GenericKeyReferenceContributor extends PsiReferenceContributor {
|
|||||||
return PsiReference.EMPTY_ARRAY;
|
return PsiReference.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(LegacyDataStore.getInstance(element.getProject()).getTranslations().getNode(value) == null) {
|
if(InstanceManager.get(element.getProject()).store().getData().getTranslation(value) == null) {
|
||||||
if(!KeyReference.isReferencable(value)) { // Creation policy
|
if(!KeyReference.isReferencable(value)) { // Creation policy
|
||||||
return PsiReference.EMPTY_ARRAY;
|
return PsiReference.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.intellij.psi.*;
|
|||||||
|
|
||||||
import com.intellij.util.ProcessingContext;
|
import com.intellij.util.ProcessingContext;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
import de.marhali.easyi18n.editor.KeyReference;
|
import de.marhali.easyi18n.editor.KeyReference;
|
||||||
import de.marhali.easyi18n.service.SettingsService;
|
import de.marhali.easyi18n.service.SettingsService;
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public class KotlinKeyReferenceContributor extends PsiReferenceContributor {
|
|||||||
return PsiReference.EMPTY_ARRAY;
|
return PsiReference.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(LegacyDataStore.getInstance(element.getProject()).getTranslations().getNode(value) == null) {
|
if(InstanceManager.get(element.getProject()).store().getData().getNode(value) == null) {
|
||||||
return PsiReference.EMPTY_ARRAY;
|
return PsiReference.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user