Make dropdown formspec elements send their value same style as buttons on change 1373/head
authorsapier <Sapier at GMX dot net>
Sat, 14 Jun 2014 10:27:56 +0000 (12:27 +0200)
committersapier <Sapier at GMX dot net>
Wed, 18 Jun 2014 16:47:41 +0000 (18:47 +0200)
src/guiFormSpecMenu.cpp

index 48bdf2d50f500d4a4abd92e0134d261dfa45b08c..c16600733699dba8589d42c7a855ba0a68357499 100644 (file)
@@ -2723,8 +2723,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                                return true;
                        }
                }
-               if((event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) ||
-                               (event.GUIEvent.EventType==gui::EGET_CHECKBOX_CHANGED)) {
+               if((event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) ||
+                               (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) ||
+                               (event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED)) {
                        unsigned int btn_id = event.GUIEvent.Caller->getID();
 
                        if (btn_id == 257) {
@@ -2756,14 +2757,36 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                                                }
                                                return true;
                                        } else {
-                                               acceptInput();
+                                               acceptInput(quit_mode_no);
                                                s.send = false;
                                                return true;
                                        }
                                }
+                               if ((s.ftype == f_DropDown) &&
+                                               (s.fid == event.GUIEvent.Caller->getID())) {
+                                       // only send the changed dropdown
+                                       for(u32 i=0; i<m_fields.size(); i++) {
+                                               FieldSpec &s2 = m_fields[i];
+                                               if (s2.ftype == f_DropDown) {
+                                                       s2.send = false;
+                                               }
+                                       }
+                                       s.send = true;
+                                       acceptInput(quit_mode_no);
+
+                                       // revert configuration to make sure dropdowns are sent on
+                                       // regular button click
+                                       for(u32 i=0; i<m_fields.size(); i++) {
+                                               FieldSpec &s2 = m_fields[i];
+                                               if (s2.ftype == f_DropDown) {
+                                                       s2.send = true;
+                                               }
+                                       }
+                                       return true;
+                               }
                        }
                }
-               if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) {
+               if(event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
                        if(event.GUIEvent.Caller->getID() > 257) {
 
                                if (m_allowclose) {
@@ -2778,7 +2801,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                        }
                }
 
-               if(event.GUIEvent.EventType==gui::EGET_TABLE_CHANGED) {
+               if(event.GUIEvent.EventType == gui::EGET_TABLE_CHANGED) {
                        int current_id = event.GUIEvent.Caller->getID();
                        if(current_id > 257) {
                                // find the element that was clicked