fix: minor ui improvements and fixes

This commit is contained in:
Carl-Robert Linnupuu 2025-01-28 02:40:10 +00:00
parent 4e149c54de
commit 71aa61b7b6
3 changed files with 74 additions and 58 deletions

View file

@ -34,7 +34,9 @@ import ee.carlrobert.codegpt.events.AnalysisFailedEventDetails;
import ee.carlrobert.codegpt.events.CodeGPTEvent;
import ee.carlrobert.codegpt.events.EventDetails;
import ee.carlrobert.codegpt.events.WebSearchEventDetails;
import ee.carlrobert.codegpt.settings.GeneralSettings;
import ee.carlrobert.codegpt.settings.GeneralSettingsConfigurable;
import ee.carlrobert.codegpt.settings.service.ServiceType;
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
import ee.carlrobert.codegpt.toolwindow.chat.StreamParser;
import ee.carlrobert.codegpt.toolwindow.chat.ThinkingOutputParser;
@ -90,13 +92,15 @@ public class ChatMessageResponseBody extends JPanel {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setOpaque(false);
if (withProgress) {
add(progressPanel);
}
if (GeneralSettings.getSelectedService() == ServiceType.CODEGPT) {
if (withProgress) {
add(progressPanel);
}
if (webSearchIncluded) {
webpageListPanel = createWebpageListPanel(webpageList);
add(webpageListPanel);
if (webSearchIncluded) {
webpageListPanel = createWebpageListPanel(webpageList);
add(webpageListPanel);
}
}
}
@ -115,27 +119,12 @@ public class ChatMessageResponseBody extends JPanel {
}
public void updateMessage(String partialMessage) {
thinkingOutputParser.processChunk(partialMessage);
var thoughtProcessPanel = (ThoughtProcessPanel) Stream.of(getComponents())
.filter(it -> it instanceof ThoughtProcessPanel)
.findFirst()
.orElse(null);
if (thinkingOutputParser.isThinking()) {
progressPanel.setVisible(false);
if (thoughtProcessPanel == null) {
thoughtProcessPanel = new ThoughtProcessPanel();
add(thoughtProcessPanel);
} else {
thoughtProcessPanel.updateText(thinkingOutputParser.getThoughtProcess());
}
if (partialMessage.isEmpty()) {
return;
}
if (thoughtProcessPanel != null && !thoughtProcessPanel.getFinished()) {
thoughtProcessPanel.setFinished();
if (handleThinking(partialMessage)) {
return;
}
for (var item : streamParser.parse(partialMessage)) {
@ -251,6 +240,37 @@ public class ChatMessageResponseBody extends JPanel {
revalidate();
}
private boolean handleThinking(String partialMessage) {
thinkingOutputParser.processChunk(partialMessage);
var thoughtProcessPanel = getExistingThoughtProcessPanel();
if (thinkingOutputParser.isThinking()) {
progressPanel.setVisible(false);
if (thoughtProcessPanel == null) {
thoughtProcessPanel = new ThoughtProcessPanel();
add(thoughtProcessPanel);
} else {
thoughtProcessPanel.updateText(thinkingOutputParser.getThoughtProcess());
}
return true;
}
if (thoughtProcessPanel != null && !thoughtProcessPanel.getFinished()) {
thoughtProcessPanel.setFinished();
}
return false;
}
private ThoughtProcessPanel getExistingThoughtProcessPanel() {
return (ThoughtProcessPanel) Stream.of(getComponents())
.filter(it -> it instanceof ThoughtProcessPanel)
.findFirst()
.orElse(null);
}
private void processResponse(String markdownInput, boolean codeResponse, boolean caretVisible) {
if (codeResponse) {
processCode(markdownInput);
@ -259,19 +279,6 @@ public class ChatMessageResponseBody extends JPanel {
}
}
private void processThinkingOutput(String thoughtProcess) {
Stream.of(getComponents())
.filter(it -> it instanceof ThoughtProcessPanel)
.findFirst()
.ifPresentOrElse(thoughtProcessPanel -> {
((ThoughtProcessPanel) thoughtProcessPanel).updateText(thoughtProcess);
}, () -> {
add(new ThoughtProcessPanel());
revalidate();
repaint();
});
}
private void processCode(String markdownCode) {
var document = Parser.builder().build().parse(markdownCode);
var child = document.getChildOfType(FencedCodeBlock.class);

View file

@ -52,7 +52,7 @@ class UserInputHeaderPanel(
private val emptyText = JBLabel("No context included").apply {
foreground = JBUI.CurrentTheme.Label.disabledForeground()
font = JBUI.Fonts.smallFont()
border = JBUI.Borders.empty(4, 4, 4, 0)
border = JBUI.Borders.empty(3, 4)
isVisible = getSelectedEditor(project) == null
}
private val selectionTagPanel = SelectionTagPanel(project)

View file

@ -32,7 +32,7 @@ abstract class TagPanel(
val id: UUID = tagDetails.id
private val label = createLabel(tagDetails)
private val label = TagLabel(tagDetails)
private val closeButton = CloseButton {
isVisible = true
onClose()
@ -59,6 +59,13 @@ abstract class TagPanel(
} else {
JBUI.CurrentTheme.Label.disabledForeground(false)
}
revalidate()
repaint()
}
override fun getPreferredSize(): Dimension {
val size = super.getPreferredSize()
return Dimension(size.width, 20)
}
override fun paintComponent(g: Graphics) {
@ -66,25 +73,6 @@ abstract class TagPanel(
PaintUtil.drawRoundedBackground(g, this, tagDetails.selected)
}
private fun createLabel(tagDetails: TagDetails): JBLabel {
return (if (tagDetails.icon == null) {
JBLabel(tagDetails.name)
} else {
JBLabel(
tagDetails.name,
IconUtil.scale(tagDetails.icon, null, 0.65f),
SwingUtilities.LEADING
)
}).apply {
foreground = if (tagDetails.selected) {
service<EditorColorsManager>().globalScheme.defaultForeground
} else {
JBUI.CurrentTheme.Label.disabledForeground(false)
}
font = JBUI.Fonts.miniFont()
}
}
private fun setupUI() {
isOpaque = false
border = JBUI.Borders.empty(2, 8)
@ -103,6 +91,27 @@ abstract class TagPanel(
})
}
private class TagLabel(tagDetails: TagDetails) : JBLabel(tagDetails.name) {
init {
if (tagDetails.icon != null) {
icon = IconUtil.scale(tagDetails.icon, null, 0.65f)
horizontalAlignment = SwingUtilities.LEADING
foreground = if (tagDetails.selected) {
service<EditorColorsManager>().globalScheme.defaultForeground
} else {
JBUI.CurrentTheme.Label.disabledForeground(false)
}
font = JBUI.Fonts.miniFont()
}
}
override fun getPreferredSize(): Dimension {
val size = super.getPreferredSize()
return Dimension(size.width, 16)
}
}
private class CloseButton(onClose: () -> Unit) : JButton(Close) {
init {
addActionListener {