From d7d004824f87763b96c98028258239b53d03a701 Mon Sep 17 00:00:00 2001 From: Stephan Janssen Date: Tue, 25 Jun 2024 09:55:55 +0200 Subject: [PATCH 1/2] Feat #112: Keep the previous selected LLM provider when changing something in settings page --- .../ui/DevoxxGenieToolWindowContent.java | 20 +++++++++++++++++-- .../ui/settings/DevoxxGenieStateService.java | 2 -- src/main/resources/META-INF/plugin.xml | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java b/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java index 0edae69a..1d8ea191 100644 --- a/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java +++ b/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java @@ -72,10 +72,11 @@ public DevoxxGenieToolWindowContent(@NotNull ToolWindow toolWindow) { */ private void setLastSelectedProvider() { String lastSelectedProvider = DevoxxGenieStateService.getInstance().getLastSelectedProvider(); - if (lastSelectedProvider != null && !lastSelectedProvider.isEmpty()) { + if (lastSelectedProvider != null && !lastSelectedProvider.isEmpty()) { llmProvidersComboBox.setSelectedItem(lastSelectedProvider); updateModelNamesComboBox(ModelProvider.valueOf(lastSelectedProvider)); } else { + // If no last selected provider, select the first item in the combobox Object selectedItem = llmProvidersComboBox.getSelectedItem(); if (selectedItem != null) { updateModelNamesComboBox(ModelProvider.valueOf((String) selectedItem)); @@ -90,6 +91,8 @@ private void setupUI() { contentPanel.setLayout(new BorderLayout()); contentPanel.add(createTopPanel(), BorderLayout.NORTH); contentPanel.add(createSplitter(), BorderLayout.CENTER); + + setLastSelectedProvider(); } /** @@ -125,8 +128,22 @@ private void setupUI() { * Refresh the UI elements because the settings have changed. */ public void settingsChanged() { + String currentProvider = (String) llmProvidersComboBox.getSelectedItem(); + String currentModel = (String) modelNameComboBox.getSelectedItem(); + llmProvidersComboBox.removeAllItems(); addLLMProvidersToComboBox(); + + if (currentProvider != null && !currentProvider.isEmpty()) { + llmProvidersComboBox.setSelectedItem(currentProvider); + updateModelNamesComboBox(ModelProvider.valueOf(currentProvider)); + if (currentModel != null && !currentModel.isEmpty()) { + modelNameComboBox.setSelectedItem(currentModel); + } + } else { + setLastSelectedProvider(); + } + actionButtonsPanel.configureSearchButtonsVisibility(); } @@ -242,7 +259,6 @@ private void handleModelProviderSelectionChange(@NotNull ActionEvent e) { if (!e.getActionCommand().equals(Constant.COMBO_BOX_CHANGED) || !isInitializationComplete) return; JComboBox comboBox = (JComboBox) e.getSource(); - String selectedLLMProvider = (String) comboBox.getSelectedItem(); if (selectedLLMProvider == null) return; diff --git a/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java b/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java index 8cf2a41e..8ae40b90 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java +++ b/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java @@ -2,7 +2,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.Service; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.util.xmlb.XmlSerializerUtil; @@ -14,7 +13,6 @@ @Getter @Setter -@Service @State( name = "com.devoxx.genie.ui.SettingsState", storages = @Storage("DevoxxGenieSettingsPlugin.xml") diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c392b833..363125a3 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -222,6 +222,7 @@ icon="/icons/pluginIcon.svg" factoryClass="com.devoxx.genie.ui.DevoxxGenieToolWindowFactory"/> + From 5bb65bf8e88e19765136c85e2cda04f9e041b720 Mon Sep 17 00:00:00 2001 From: Stephan Janssen Date: Tue, 25 Jun 2024 09:56:37 +0200 Subject: [PATCH 2/2] Updated change notes --- src/main/resources/META-INF/plugin.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 363125a3..05f7761a 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -35,6 +35,7 @@

v0.1.19

  • Feat #98: Allow a streaming response to be stopped
  • +
  • Feat #112: Keep selected LLM provider after settings page

v0.1.18