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..05f7761a 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -35,6 +35,7 @@