Skip to content

Commit 233f856

Browse files
committed
feat: add tooltips for input editor tags (closes #1109)
1 parent fc64dfb commit 233f856

File tree

6 files changed

+77
-20
lines changed

6 files changed

+77
-20
lines changed

src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/diff/DiffAcceptedPanel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DiffAcceptedPanel(
5353
LocalFileSystem.getInstance().findFileByPath(filePath)?.let { vFile ->
5454
FileEditorManager.getInstance(project).openFile(vFile, true)
5555
}
56-
}
56+
}.apply { toolTipText = filePath }
5757

5858
private fun createLeftPanel(fileLink: ActionLink, statsPanel: JPanel): JPanel =
5959
JPanel().apply {
@@ -115,4 +115,4 @@ class DiffAcceptedPanel(
115115
add(viewDetailsLink)
116116
}
117117
}
118-
}
118+
}

src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/header/HeaderPanel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ abstract class HeaderPanel(protected val config: HeaderConfig) : BorderLayoutPan
138138
OpenFileAction.openFile(virtualFile, config.project)
139139
}.apply {
140140
setExternalLinkIcon()
141+
toolTipText = virtualFile.path
141142
})
142143
add(statsComponent)
143144
}
@@ -176,7 +177,10 @@ abstract class HeaderPanel(protected val config: HeaderConfig) : BorderLayoutPan
176177
ProjectView.getInstance(config.project).select(null, newFile, true)
177178
}
178179
}
179-
}.apply { icon = AllIcons.General.InlineAdd }
180+
}.apply {
181+
icon = AllIcons.General.InlineAdd
182+
toolTipText = filePath
183+
}
180184
return actionLink
181185
}
182186

src/main/kotlin/ee/carlrobert/codegpt/toolwindow/ui/UserMessagePanel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class UserMessagePanel(
214214
})
215215
actionLink.icon =
216216
if (it.isDirectory) AllIcons.Nodes.Folder else it.fileType.icon
217+
actionLink.toolTipText = it.path
217218
actionLink
218219
}
219220
.toList()
@@ -258,4 +259,4 @@ class UserMessagePanel(
258259
})
259260
}
260261
}
261-
}
262+
}

src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/UserInputHeaderPanel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ class UserInputHeaderPanel(
140140

141141
private fun createTagPanel(tagDetails: TagDetails) =
142142
(if (tagDetails is EditorSelectionTagDetails) {
143-
SelectionTagPanel(tagDetails, tagManager, promptTextField)
143+
SelectionTagPanel(tagDetails, tagManager, promptTextField, project)
144144
} else {
145-
object : TagPanel(tagDetails, tagManager, false) {
145+
object : TagPanel(tagDetails, tagManager, false, project) {
146146

147147
init {
148148
cursor = if (tagDetails is FileTagDetails)

src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/tag/TagDetails.kt

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ sealed class TagDetails(
2020

2121
var selected: Boolean = true
2222

23+
abstract fun getTooltipText(): String?
24+
2325
override fun equals(other: Any?): Boolean {
2426
if (this === other) return true
2527
if (other !is TagDetails) return false
@@ -36,6 +38,8 @@ class EditorTagDetails(val virtualFile: VirtualFile, isRemovable: Boolean = true
3638

3739
private val type: String = "EditorTagDetails"
3840

41+
override fun getTooltipText(): String = virtualFile.path
42+
3943
override fun equals(other: Any?): Boolean {
4044
if (this === other) return true
4145
if (javaClass != other?.javaClass) return false
@@ -58,6 +62,8 @@ class FileTagDetails(val virtualFile: VirtualFile) :
5862

5963
private val type: String = "FileTagDetails"
6064

65+
override fun getTooltipText(): String = virtualFile.path
66+
6167
override fun equals(other: Any?): Boolean {
6268
if (this === other) return true
6369
if (javaClass != other?.javaClass) return false
@@ -83,6 +89,8 @@ data class SelectionTagDetails(
8389
) {
8490
var selectedText: String? = selectionModel.selectedText
8591
private set
92+
93+
override fun getTooltipText(): String = virtualFile.path
8694
}
8795

8896
class EditorSelectionTagDetails(
@@ -99,6 +107,8 @@ class EditorSelectionTagDetails(
99107
var selectedText: String? = selectionModel.selectedText
100108
private set
101109

110+
override fun getTooltipText(): String = virtualFile.path
111+
102112
override fun equals(other: Any?): Boolean {
103113
if (other === null) return false
104114
return other::class == this::class
@@ -110,33 +120,55 @@ class EditorSelectionTagDetails(
110120
}
111121

112122
data class DocumentationTagDetails(var documentationDetails: DocumentationDetails) :
113-
TagDetails(documentationDetails.name, AllIcons.Toolwindows.Documentation)
123+
TagDetails(documentationDetails.name, AllIcons.Toolwindows.Documentation) {
124+
override fun getTooltipText(): String? = documentationDetails.url
125+
}
114126

115127
data class PersonaTagDetails(var personaDetails: PersonaDetails) :
116-
TagDetails(personaDetails.name, AllIcons.General.User)
128+
TagDetails(personaDetails.name, AllIcons.General.User) {
129+
override fun getTooltipText(): String? = null
130+
}
117131

118132
data class GitCommitTagDetails(var gitCommit: GitCommit) :
119-
TagDetails(gitCommit.id.asString().take(6), AllIcons.Vcs.CommitNode)
133+
TagDetails(gitCommit.id.asString().take(6), AllIcons.Vcs.CommitNode) {
134+
override fun getTooltipText(): String? = gitCommit.fullMessage
135+
}
120136

121137
class CurrentGitChangesTagDetails :
122-
TagDetails("Current Git Changes", AllIcons.Vcs.CommitNode)
138+
TagDetails("Current Git Changes", AllIcons.Vcs.CommitNode) {
139+
override fun getTooltipText(): String? = null
140+
}
123141

124142
data class FolderTagDetails(var folder: VirtualFile) :
125-
TagDetails(folder.name, AllIcons.Nodes.Folder)
143+
TagDetails(folder.name, AllIcons.Nodes.Folder) {
144+
override fun getTooltipText(): String = folder.path
145+
}
126146

127-
class WebTagDetails : TagDetails("Web", AllIcons.General.Web)
147+
class WebTagDetails : TagDetails("Web", AllIcons.General.Web) {
148+
override fun getTooltipText(): String? = null
149+
}
128150

129151
data class ImageTagDetails(val imagePath: String) :
130-
TagDetails(imagePath.substringAfterLast('/'), AllIcons.FileTypes.Image)
152+
TagDetails(imagePath.substringAfterLast('/'), AllIcons.FileTypes.Image) {
153+
override fun getTooltipText(): String = imagePath
154+
}
131155

132156
data class HistoryTagDetails(
133157
val conversationId: UUID,
134158
val title: String,
135-
) : TagDetails(title, AllIcons.General.Balloon)
159+
) : TagDetails(title, AllIcons.General.Balloon) {
160+
override fun getTooltipText(): String? = null
161+
}
136162

137-
class EmptyTagDetails : TagDetails("")
163+
class EmptyTagDetails : TagDetails("") {
164+
override fun getTooltipText(): String? = null
165+
}
138166

139-
class CodeAnalyzeTagDetails : TagDetails("Code Analyze", AllIcons.Actions.DependencyAnalyzer)
167+
class CodeAnalyzeTagDetails : TagDetails("Code Analyze", AllIcons.Actions.DependencyAnalyzer) {
168+
override fun getTooltipText(): String? = null
169+
}
140170

141171
data class DiagnosticsTagDetails(val virtualFile: VirtualFile) :
142-
TagDetails("${virtualFile.name} Problems", AllIcons.General.InspectionsEye)
172+
TagDetails("${virtualFile.name} Problems", AllIcons.General.InspectionsEye) {
173+
override fun getTooltipText(): String = virtualFile.path
174+
}

src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/tag/TagPanel.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.intellij.icons.AllIcons
44
import com.intellij.icons.AllIcons.Actions.Close
55
import com.intellij.openapi.components.service
66
import com.intellij.openapi.editor.colors.EditorColorsManager
7+
import com.intellij.openapi.project.Project
78
import com.intellij.ui.components.JBLabel
89
import com.intellij.util.IconUtil
910
import com.intellij.util.ui.JBUI
@@ -23,8 +24,8 @@ abstract class TagPanel(
2324
var tagDetails: TagDetails,
2425
private val tagManager: TagManager,
2526
private val shouldPreventDeselection: Boolean = true,
27+
protected val project: Project,
2628
) : JToggleButton() {
27-
2829
private val label = TagLabel(tagDetails.name, tagDetails.icon, tagDetails.selected)
2930
private val closeButton = CloseButton {
3031
isVisible = isSelected && tagDetails.isRemovable
@@ -43,6 +44,11 @@ abstract class TagPanel(
4344
fun update(text: String, icon: Icon? = null) {
4445
closeButton.isVisible = isSelected && tagDetails.isRemovable
4546
label.update(text, icon, isSelected)
47+
tagDetails.getTooltipText()?.let { tooltip ->
48+
val relativeTooltipText = toProjectRelative(tooltip)
49+
this.toolTipText = relativeTooltipText
50+
label.toolTipText = relativeTooltipText
51+
}
4652
revalidate()
4753
repaint()
4854
}
@@ -67,6 +73,11 @@ abstract class TagPanel(
6773
cursor = Cursor(Cursor.HAND_CURSOR)
6874
isSelected = tagDetails.selected
6975
closeButton.isVisible = isSelected && tagDetails.isRemovable
76+
tagDetails.getTooltipText()?.let { tooltip ->
77+
val relativeTooltipText = toProjectRelative(tooltip)
78+
this.toolTipText = relativeTooltipText
79+
label.toolTipText = relativeTooltipText
80+
}
7081

7182
val gbc = GridBagConstraints().apply {
7283
gridx = 0
@@ -100,6 +111,14 @@ abstract class TagPanel(
100111
repaint()
101112
}
102113

114+
private fun toProjectRelative(path: String): String? {
115+
val base = project.basePath ?: return path
116+
val baseTrim = base.trimEnd('/', '\\')
117+
return if (path.startsWith("$baseTrim/") || path.startsWith("$baseTrim\\")) {
118+
path.substring(baseTrim.length + 1)
119+
} else path
120+
}
121+
103122
private class TagLabel(
104123
name: String,
105124
icon: Icon? = null,
@@ -158,7 +177,8 @@ class SelectionTagPanel(
158177
tagDetails: EditorSelectionTagDetails,
159178
tagManager: TagManager,
160179
private val promptTextField: PromptTextField,
161-
) : TagPanel(tagDetails, tagManager, true) {
180+
project: Project,
181+
) : TagPanel(tagDetails, tagManager, true, project) {
162182

163183
init {
164184
cursor = Cursor(Cursor.DEFAULT_CURSOR)
@@ -175,4 +195,4 @@ class SelectionTagPanel(
175195
override fun onClose() {
176196
(tagDetails as? EditorSelectionTagDetails)?.selectionModel?.removeSelection()
177197
}
178-
}
198+
}

0 commit comments

Comments
 (0)