package org.iwakura.larcjb.actions import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.vcs.ProjectLevelVcsManager import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.components.JBScrollPane import com.intellij.ui.components.JBTextArea import org.iwakura.larcjb.LarcExecutable import org.iwakura.larcjb.LarcVcs import java.awt.Dimension import javax.swing.JComponent /** * Action to show commit log. * TODO(kroot): Replace with proper VcsHistoryProvider integration */ class LarcLogAction : AnAction(), DumbAware { override fun actionPerformed(e: AnActionEvent) { val project = e.project ?: return val roots = getLarcRoots(project) if (roots.isEmpty()) return val executable = LarcExecutable(project) /* * For now, show simple dialog with log output * Later: integrate with VcsLogProvider for proper UI */ val logOutput = buildString { for (root in roots) { appendLine("${root.name}") val result = executable.log(root, 50) if (result.isSuccess) { appendLine(result.stdout) } else { appendLine("Error: ${result.stderr}") } appendLine() } } LogDialog(project, logOutput).show() } override fun update(e: AnActionEvent) { val project = e.project e.presentation.isEnabledAndVisible = project != null && getLarcRoots(project).isNotEmpty() } override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT private fun getLarcRoots(project: Project): List { return ProjectLevelVcsManager.getInstance(project) .allVcsRoots .filter { it.vcs?.name == LarcVcs.NAME } .mapNotNull { it.path } } private class LogDialog(project: Project, private val logContent: String) : DialogWrapper(project) { init { title = "Larc Log" init() } override fun createCenterPanel(): JComponent { val textArea = JBTextArea(logContent).apply { isEditable = false font = java.awt.Font("Monospaced", java.awt.Font.PLAIN, 12) } return JBScrollPane(textArea).apply { preferredSize = Dimension(800, 600) } } } }