forked from JetBrains-Research/RefactorInsight
/
ToggleRefactoringViewAction.java
44 lines (38 loc) · 1.62 KB
/
ToggleRefactoringViewAction.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
package org.jetbrains.research.refactorinsight.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAwareToggleAction;
import com.intellij.openapi.project.Project;
import com.intellij.vcs.log.ui.MainVcsLogUi;
import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.research.refactorinsight.services.WindowService;
/**
* This is the Show Refactorings Action.
* Adds a toggle button in the git tool window,
* toggles between classical diff view and refactoring view.
* Invokes the added git ui.
*/
public class ToggleRefactoringViewAction extends DumbAwareToggleAction {
@Override
public void setSelected(@NotNull AnActionEvent e, boolean state) {
Project project = e.getRequiredData(PlatformDataKeys.PROJECT);
MainVcsLogUi vcsLogUi = e.getRequiredData(VcsLogInternalDataKeys.MAIN_UI);
WindowService.getInstance(project).setSelected(vcsLogUi, state);
}
@Override
public boolean isSelected(@NotNull AnActionEvent e) {
if (!isEnabled(e)) return false;
Project project = e.getRequiredData(PlatformDataKeys.PROJECT);
MainVcsLogUi vcsLogUi = e.getRequiredData(VcsLogInternalDataKeys.MAIN_UI);
return WindowService.getInstance(project).isSelected(vcsLogUi);
}
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(isEnabled(e));
super.update(e);
}
private boolean isEnabled(@NotNull AnActionEvent e) {
return e.getProject() != null && e.getData(VcsLogInternalDataKeys.MAIN_UI) != null;
}
}