| 1 |
package org.iwakura.larcjb.actions |
| 2 |
|
| 3 |
import com.intellij.openapi.actionSystem.ActionUpdateThread |
| 4 |
import com.intellij.openapi.actionSystem.AnAction |
| 5 |
import com.intellij.openapi.actionSystem.AnActionEvent |
| 6 |
import com.intellij.openapi.project.DumbAware |
| 7 |
import com.intellij.openapi.project.Project |
| 8 |
import com.intellij.openapi.ui.DialogWrapper |
| 9 |
import com.intellij.openapi.vcs.ProjectLevelVcsManager |
| 10 |
import com.intellij.openapi.vfs.VirtualFile |
| 11 |
import com.intellij.ui.components.JBScrollPane |
| 12 |
import com.intellij.ui.components.JBTextArea |
| 13 |
import org.iwakura.larcjb.LarcExecutable |
| 14 |
import org.iwakura.larcjb.LarcVcs |
| 15 |
import java.awt.Dimension |
| 16 |
import javax.swing.JComponent |
| 17 |
|
| 18 |
/** |
| 19 |
* Action to show commit log. |
| 20 |
* TODO(kroot): Replace with proper VcsHistoryProvider integration |
| 21 |
*/ |
| 22 |
class LarcLogAction : AnAction(), DumbAware { |
| 23 |
|
| 24 |
override fun actionPerformed(e: AnActionEvent) { |
| 25 |
val project = e.project ?: return |
| 26 |
val roots = getLarcRoots(project) |
| 27 |
|
| 28 |
if (roots.isEmpty()) return |
| 29 |
|
| 30 |
val executable = LarcExecutable(project) |
| 31 |
|
| 32 |
/* |
| 33 |
* For now, show simple dialog with log output |
| 34 |
* Later: integrate with VcsLogProvider for proper UI |
| 35 |
*/ |
| 36 |
val logOutput = buildString { |
| 37 |
for (root in roots) { |
| 38 |
appendLine("${root.name}") |
| 39 |
val result = executable.log(root, 50) |
| 40 |
if (result.isSuccess) { |
| 41 |
appendLine(result.stdout) |
| 42 |
} else { |
| 43 |
appendLine("Error: ${result.stderr}") |
| 44 |
} |
| 45 |
appendLine() |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
LogDialog(project, logOutput).show() |
| 50 |
} |
| 51 |
|
| 52 |
override fun update(e: AnActionEvent) { |
| 53 |
val project = e.project |
| 54 |
e.presentation.isEnabledAndVisible = project != null && getLarcRoots(project).isNotEmpty() |
| 55 |
} |
| 56 |
|
| 57 |
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT |
| 58 |
|
| 59 |
private fun getLarcRoots(project: Project): List<VirtualFile> { |
| 60 |
return ProjectLevelVcsManager.getInstance(project) |
| 61 |
.allVcsRoots |
| 62 |
.filter { it.vcs?.name == LarcVcs.NAME } |
| 63 |
.mapNotNull { it.path } |
| 64 |
} |
| 65 |
|
| 66 |
private class LogDialog(project: Project, private val logContent: String) : DialogWrapper(project) { |
| 67 |
init { |
| 68 |
title = "Larc Log" |
| 69 |
init() |
| 70 |
} |
| 71 |
|
| 72 |
override fun createCenterPanel(): JComponent { |
| 73 |
val textArea = JBTextArea(logContent).apply { |
| 74 |
isEditable = false |
| 75 |
font = java.awt.Font("Monospaced", java.awt.Font.PLAIN, 12) |
| 76 |
} |
| 77 |
return JBScrollPane(textArea).apply { |
| 78 |
preferredSize = Dimension(800, 600) |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|