fix typos and submenu mnemonic bug
[fanfix.git] / src / jexer / TComboBox.java
index bb223c3a12aa4b6b3340bdaf544858a6025fde25..1ef6bcd4ffd8ecd3a518646f7095412236e4d629 100644 (file)
@@ -96,13 +96,12 @@ public class TComboBox extends TWidget {
 
         this.updateAction = updateAction;
 
-        field = new TField(this, 0, 0, width - 3, false, "",
-            updateAction, null);
+        field = addField(0, 0, width - 3, false, "", updateAction, null);
         if (valuesIndex >= 0) {
             field.setText(values.get(valuesIndex));
         }
 
-        list = new TList(this, values, 0, 1, width, valuesHeight,
+        list = addList(values, 0, 1, width, valuesHeight,
             new TAction() {
                 public void DO() {
                     field.setText(list.getSelected());
@@ -249,7 +248,7 @@ public class TComboBox extends TWidget {
             }
         }
 
-        if (isAbsoluteActive() && (limitToListValue == false)) {
+        if (isAbsoluteActive()) {
             comboBoxColor = getTheme().getColor("tcombobox.active");
         } else {
             comboBoxColor = getTheme().getColor("tcombobox.inactive");
@@ -282,11 +281,29 @@ public class TComboBox extends TWidget {
      * @param text the new text in the edit field
      */
     public void setText(final String text) {
+        setText(text, true);
+    }
+
+    /**
+     * Set combobox text value.
+     *
+     * @param text the new text in the edit field
+     * @param caseSensitive if true, perform a case-sensitive search for the
+     * list item
+     */
+    public void setText(final String text, final boolean caseSensitive) {
         field.setText(text);
         for (int i = 0; i < list.getMaxSelectedIndex(); i++) {
-            if (list.getSelected().equals(text)) {
-                list.setSelectedIndex(i);
-                return;
+            if (caseSensitive == true) {
+                if (list.getListItem(i).equals(text)) {
+                    list.setSelectedIndex(i);
+                    return;
+                }
+            } else {
+                if (list.getListItem(i).toLowerCase().equals(text.toLowerCase())) {
+                    list.setSelectedIndex(i);
+                    return;
+                }
             }
         }
         list.setSelectedIndex(-1);