fix: UI issues when image in context

This commit is contained in:
Carl-Robert Linnupuu 2025-04-04 17:44:14 +01:00
parent 8f00550e8b
commit eab997aaed
4 changed files with 24 additions and 32 deletions

View file

@ -455,10 +455,6 @@ public class ChatToolWindowTabPanel implements Disposable {
.build(),
userMessagePanel));
userMessagePanel.addDeleteAction(() -> removeMessage(message.getId(), conversation));
var imageFilePath = message.getImageFilePath();
if (imageFilePath != null && !imageFilePath.isEmpty()) {
userMessagePanel.displayImage(imageFilePath);
}
return userMessagePanel;
}

View file

@ -65,8 +65,9 @@ public class ImageAccordion extends JPanel {
accordionToggle.setSelectedIcon(General.ArrowUp);
accordionToggle.setBorder(null);
accordionToggle.setSelected(true);
accordionToggle.setHorizontalAlignment(SwingConstants.LEADING);
accordionToggle.setHorizontalTextPosition(SwingConstants.LEADING);
accordionToggle.setHorizontalAlignment(SwingConstants.LEFT);
accordionToggle.setHorizontalTextPosition(SwingConstants.RIGHT);
accordionToggle.setIconTextGap(4);
accordionToggle.addItemListener(e ->
contentPane.setVisible(e.getStateChange() == ItemEvent.SELECTED));
return accordionToggle;

View file

@ -41,11 +41,11 @@ public class SelectedFilesAccordion extends JPanel {
private JToggleButton createToggleButton(JPanel contentPane, int fileCount) {
var accordionToggle = new JToggleButton(
format("Referenced files (+%d)", fileCount), General.ArrowUp);
format("Referenced files (+%d)", fileCount), General.ArrowDown);
accordionToggle.setFocusPainted(false);
accordionToggle.setContentAreaFilled(false);
accordionToggle.setBackground(getBackground());
accordionToggle.setSelectedIcon(General.ArrowDown);
accordionToggle.setSelectedIcon(General.ArrowUp);
accordionToggle.setBorder(null);
accordionToggle.setSelected(true);
accordionToggle.setHorizontalAlignment(SwingConstants.LEFT);

View file

@ -47,7 +47,6 @@ class UserMessagePanel(
background = ColorUtil.brighter(getBackground(), 2)
setupAdditionalContext()
setupImageIfPresent()
setupResponseBody()
}
@ -117,21 +116,6 @@ class UserMessagePanel(
)
}
fun displayImage(imageFilePath: String) {
try {
val path = Paths.get(imageFilePath)
body.addToTop(ImageAccordion(path.fileName.toString(), Files.readAllBytes(path)))
} catch (e: IOException) {
body.addToTop(
JBLabel(
"<html><small>Unable to load image $imageFilePath</small></html>",
AllIcons.General.Error,
SwingConstants.LEFT
)
)
}
}
private fun setupAdditionalContext() {
val additionalContextPanel = getAdditionalContextPanel(project, message)
if (additionalContextPanel != null) {
@ -139,14 +123,6 @@ class UserMessagePanel(
}
}
private fun setupImageIfPresent() {
message.imageFilePath?.let { imageFilePath ->
if (imageFilePath.isNotEmpty()) {
displayImage(imageFilePath)
}
}
}
private fun setupResponseBody() {
addContent(
ChatMessageResponseBody(project, true, false, false, parentDisposable)
@ -217,6 +193,25 @@ class UserMessagePanel(
}
}
}
message.imageFilePath?.let { imageFilePath ->
if (imageFilePath.isNotEmpty()) {
try {
val path = Paths.get(imageFilePath)
additionalContextPanel.add(
ImageAccordion(path.fileName.toString(), Files.readAllBytes(path))
)
} catch (e: IOException) {
additionalContextPanel.add(
JBLabel(
"<html><small>Unable to load image $imageFilePath</small></html>",
AllIcons.General.Error,
SwingConstants.LEFT
)
)
}
}
}
}
}