diff --git a/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/MyApplyPatchFromClipboardDialog.kt b/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/MyApplyPatchFromClipboardDialog.kt new file mode 100644 index 000000000..987ddf301 --- /dev/null +++ b/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/MyApplyPatchFromClipboardDialog.kt @@ -0,0 +1,37 @@ +package com.phodal.shirecore.ui.viewer + +import com.intellij.openapi.project.Project +import com.intellij.openapi.vcs.VcsApplicationSettings +import com.intellij.openapi.vcs.VcsBundle +import com.intellij.openapi.vcs.changes.patch.ApplyPatchDefaultExecutor +import com.intellij.openapi.vcs.changes.patch.ApplyPatchDifferentiatedDialog +import com.intellij.openapi.vcs.changes.patch.ApplyPatchMode +import com.intellij.testFramework.LightVirtualFile +import java.awt.event.ActionEvent +import java.awt.event.KeyEvent +import javax.swing.JCheckBox +import javax.swing.JComponent + +class MyApplyPatchFromClipboardDialog(project: Project, clipboardText: String) : + ApplyPatchDifferentiatedDialog( + project, ApplyPatchDefaultExecutor(project), emptyList(), ApplyPatchMode.APPLY_PATCH_IN_MEMORY, + LightVirtualFile("clipboardPatchFile", clipboardText), null, null, //NON-NLS + null, null, null, false + ) { + override fun createDoNotAskCheckbox(): JComponent? { + return createAnalyzeOnTheFlyOptionPanel() + } + + companion object { + private fun createAnalyzeOnTheFlyOptionPanel(): JCheckBox { + val removeOptionCheckBox = + JCheckBox(VcsBundle.message("patch.apply.analyze.from.clipboard.on.the.fly.checkbox")) + removeOptionCheckBox.mnemonic = KeyEvent.VK_L + removeOptionCheckBox.isSelected = VcsApplicationSettings.getInstance().DETECT_PATCH_ON_THE_FLY + removeOptionCheckBox.addActionListener { e: ActionEvent? -> + VcsApplicationSettings.getInstance().DETECT_PATCH_ON_THE_FLY = removeOptionCheckBox.isSelected + } + return removeOptionCheckBox + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/SingleFileDiffLangSketch.kt b/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/SingleFileDiffLangSketch.kt index 088f895aa..f4ca5e5fa 100644 --- a/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/SingleFileDiffLangSketch.kt +++ b/core/src/main/kotlin/com/phodal/shirecore/ui/viewer/SingleFileDiffLangSketch.kt @@ -1,27 +1,22 @@ package com.phodal.shirecore.ui.viewer -import com.intellij.diff.DiffContentFactory -import com.intellij.diff.DiffManager -import com.intellij.diff.contents.DocumentContent -import com.intellij.diff.requests.SimpleDiffRequest -import com.intellij.diff.util.DiffUserDataKeys -import com.intellij.execution.ui.ConsoleViewContentType import com.intellij.icons.AllIcons import com.intellij.lang.Language import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.application.runInEdt import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.diff.impl.patch.PatchReader import com.intellij.openapi.diff.impl.patch.TextFilePatch import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.progress.ProgressManager +import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.DialogWrapper -import com.intellij.openapi.vcs.VcsApplicationSettings -import com.intellij.openapi.vcs.VcsBundle +import com.intellij.openapi.vcs.VcsException import com.intellij.openapi.vcs.changes.patch.* +import com.intellij.openapi.vcs.changes.ui.RollbackProgressModifier +import com.intellij.openapi.vcs.impl.projectlevelman.AllVcses +import com.intellij.openapi.vcs.rollback.RollbackEnvironment import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightVirtualFile -import com.intellij.ui.IdeBorderFactory import com.intellij.ui.JBColor import com.intellij.ui.components.JBLabel import com.intellij.ui.components.panels.VerticalLayout @@ -33,8 +28,6 @@ import com.phodal.shirecore.ShireCoreBundle import com.phodal.shirecore.ShirelangNotifications import com.phodal.shirecore.findFile import java.awt.BorderLayout -import java.awt.event.ActionEvent -import java.awt.event.KeyEvent import java.awt.event.MouseAdapter import java.awt.event.MouseEvent import javax.swing.* @@ -84,16 +77,16 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S } val rejectButton = JButton(ShireCoreBundle.message("sketch.patch.action.reject")).apply { - icon = AllIcons.Actions.Rollback - toolTipText = ShireCoreBundle.message("sketch.patch.action.reject.tooltip") + this.icon = AllIcons.Actions.Rollback + this.toolTipText = ShireCoreBundle.message("sketch.patch.action.reject.tooltip") addActionListener { handleRejectAction() } } val viewDiffButton = JButton(ShireCoreBundle.message("sketch.patch.action.viewDiff")).apply { - toolTipText = ShireCoreBundle.message("sketch.patch.action.viewDiff.tooltip") - icon = AllIcons.Actions.ListChanges + this.toolTipText = ShireCoreBundle.message("sketch.patch.action.viewDiff.tooltip") + this.icon = AllIcons.Actions.ListChanges addActionListener { handleViewDiffAction() } @@ -120,18 +113,37 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S patchGroups.putValue(patchInProgress.base, patchInProgress) } - if(filePatches.isEmpty() ) { + if (filePatches.isEmpty()) { ShirelangNotifications.error(myProject, "PatchProcessor: no patches found") return@invokeAndWait } - val additionalInfo = myReader.getAdditionalInfo(ApplyPatchDefaultExecutor.pathsFromGroups(patchGroups)) + val pathsFromGroups = ApplyPatchDefaultExecutor.pathsFromGroups(patchGroups) + val additionalInfo = myReader.getAdditionalInfo(pathsFromGroups) shelfExecutor.apply(filePatches, patchGroups, null, "LlmGen.diff", additionalInfo) } } private fun handleRejectAction() { // + val instance = AllVcses.getInstance(myProject) + val rollbackEnvironment = instance.all.firstOrNull { + it is RollbackEnvironment + } as? RollbackEnvironment + + val exceptions: MutableList = ArrayList() + ApplicationManager.getApplication().invokeAndWait { + val indicator = + BackgroundableProcessIndicator( + myProject, "", null, null, true + ) + filePatches.forEach { patch -> + val originFile = myProject.findFile(patch.beforeFileName!!) ?: return@forEach + rollbackEnvironment?.rollbackModifiedWithoutCheckout( + listOf(originFile), exceptions, RollbackProgressModifier(1.0, indicator) + ) + } + } } private fun handleViewDiffAction() { @@ -166,7 +178,7 @@ class SingleFileDiffLangSketch(private val myProject: Project, private val filep addMouseListener(object : MouseAdapter() { override fun mouseEntered(e: MouseEvent) { - foreground = JBColor(0x0000FF, 0x0000FF) + background = JBColor(0x0000FF, 0x0000FF) } override fun mouseClicked(e: MouseEvent?) { @@ -219,27 +231,3 @@ class SingleFileDiffLangSketch(private val myProject: Project, private val filep return mainPanel } } - -class MyApplyPatchFromClipboardDialog(project: Project, clipboardText: String) : - ApplyPatchDifferentiatedDialog( - project, ApplyPatchDefaultExecutor(project), emptyList(), ApplyPatchMode.APPLY_PATCH_IN_MEMORY, - LightVirtualFile("clipboardPatchFile", clipboardText), null, null, //NON-NLS - null, null, null, false - ) { - override fun createDoNotAskCheckbox(): JComponent? { - return createAnalyzeOnTheFlyOptionPanel() - } - - companion object { - private fun createAnalyzeOnTheFlyOptionPanel(): JCheckBox { - val removeOptionCheckBox = - JCheckBox(VcsBundle.message("patch.apply.analyze.from.clipboard.on.the.fly.checkbox")) - removeOptionCheckBox.mnemonic = KeyEvent.VK_L - removeOptionCheckBox.isSelected = VcsApplicationSettings.getInstance().DETECT_PATCH_ON_THE_FLY - removeOptionCheckBox.addActionListener { e: ActionEvent? -> - VcsApplicationSettings.getInstance().DETECT_PATCH_ON_THE_FLY = removeOptionCheckBox.isSelected - } - return removeOptionCheckBox - } - } -}