add option to force key folding
This commit is contained in:
parent
091acb2e32
commit
433ce8e844
@ -11,6 +11,7 @@
|
||||
- Extract translation intention
|
||||
- Full language support for Java, Kotlin, JavaScript / TypeScript, Vue and PHP
|
||||
- Expand already expanded nodes after data update
|
||||
- Experimental option to force translation key folding
|
||||
- Individual icon for tool-window and lookup items
|
||||
- Dedicated configuration file (easy-i18n.xml) inside <kbd>.idea</kbd> folder
|
||||
|
||||
|
@ -14,6 +14,7 @@ import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.assistance.OptionalAssistance;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationValue;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||
|
||||
@ -22,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Language specific translation key folding with representative locale value.
|
||||
@ -52,8 +54,9 @@ abstract class AbstractFoldingBuilder extends FoldingBuilderEx implements Option
|
||||
|
||||
List<FoldingDescriptor> descriptors = new ArrayList<>();
|
||||
|
||||
ProjectSettings settings = ProjectSettingsService.get(root.getProject()).getState();
|
||||
TranslationData data = InstanceManager.get(root.getProject()).store().getData();
|
||||
KeyPathConverter converter = new KeyPathConverter(root.getProject());
|
||||
KeyPathConverter converter = new KeyPathConverter(settings);
|
||||
|
||||
for(Pair<String, PsiElement> region : extractRegions(root)) {
|
||||
if(data.getTranslation(converter.fromString(region.first)) == null) {
|
||||
@ -64,7 +67,8 @@ abstract class AbstractFoldingBuilder extends FoldingBuilderEx implements Option
|
||||
region.second.getTextRange().getEndOffset() - 1);
|
||||
|
||||
// Some language implementations like [Vue Template] does not support FoldingGroup's
|
||||
FoldingDescriptor descriptor = new FoldingDescriptor(region.second.getNode(), range);
|
||||
FoldingDescriptor descriptor = new FoldingDescriptor(region.second.getNode(), range,
|
||||
null, Set.of(), settings.isAlwaysFold());
|
||||
|
||||
descriptors.add(descriptor);
|
||||
}
|
||||
|
@ -29,4 +29,7 @@ public interface ProjectSettings {
|
||||
|
||||
boolean isNestedKeys();
|
||||
boolean isAssistance();
|
||||
|
||||
// Experimental Configuration
|
||||
boolean isAlwaysFold();
|
||||
}
|
||||
|
@ -60,6 +60,9 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
||||
.addVerticalGap(12)
|
||||
.addComponent(constructNestedKeysField())
|
||||
.addComponent(constructAssistanceField())
|
||||
.addVerticalGap(24)
|
||||
.addComponent(new TitledSeparator(bundle.getString("settings.experimental.title")))
|
||||
.addComponent(constructAlwaysFoldField())
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
@ -203,6 +206,12 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
||||
return assistance;
|
||||
}
|
||||
|
||||
private JComponent constructAlwaysFoldField() {
|
||||
alwaysFold = new JBCheckBox(bundle.getString("settings.experimental.always-fold.title"));
|
||||
alwaysFold.setToolTipText(bundle.getString("settings.experimental.always-fold.tooltip"));
|
||||
return alwaysFold;
|
||||
}
|
||||
|
||||
private ItemListener handleParserChange() {
|
||||
return e -> {
|
||||
if(e.getStateChange() == ItemEvent.SELECTED) {
|
||||
|
@ -36,6 +36,9 @@ public class ProjectSettingsComponentState {
|
||||
protected JCheckBox nestedKeys;
|
||||
protected JCheckBox assistance;
|
||||
|
||||
// Experimental configuration
|
||||
protected JCheckBox alwaysFold;
|
||||
|
||||
protected ProjectSettingsState getState() {
|
||||
// Every field needs to provide its state
|
||||
ProjectSettingsState state = new ProjectSettingsState();
|
||||
@ -57,6 +60,8 @@ public class ProjectSettingsComponentState {
|
||||
state.setNestedKeys(nestedKeys.isSelected());
|
||||
state.setAssistance(assistance.isSelected());
|
||||
|
||||
state.setAlwaysFold(alwaysFold.isSelected());
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -78,5 +83,7 @@ public class ProjectSettingsComponentState {
|
||||
|
||||
nestedKeys.setSelected(state.isNestedKeys());
|
||||
assistance.setSelected(state.isAssistance());
|
||||
|
||||
alwaysFold.setSelected(state.isAlwaysFold());
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ public class ProjectSettingsState implements ProjectSettings {
|
||||
private Boolean nestedKeys;
|
||||
private Boolean assistance;
|
||||
|
||||
// Experimental configuration
|
||||
private Boolean alwaysFold;
|
||||
|
||||
public ProjectSettingsState() {}
|
||||
|
||||
@Override
|
||||
@ -102,6 +105,11 @@ public class ProjectSettingsState implements ProjectSettings {
|
||||
return assistance != null ? assistance : defaults.isAssistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysFold() {
|
||||
return alwaysFold != null ? alwaysFold : defaults.isAlwaysFold();
|
||||
}
|
||||
|
||||
public void setLocalesDirectory(String localesDirectory) {
|
||||
this.localesDirectory = localesDirectory;
|
||||
}
|
||||
@ -153,4 +161,8 @@ public class ProjectSettingsState implements ProjectSettings {
|
||||
public void setAssistance(Boolean assistance) {
|
||||
this.assistance = assistance;
|
||||
}
|
||||
|
||||
public void setAlwaysFold(Boolean alwaysFold) {
|
||||
this.alwaysFold = alwaysFold;
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,9 @@ public class DefaultPreset implements ProjectSettings {
|
||||
public boolean isAssistance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysFold() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,9 @@ public class ReactI18NextPreset implements ProjectSettings {
|
||||
public boolean isAssistance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysFold() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -75,4 +75,9 @@ public class VueI18nPreset implements ProjectSettings {
|
||||
public boolean isAssistance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysFold() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ settings.editor.key.nesting.title=Escape section delimiter within a section laye
|
||||
settings.editor.key.nesting.tooltip=Escapes the section delimiter within a section to properly reconstruct nested key sections. Disable this feature if nested key sections are the exception rather than the rule in your translation file.
|
||||
settings.editor.assistance.title=Editor code assistance for translations
|
||||
settings.editor.assistance.tooltip=Activates editor support to reference, auto-complete and folding of existing translations.
|
||||
# Experimental configuration
|
||||
settings.experimental.title=Experimental Configuration
|
||||
settings.experimental.always-fold.title=Always fold translation keys
|
||||
settings.experimental.always-fold.tooltip=Forces the editor to always display the value behind a translation key. The value cannot be unfolded when this function is active.
|
||||
error.io=An error occurred while processing translation files. \n\
|
||||
Config: {0} => {1} ({2}) \n\
|
||||
Path: {3} \n\
|
||||
|
Loading…
x
Reference in New Issue
Block a user