Skip to content

Commit 1ec5e3a

Browse files
committed
fix: UI issues when image in context
1 parent 109aa46 commit 1ec5e3a

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ChatToolWindowTabPanel.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,6 @@ private UserMessagePanel getUserMessagePanel(Message message) {
455455
.build(),
456456
userMessagePanel));
457457
userMessagePanel.addDeleteAction(() -> removeMessage(message.getId(), conversation));
458-
var imageFilePath = message.getImageFilePath();
459-
if (imageFilePath != null && !imageFilePath.isEmpty()) {
460-
userMessagePanel.displayImage(imageFilePath);
461-
}
462458
return userMessagePanel;
463459
}
464460

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ImageAccordion.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ private JToggleButton createToggleButton(JPanel contentPane) {
6565
accordionToggle.setSelectedIcon(General.ArrowUp);
6666
accordionToggle.setBorder(null);
6767
accordionToggle.setSelected(true);
68-
accordionToggle.setHorizontalAlignment(SwingConstants.LEADING);
69-
accordionToggle.setHorizontalTextPosition(SwingConstants.LEADING);
68+
accordionToggle.setHorizontalAlignment(SwingConstants.LEFT);
69+
accordionToggle.setHorizontalTextPosition(SwingConstants.RIGHT);
70+
accordionToggle.setIconTextGap(4);
7071
accordionToggle.addItemListener(e ->
7172
contentPane.setVisible(e.getStateChange() == ItemEvent.SELECTED));
7273
return accordionToggle;

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/SelectedFilesAccordion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ private JPanel createContentPanel(List<ActionLink> links) {
4141

4242
private JToggleButton createToggleButton(JPanel contentPane, int fileCount) {
4343
var accordionToggle = new JToggleButton(
44-
format("Referenced files (+%d)", fileCount), General.ArrowUp);
44+
format("Referenced files (+%d)", fileCount), General.ArrowDown);
4545
accordionToggle.setFocusPainted(false);
4646
accordionToggle.setContentAreaFilled(false);
4747
accordionToggle.setBackground(getBackground());
48-
accordionToggle.setSelectedIcon(General.ArrowDown);
48+
accordionToggle.setSelectedIcon(General.ArrowUp);
4949
accordionToggle.setBorder(null);
5050
accordionToggle.setSelected(true);
5151
accordionToggle.setHorizontalAlignment(SwingConstants.LEFT);

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class UserMessagePanel(
4747
background = ColorUtil.brighter(getBackground(), 2)
4848

4949
setupAdditionalContext()
50-
setupImageIfPresent()
5150
setupResponseBody()
5251
}
5352

@@ -117,36 +116,13 @@ class UserMessagePanel(
117116
)
118117
}
119118

120-
fun displayImage(imageFilePath: String) {
121-
try {
122-
val path = Paths.get(imageFilePath)
123-
body.addToTop(ImageAccordion(path.fileName.toString(), Files.readAllBytes(path)))
124-
} catch (e: IOException) {
125-
body.addToTop(
126-
JBLabel(
127-
"<html><small>Unable to load image $imageFilePath</small></html>",
128-
AllIcons.General.Error,
129-
SwingConstants.LEFT
130-
)
131-
)
132-
}
133-
}
134-
135119
private fun setupAdditionalContext() {
136120
val additionalContextPanel = getAdditionalContextPanel(project, message)
137121
if (additionalContextPanel != null) {
138122
body.addToTop(additionalContextPanel)
139123
}
140124
}
141125

142-
private fun setupImageIfPresent() {
143-
message.imageFilePath?.let { imageFilePath ->
144-
if (imageFilePath.isNotEmpty()) {
145-
displayImage(imageFilePath)
146-
}
147-
}
148-
}
149-
150126
private fun setupResponseBody() {
151127
addContent(
152128
ChatMessageResponseBody(project, true, false, false, parentDisposable)
@@ -217,6 +193,25 @@ class UserMessagePanel(
217193
}
218194
}
219195
}
196+
197+
message.imageFilePath?.let { imageFilePath ->
198+
if (imageFilePath.isNotEmpty()) {
199+
try {
200+
val path = Paths.get(imageFilePath)
201+
additionalContextPanel.add(
202+
ImageAccordion(path.fileName.toString(), Files.readAllBytes(path))
203+
)
204+
} catch (e: IOException) {
205+
additionalContextPanel.add(
206+
JBLabel(
207+
"<html><small>Unable to load image $imageFilePath</small></html>",
208+
AllIcons.General.Error,
209+
SwingConstants.LEFT
210+
)
211+
)
212+
}
213+
}
214+
}
220215
}
221216
}
222217

0 commit comments

Comments
 (0)