mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-20 01:02:02 +00:00
fix: external file handling
This commit is contained in:
parent
14ff01212c
commit
c481b8fe94
3 changed files with 49 additions and 37 deletions
|
|
@ -54,13 +54,12 @@ class AutoApplyAction(
|
|||
}
|
||||
|
||||
val selectedEditor = EditorUtil.getSelectedEditor(project)
|
||||
anActionLink.text = if (selectedEditor?.virtualFile == null) {
|
||||
"Apply"
|
||||
} else {
|
||||
"Apply to ${selectedEditor.virtualFile.name}"
|
||||
}
|
||||
anActionLink.isEnabled = selectedEditor != null
|
||||
anActionLink.isVisible = true
|
||||
val selectedEditorFile = selectedEditor?.virtualFile
|
||||
val canApply = selectedEditorFile != null && selectedEditorFile.isWritable
|
||||
|
||||
anActionLink.text = if (canApply) "Apply to ${selectedEditorFile.name}" else "Apply"
|
||||
anActionLink.isEnabled = canApply
|
||||
anActionLink.isVisible = canApply
|
||||
}
|
||||
|
||||
override fun createCustomComponent(presentation: Presentation, place: String): JComponent {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.intellij.ui.components.JBLabel
|
|||
import com.intellij.util.ui.JBUI
|
||||
import com.intellij.util.ui.components.BorderLayoutPanel
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.editor.diff.DiffStatsComponent
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Dimension
|
||||
import java.io.File
|
||||
|
|
@ -43,14 +44,7 @@ abstract class HeaderPanel(protected val config: HeaderConfig) : BorderLayoutPan
|
|||
font = JBUI.Fonts.smallFont()
|
||||
}
|
||||
|
||||
protected var virtualFile: VirtualFile? = config.filePath?.let {
|
||||
try {
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(File(it))
|
||||
} catch (t: Throwable) {
|
||||
logger.error(t)
|
||||
null
|
||||
}
|
||||
}
|
||||
protected var virtualFile: VirtualFile? = FileUtil.resolveVirtualFile(config.filePath)
|
||||
|
||||
private val rightPanel = JPanel().apply {
|
||||
layout = BoxLayout(this, BoxLayout.X_AXIS)
|
||||
|
|
@ -70,7 +64,7 @@ abstract class HeaderPanel(protected val config: HeaderConfig) : BorderLayoutPan
|
|||
|
||||
protected fun setupUI() {
|
||||
setupPanelAppearance()
|
||||
setupFilePathOrLanguageLabel(virtualFile)
|
||||
setupFileLinkOrLanguageLabel(virtualFile)
|
||||
rightPanel.removeAll()
|
||||
initializeRightPanel(rightPanel)
|
||||
|
||||
|
|
@ -107,26 +101,25 @@ abstract class HeaderPanel(protected val config: HeaderConfig) : BorderLayoutPan
|
|||
minimumSize = Dimension(preferredSize.width, 32)
|
||||
}
|
||||
|
||||
protected fun setupFilePathOrLanguageLabel(virtualFile: VirtualFile?) {
|
||||
private fun setupFileLinkOrLanguageLabel(virtualFile: VirtualFile?) {
|
||||
val filePath = config.filePath
|
||||
if (filePath != null) {
|
||||
if (virtualFile == null) {
|
||||
val newFileLink = createNewFileLink(filePath, config.editorEx)
|
||||
addToLeft(newFileLink)
|
||||
} else {
|
||||
addToLeft(JPanel().apply {
|
||||
layout = BoxLayout(this, BoxLayout.X_AXIS)
|
||||
isOpaque = false
|
||||
add(ActionLink(virtualFile.name) {
|
||||
OpenFileAction.openFile(virtualFile, config.project)
|
||||
}.apply {
|
||||
setExternalLinkIcon()
|
||||
})
|
||||
add(statsComponent)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
addToLeft(createLanguageLabel())
|
||||
when {
|
||||
filePath == null -> addToLeft(createLanguageLabel())
|
||||
virtualFile == null -> addToLeft(createNewFileLink(filePath, config.editorEx))
|
||||
else -> addToLeft(createFileLinkPanel(virtualFile))
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFileLinkPanel(virtualFile: VirtualFile): JPanel {
|
||||
return JPanel().apply {
|
||||
layout = BoxLayout(this, BoxLayout.X_AXIS)
|
||||
isOpaque = false
|
||||
add(ActionLink(virtualFile.name) {
|
||||
OpenFileAction.openFile(virtualFile, config.project)
|
||||
}.apply {
|
||||
setExternalLinkIcon()
|
||||
})
|
||||
add(statsComponent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +150,7 @@ abstract class HeaderPanel(protected val config: HeaderConfig) : BorderLayoutPan
|
|||
}
|
||||
|
||||
remove(actionLink)
|
||||
setupFilePathOrLanguageLabel(newFile)
|
||||
setupFileLinkOrLanguageLabel(newFile)
|
||||
|
||||
OpenFileAction.openFile(newFile, config.project)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.util.io.FileUtil.createDirectory
|
||||
import com.intellij.openapi.vfs.JarFileSystem
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.*
|
||||
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings.getLlamaModelsPath
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
|
@ -25,6 +26,7 @@ import java.nio.file.StandardOpenOption
|
|||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.Throws
|
||||
|
||||
object FileUtil {
|
||||
|
||||
|
|
@ -234,4 +236,22 @@ object FileUtil {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun resolveVirtualFile(filePath: String?): VirtualFile? {
|
||||
if (filePath == null) return null
|
||||
return try {
|
||||
if (filePath.contains("!")) {
|
||||
val jarSeparatorIndex = filePath.indexOf('!')
|
||||
val archivePath = filePath.substring(0, jarSeparatorIndex)
|
||||
val internalPath = filePath.substring(jarSeparatorIndex + 1).removePrefix("/")
|
||||
val jarFileSystemPath = "$archivePath!/$internalPath"
|
||||
JarFileSystem.getInstance().findFileByPath(jarFileSystemPath)
|
||||
} else {
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(File(filePath))
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
logger.error(t)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue