mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-18 14:23:56 -07:00
Allow the GUI to subscribe to text edit events to redeem three workarounds in the options page.
Differential Revision: https://code.wildfiregames.com/D860 Refs #2451, #3511,5c61f68600(registerChanges),7fa2962c45(onMouseLeave),e909567004(onPress) Reviewed By: Vladislav This was SVN commit r20091.
This commit is contained in:
parent
2cb6139761
commit
7a157faf3c
3 changed files with 16 additions and 20 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue