From 744a40f3d4a6ee8c7dce01e1c81b80a3e3bbbb36 Mon Sep 17 00:00:00 2001 From: Denis Rosa Date: Mon, 27 May 2024 12:36:15 +0200 Subject: [PATCH] fixes in the named parameter dialog --- .idea/codeStyles/codeStyleConfig.xml | 1 + .../workbench/NamedParameterDialog.java | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index 79ee123c..6e6eec11 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/workbench/NamedParameterDialog.java b/src/main/java/com/couchbase/intellij/workbench/NamedParameterDialog.java index 3a7a5340..a2130d2b 100644 --- a/src/main/java/com/couchbase/intellij/workbench/NamedParameterDialog.java +++ b/src/main/java/com/couchbase/intellij/workbench/NamedParameterDialog.java @@ -26,6 +26,7 @@ import java.awt.event.MouseEvent; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; public class NamedParameterDialog extends DialogWrapper { private final DefaultListModel listModel = new DefaultListModel<>(); @@ -39,8 +40,8 @@ public class NamedParameterDialog extends DialogWrapper { private final EditorEx editor; private final EditorEx editorBuiltIn; private final Map editorContentMap = new HashMap<>(); + private final JLabel errorLabel; private Map projectNamedParams; - private JLabel errorLabel; protected NamedParameterDialog(Project project) { @@ -142,7 +143,12 @@ public void actionPerformed(ActionEvent e) { String selectedValue = list.getSelectedValue(); if (selectedValue != null) { NamedParams params = NamedParamsStorage.getInstance().getValue(); - String content = params.getParams().getOrDefault(selectedValue, ""); + String content; + if (editorContentMap.containsKey(selectedValue)) { + content = editorContentMap.get(selectedValue); + } else { + content = params.getParams().getOrDefault(selectedValue, ""); + } ApplicationManager.getApplication().runWriteAction(() -> editor.getDocument().setText(content)); editor.setViewer(false); } else { @@ -153,12 +159,14 @@ public void actionPerformed(ActionEvent e) { }); NamedParams params = NamedParamsStorage.getInstance().getValue(); - params.getParams().forEach((key, value) -> addItem(key)); + TreeMap sortedMap = new TreeMap<>(params.getParams()); + sortedMap.forEach((key, value) -> addItem(key)); try { projectNamedParams = NamedParametersUtil.readProjectNamedParameters(project); + TreeMap treeMap = new TreeMap<>(projectNamedParams); - for (String name : projectNamedParams.keySet()) { + for (String name : treeMap.keySet()) { builtinListModel.addElement(name); } @@ -166,7 +174,11 @@ public void actionPerformed(ActionEvent e) { if (!evt.getValueIsAdjusting()) { JBList list = (JBList) evt.getSource(); if (list.getSelectedIndex() != -1) { - ApplicationManager.getApplication().runWriteAction(() -> editorBuiltIn.getDocument().setText(projectNamedParams.get(list.getSelectedValue().toString()))); + ApplicationManager.getApplication().runWriteAction(() -> { + + editorBuiltIn.getDocument().setText(projectNamedParams.get(list.getSelectedValue().toString())); + + }); } } });