mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-20 17:52:23 +00:00
fix: UI issues when image in context
This commit is contained in:
parent
8f00550e8b
commit
eab997aaed
4 changed files with 24 additions and 32 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue