larc r17

40 lines ยท 1.3 KB Raw
1 package org.iwakura.larcjb.actions
2
3 import com.intellij.openapi.actionSystem.ActionManager
4 import com.intellij.openapi.actionSystem.ActionUpdateThread
5 import com.intellij.openapi.actionSystem.AnAction
6 import com.intellij.openapi.actionSystem.AnActionEvent
7 import com.intellij.openapi.project.DumbAware
8 import com.intellij.openapi.vcs.ProjectLevelVcsManager
9 import org.iwakura.larcjb.LarcVcs
10
11 /**
12 * Action to open commit dialog for Larc.
13 */
14 class LarcCommitAction : AnAction(), DumbAware {
15
16 override fun actionPerformed(e: AnActionEvent) {
17 /* Trigger the standard IDE commit action */
18 val checkinAction = ActionManager.getInstance().getAction("CheckinProject")
19 checkinAction?.actionPerformed(e)
20 }
21
22 override fun update(e: AnActionEvent) {
23 val project = e.project
24 if (project == null) {
25 e.presentation.isEnabledAndVisible = false
26 return
27 }
28
29 /* Check if Larc is active for any root */
30 val vcsManager = ProjectLevelVcsManager.getInstance(project)
31 val hasLarcRoots = vcsManager.allVcsRoots.any {
32 it.vcs?.name == LarcVcs.NAME
33 }
34
35 e.presentation.isEnabledAndVisible = hasLarcRoots
36 }
37
38 override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
39 }
40