diff --git a/binaries/data/mods/public/gui/options/options.js b/binaries/data/mods/public/gui/options/options.js index 84a1a6cbc1..4fa4bb067e 100644 --- a/binaries/data/mods/public/gui/options/options.js +++ b/binaries/data/mods/public/gui/options/options.js @@ -196,10 +196,6 @@ function setupControl(option, i, category) } } - // as the enter key is not necessarily pressed after modifying an entry, we will register the input also - // - when the mouse leave the control (MouseLeave event) - // - or when saving or closing the window (registerChanges function) - // so we must ensure that something has indeed been modified onUpdate = function(key, functionBody, minval, maxval) { return function() @@ -219,8 +215,7 @@ function setupControl(option, i, category) }(key, functionBody, minval, maxval); control.caption = caption; - control.onPress = onUpdate; - control.onMouseLeave = onUpdate; + control.onTextEdit = onUpdate; break; case "dropdown": { @@ -303,16 +298,6 @@ function updateOptionPanel() Engine.GetGUIObjectByName("saveChanges").enabled = hasChanges; } -/** - * Register changes of input (text and number) controls - */ -function registerChanges() -{ - for (let item in g_Controls) - if (g_Controls[item].type == "number" || g_Controls[item].type == "string") - g_Controls[item].control.onPress(); -} - function setDefaults() { messageBox( @@ -356,7 +341,6 @@ function revertChanges() function saveChanges() { - registerChanges(); Engine.ConfigDB_WriteFile("user", "config/user.cfg"); Engine.ConfigDB_SetChanges("user", false); updateOptionPanel(); @@ -367,7 +351,6 @@ function saveChanges() **/ function closePage() { - registerChanges(); if (Engine.ConfigDB_HasChanges("user")) { messageBox( diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index 5e94892f47..16b82f378f 100644 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -138,6 +138,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) m_iBufferPos_Tail = -1; UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); return IN_HANDLED; } @@ -187,6 +188,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); return IN_HANDLED; } @@ -226,6 +228,8 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* case SDLK_TAB: { SendEvent(GUIM_TAB, "tab"); + // Don't send a textedit event, because it should only + // be sent if the GUI control changes the text break; } case SDLK_BACKSPACE: @@ -253,6 +257,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* } UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); break; } case SDLK_DELETE: @@ -273,6 +278,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* } UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); break; } case SDLK_KP_ENTER: @@ -321,6 +327,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* ++m_iBufferPos; UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); break; } } @@ -593,6 +600,8 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) UpdateBufferPositionSetting(); sys_clipboard_free(text); + + SendEvent(GUIM_TEXTEDIT, "textedit"); } return IN_HANDLED; @@ -628,6 +637,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) { DeleteCurSelection(); UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); } } @@ -674,6 +684,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) UpdateBufferPositionSetting(); DeleteCurSelection(); + SendEvent(GUIM_TEXTEDIT, "textedit"); } UpdateAutoScroll(); return IN_HANDLED; @@ -712,6 +723,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) DeleteCurSelection(); } UpdateAutoScroll(); + SendEvent(GUIM_TEXTEDIT, "textedit"); return IN_HANDLED; } else if (hotkey == "text.move.left") diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h index e17b4bb667..43df71abea 100644 --- a/source/gui/GUIbase.h +++ b/source/gui/GUIbase.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -81,7 +81,8 @@ enum EGUIMessageType GUIM_LOST_FOCUS, GUIM_PRESSED_MOUSE_RIGHT, GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, - GUIM_TAB // Used by CInput + GUIM_TAB, // Used by CInput + GUIM_TEXTEDIT }; /**