-
Notifications
You must be signed in to change notification settings - Fork 44
/
CsvChangeSeparatorActionGroup.java
49 lines (42 loc) · 2.03 KB
/
CsvChangeSeparatorActionGroup.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package net.seesharpsoft.intellij.plugins.csv.actions;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.psi.PsiFile;
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
import net.seesharpsoft.intellij.plugins.csv.CsvLanguage;
import net.seesharpsoft.intellij.plugins.csv.CsvSeparatorHolder;
import net.seesharpsoft.intellij.plugins.csv.CsvValueSeparator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CsvChangeSeparatorActionGroup extends ActionGroup {
private static final AnAction[] CSV_SEPARATOR_CHANGE_ACTIONS;
static {
CSV_SEPARATOR_CHANGE_ACTIONS = new AnAction[CsvValueSeparator.values().length + 1];
for (int i = 0; i < CSV_SEPARATOR_CHANGE_ACTIONS.length - 1; ++i) {
CSV_SEPARATOR_CHANGE_ACTIONS[i] = new CsvChangeSeparatorAction(CsvValueSeparator.values()[i]);
}
CSV_SEPARATOR_CHANGE_ACTIONS[CSV_SEPARATOR_CHANGE_ACTIONS.length - 1] = new CsvDefaultSeparatorAction();
}
@Override
public void update(AnActionEvent anActionEvent) {
PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
Language language = psiFile == null ? null : psiFile.getLanguage();
anActionEvent.getPresentation().setEnabledAndVisible(psiFile != null && language != null &&
language.isKindOf(CsvLanguage.INSTANCE) && !(language instanceof CsvSeparatorHolder)
);
if (psiFile != null) {
anActionEvent.getPresentation()
.setText(String.format("CSV Value Separator: %s",
CsvHelper.getCurrentValueSeparator(psiFile).getDisplay())
);
}
}
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent anActionEvent) {
return CSV_SEPARATOR_CHANGE_ACTIONS;
}
}